Skip to content

Commit

Permalink
feat: use the filename when present #374
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Jan 22, 2024
1 parent dc5badc commit a650f4e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cmd/registry/apis/versions/specs/crtspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package specs

import (
"encoding/base64"
"path/filepath"

"internal/apiclient"

Expand All @@ -40,6 +41,7 @@ var CreateSpecCmd = &cobra.Command{
if err != nil {
return err
}
fileName := filepath.Base(filePath)
contents := base64.URLEncoding.EncodeToString(fileContents)
_, err = versions.CreateSpec(apiName, apiVersion, apiSpecID,
name, fileName, description, sourceURI, contents, labels, annotations)
Expand All @@ -48,8 +50,8 @@ var CreateSpecCmd = &cobra.Command{
}

var (
labels, annotations map[string]string
apiSpecID, fileName, description, sourceURI, filePath string
labels, annotations map[string]string
apiSpecID, description, sourceURI, filePath string
)

func init() {
Expand All @@ -61,8 +63,6 @@ func init() {
"", "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",
Expand Down
21 changes: 20 additions & 1 deletion internal/client/registry/apis/versions/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package versions

import (
"encoding/json"
"fmt"
"net/url"
"path"
"strconv"
Expand Down Expand Up @@ -114,9 +116,26 @@ func GetSpec(apiName string, apiVersion string, name string) (respBody []byte, e

// GetSpecContents
func GetSpecContents(apiName string, apiVersion string, name string) (err error) {
apiclient.ClientPrintHttpResponse.Set(false)
var specMap map[string]interface{}
var specFileName string
respBody, err := GetSpec(apiName, apiVersion, name)
if err != nil {
return err
}
err = json.Unmarshal(respBody, &specMap)
if err != nil {
return err
}
if specMap["filename"] != "" {
specFileName = fmt.Sprintf("%s", specMap["filename"])
} else {
specFileName = name + ".txt"
}
apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())
u, _ := url.Parse(apiclient.GetApigeeRegistryURL())
u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "specs", name+":getContents")
return apiclient.DownloadResource(u.String(), name+".txt", "", true)
return apiclient.DownloadResource(u.String(), specFileName, "", true)
}

// ListSpecs
Expand Down

0 comments on commit a650f4e

Please sign in to comment.