Skip to content

Commit

Permalink
feat: add create operation for specs #374
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Jan 9, 2024
1 parent 104ba3f commit 2d583b6
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
76 changes: 76 additions & 0 deletions cmd/registry/apis/versions/specs/crtspec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package specs

import (
"internal/apiclient"

"internal/client/registry/apis/versions"

"github.com/apigee/apigeecli/cmd/utils"
"github.com/spf13/cobra"
)

// CreateSpecCmd to get instance
var CreateSpecCmd = &cobra.Command{
Use: "create",
Short: "Create a spec associated with an API version",
Long: "Create a spec associated with an API version in Apigee Registry",
Args: func(cmd *cobra.Command, args []string) (err error) {
apiclient.SetProjectID(utils.ProjectID)
apiclient.SetRegion(utils.Region)
return apiclient.SetApigeeOrg(utils.Org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
fileContents, err := utils.ReadFile(filePath)
if err != nil {
return err
}
_, err = versions.CreateSpec(apiName, apiVersion, apiSpecId,
name, fileName, description, sourceURI, string(fileContents), labels, annotations)
return
},
}

var labels, annotations map[string]string

Check failure on line 47 in cmd/registry/apis/versions/specs/crtspec.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)

Check failure on line 47 in cmd/registry/apis/versions/specs/crtspec.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
var apiSpecId, fileName, description, sourceURI, filePath string

Check warning on line 48 in cmd/registry/apis/versions/specs/crtspec.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var apiSpecId should be apiSpecID (revive)

Check warning on line 48 in cmd/registry/apis/versions/specs/crtspec.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var apiSpecId should be apiSpecID (revive)

func init() {
CreateSpecCmd.Flags().StringVarP(&apiName, "api-name", "",
"", "API Name")
CreateSpecCmd.Flags().StringVarP(&apiVersion, "api-version", "",
"", "API Version")
CreateSpecCmd.Flags().StringVarP(&apiVersion, "api-specid", "",
"", "API Spec Id")
CreateSpecCmd.Flags().StringVarP(&name, "name", "n",
"", "API Version Spec name")
CreateSpecCmd.Flags().StringVarP(&fileName, "file-name", "",
"", "A possibly-hierarchical name used to refer to the spec from other specs")
CreateSpecCmd.Flags().StringVarP(&description, "desc", "d",
"", "A detailed description for the spec")
CreateSpecCmd.Flags().StringVarP(&filePath, "file-path", "f",
"", "A path to file containing the spec")
CreateSpecCmd.Flags().StringVarP(&sourceURI, "source-uri", "s",
"", "Source URI")
CreateSpecCmd.Flags().StringToStringVar(&labels, "labels",
nil, "Labels attach identifying metadata to resources")
CreateSpecCmd.Flags().StringToStringVar(&annotations, "annotations",
nil, "Annotations attach non-identifying metadata to resources")

_ = CreateSpecCmd.MarkFlagRequired("api-name")
_ = CreateSpecCmd.MarkFlagRequired("api-version")
_ = CreateSpecCmd.MarkFlagRequired("name")
_ = CreateSpecCmd.MarkFlagRequired("file-path")
}
2 changes: 2 additions & 0 deletions cmd/registry/apis/versions/specs/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ var SpecCmd = &cobra.Command{
func init() {
SpecCmd.AddCommand(ListSpecCmd)
SpecCmd.AddCommand(GetSpecCmd)
SpecCmd.AddCommand(DeleteSpecCmd)
SpecCmd.AddCommand(CreateSpecCmd)
SpecCmd.AddCommand(artifacts.ArtifactCmd)
}

0 comments on commit 2d583b6

Please sign in to comment.