Skip to content

Commit

Permalink
bug: fixes issues exporting more than 10000 apps #611
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Dec 24, 2024
1 parent 05f50b4 commit 6355cb8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
56 changes: 46 additions & 10 deletions internal/client/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,7 @@ func Export(conn int) (payload [][]byte, err error) {
var mu sync.Mutex
const entityType = "apps"

u, _ := url.Parse(apiclient.GetApigeeBaseURL())
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), entityType)

respBody, err := apiclient.HttpClient(u.String())
if err != nil {
return apiclient.GetEntityPayloadList(), err
}

entities := apps{}
err = json.Unmarshal(respBody, &entities)
entities, err := listAllApps()
if err != nil {
return apiclient.GetEntityPayloadList(), err
}
Expand Down Expand Up @@ -574,3 +565,48 @@ func getNewDeveloperId(oldDeveloperId string, developerEntities developers.Appde
}
return "", "", fmt.Errorf("developer not imported into Apigee")
}

func listAllApps() (appList apps, err error) {
var startKey string
appList = apps{}

u, _ := url.Parse(apiclient.GetApigeeBaseURL())
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apps")

// don't print to sysout
apiclient.ClientPrintHttpResponse.Set(false)

for {

a := apps{}

if startKey != "" {
q := u.Query()
q.Set("startKey", startKey)
q.Set("rows", "10000")
u.RawQuery = q.Encode()
}

respBody, err := apiclient.HttpClient(u.String())
startKey = ""
if err != nil {
return appList, err
}

err = json.Unmarshal(respBody, &a)
if err != nil {
return appList, err
}

appList.Apps = append(appList.Apps, a.Apps...)

if len(a.Apps) == 10000 {
startKey = a.Apps[len(a.Apps)-1].AppID
} else if len(a.Apps) < 10000 {
break
}
}

apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())
return appList, nil
}
1 change: 1 addition & 0 deletions internal/cmd/apps/expapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var ExpCmd = &cobra.Command{
cmd.SilenceUsage = true

const exportFileName = "apps.json"
apiclient.DisableCmdPrintHttpResponse()
payload, err := apps.Export(conn)
if err != nil {
return err
Expand Down

0 comments on commit 6355cb8

Please sign in to comment.