Skip to content

Commit

Permalink
feat: accept allowed value id from user #532
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Sep 16, 2024
1 parent c75b324 commit 139b817
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
22 changes: 14 additions & 8 deletions internal/client/hub/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,15 +801,15 @@ func getDeployment(displayName string, description string, deploymentName string
}

func CreateExternalAPI(externalApiID string, displayName string, description string,
endpoints []string, paths []string, externalUri string, attribute string,
endpoints []string, paths []string, externalUri string, attribute string, allowedValueID string,
) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.GetApigeeRegistryURL())
u.Path = path.Join(u.Path, "externalApis")
q := u.Query()
q.Set("externalApiId", externalApiID)
u.RawQuery = q.Encode()

payload, err := getExternalApi(displayName, description, endpoints, paths, externalUri, attribute)
payload, err := getExternalApi(displayName, description, endpoints, paths, externalUri, attribute, allowedValueID)
if err != nil {
return nil, err
}
Expand All @@ -836,7 +836,7 @@ func ListExternalAPIs(filter string, pageSize int, pageToken string) (respBody [
}

func UpdateExternalAPI(externalApiID string, displayName string, description string,
endpoints []string, paths []string, externalUri string, apiType string,
endpoints []string, paths []string, externalUri string, apiType string, allowedValueID string,
) (respBody []byte, err error) {
updateMask := []string{}

Expand Down Expand Up @@ -865,7 +865,7 @@ func UpdateExternalAPI(externalApiID string, displayName string, description str
q.Set("updateMask", strings.Join(updateMask, ","))
u.RawQuery = q.Encode()

payload, err := getExternalApi(displayName, description, endpoints, paths, externalUri, apiType)
payload, err := getExternalApi(displayName, description, endpoints, paths, externalUri, apiType, allowedValueID)
if err != nil {
return nil, err
}
Expand All @@ -875,7 +875,7 @@ func UpdateExternalAPI(externalApiID string, displayName string, description str
}

func getExternalApi(displayName string, description string,
endpoints []string, paths []string, externalUri string, attribute string,
endpoints []string, paths []string, externalUri string, attribute string, allowedValueID string,
) (string, error) {
type documentation struct {
ExternalURI string `json:"externalUri,omitempty"`
Expand Down Expand Up @@ -906,7 +906,7 @@ func getExternalApi(displayName string, description string,
e.Endpoints = endpoints
}

a, err := getAttributeAllowedValue(attribute, 0)
a, err := getAttributeAllowedValue(attribute, allowedValueID)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -1305,7 +1305,7 @@ func getSpecIDList(s []byte) (sList []string) {
return sList
}

func getAttributeAllowedValue(attributeID string, index int) (allowedValue, error) {
func getAttributeAllowedValue(attributeID string, allowedValueID string) (allowedValue, error) {
type attribute struct {
Name string `json:"name,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Expand All @@ -1332,5 +1332,11 @@ func getAttributeAllowedValue(attributeID string, index int) (allowedValue, erro
return allowedValue{}, err
}

return a.AllowedValues[index], nil
for _, i := range a.AllowedValues {
if i.Id == allowedValueID {
return i, nil
}
}

return allowedValue{}, fmt.Errorf("allowedValue not found")
}
8 changes: 5 additions & 3 deletions internal/cmd/apihub/externalapis/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ var CrtCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) (err error) {
cmd.SilenceUsage = true
_, err = hub.CreateExternalAPI(externalApiID, displayName, description,
endpoints, paths, externalURI, attribute)
endpoints, paths, externalURI, attribute, allowedValueID)
return
},
}

var (
externalApiID, displayName, description, externalURI, resourceURI, attribute string
endpoints, paths []string
externalApiID, displayName, description, externalURI, resourceURI, attribute, allowedValueID string
endpoints, paths []string
)

func init() {
Expand All @@ -57,6 +57,8 @@ func init() {

CrtCmd.Flags().StringVarP(&attribute, "attribute", "",
"", "The name of the attribute for the external api")
CrtCmd.Flags().StringVarP(&allowedValueID, "attribute-allowed-value-id", "",
"", "The allowed value id for the attribute")

CrtCmd.Flags().StringArrayVarP(&paths, "paths", "",
[]string{}, " API base paths")
Expand Down
4 changes: 3 additions & 1 deletion internal/cmd/apihub/externalapis/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var UpdateCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) (err error) {
cmd.SilenceUsage = true
_, err = hub.UpdateExternalAPI(externalApiID, displayName,
description, endpoints, paths, externalURI, attribute)
description, endpoints, paths, externalURI, attribute, allowedValueID)
return
},
}
Expand All @@ -51,6 +51,8 @@ func init() {
[]string{}, " The endpoints at which this deployment resource is listening for API requests")
UpdateCmd.Flags().StringVarP(&attribute, "attribute", "",
"", "The name of the attribute for the external api")
UpdateCmd.Flags().StringVarP(&allowedValueID, "attribute-allowed-value-id", "",
"", "The allowed value id for the attribute")
UpdateCmd.Flags().StringArrayVarP(&paths, "paths", "",
[]string{}, " API base paths")

Expand Down

0 comments on commit 139b817

Please sign in to comment.