Skip to content

Commit

Permalink
feat: allow delete by app name only #338 (#339)
Browse files Browse the repository at this point in the history
* feat: allow delete by app name only #338

* chore: fix linting issues #338

* bug: undo delete by appname #338

* feat: return all apps that match name #338
  • Loading branch information
srinandan authored Dec 5, 2023
1 parent 9d3ff8b commit 42d0e76
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
1 change: 0 additions & 1 deletion cmd/apps/delapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func init() {
"", "Name of the developer app")
DelCmd.Flags().StringVarP(&id, "id", "i",
"", "Developer Id")

_ = DelCmd.MarkFlagRequired("name")
_ = DelCmd.MarkFlagRequired("id")
}
24 changes: 20 additions & 4 deletions cmd/apps/listapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ var ListCmd = &cobra.Command{
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = apps.List(includeCred, expand, count)
_, err = apps.List(includeCred, expand, count, status,
startKey, ids, keyStatus, apiProduct, pageSize, pageToken, filter)
return
},
}

var (
expand = false
includeCred = false
count int
status, startKey, ids, keyStatus, apiProduct, pageToken, filter string
expand = false
includeCred = false
count, pageSize int
)

func init() {
Expand All @@ -49,4 +51,18 @@ func init() {
false, "Expand Details")
ListCmd.Flags().BoolVarP(&includeCred, "inclCred", "i",
false, "Include Credentials")
ListCmd.Flags().StringVarP(&status, "status", "s",
"", "Filter by the status of the app. Valid values are approved or revoked")
ListCmd.Flags().StringVarP(&ids, "ids", "",
"", "Comma-separated list of app IDs")
ListCmd.Flags().StringVarP(&keyStatus, "key-status", "k",
"", "Key status of the app. Valid values include approved or revoked")
ListCmd.Flags().StringVarP(&apiProduct, "api-product", "p",
"", "Name of the API Product to filter by")
ListCmd.Flags().IntVarP(&pageSize, "page-size", "",
-1, "Count of apps a single page can have in the response")
ListCmd.Flags().StringVarP(&pageToken, "page-token", "",
"", "The starting index record for listing the apps")
ListCmd.Flags().StringVarP(&filter, "filter", "f",
"", "The filter expression to be used to get the list of apps")
}
33 changes: 28 additions & 5 deletions internal/client/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,9 @@ func SearchApp(name string) (respBody []byte, err error) {
defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())

u, _ := url.Parse(apiclient.BaseURL)
// search by name is not implemented; use list and return the appropriate app
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apps")
q := u.Query()
q.Set("expand", "true")
q.Set("includeCred", "false")
q.Set("filter", "appName="+name)
u.RawQuery = q.Encode()

respBody, err = apiclient.HttpClient(u.String())
Expand All @@ -200,7 +198,10 @@ func SearchApp(name string) (respBody []byte, err error) {
}

// List
func List(includeCred bool, expand bool, count int) (respBody []byte, err error) {
func List(includeCred bool, expand bool, count int, status string, startKey string,
ids string, keyStatus string, apiProduct string, pageSize int,
pageToken string, filter string,
) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apps")
q := u.Query()
Expand All @@ -215,8 +216,30 @@ func List(includeCred bool, expand bool, count int) (respBody []byte, err error)
q.Set("includeCred", "false")
}
if count != -1 {
q.Set("row", strconv.Itoa(count))
q.Set("rows", strconv.Itoa(count))
}
if startKey != "" {
q.Set("startKey", startKey)
}
if ids != "" {
q.Set("ids", ids)
}
if keyStatus != "" {
q.Set("keyStatus", keyStatus)
}
if apiProduct != "" {
q.Set("apiProduct", apiProduct)
}
if pageSize != -1 {
q.Set("pageSize", strconv.Itoa(pageSize))
}
if pageToken != "" {
q.Set("pageToken", pageToken)
}
if filter != "" {
q.Set("filter", filter)
}

u.RawQuery = q.Encode()
respBody, err = apiclient.HttpClient(u.String())
return respBody, err
Expand Down

0 comments on commit 42d0e76

Please sign in to comment.