From bac0e9c90f525ef7333d172cd9659251715a4af4 Mon Sep 17 00:00:00 2001 From: Srinandan Sridhar <13950006+srinandan@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:09:19 -0800 Subject: [PATCH] Adds support for API Registry and enable data residency (#374) * chore: fix linting issues * bug: allow removal of api products #371 * feat: adds support for api hub * feat: adds support for data residency * chore: fix linting issues * chore: allow versions higher than one * chore: harmonize flags across all commands * bug: check for mandatory params #374 * feat: add remaining cmds for registry #374 * bug: fix cmd structure #374 * feat: add create operation for specs #374 * chore; fix linting errors #374 * bug: use download resource for specs #374 * bug: get specs returns one return value #374 * chore: fix linting issues #374 * feat: adds pagination to dev export #375 * feat: use the filename when present #374 --- .github/workflows/docker-publish.yml | 4 +- .github/workflows/gen-docs.yml | 2 +- .github/workflows/gorelease-action.yml | 4 +- cmd/apicategories/apicategories.go | 6 +- cmd/apicategories/create.go | 1 + cmd/apicategories/delete.go | 1 + cmd/apicategories/export.go | 1 + cmd/apicategories/get.go | 1 + cmd/apicategories/import.go | 1 + cmd/apicategories/list.go | 1 + cmd/apidocs/apidocs.go | 4 +- cmd/apidocs/create.go | 1 + cmd/apidocs/delete.go | 1 + cmd/apidocs/export.go | 1 + cmd/apidocs/get.go | 1 + cmd/apidocs/getdocs.go | 1 + cmd/apidocs/import.go | 1 + cmd/apidocs/list.go | 1 + cmd/apidocs/update.go | 1 + cmd/apidocs/updatedocs.go | 3 +- cmd/apis/apis.go | 6 +- cmd/apis/bundlecrtapis.go | 3 +- cmd/apis/cleanapi.go | 1 + cmd/apis/cloneapi.go | 5 +- cmd/apis/crtapikvm.go | 1 + cmd/apis/crttrcapi.go | 1 + cmd/apis/delapi.go | 1 + cmd/apis/delapikvm.go | 1 + cmd/apis/depapi.go | 3 +- cmd/apis/expapis.go | 1 + cmd/apis/fetchapi.go | 1 + cmd/apis/getapi.go | 1 + cmd/apis/gettrcapi.go | 1 + cmd/apis/ghcrtapis.go | 4 +- cmd/apis/gqlcrtapis.go | 1 + cmd/apis/impapis.go | 1 + cmd/apis/integrationapis.go | 1 + cmd/apis/listapikvm.go | 1 + cmd/apis/listapis.go | 1 + cmd/apis/listdeploy.go | 3 +- cmd/apis/listtrcapi.go | 1 + cmd/apis/oascrtapis.go | 3 +- cmd/apis/swaggerapis.go | 1 + cmd/apis/undepapi.go | 1 + cmd/apis/updapis.go | 1 + cmd/appgroups/appgroups.go | 4 +- cmd/appgroups/createkey.go | 3 +- cmd/appgroups/crtapp.go | 1 + cmd/appgroups/crtappgroup.go | 1 + cmd/appgroups/delapp.go | 1 + cmd/appgroups/delappgroup.go | 1 + cmd/appgroups/delkey.go | 1 + cmd/appgroups/delkeyprod.go | 1 + cmd/appgroups/expappgroups.go | 1 + cmd/appgroups/expapps.go | 1 + cmd/appgroups/getapp.go | 1 + cmd/appgroups/getappgroup.go | 1 + cmd/appgroups/getkey.go | 1 + cmd/appgroups/impappgroup.go | 1 + cmd/appgroups/impapps.go | 1 + cmd/appgroups/listappgroups.go | 1 + cmd/appgroups/listapps.go | 1 + cmd/appgroups/manageapp.go | 1 + cmd/appgroups/managekey.go | 1 + cmd/appgroups/updateapp.go | 1 + cmd/appgroups/updateappgroup.go | 1 + cmd/appgroups/updateappkeyprods.go | 1 + cmd/apps/apps.go | 6 +- cmd/apps/createkey.go | 3 +- cmd/apps/crtapp.go | 1 + cmd/apps/delapp.go | 1 + cmd/apps/deletekey.go | 1 + cmd/apps/expapp.go | 1 + cmd/apps/genkey.go | 1 + cmd/apps/getapp.go | 1 + cmd/apps/getkey.go | 1 + cmd/apps/impapps.go | 1 + cmd/apps/listapp.go | 3 +- cmd/apps/manageapp.go | 1 + cmd/apps/managekey.go | 1 + cmd/apps/updateapp.go | 1 + cmd/apps/updatekey.go | 6 + cmd/cache/cache.go | 5 +- cmd/cache/delcache.go | 1 + cmd/cache/listcache.go | 1 + cmd/datacollectors/crtdatacollector.go | 1 + cmd/datacollectors/datacollectors.go | 4 +- cmd/datacollectors/deldatacollector.go | 1 + cmd/datacollectors/expdatacollector.go | 1 + cmd/datacollectors/getdatacollector.go | 1 + cmd/datacollectors/impdatacolletcor.go | 1 + cmd/datacollectors/listdatacollector.go | 1 + cmd/datastores/create.go | 1 + cmd/datastores/datastores.go | 4 +- cmd/datastores/delete.go | 1 + cmd/datastores/get.go | 1 + cmd/datastores/list.go | 1 + cmd/datastores/test.go | 1 + cmd/datastores/update.go | 1 + cmd/developers/adjust.go | 1 + cmd/developers/credit.go | 1 + cmd/developers/crtdev.go | 1 + cmd/developers/crtsub.go | 1 + cmd/developers/deldev.go | 1 + cmd/developers/developers.go | 6 +- cmd/developers/expdev.go | 1 + cmd/developers/expiresub.go | 1 + cmd/developers/expsub.go | 1 + cmd/developers/getdev.go | 1 + cmd/developers/getdevapps.go | 1 + cmd/developers/getsub.go | 1 + cmd/developers/impdev.go | 1 + cmd/developers/listdev.go | 17 +- cmd/developers/listsub.go | 1 + cmd/developers/upddev.go | 1 + cmd/env/crtarchive.go | 1 + cmd/env/crtenv.go | 1 + cmd/env/crtsecactions.go | 1 + cmd/env/crttraceoverrides.go | 5 +- cmd/env/delarchive.go | 1 + cmd/env/delenv.go | 1 + cmd/env/disablesecactions.go | 1 + cmd/env/disablesectionscfg.go | 1 + cmd/env/disabletracecfg.go | 1 + cmd/env/enableaxob.go | 1 + cmd/env/enablesecactions.go | 1 + cmd/env/enablesectionscfg.go | 1 + cmd/env/env.go | 4 +- cmd/env/getarchive.go | 1 + cmd/env/getdebugmask.go | 1 + cmd/env/getdeloyedconfig.go | 1 + cmd/env/getdeployments.go | 1 + cmd/env/getenv.go | 1 + cmd/env/getiam.go | 1 + cmd/env/getsecactions.go | 1 + cmd/env/getsecactionscfg.go | 1 + cmd/env/getsecin.go | 1 + cmd/env/getsecreport.go | 1 + cmd/env/gettracecfg.go | 1 + cmd/env/gettraceoverrides.go | 1 + cmd/env/listarchives.go | 1 + cmd/env/listsecact.go | 4 +- cmd/env/listsecin.go | 4 +- cmd/env/listsecreports.go | 4 +- cmd/env/removerole.go | 2 +- cmd/env/setadmin.go | 2 +- cmd/env/setax.go | 4 +- cmd/env/setcustom.go | 4 +- cmd/env/setdeploy.go | 2 +- cmd/env/setsync.go | 2 +- cmd/env/testiam.go | 2 +- cmd/env/updatetracecfg.go | 4 +- cmd/envgroup/attachenv.go | 1 + cmd/envgroup/crtenvgroup.go | 1 + cmd/envgroup/delenvgroup.go | 1 + cmd/envgroup/detachenv.go | 1 + cmd/envgroup/envgroup.go | 6 +- cmd/envgroup/getenvgroup.go | 1 + cmd/envgroup/listattach.go | 1 + cmd/envgroup/listenvgroup.go | 1 + cmd/envgroup/updateenvgroup.go | 1 + cmd/eptattachment/crteptattachment.go | 1 + cmd/eptattachment/deleptattachment.go | 1 + cmd/eptattachment/eptattachment.go | 4 +- cmd/eptattachment/geteptattachment.go | 1 + cmd/eptattachment/listeptattachment.go | 1 + cmd/flowhooks/crtfh.go | 1 + cmd/flowhooks/delfh.go | 1 + cmd/flowhooks/flowhooks.go | 4 +- cmd/flowhooks/getfh.go | 1 + cmd/flowhooks/listfh.go | 1 + cmd/iam/create.go | 2 +- cmd/instances/activatenat.go | 1 + cmd/instances/crtattachment.go | 1 + cmd/instances/crtinstance.go | 1 + cmd/instances/delattachment.go | 1 + cmd/instances/deletenat.go | 1 + cmd/instances/delinstance.go | 1 + cmd/instances/getattachment.go | 1 + cmd/instances/getinstance.go | 1 + cmd/instances/instances.go | 4 +- cmd/instances/listattachments.go | 1 + cmd/instances/listintance.go | 1 + cmd/instances/listnat.go | 1 + cmd/instances/reservenat.go | 1 + cmd/instances/updtinstance.go | 1 + cmd/keyaliases/crtka.go | 9 +- cmd/keyaliases/csr.go | 1 + cmd/keyaliases/delka.go | 1 + cmd/keyaliases/getcert.go | 1 + cmd/keyaliases/getka.go | 1 + cmd/keyaliases/keyaliases.go | 4 +- cmd/keyaliases/listka.go | 1 + cmd/keyaliases/updateka.go | 3 +- cmd/keystores/crtks.go | 1 + cmd/keystores/delks.go | 1 + cmd/keystores/getks.go | 1 + cmd/keystores/impks.go | 1 + cmd/keystores/keystores.go | 4 +- cmd/keystores/listks.go | 1 + cmd/kvm/crtentry.go | 1 + cmd/kvm/crtkvm.go | 1 + cmd/kvm/delentry.go | 1 + cmd/kvm/delkvm.go | 1 + cmd/kvm/expentries.go | 1 + cmd/kvm/expkvm.go | 1 + cmd/kvm/getentry.go | 1 + cmd/kvm/impentries.go | 1 + cmd/kvm/impkvms.go | 1 + cmd/kvm/kvm.go | 4 +- cmd/kvm/listentry.go | 1 + cmd/kvm/listkvm.go | 1 + cmd/ops/getops.go | 1 + cmd/ops/listops.go | 3 +- cmd/ops/ops.go | 4 +- cmd/org/createorg.go | 2 +- cmd/org/delorg.go | 2 +- cmd/org/export.go | 4 +- cmd/org/import.go | 4 +- cmd/preferences/setpref.go | 15 +- cmd/products/crtprod.go | 3 +- cmd/products/crtrateplan.go | 1 + cmd/products/delattrprod.go | 1 + cmd/products/delprod.go | 1 + cmd/products/delrateplan.go | 3 +- cmd/products/expprod.go | 1 + cmd/products/exprateplan.go | 1 + cmd/products/getattrprod.go | 1 + cmd/products/getprod.go | 1 + cmd/products/getrateplan.go | 3 +- cmd/products/impprod.go | 1 + cmd/products/listattrprod.go | 1 + cmd/products/listproducts.go | 1 + cmd/products/listrateplan.go | 1 + cmd/products/products.go | 6 +- cmd/products/updattrprod.go | 1 + cmd/products/updprod.go | 3 +- cmd/references/crtref.go | 2 +- cmd/references/references.go | 5 +- cmd/references/updateref.go | 2 +- cmd/registry/apis/apis.go | 44 +++++ cmd/registry/apis/artifacts/artifacts.go | 33 ++++ cmd/registry/apis/artifacts/crtartifact.go | 70 +++++++ cmd/registry/apis/artifacts/delartifact.go | 51 ++++++ cmd/registry/apis/artifacts/getartifact.go | 57 ++++++ cmd/registry/apis/artifacts/listartifacts.go | 58 ++++++ cmd/registry/apis/crtapis.go | 67 +++++++ cmd/registry/apis/delapis.go | 45 +++++ cmd/registry/apis/deployments/crtdeploy.go | 75 ++++++++ cmd/registry/apis/deployments/deldeploy.go | 60 ++++++ cmd/registry/apis/deployments/deployments.go | 35 ++++ cmd/registry/apis/deployments/getdeploy.go | 49 +++++ cmd/registry/apis/deployments/listdeploy.go | 64 +++++++ .../apis/deployments/rollbackdeploy.go | 55 ++++++ cmd/registry/apis/deployments/tagdeploy.go | 55 ++++++ cmd/registry/apis/getapis.go | 45 +++++ cmd/registry/apis/listapis.go | 54 ++++++ .../apis/versions/artifacts/artifacts.go | 35 ++++ .../apis/versions/artifacts/crtartifact.go | 70 +++++++ .../apis/versions/artifacts/delartifact.go | 53 ++++++ .../apis/versions/artifacts/getartifact.go | 59 ++++++ .../apis/versions/artifacts/listartifacts.go | 61 ++++++ cmd/registry/apis/versions/crtversion.go | 66 +++++++ cmd/registry/apis/versions/deleteversion.go | 54 ++++++ cmd/registry/apis/versions/getversion.go | 52 ++++++ cmd/registry/apis/versions/listversion.go | 58 ++++++ .../versions/specs/artifacts/artifacts.go | 35 ++++ .../versions/specs/artifacts/crtartifact.go | 75 ++++++++ .../versions/specs/artifacts/delartifact.go | 56 ++++++ .../versions/specs/artifacts/getartifact.go | 56 ++++++ .../versions/specs/artifacts/listartifacts.go | 64 +++++++ cmd/registry/apis/versions/specs/crtspec.go | 81 ++++++++ cmd/registry/apis/versions/specs/delspec.go | 53 ++++++ cmd/registry/apis/versions/specs/getspec.go | 64 +++++++ cmd/registry/apis/versions/specs/listspecs.go | 61 ++++++ cmd/registry/apis/versions/specs/specs.go | 35 ++++ cmd/registry/apis/versions/versions.go | 37 ++++ cmd/registry/artifacts/artifacts.go | 35 ++++ cmd/registry/artifacts/crtartifact.go | 65 +++++++ cmd/registry/artifacts/delartifact.go | 45 +++++ cmd/registry/artifacts/getartifact.go | 52 ++++++ cmd/registry/artifacts/listartifact.go | 54 ++++++ cmd/registry/instances/crtinstance.go | 48 +++++ cmd/registry/instances/delinstance.go | 43 +++++ cmd/registry/instances/getinstance.go | 43 +++++ cmd/registry/instances/instances.go | 32 ++++ cmd/registry/registry.go | 43 +++++ cmd/res/crtres.go | 3 +- cmd/res/delres.go | 1 + cmd/res/getres.go | 1 + cmd/res/listres.go | 1 + cmd/res/res.go | 5 +- cmd/res/updres.go | 3 +- cmd/root.go | 2 + cmd/securityprofiles/attach.go | 3 +- cmd/securityprofiles/compute.go | 1 + cmd/securityprofiles/create.go | 1 + cmd/securityprofiles/delete.go | 1 + cmd/securityprofiles/detach.go | 1 + cmd/securityprofiles/export.go | 1 + cmd/securityprofiles/get.go | 3 +- cmd/securityprofiles/import.go | 1 + cmd/securityprofiles/list.go | 1 + cmd/securityprofiles/listrevisions.go | 1 + cmd/securityprofiles/securityprofiles.go | 4 +- cmd/securityprofiles/update.go | 1 + cmd/sharedflows/bundlecrtsf.go | 3 +- cmd/sharedflows/cleansf.go | 1 + cmd/sharedflows/delsf.go | 1 + cmd/sharedflows/depsf.go | 3 +- cmd/sharedflows/expsf.go | 1 + cmd/sharedflows/fetchsf.go | 1 + cmd/sharedflows/getsf.go | 1 + cmd/sharedflows/ghcrtsf.go | 4 +- cmd/sharedflows/impsfs.go | 1 + cmd/sharedflows/listdeploy.go | 3 +- cmd/sharedflows/listsf.go | 3 +- cmd/sharedflows/sharedflows.go | 6 +- cmd/sharedflows/undepsf.go | 1 + cmd/sites/list.go | 1 + cmd/sites/sites.go | 5 +- cmd/sync/getsync.go | 1 + cmd/sync/removesync.go | 1 + cmd/sync/resetsync.go | 1 + cmd/sync/setsync.go | 1 + cmd/sync/sync.go | 4 +- cmd/targetservers/crtts.go | 11 +- cmd/targetservers/delts.go | 1 + cmd/targetservers/expts.go | 1 + cmd/targetservers/getts.go | 1 + cmd/targetservers/impts.go | 1 + cmd/targetservers/listts.go | 1 + cmd/targetservers/targetservers.go | 4 +- cmd/targetservers/updatets.go | 11 +- cmd/utils/utils.go | 9 + internal/apiclient/bundles.go | 4 +- internal/apiclient/clifile.go | 42 ++--- internal/apiclient/httpclient.go | 13 +- internal/apiclient/iam.go | 8 +- internal/apiclient/options.go | 61 +++++- .../client/apicategories/apicategories.go | 12 +- internal/client/apidocs/apidocs.go | 12 +- internal/client/apis/apis.go | 32 ++-- internal/client/apis/kvm.go | 6 +- internal/client/apis/trace.go | 6 +- internal/client/appgroups/app.go | 10 +- internal/client/appgroups/appgroups.go | 12 +- internal/client/appgroups/keys.go | 12 +- internal/client/apps/apps.go | 26 +-- internal/client/apps/keys.go | 59 ++++-- internal/client/cache/cache.go | 4 +- .../client/datacollectors/datacollectors.go | 8 +- internal/client/datastores/datastores.go | 8 +- internal/client/developers/balance.go | 4 +- internal/client/developers/developers.go | 65 +++++-- internal/client/developers/subscriptions.go | 10 +- internal/client/env/archives.go | 10 +- internal/client/env/debugmask.go | 4 +- internal/client/env/env.go | 26 +-- internal/client/env/iam.go | 4 +- internal/client/env/reports.go | 2 +- internal/client/env/securityactions.go | 10 +- internal/client/env/securityincidents.go | 4 +- internal/client/env/securityreports.go | 8 +- internal/client/env/traceconfig.go | 8 +- internal/client/env/traceoverrides.go | 8 +- internal/client/envgroups/envgroups.go | 16 +- internal/client/eptattachment/eptattchment.go | 8 +- internal/client/flowhooks/flowhooks.go | 8 +- internal/client/instances/attachments.go | 12 +- internal/client/instances/instances.go | 10 +- internal/client/instances/nat.go | 8 +- internal/client/keyaliases/keyaliases.go | 14 +- internal/client/keystores/keystores.go | 10 +- internal/client/kvm/entries.go | 10 +- internal/client/kvm/kvm.go | 6 +- internal/client/operations/operations.go | 4 +- internal/client/orgs/orgs.go | 32 ++-- internal/client/products/products.go | 20 +- internal/client/products/rateplans.go | 10 +- internal/client/references/references.go | 14 +- internal/client/registry/apis/apis.go | 113 ++++++++++++ internal/client/registry/apis/artifacts.go | 94 ++++++++++ internal/client/registry/apis/deployments.go | 173 ++++++++++++++++++ .../registry/apis/deployments/artifacts.go | 95 ++++++++++ internal/client/registry/apis/versions.go | 115 ++++++++++++ .../registry/apis/versions/artifacts.go | 95 ++++++++++ .../registry/apis/versions/specartifacts.go | 100 ++++++++++ .../client/registry/apis/versions/specs.go | 164 +++++++++++++++++ .../client/registry/artifacts/artifacts.go | 94 ++++++++++ internal/client/registry/common/common.go | 74 ++++++++ .../client/registry/instances/instances.go | 63 +++++++ internal/client/res/res.go | 10 +- .../securityprofiles/securityprofiles.go | 18 +- internal/client/sharedflows/sharedflows.go | 24 +-- internal/client/sites/sites.go | 2 +- internal/client/sync/sync.go | 16 +- .../client/targetservers/targetservers.go | 12 +- 398 files changed, 4553 insertions(+), 446 deletions(-) create mode 100644 cmd/registry/apis/apis.go create mode 100644 cmd/registry/apis/artifacts/artifacts.go create mode 100644 cmd/registry/apis/artifacts/crtartifact.go create mode 100644 cmd/registry/apis/artifacts/delartifact.go create mode 100644 cmd/registry/apis/artifacts/getartifact.go create mode 100644 cmd/registry/apis/artifacts/listartifacts.go create mode 100644 cmd/registry/apis/crtapis.go create mode 100644 cmd/registry/apis/delapis.go create mode 100644 cmd/registry/apis/deployments/crtdeploy.go create mode 100644 cmd/registry/apis/deployments/deldeploy.go create mode 100644 cmd/registry/apis/deployments/deployments.go create mode 100644 cmd/registry/apis/deployments/getdeploy.go create mode 100644 cmd/registry/apis/deployments/listdeploy.go create mode 100644 cmd/registry/apis/deployments/rollbackdeploy.go create mode 100644 cmd/registry/apis/deployments/tagdeploy.go create mode 100644 cmd/registry/apis/getapis.go create mode 100644 cmd/registry/apis/listapis.go create mode 100644 cmd/registry/apis/versions/artifacts/artifacts.go create mode 100644 cmd/registry/apis/versions/artifacts/crtartifact.go create mode 100644 cmd/registry/apis/versions/artifacts/delartifact.go create mode 100644 cmd/registry/apis/versions/artifacts/getartifact.go create mode 100644 cmd/registry/apis/versions/artifacts/listartifacts.go create mode 100644 cmd/registry/apis/versions/crtversion.go create mode 100644 cmd/registry/apis/versions/deleteversion.go create mode 100644 cmd/registry/apis/versions/getversion.go create mode 100644 cmd/registry/apis/versions/listversion.go create mode 100644 cmd/registry/apis/versions/specs/artifacts/artifacts.go create mode 100644 cmd/registry/apis/versions/specs/artifacts/crtartifact.go create mode 100644 cmd/registry/apis/versions/specs/artifacts/delartifact.go create mode 100644 cmd/registry/apis/versions/specs/artifacts/getartifact.go create mode 100644 cmd/registry/apis/versions/specs/artifacts/listartifacts.go create mode 100644 cmd/registry/apis/versions/specs/crtspec.go create mode 100644 cmd/registry/apis/versions/specs/delspec.go create mode 100644 cmd/registry/apis/versions/specs/getspec.go create mode 100644 cmd/registry/apis/versions/specs/listspecs.go create mode 100644 cmd/registry/apis/versions/specs/specs.go create mode 100644 cmd/registry/apis/versions/versions.go create mode 100644 cmd/registry/artifacts/artifacts.go create mode 100644 cmd/registry/artifacts/crtartifact.go create mode 100644 cmd/registry/artifacts/delartifact.go create mode 100644 cmd/registry/artifacts/getartifact.go create mode 100644 cmd/registry/artifacts/listartifact.go create mode 100644 cmd/registry/instances/crtinstance.go create mode 100644 cmd/registry/instances/delinstance.go create mode 100644 cmd/registry/instances/getinstance.go create mode 100644 cmd/registry/instances/instances.go create mode 100644 cmd/registry/registry.go create mode 100644 internal/client/registry/apis/apis.go create mode 100644 internal/client/registry/apis/artifacts.go create mode 100644 internal/client/registry/apis/deployments.go create mode 100644 internal/client/registry/apis/deployments/artifacts.go create mode 100644 internal/client/registry/apis/versions.go create mode 100644 internal/client/registry/apis/versions/artifacts.go create mode 100644 internal/client/registry/apis/versions/specartifacts.go create mode 100644 internal/client/registry/apis/versions/specs.go create mode 100644 internal/client/registry/artifacts/artifacts.go create mode 100644 internal/client/registry/common/common.go create mode 100644 internal/client/registry/instances/instances.go diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 4f0577a33..ce9441827 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -23,8 +23,8 @@ on: push: # Publish semver tags as releases. tags: - - v[0-1].[0-9]+.[0-9] - - v[0-1].[0-9]+.[0-9]+-beta + - v[0-9].[0-9]+.[0-9] + - v[0-9].[0-9]+.[0-9]+-beta workflow_dispatch: env: diff --git a/.github/workflows/gen-docs.yml b/.github/workflows/gen-docs.yml index 9f500b583..3f503792f 100644 --- a/.github/workflows/gen-docs.yml +++ b/.github/workflows/gen-docs.yml @@ -19,7 +19,7 @@ on: push: # Publish semver tags as releases. tags: - - v[0-1].[0-9]+.[0-9] + - v[0-9].[0-9]+.[0-9] workflow_dispatch: jobs: diff --git a/.github/workflows/gorelease-action.yml b/.github/workflows/gorelease-action.yml index 3d9ed5517..7e14b1c98 100644 --- a/.github/workflows/gorelease-action.yml +++ b/.github/workflows/gorelease-action.yml @@ -18,8 +18,8 @@ on: push: # Publish semver tags as releases. tags: - - v[0-1].[0-9]+.[0-9] - - v[0-1].[0-9]+.[0-9]+-beta + - v[0-9].[0-9]+.[0-9] + - v[0-9].[0-9]+.[0-9]+-beta workflow_dispatch: jobs: diff --git a/cmd/apicategories/apicategories.go b/cmd/apicategories/apicategories.go index 858116a2b..9ef889e7d 100644 --- a/cmd/apicategories/apicategories.go +++ b/cmd/apicategories/apicategories.go @@ -25,14 +25,18 @@ var Cmd = &cobra.Command{ Long: "Manage Apigee API categories that are tagged on catalog items", } -var org, siteid, id string +var org, siteid, id, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(&siteid, "siteid", "s", "", "Name or siteid of the portal") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") + Cmd.AddCommand(ListCmd) Cmd.AddCommand(GetCmd) Cmd.AddCommand(DelCmd) diff --git a/cmd/apicategories/create.go b/cmd/apicategories/create.go index b148dd288..26d5c6817 100644 --- a/cmd/apicategories/create.go +++ b/cmd/apicategories/create.go @@ -30,6 +30,7 @@ var CreateCmd = &cobra.Command{ Short: "Creates a new API category", Long: "Creates a new API category", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apicategories/delete.go b/cmd/apicategories/delete.go index 8e9be6e6b..e9d3c4b1c 100644 --- a/cmd/apicategories/delete.go +++ b/cmd/apicategories/delete.go @@ -38,6 +38,7 @@ var DelCmd = &cobra.Command{ if name != "" && id != "" { return fmt.Errorf("name and id cannot be set as a parameter") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apicategories/export.go b/cmd/apicategories/export.go index eef24b64c..bbbf583a4 100644 --- a/cmd/apicategories/export.go +++ b/cmd/apicategories/export.go @@ -30,6 +30,7 @@ var ExpCmd = &cobra.Command{ Short: "Export API Categories across all sites", Long: "Export API Categories across all sites", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apicategories/get.go b/cmd/apicategories/get.go index 3f19b223d..affa4f7d8 100644 --- a/cmd/apicategories/get.go +++ b/cmd/apicategories/get.go @@ -39,6 +39,7 @@ var GetCmd = &cobra.Command{ if name != "" && id != "" { return fmt.Errorf("name and id cannot be set as a parameter") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apicategories/import.go b/cmd/apicategories/import.go index 907850728..f6fddd681 100644 --- a/cmd/apicategories/import.go +++ b/cmd/apicategories/import.go @@ -30,6 +30,7 @@ var ImpCmd = &cobra.Command{ Short: "Import from a folder containing apicategories", Long: "Import from a folder containing apicategories", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/apicategories/list.go b/cmd/apicategories/list.go index 8408a7b47..659263c56 100644 --- a/cmd/apicategories/list.go +++ b/cmd/apicategories/list.go @@ -32,6 +32,7 @@ var ListCmd = &cobra.Command{ if siteid == "" { return fmt.Errorf("siteid is a mandatory parameter") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apidocs/apidocs.go b/cmd/apidocs/apidocs.go index 11dc44b34..50eccac68 100644 --- a/cmd/apidocs/apidocs.go +++ b/cmd/apidocs/apidocs.go @@ -25,13 +25,15 @@ var Cmd = &cobra.Command{ Long: "Manage Apigee API catalog item through ApiDoc", } -var org, siteid, id, name string +var org, siteid, id, name, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") Cmd.PersistentFlags().StringVarP(&siteid, "siteid", "s", "", "Name or siteid of the portal") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(ListCmd) Cmd.AddCommand(GetCmd) diff --git a/cmd/apidocs/create.go b/cmd/apidocs/create.go index 1a41e370a..3438a0860 100644 --- a/cmd/apidocs/create.go +++ b/cmd/apidocs/create.go @@ -46,6 +46,7 @@ var CreateCmd = &cobra.Command{ if siteid == "" { return fmt.Errorf("siteid is a mandatory parameter") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apidocs/delete.go b/cmd/apidocs/delete.go index 33d1410d4..07dff9ef6 100644 --- a/cmd/apidocs/delete.go +++ b/cmd/apidocs/delete.go @@ -32,6 +32,7 @@ var DelCmd = &cobra.Command{ if siteid == "" { return fmt.Errorf("siteid is a mandatory parameter") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apidocs/export.go b/cmd/apidocs/export.go index 60212cfc6..618defe82 100644 --- a/cmd/apidocs/export.go +++ b/cmd/apidocs/export.go @@ -30,6 +30,7 @@ var ExpCmd = &cobra.Command{ Short: "Export API Docs to a file", Long: "Export API Docs to a file", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apidocs/get.go b/cmd/apidocs/get.go index c974f22bf..0bb617fb6 100644 --- a/cmd/apidocs/get.go +++ b/cmd/apidocs/get.go @@ -38,6 +38,7 @@ var GetCmd = &cobra.Command{ if name != "" && id != "" { return fmt.Errorf("title and id cannot be set as a parameter") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apidocs/getdocs.go b/cmd/apidocs/getdocs.go index 4a57bcc74..0810b88fa 100644 --- a/cmd/apidocs/getdocs.go +++ b/cmd/apidocs/getdocs.go @@ -32,6 +32,7 @@ var GetDocCmd = &cobra.Command{ if siteid == "" { return fmt.Errorf("siteid is a mandatory parameter") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apidocs/import.go b/cmd/apidocs/import.go index 65de3598e..f5d4b4c40 100644 --- a/cmd/apidocs/import.go +++ b/cmd/apidocs/import.go @@ -45,6 +45,7 @@ var ImpCmd = &cobra.Command{ if siteid == "" { return fmt.Errorf("siteid is a mandatory parameter") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/apidocs/list.go b/cmd/apidocs/list.go index 35b5b1522..99f92a832 100644 --- a/cmd/apidocs/list.go +++ b/cmd/apidocs/list.go @@ -32,6 +32,7 @@ var ListCmd = &cobra.Command{ if siteid == "" { return fmt.Errorf("siteid is a mandatory parameter") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apidocs/update.go b/cmd/apidocs/update.go index 1e0fcd254..a5de28f7e 100644 --- a/cmd/apidocs/update.go +++ b/cmd/apidocs/update.go @@ -47,6 +47,7 @@ var UpdateCmd = &cobra.Command{ if siteid == "" { return fmt.Errorf("siteid is a mandatory parameter") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apidocs/updatedocs.go b/cmd/apidocs/updatedocs.go index 525f0b821..1fff9b167 100644 --- a/cmd/apidocs/updatedocs.go +++ b/cmd/apidocs/updatedocs.go @@ -40,6 +40,7 @@ var UpdateDocCmd = &cobra.Command{ if graphQLPath != "" && endpointUri == "" { return fmt.Errorf("The flags graphQLPath and endpointUri must be set together") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -86,7 +87,7 @@ func init() { "", "Path to a file containing OpenAPI Specification documentation") UpdateDocCmd.Flags().StringVarP(&graphQLPath, "graphql", "q", "", "Path to a file containing GraphQL documentation") - UpdateDocCmd.Flags().StringVarP(&endpointUri, "endpointUri", "e", + UpdateDocCmd.Flags().StringVarP(&endpointUri, "endpoint-uri", "e", "", "URI for the GraphQL proxy") _ = UpdateDocCmd.MarkFlagRequired("id") diff --git a/cmd/apis/apis.go b/cmd/apis/apis.go index 343299b5f..ffc3622f9 100644 --- a/cmd/apis/apis.go +++ b/cmd/apis/apis.go @@ -26,8 +26,8 @@ var Cmd = &cobra.Command{ } var ( - org, env, name string - conn, revision int + org, region, env, name string + conn, revision int ) const zipExt = ".zip" @@ -35,6 +35,8 @@ const zipExt = ".zip" func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(ListCmd) Cmd.AddCommand(ListDepCmd) diff --git a/cmd/apis/bundlecrtapis.go b/cmd/apis/bundlecrtapis.go index 5adaed46c..8c1f7c3e6 100644 --- a/cmd/apis/bundlecrtapis.go +++ b/cmd/apis/bundlecrtapis.go @@ -49,6 +49,7 @@ var BundleCreateCmd = &cobra.Command{ if env != "" { apiclient.SetApigeeEnv(env) } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -110,7 +111,7 @@ func init() { BundleCreateCmd.Flags().StringVarP(&env, "env", "e", "", "Name of the environment to deploy the proxy") - BundleCreateCmd.Flags().BoolVarP(&overrides, "ovr", "r", + BundleCreateCmd.Flags().BoolVarP(&overrides, "ovr", "", false, "Forces deployment of the new revision") BundleCreateCmd.Flags().BoolVarP(&wait, "wait", "", false, "Waits for the deployment to finish, with success or error") diff --git a/cmd/apis/cleanapi.go b/cmd/apis/cleanapi.go index b6e92a0f1..6acb4ce8d 100644 --- a/cmd/apis/cleanapi.go +++ b/cmd/apis/cleanapi.go @@ -28,6 +28,7 @@ var CleanCmd = &cobra.Command{ Short: "Deletes undeployed/unused revisions of an API proxy", Long: "Deletes undeployed/unused revisions of an API proxy", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/cloneapi.go b/cmd/apis/cloneapi.go index 924f1fd1c..64977e666 100644 --- a/cmd/apis/cloneapi.go +++ b/cmd/apis/cloneapi.go @@ -53,6 +53,7 @@ var CloneCmd = &cobra.Command{ if !strings.HasPrefix(basePath, "/") { return fmt.Errorf("basePath must start with /") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -101,13 +102,13 @@ func init() { CloneCmd.Flags().StringVarP(&proxyZip, "proxy-zip", "p", "", "Path to the Sharedflow bundle/zip file") - CloneCmd.Flags().StringVarP(&basePath, "base-path", "b", + CloneCmd.Flags().StringVarP(&basePath, "basepath", "b", "", "A new basePath for the cloned proxy") CloneCmd.Flags().StringVarP(&proxyFolder, "proxy-folder", "f", "", "Path to the Sharedflow Bundle; ex: ./test/apiproxy") _ = CloneCmd.MarkFlagRequired("name") - _ = CloneCmd.MarkFlagRequired("base-path") + _ = CloneCmd.MarkFlagRequired("basepath") } func copyDirectory() (tmpDir string, err error) { diff --git a/cmd/apis/crtapikvm.go b/cmd/apis/crtapikvm.go index d6259f76b..838eb364f 100644 --- a/cmd/apis/crtapikvm.go +++ b/cmd/apis/crtapikvm.go @@ -28,6 +28,7 @@ var CreateKvmCmd = &cobra.Command{ Short: "Create an API Proxy scoped KVM", Long: "Create an API Proxy scoped KVM", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/crttrcapi.go b/cmd/apis/crttrcapi.go index 2fc65604b..5ed642be3 100644 --- a/cmd/apis/crttrcapi.go +++ b/cmd/apis/crttrcapi.go @@ -29,6 +29,7 @@ var CreateTrcCmd = &cobra.Command{ Long: "Create a new debug session for Apigee API proxy revision deployed in an environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/delapi.go b/cmd/apis/delapi.go index c2b5052d9..4d9145579 100644 --- a/cmd/apis/delapi.go +++ b/cmd/apis/delapi.go @@ -29,6 +29,7 @@ var DelCmd = &cobra.Command{ Long: "Deletes an API proxy and all associated endpoints, policies, resources, and revisions." + "The proxy must be undeployed first.", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/delapikvm.go b/cmd/apis/delapikvm.go index f8df866ce..d29255a76 100644 --- a/cmd/apis/delapikvm.go +++ b/cmd/apis/delapikvm.go @@ -28,6 +28,7 @@ var DelKvmCmd = &cobra.Command{ Short: "Deletes an API Proxy scoped KVM", Long: "Deletes an API Proxy scoped KVM", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/depapi.go b/cmd/apis/depapi.go index b9669ef61..69d4dcd13 100644 --- a/cmd/apis/depapi.go +++ b/cmd/apis/depapi.go @@ -30,6 +30,7 @@ var DepCmd = &cobra.Command{ "in an organization, optionally waits for deployment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -68,7 +69,7 @@ func init() { "", "Apigee environment name") DepCmd.Flags().IntVarP(&revision, "rev", "v", -1, "API Proxy revision. If not set, the highest revision is used") - DepCmd.Flags().BoolVarP(&overrides, "ovr", "r", + DepCmd.Flags().BoolVarP(&overrides, "ovr", "", false, "Forces deployment of the new revision") DepCmd.Flags().BoolVarP(&wait, "wait", "", false, "Waits for the deployment to finish, with success or error") diff --git a/cmd/apis/expapis.go b/cmd/apis/expapis.go index 209890179..cda3d2d3a 100644 --- a/cmd/apis/expapis.go +++ b/cmd/apis/expapis.go @@ -28,6 +28,7 @@ var ExpCmd = &cobra.Command{ Short: "export API proxy bundles from an org", Long: "export API proxy bundles from an org", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/fetchapi.go b/cmd/apis/fetchapi.go index 3e04741c2..288f743c3 100644 --- a/cmd/apis/fetchapi.go +++ b/cmd/apis/fetchapi.go @@ -28,6 +28,7 @@ var FetCmd = &cobra.Command{ Short: "Returns a zip-formatted proxy bundle ", Long: "Returns a zip-formatted proxy bundle of code and config files", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/getapi.go b/cmd/apis/getapi.go index f8b0fe2a4..14bea7491 100644 --- a/cmd/apis/getapi.go +++ b/cmd/apis/getapi.go @@ -28,6 +28,7 @@ var GetCmd = &cobra.Command{ Short: "Gets an API Proxy by name", Long: "Gets an API Proxy by name, including a list of its revisions.", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/gettrcapi.go b/cmd/apis/gettrcapi.go index 5cf1dc502..9d3b49db8 100644 --- a/cmd/apis/gettrcapi.go +++ b/cmd/apis/gettrcapi.go @@ -29,6 +29,7 @@ var GetTrcCmd = &cobra.Command{ Long: "Get a debug session for an API proxy revision deployed in an environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/ghcrtapis.go b/cmd/apis/ghcrtapis.go index e1c499377..b542d7ff2 100644 --- a/cmd/apis/ghcrtapis.go +++ b/cmd/apis/ghcrtapis.go @@ -41,7 +41,7 @@ var GhCreateCmd = &cobra.Command{ if ok := re.Match([]byte(ghPath)); !ok { return fmt.Errorf("github path must end with /apiproxy") } - + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -67,7 +67,7 @@ func init() { "", "API Proxy name") GhCreateCmd.Flags().StringVarP(&ghOwner, "owner", "u", "", "The github organization or username. ex: In https://github.com/apigee, apigee is the owner name") - GhCreateCmd.Flags().StringVarP(&ghRepo, "repo", "r", + GhCreateCmd.Flags().StringVarP(&ghRepo, "repo", "", "", "The github repo name. ex: https://github.com/apigee/api-platform-samples, api-platform-samples is the repo") GhCreateCmd.Flags().StringVarP(&ghPath, "proxy-path", "p", "", "The path in the repo to the apiproxy folder. ex: sample-proxies/apikey/apiproxy") diff --git a/cmd/apis/gqlcrtapis.go b/cmd/apis/gqlcrtapis.go index d4930718c..008383c8f 100644 --- a/cmd/apis/gqlcrtapis.go +++ b/cmd/apis/gqlcrtapis.go @@ -47,6 +47,7 @@ var GqlCreateCmd = &cobra.Command{ if targetURL != "" && targetURLRef != "" { return fmt.Errorf("either target-url or target-url-ref must be passed, not both") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/impapis.go b/cmd/apis/impapis.go index bacacbc2b..dc0332090 100644 --- a/cmd/apis/impapis.go +++ b/cmd/apis/impapis.go @@ -31,6 +31,7 @@ var ImpCmd = &cobra.Command{ Short: "Import a folder containing API proxy bundles", Long: "Import a folder containing API proxy bundles", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/integrationapis.go b/cmd/apis/integrationapis.go index 4966b52e4..33a5b7506 100644 --- a/cmd/apis/integrationapis.go +++ b/cmd/apis/integrationapis.go @@ -31,6 +31,7 @@ var IntegrationCmd = &cobra.Command{ Short: "Creates an API proxy template for Application Integration", Long: "Creates an API proxy template for Application Integration with an API Trigger", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/listapikvm.go b/cmd/apis/listapikvm.go index b0b90af85..97d6f8676 100644 --- a/cmd/apis/listapikvm.go +++ b/cmd/apis/listapikvm.go @@ -28,6 +28,7 @@ var ListKvmCmd = &cobra.Command{ Short: "List all KVMs for an API proxy", Long: "List all KVMs for an API proxy", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/listapis.go b/cmd/apis/listapis.go index 84beab63d..0a46918bc 100644 --- a/cmd/apis/listapis.go +++ b/cmd/apis/listapis.go @@ -28,6 +28,7 @@ var ListCmd = &cobra.Command{ Short: "List APIs in an Apigee Org", Long: "List APIs in an Apigee Org", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/listdeploy.go b/cmd/apis/listdeploy.go index a79a28e79..1d82ef24f 100644 --- a/cmd/apis/listdeploy.go +++ b/cmd/apis/listdeploy.go @@ -40,6 +40,7 @@ var ListDepCmd = &cobra.Command{ if name != "" && revision == -1 && apiclient.GetApigeeEnv() != "" { return fmt.Errorf("revision must be supplied with proxy name and env") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -67,7 +68,7 @@ func init() { "", "API proxy name") ListDepCmd.Flags().StringVarP(&env, "env", "e", "", "Apigee environment name") - ListDepCmd.Flags().IntVarP(&revision, "rev", "r", + ListDepCmd.Flags().IntVarP(&revision, "rev", "v", -1, "API Proxy revision") ListDepCmd.Flags().BoolVarP(&report, "report", "", false, "Generate Deploy Change Report; Default is false") diff --git a/cmd/apis/listtrcapi.go b/cmd/apis/listtrcapi.go index 90d1a3c5d..00d291554 100644 --- a/cmd/apis/listtrcapi.go +++ b/cmd/apis/listtrcapi.go @@ -29,6 +29,7 @@ var ListTrcCmd = &cobra.Command{ Long: "List all debug sessions for an API proxy revision deployed in an environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/oascrtapis.go b/cmd/apis/oascrtapis.go index 18fb0b4f9..83ce2b320 100644 --- a/cmd/apis/oascrtapis.go +++ b/cmd/apis/oascrtapis.go @@ -48,6 +48,7 @@ var OasCreateCmd = &cobra.Command{ if (targetURL != "" || targetURLRef != "") && (integration != "" || apitrigger != "") { return fmt.Errorf("integration or apitrigger cannot be set if targetURL or targetURLRef is set") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -155,7 +156,7 @@ func init() { false, "Skip adding the OAS Validate policy") OasCreateCmd.Flags().BoolVarP(&addCORS, "add-cors", "", false, "Add a CORS policy") - OasCreateCmd.Flags().BoolVarP(&formatValidation, "formatValidation", "", + OasCreateCmd.Flags().BoolVarP(&formatValidation, "format-validation", "", true, "disables validation of schema type formats") _ = OasCreateCmd.MarkFlagRequired("name") diff --git a/cmd/apis/swaggerapis.go b/cmd/apis/swaggerapis.go index 5caee770c..c55da3ab9 100644 --- a/cmd/apis/swaggerapis.go +++ b/cmd/apis/swaggerapis.go @@ -35,6 +35,7 @@ var SwaggerCreateCmd = &cobra.Command{ if swaggerFile == "" && swaggerURI == "" { return fmt.Errorf("either swaggerfile or swaggeruri must be passed") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/undepapi.go b/cmd/apis/undepapi.go index 6efc66940..ad582a972 100644 --- a/cmd/apis/undepapi.go +++ b/cmd/apis/undepapi.go @@ -29,6 +29,7 @@ var UndepCmd = &cobra.Command{ Long: "Undeploys a revision of an existing API proxy to an environment in an organization", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apis/updapis.go b/cmd/apis/updapis.go index 7cca8b615..6f95e7c9a 100644 --- a/cmd/apis/updapis.go +++ b/cmd/apis/updapis.go @@ -28,6 +28,7 @@ var UpdateCmd = &cobra.Command{ Short: "Update APIs in an Apigee Org", Long: "Update APIs in an Apigee Org", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/appgroups.go b/cmd/appgroups/appgroups.go index 858a71799..913f27767 100644 --- a/cmd/appgroups/appgroups.go +++ b/cmd/appgroups/appgroups.go @@ -25,11 +25,13 @@ var Cmd = &cobra.Command{ Long: "Manage Apigee Application Groups", } -var org string +var org, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(ListCmd) Cmd.AddCommand(GetCmd) diff --git a/cmd/appgroups/createkey.go b/cmd/appgroups/createkey.go index 47b561716..bc3ede589 100644 --- a/cmd/appgroups/createkey.go +++ b/cmd/appgroups/createkey.go @@ -33,6 +33,7 @@ var CreateKeyCmd = &cobra.Command{ if (key != "" && secret == "") || (secret != "" && key == "") { return fmt.Errorf("key and secret must both be passed or neither must be sent") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -55,7 +56,7 @@ func init() { "", "Name of the app") CreateKeyCmd.Flags().StringVarP(&key, "key", "k", "", "Import an existing AppGroup app consumer key") - CreateKeyCmd.Flags().StringVarP(&secret, "secret", "r", + CreateKeyCmd.Flags().StringVarP(&secret, "secret", "c", "", "Import an existing AppGroup app consumer secret") CreateKeyCmd.Flags().StringVarP(&expires, "expires", "x", "", "A setting, in seconds, for the lifetime of the consumer key") diff --git a/cmd/appgroups/crtapp.go b/cmd/appgroups/crtapp.go index 87c87ae2a..0b85f1afb 100644 --- a/cmd/appgroups/crtapp.go +++ b/cmd/appgroups/crtapp.go @@ -31,6 +31,7 @@ var CreateAppCmd = &cobra.Command{ Short: "Create an App", Long: "Create an App in an AppGroup", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/crtappgroup.go b/cmd/appgroups/crtappgroup.go index 55ba575bd..36577532f 100644 --- a/cmd/appgroups/crtappgroup.go +++ b/cmd/appgroups/crtappgroup.go @@ -27,6 +27,7 @@ var CreateCmd = &cobra.Command{ Short: "Create an AppGroup", Long: "Create an AppGroup", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/delapp.go b/cmd/appgroups/delapp.go index c66e2c982..b702bfd15 100644 --- a/cmd/appgroups/delapp.go +++ b/cmd/appgroups/delapp.go @@ -27,6 +27,7 @@ var DelAppCmd = &cobra.Command{ Short: "Delete an App in an AppGroup", Long: "Delete an in an AppGroup", Args: func(cmd *cobra.Command, args []string) error { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/delappgroup.go b/cmd/appgroups/delappgroup.go index e2bf817fd..b1fbbdc28 100644 --- a/cmd/appgroups/delappgroup.go +++ b/cmd/appgroups/delappgroup.go @@ -27,6 +27,7 @@ var DelCmd = &cobra.Command{ Short: "Delete AppGroup in an Organization by AppGroup Name", Long: "Delete AppGroup in an Organization by AppGroup Name", Args: func(cmd *cobra.Command, args []string) error { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/delkey.go b/cmd/appgroups/delkey.go index e46bfeb8e..1969a6ee8 100644 --- a/cmd/appgroups/delkey.go +++ b/cmd/appgroups/delkey.go @@ -28,6 +28,7 @@ var DelKeyCmd = &cobra.Command{ Short: "Deletes a consumer key for a AppGroup app", Long: "Deletes a consumer key for a AppGroup app", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/delkeyprod.go b/cmd/appgroups/delkeyprod.go index 28b4251cd..de2d534a4 100644 --- a/cmd/appgroups/delkeyprod.go +++ b/cmd/appgroups/delkeyprod.go @@ -28,6 +28,7 @@ var DelProdKeyCmd = &cobra.Command{ Short: "Deletes a product from an App in an AppGroup app", Long: "Deletes a product from an App in an AppGroup app", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/expappgroups.go b/cmd/appgroups/expappgroups.go index 99dadba87..a6e0fda66 100644 --- a/cmd/appgroups/expappgroups.go +++ b/cmd/appgroups/expappgroups.go @@ -28,6 +28,7 @@ var ExpCmd = &cobra.Command{ Short: "Export AppGroups to a file", Long: "Export AppGroups to a file", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/expapps.go b/cmd/appgroups/expapps.go index 8b776c4b3..211fae141 100644 --- a/cmd/appgroups/expapps.go +++ b/cmd/appgroups/expapps.go @@ -33,6 +33,7 @@ var ExpAppCmd = &cobra.Command{ if name == "" && !all { return fmt.Errorf("either all must be set to true or a name must be passed") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/getapp.go b/cmd/appgroups/getapp.go index afa63d51b..793434cc6 100644 --- a/cmd/appgroups/getapp.go +++ b/cmd/appgroups/getapp.go @@ -27,6 +27,7 @@ var GetAppCmd = &cobra.Command{ Short: "Get App in an AppGroup", Long: "Get App in an AppGroup", Args: func(cmd *cobra.Command, args []string) error { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/getappgroup.go b/cmd/appgroups/getappgroup.go index 84ff1bcd1..b17642907 100644 --- a/cmd/appgroups/getappgroup.go +++ b/cmd/appgroups/getappgroup.go @@ -27,6 +27,7 @@ var GetCmd = &cobra.Command{ Short: "Get AppGroup in an Organization by AppGroup Name", Long: "Returns the app group details for the specified app group name", Args: func(cmd *cobra.Command, args []string) error { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/getkey.go b/cmd/appgroups/getkey.go index 852df14c2..13170ab4b 100644 --- a/cmd/appgroups/getkey.go +++ b/cmd/appgroups/getkey.go @@ -28,6 +28,7 @@ var GetKeyCmd = &cobra.Command{ Short: "Gets details for a consumer key for a AppGroup app", Long: "Gets details for a consumer key for a AppGroup app", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/impappgroup.go b/cmd/appgroups/impappgroup.go index cdc1e4c91..3f286d867 100644 --- a/cmd/appgroups/impappgroup.go +++ b/cmd/appgroups/impappgroup.go @@ -28,6 +28,7 @@ var ImpCmd = &cobra.Command{ Short: "Import a file containing AppGroups", Long: "Import a file containing AppGroups", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/appgroups/impapps.go b/cmd/appgroups/impapps.go index fda3c3435..7267cd133 100644 --- a/cmd/appgroups/impapps.go +++ b/cmd/appgroups/impapps.go @@ -33,6 +33,7 @@ var ImpAppCmd = &cobra.Command{ if name == "" && !all { return fmt.Errorf("either all must be set to true or a name must be passed") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/appgroups/listappgroups.go b/cmd/appgroups/listappgroups.go index 86f239203..1484748b8 100644 --- a/cmd/appgroups/listappgroups.go +++ b/cmd/appgroups/listappgroups.go @@ -28,6 +28,7 @@ var ListCmd = &cobra.Command{ Short: "Returns a list of AppGroups", Long: "Returns a list of AppGroups", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/listapps.go b/cmd/appgroups/listapps.go index 1cb3b81c5..b1a69f828 100644 --- a/cmd/appgroups/listapps.go +++ b/cmd/appgroups/listapps.go @@ -28,6 +28,7 @@ var ListAppCmd = &cobra.Command{ Short: "Returns a list of Developer Applications", Long: "Returns a list of app IDs within an organization based on app status", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/manageapp.go b/cmd/appgroups/manageapp.go index 5c015cced..60d03fcfa 100644 --- a/cmd/appgroups/manageapp.go +++ b/cmd/appgroups/manageapp.go @@ -27,6 +27,7 @@ var ManageAppCmd = &cobra.Command{ Short: "Approve or revoke an app", Long: "Approve or revoke an app", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/managekey.go b/cmd/appgroups/managekey.go index 20ddc9407..75aea71a9 100644 --- a/cmd/appgroups/managekey.go +++ b/cmd/appgroups/managekey.go @@ -27,6 +27,7 @@ var ManageKeyCmd = &cobra.Command{ Short: "Approve or revoke an app key", Long: "Approve or revoke an app key", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/updateapp.go b/cmd/appgroups/updateapp.go index 8083f78d7..0b4e183ab 100644 --- a/cmd/appgroups/updateapp.go +++ b/cmd/appgroups/updateapp.go @@ -31,6 +31,7 @@ var UpdateAppCmd = &cobra.Command{ Short: "Update an App in an AppGroup", Long: "Update an App in an AppGroup", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/updateappgroup.go b/cmd/appgroups/updateappgroup.go index 687345f0f..f50b8407f 100644 --- a/cmd/appgroups/updateappgroup.go +++ b/cmd/appgroups/updateappgroup.go @@ -27,6 +27,7 @@ var UpdateCmd = &cobra.Command{ Short: "Update an AppGroup", Long: "Update an AppGroup", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/appgroups/updateappkeyprods.go b/cmd/appgroups/updateappkeyprods.go index 484594f21..54fdddaf2 100644 --- a/cmd/appgroups/updateappkeyprods.go +++ b/cmd/appgroups/updateappkeyprods.go @@ -27,6 +27,7 @@ var UpdateKeyProdCmd = &cobra.Command{ Short: "Update products in an app key contained in an AppGroup", Long: "Update products in an app key contained in an AppGroup", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apps/apps.go b/cmd/apps/apps.go index 02ab1c71d..1618980e3 100644 --- a/cmd/apps/apps.go +++ b/cmd/apps/apps.go @@ -27,13 +27,15 @@ var Cmd = &cobra.Command{ } var ( - appID, name, org string - conn int + appID, name, org, region string + conn int ) func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(ListCmd) Cmd.AddCommand(GetCmd) diff --git a/cmd/apps/createkey.go b/cmd/apps/createkey.go index 281fdee4c..717c42130 100644 --- a/cmd/apps/createkey.go +++ b/cmd/apps/createkey.go @@ -31,6 +31,7 @@ var CreateKeyCmd = &cobra.Command{ Short: "Create a developer app key", Long: "Create a a developer app key", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -47,7 +48,7 @@ var CreateKeyCmd = &cobra.Command{ func init() { CreateKeyCmd.Flags().StringVarP(&key, "key", "k", "", "Developer app consumer key") - CreateKeyCmd.Flags().StringVarP(&secret, "secret", "r", + CreateKeyCmd.Flags().StringVarP(&secret, "secret", "c", "", "Developer app consumer secret") CreateKeyCmd.Flags().StringArrayVarP(&apiProducts, "prods", "p", []string{}, "A list of api products") diff --git a/cmd/apps/crtapp.go b/cmd/apps/crtapp.go index e6761db8d..b2c569977 100644 --- a/cmd/apps/crtapp.go +++ b/cmd/apps/crtapp.go @@ -31,6 +31,7 @@ var CreateCmd = &cobra.Command{ Short: "Create a Developer App", Long: "Create a Developer App", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apps/delapp.go b/cmd/apps/delapp.go index 99647e86d..5e222aa54 100644 --- a/cmd/apps/delapp.go +++ b/cmd/apps/delapp.go @@ -28,6 +28,7 @@ var DelCmd = &cobra.Command{ Short: "Deletes a Developer App from an organization", Long: "Deletes a Developer Appfrom an organization", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apps/deletekey.go b/cmd/apps/deletekey.go index 61b5c8e98..c17ce4fac 100644 --- a/cmd/apps/deletekey.go +++ b/cmd/apps/deletekey.go @@ -28,6 +28,7 @@ var DeleteKeyCmd = &cobra.Command{ Short: "Delete a developer app key", Long: "Delete a a developer app key", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apps/expapp.go b/cmd/apps/expapp.go index 0f3df8d8a..8ae0a67bf 100644 --- a/cmd/apps/expapp.go +++ b/cmd/apps/expapp.go @@ -28,6 +28,7 @@ var ExpCmd = &cobra.Command{ Short: "Export Developer Apps to a file", Long: "Export Developer Apps to a file", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apps/genkey.go b/cmd/apps/genkey.go index 924d4a271..4d9424066 100644 --- a/cmd/apps/genkey.go +++ b/cmd/apps/genkey.go @@ -31,6 +31,7 @@ var GenKeyCmd = &cobra.Command{ Short: "Generate a new developer KeyPair", Long: "Generate a new developer KeyPair", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apps/getapp.go b/cmd/apps/getapp.go index 129eaf866..3878acbb7 100644 --- a/cmd/apps/getapp.go +++ b/cmd/apps/getapp.go @@ -36,6 +36,7 @@ var GetCmd = &cobra.Command{ if appID != "" && name != "" { return fmt.Errorf("name and appId cannot be used together") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apps/getkey.go b/cmd/apps/getkey.go index 02e4250ec..5279e4484 100644 --- a/cmd/apps/getkey.go +++ b/cmd/apps/getkey.go @@ -28,6 +28,7 @@ var GetKeyCmd = &cobra.Command{ Short: "Get a developer app key", Long: "Get a a developer app key", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apps/impapps.go b/cmd/apps/impapps.go index 33ac73f76..e249c8b66 100644 --- a/cmd/apps/impapps.go +++ b/cmd/apps/impapps.go @@ -28,6 +28,7 @@ var ImpCmd = &cobra.Command{ Short: "Import a file containing Developer Apps", Long: "Import a file containing Developer Apps", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/apps/listapp.go b/cmd/apps/listapp.go index 656351f54..419a2e423 100644 --- a/cmd/apps/listapp.go +++ b/cmd/apps/listapp.go @@ -28,6 +28,7 @@ var ListCmd = &cobra.Command{ Short: "Returns a list of Developer Applications", Long: "Returns a list of app IDs within an organization based on app status", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -49,7 +50,7 @@ func init() { -1, "Number of apps; limit is 1000") ListCmd.Flags().BoolVarP(&expand, "expand", "x", false, "Expand Details") - ListCmd.Flags().BoolVarP(&includeCred, "inclCred", "i", + ListCmd.Flags().BoolVarP(&includeCred, "incl-cred", "i", false, "Include Credentials") ListCmd.Flags().StringVarP(&status, "status", "s", "", "Filter by the status of the app. Valid values are approved or revoked") diff --git a/cmd/apps/manageapp.go b/cmd/apps/manageapp.go index 1d01c70de..34b68040b 100644 --- a/cmd/apps/manageapp.go +++ b/cmd/apps/manageapp.go @@ -28,6 +28,7 @@ var ManageCmd = &cobra.Command{ Short: "Approve or revoke a developer app", Long: "Approve or revoke a developer app", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apps/managekey.go b/cmd/apps/managekey.go index 2e156440c..fdad7ef2b 100644 --- a/cmd/apps/managekey.go +++ b/cmd/apps/managekey.go @@ -28,6 +28,7 @@ var ManageKeyCmd = &cobra.Command{ Short: "Approve or revoke a developer app key", Long: "Approve or revoke a developer app key", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apps/updateapp.go b/cmd/apps/updateapp.go index 75e68eb21..5d3f8fa85 100644 --- a/cmd/apps/updateapp.go +++ b/cmd/apps/updateapp.go @@ -31,6 +31,7 @@ var UpdateCmd = &cobra.Command{ Short: "Update a Developer App", Long: "Update a Developer App", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/apps/updatekey.go b/cmd/apps/updatekey.go index 791563fd6..065f276f9 100644 --- a/cmd/apps/updatekey.go +++ b/cmd/apps/updatekey.go @@ -15,6 +15,8 @@ package apps import ( + "fmt" + "internal/apiclient" "internal/client/apps" @@ -28,6 +30,10 @@ var UpdateKeyCmd = &cobra.Command{ Short: "Update a developer app key", Long: "Update a a developer app key", Args: func(cmd *cobra.Command, args []string) (err error) { + if name == "" { + return fmt.Errorf("developer app name is a mandatory parameter") + } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/cache/cache.go b/cmd/cache/cache.go index 3aafd1ebb..5db49e722 100644 --- a/cmd/cache/cache.go +++ b/cmd/cache/cache.go @@ -25,7 +25,7 @@ var Cmd = &cobra.Command{ Long: "Manage caches within an Apigee environment", } -var org, env string +var org, env, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", @@ -34,6 +34,9 @@ func init() { Cmd.PersistentFlags().StringVarP(&env, "env", "e", "", "Apigee environment name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") + _ = Cmd.MarkPersistentFlagRequired("env") Cmd.AddCommand(ListCmd) diff --git a/cmd/cache/delcache.go b/cmd/cache/delcache.go index 3be4c3ab6..2e2e4bb39 100644 --- a/cmd/cache/delcache.go +++ b/cmd/cache/delcache.go @@ -29,6 +29,7 @@ var DelCmd = &cobra.Command{ Long: "Delete a cache resource from the environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/cache/listcache.go b/cmd/cache/listcache.go index 2f7b37c17..2f62100b7 100644 --- a/cmd/cache/listcache.go +++ b/cmd/cache/listcache.go @@ -29,6 +29,7 @@ var ListCmd = &cobra.Command{ Long: "List all caches in your environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/datacollectors/crtdatacollector.go b/cmd/datacollectors/crtdatacollector.go index 71e3574f8..b5d506a55 100644 --- a/cmd/datacollectors/crtdatacollector.go +++ b/cmd/datacollectors/crtdatacollector.go @@ -33,6 +33,7 @@ var CreateCmd = &cobra.Command{ if !isValidType() { return fmt.Errorf("invalid collector type %s. Valid types are %s", collectorType, allowedTypes) } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/datacollectors/datacollectors.go b/cmd/datacollectors/datacollectors.go index 6fb9c0388..0150f2d5e 100644 --- a/cmd/datacollectors/datacollectors.go +++ b/cmd/datacollectors/datacollectors.go @@ -26,11 +26,13 @@ var Cmd = &cobra.Command{ Long: "Manage Apigee datacollectors entities", } -var org, name string +var org, name, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(CreateCmd) Cmd.AddCommand(ListCmd) diff --git a/cmd/datacollectors/deldatacollector.go b/cmd/datacollectors/deldatacollector.go index a1504fd78..eb0191d22 100644 --- a/cmd/datacollectors/deldatacollector.go +++ b/cmd/datacollectors/deldatacollector.go @@ -28,6 +28,7 @@ var DelCmd = &cobra.Command{ Short: "Delete a Data Collector", Long: "Delete a Data Collector", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/datacollectors/expdatacollector.go b/cmd/datacollectors/expdatacollector.go index 4fa48b78a..b83e9bfd0 100644 --- a/cmd/datacollectors/expdatacollector.go +++ b/cmd/datacollectors/expdatacollector.go @@ -28,6 +28,7 @@ var ExpCmd = &cobra.Command{ Short: "Export Data Collectors", Long: "Export Data Collectors", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/datacollectors/getdatacollector.go b/cmd/datacollectors/getdatacollector.go index f9774a4f1..361243eba 100644 --- a/cmd/datacollectors/getdatacollector.go +++ b/cmd/datacollectors/getdatacollector.go @@ -28,6 +28,7 @@ var GetCmd = &cobra.Command{ Short: "Get a Data Collector", Long: "Get a Data Collector", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/datacollectors/impdatacolletcor.go b/cmd/datacollectors/impdatacolletcor.go index 0294e3b17..ca6ef6320 100644 --- a/cmd/datacollectors/impdatacolletcor.go +++ b/cmd/datacollectors/impdatacolletcor.go @@ -28,6 +28,7 @@ var ImpCmd = &cobra.Command{ Short: "Import Data Collectors", Long: "Import Data Collectors", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/datacollectors/listdatacollector.go b/cmd/datacollectors/listdatacollector.go index f1d5dd0a6..30639116d 100644 --- a/cmd/datacollectors/listdatacollector.go +++ b/cmd/datacollectors/listdatacollector.go @@ -28,6 +28,7 @@ var ListCmd = &cobra.Command{ Short: "List Data Collectors", Long: "List Data Collectors", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/datastores/create.go b/cmd/datastores/create.go index 6d95fedbf..a0dd8f237 100644 --- a/cmd/datastores/create.go +++ b/cmd/datastores/create.go @@ -31,6 +31,7 @@ var CreateCmd = &cobra.Command{ tablePrefix, datasetName); err != nil { return err } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/datastores/datastores.go b/cmd/datastores/datastores.go index 540d1f2d9..2f619e4ea 100644 --- a/cmd/datastores/datastores.go +++ b/cmd/datastores/datastores.go @@ -27,11 +27,13 @@ var Cmd = &cobra.Command{ Long: "Manage data stores to export analytics data", } -var org, name, targetType string +var org, name, targetType, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(ListCmd) Cmd.AddCommand(GetCmd) diff --git a/cmd/datastores/delete.go b/cmd/datastores/delete.go index 2e6cc14c9..1865e022b 100644 --- a/cmd/datastores/delete.go +++ b/cmd/datastores/delete.go @@ -35,6 +35,7 @@ var DeleteCmd = &cobra.Command{ if name != "" && id != "" { return fmt.Errorf("id and name cannot be passed together") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/datastores/get.go b/cmd/datastores/get.go index ae612dd74..ec00f5b30 100644 --- a/cmd/datastores/get.go +++ b/cmd/datastores/get.go @@ -35,6 +35,7 @@ var GetCmd = &cobra.Command{ if name != "" && id != "" { return fmt.Errorf("id and name cannot be passed together") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/datastores/list.go b/cmd/datastores/list.go index 8b33cdfc4..4783645d0 100644 --- a/cmd/datastores/list.go +++ b/cmd/datastores/list.go @@ -27,6 +27,7 @@ var ListCmd = &cobra.Command{ Short: "Returns a list of data stores in the org", Long: "Returns a list of data stores in the org", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/datastores/test.go b/cmd/datastores/test.go index 7ff56305b..40c6ef680 100644 --- a/cmd/datastores/test.go +++ b/cmd/datastores/test.go @@ -31,6 +31,7 @@ var TestCmd = &cobra.Command{ tablePrefix, datasetName); err != nil { return err } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/datastores/update.go b/cmd/datastores/update.go index 76995387b..c991fa1ad 100644 --- a/cmd/datastores/update.go +++ b/cmd/datastores/update.go @@ -31,6 +31,7 @@ var UpdateCmd = &cobra.Command{ tablePrefix, datasetName); err != nil { return err } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/developers/adjust.go b/cmd/developers/adjust.go index 22c8f941f..2182baa15 100644 --- a/cmd/developers/adjust.go +++ b/cmd/developers/adjust.go @@ -27,6 +27,7 @@ var AdjustCmd = &cobra.Command{ Use: "adjust", Short: "Adjust the prepaid balance for the developer", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, Long: "Adjust the prepaid balance for the developer", diff --git a/cmd/developers/credit.go b/cmd/developers/credit.go index 92ef2eef7..d21417d93 100644 --- a/cmd/developers/credit.go +++ b/cmd/developers/credit.go @@ -27,6 +27,7 @@ var CreditCmd = &cobra.Command{ Use: "credit", Short: "Credits the account balance for the developer", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, Long: "Credits the account balance for the developer", diff --git a/cmd/developers/crtdev.go b/cmd/developers/crtdev.go index c65d55fc3..1db60c114 100644 --- a/cmd/developers/crtdev.go +++ b/cmd/developers/crtdev.go @@ -28,6 +28,7 @@ var CreateCmd = &cobra.Command{ Short: "Create a developer", Long: "Create a developer", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/developers/crtsub.go b/cmd/developers/crtsub.go index b5fd9103a..d8172fabc 100644 --- a/cmd/developers/crtsub.go +++ b/cmd/developers/crtsub.go @@ -28,6 +28,7 @@ var CreateSubCmd = &cobra.Command{ Short: "Create a subcription for a developer", Long: "Create a developer", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/developers/deldev.go b/cmd/developers/deldev.go index 44ed3e654..63162683b 100644 --- a/cmd/developers/deldev.go +++ b/cmd/developers/deldev.go @@ -28,6 +28,7 @@ var DelCmd = &cobra.Command{ Short: "Deletes an App Developer from an organization", Long: "Deletes an App Developer from an organization", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/developers/developers.go b/cmd/developers/developers.go index f02f6a41e..1af53e36e 100644 --- a/cmd/developers/developers.go +++ b/cmd/developers/developers.go @@ -27,13 +27,15 @@ var Cmd = &cobra.Command{ } var ( - org, email string - expand bool + org, email, region string + expand bool ) func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(ListCmd) Cmd.AddCommand(GetCmd) diff --git a/cmd/developers/expdev.go b/cmd/developers/expdev.go index 19394e20b..f304331a2 100644 --- a/cmd/developers/expdev.go +++ b/cmd/developers/expdev.go @@ -28,6 +28,7 @@ var ExpCmd = &cobra.Command{ Short: "Export Developers to a file", Long: "Export Developers to a file", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/developers/expiresub.go b/cmd/developers/expiresub.go index 4680a952b..4b026dcc2 100644 --- a/cmd/developers/expiresub.go +++ b/cmd/developers/expiresub.go @@ -27,6 +27,7 @@ var ExpSubCmd = &cobra.Command{ Use: "expire", Short: "Expires a Developer subscription", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, Long: "Expires a Developer subscription", diff --git a/cmd/developers/expsub.go b/cmd/developers/expsub.go index a355547ae..d64845fab 100644 --- a/cmd/developers/expsub.go +++ b/cmd/developers/expsub.go @@ -28,6 +28,7 @@ var ExportSubCmd = &cobra.Command{ Short: "Export Developer subscriptions to a file", Long: "Export Developer subscriptions to a file", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/developers/getdev.go b/cmd/developers/getdev.go index e51b8793e..208aae2c4 100644 --- a/cmd/developers/getdev.go +++ b/cmd/developers/getdev.go @@ -28,6 +28,7 @@ var GetCmd = &cobra.Command{ Short: "Returns the profile for a developer by email address or ID", Long: "Returns the profile for a developer by email address or ID", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/developers/getdevapps.go b/cmd/developers/getdevapps.go index 1c31be1f1..ecfa50c58 100644 --- a/cmd/developers/getdevapps.go +++ b/cmd/developers/getdevapps.go @@ -28,6 +28,7 @@ var GetAppCmd = &cobra.Command{ Short: "Returns the apps owned by a developer by email address", Long: "Returns the apps owned by a developer by email address", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/developers/getsub.go b/cmd/developers/getsub.go index b2d8d78eb..750384571 100644 --- a/cmd/developers/getsub.go +++ b/cmd/developers/getsub.go @@ -27,6 +27,7 @@ var GetSubCmd = &cobra.Command{ Use: "get", Short: "Returns a Developer subscription", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, Long: "Returns a Developer subscription", diff --git a/cmd/developers/impdev.go b/cmd/developers/impdev.go index 94f0fd5e2..6bede1cf3 100644 --- a/cmd/developers/impdev.go +++ b/cmd/developers/impdev.go @@ -28,6 +28,7 @@ var ImpCmd = &cobra.Command{ Short: "Import a file containing App Developers", Long: "Import a file containing App Developers", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/developers/listdev.go b/cmd/developers/listdev.go index fdebed82e..199bbc466 100644 --- a/cmd/developers/listdev.go +++ b/cmd/developers/listdev.go @@ -27,18 +27,20 @@ var ListCmd = &cobra.Command{ Use: "list", Short: "Returns a list of App Developers", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, Long: "Lists all developers in an organization by email address", RunE: func(cmd *cobra.Command, args []string) (err error) { - _, err = developers.List(count, expand, ids) + _, err = developers.List(count, expand, ids, startKey, app, includeCompany) return }, } var ( - count int - ids string + count int + ids, startKey, app string + includeCompany bool ) func init() { @@ -50,4 +52,13 @@ func init() { ListCmd.Flags().StringVarP(&ids, "ids", "i", "", "List of IDs to include, separated by commas") + + ListCmd.Flags().StringVarP(&startKey, "start-key", "s", + "", "Email address of the developer from which to start displaying the list of developers") + + ListCmd.Flags().BoolVarP(&includeCompany, "include-company", "", + false, "Flag that specifies whether to include company details in the response") + + ListCmd.Flags().StringVarP(&app, "app", "", + "", "List only Developers that are associated with the app") } diff --git a/cmd/developers/listsub.go b/cmd/developers/listsub.go index dc163586e..eedef7efa 100644 --- a/cmd/developers/listsub.go +++ b/cmd/developers/listsub.go @@ -27,6 +27,7 @@ var ListSubCmd = &cobra.Command{ Use: "list", Short: "Returns a list of Developer subscriptions", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, Long: "Returns a list of Developer subscriptions", diff --git a/cmd/developers/upddev.go b/cmd/developers/upddev.go index 8e3cfefb6..980caccf9 100644 --- a/cmd/developers/upddev.go +++ b/cmd/developers/upddev.go @@ -30,6 +30,7 @@ var UpdateCmd = &cobra.Command{ Short: "Update an Apigee developer configuration", Long: "Update an Apigee developer configuration", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/crtarchive.go b/cmd/env/crtarchive.go index 5b50ab60c..6f73bc02e 100644 --- a/cmd/env/crtarchive.go +++ b/cmd/env/crtarchive.go @@ -60,6 +60,7 @@ var CreateArchiveCmd = &cobra.Command{ return fmt.Errorf("both zipfile and folder path cannot be passed") } apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/crtenv.go b/cmd/env/crtenv.go index 70a9f066c..c611ad96d 100644 --- a/cmd/env/crtenv.go +++ b/cmd/env/crtenv.go @@ -36,6 +36,7 @@ var CreateCmd = &cobra.Command{ return fmt.Errorf("invalid URI string for fwdProxyURI: %v", err) } apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/crtsecactions.go b/cmd/env/crtsecactions.go index 19e9dac92..e8f6fa498 100644 --- a/cmd/env/crtsecactions.go +++ b/cmd/env/crtsecactions.go @@ -29,6 +29,7 @@ var CreateSecActCmd = &cobra.Command{ Long: "Create a new SecurityAction", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/crttraceoverrides.go b/cmd/env/crttraceoverrides.go index 4340ae97a..693c29fcf 100644 --- a/cmd/env/crttraceoverrides.go +++ b/cmd/env/crttraceoverrides.go @@ -29,6 +29,7 @@ var CrtTraceOverridesCmd = &cobra.Command{ Long: "Create a new Distributed Trace config override", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -44,11 +45,11 @@ func init() { "", "API Proxy name") CrtTraceOverridesCmd.Flags().StringVarP(&exporter, "exporter", "x", "", "Trace exporter can be JAEGER or CLOUD_TRACE") - CrtTraceOverridesCmd.Flags().StringVarP(&endpoint, "endpoint", "p", + CrtTraceOverridesCmd.Flags().StringVarP(&endpoint, "endpoint-uri", "p", "", "Trace endpoint, used only with JAEGER") CrtTraceOverridesCmd.Flags().StringVarP(&sampler, "sampler", "s", "PROBABILITY", "Sampler can be set to PROBABILITY or OFF") - CrtTraceOverridesCmd.Flags().StringVarP(&sampleRate, "rate", "r", + CrtTraceOverridesCmd.Flags().StringVarP(&sampleRate, "rate", "", "", "Sampler Rate") _ = CrtTraceOverridesCmd.MarkFlagRequired("exporter") diff --git a/cmd/env/delarchive.go b/cmd/env/delarchive.go index f9414beb5..4c41b0113 100644 --- a/cmd/env/delarchive.go +++ b/cmd/env/delarchive.go @@ -29,6 +29,7 @@ var DelArchiveCmd = &cobra.Command{ Long: "Delete Apigee Archive from the environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/delenv.go b/cmd/env/delenv.go index e6dbcf818..474a9cf49 100644 --- a/cmd/env/delenv.go +++ b/cmd/env/delenv.go @@ -29,6 +29,7 @@ var DelCmd = &cobra.Command{ Long: "Delete an environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/disablesecactions.go b/cmd/env/disablesecactions.go index ce1bafdcb..201368a7d 100644 --- a/cmd/env/disablesecactions.go +++ b/cmd/env/disablesecactions.go @@ -29,6 +29,7 @@ var DisableSecActCmd = &cobra.Command{ Long: "Disable a SecurityAction", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/disablesectionscfg.go b/cmd/env/disablesectionscfg.go index 848ed85a1..a1a556db3 100644 --- a/cmd/env/disablesectionscfg.go +++ b/cmd/env/disablesectionscfg.go @@ -29,6 +29,7 @@ var DisableSecActCfgCmd = &cobra.Command{ Long: "Disables SecurityActions on the environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/disabletracecfg.go b/cmd/env/disabletracecfg.go index 7cd53c979..f8375bd61 100644 --- a/cmd/env/disabletracecfg.go +++ b/cmd/env/disabletracecfg.go @@ -29,6 +29,7 @@ var DisableTraceConfigCmd = &cobra.Command{ Long: "Disable Distributed Trace config for the environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/enableaxob.go b/cmd/env/enableaxob.go index f4a782b8f..597854625 100644 --- a/cmd/env/enableaxob.go +++ b/cmd/env/enableaxob.go @@ -31,6 +31,7 @@ var ObCmd = &cobra.Command{ Long: "Obfuscate analytics fields before sending to control plane", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/enablesecactions.go b/cmd/env/enablesecactions.go index 126fb0b47..67c1b6c8c 100644 --- a/cmd/env/enablesecactions.go +++ b/cmd/env/enablesecactions.go @@ -29,6 +29,7 @@ var EnableSecActCmd = &cobra.Command{ Long: "Enable a SecurityAction", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/enablesectionscfg.go b/cmd/env/enablesectionscfg.go index ddea7de86..b9ce683cf 100644 --- a/cmd/env/enablesectionscfg.go +++ b/cmd/env/enablesectionscfg.go @@ -29,6 +29,7 @@ var EnableSecActCfgCmd = &cobra.Command{ Long: "Enables SecurityActions on the environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/env.go b/cmd/env/env.go index 99717c62c..218e02ee8 100644 --- a/cmd/env/env.go +++ b/cmd/env/env.go @@ -26,11 +26,13 @@ var Cmd = &cobra.Command{ Long: "Manage Apigee environments", } -var org, environment string +var org, environment, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(ListCmd) Cmd.AddCommand(CreateCmd) diff --git a/cmd/env/getarchive.go b/cmd/env/getarchive.go index 7ad733551..e7d895305 100644 --- a/cmd/env/getarchive.go +++ b/cmd/env/getarchive.go @@ -29,6 +29,7 @@ var GetArchiveCmd = &cobra.Command{ Long: "Get archive details", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/getdebugmask.go b/cmd/env/getdebugmask.go index 3408aedec..6ce4f4f8d 100644 --- a/cmd/env/getdebugmask.go +++ b/cmd/env/getdebugmask.go @@ -29,6 +29,7 @@ var GetDebugCmd = &cobra.Command{ Long: "Get debugmasks for an Environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/getdeloyedconfig.go b/cmd/env/getdeloyedconfig.go index 0a835bd05..7d2e14fab 100644 --- a/cmd/env/getdeloyedconfig.go +++ b/cmd/env/getdeloyedconfig.go @@ -29,6 +29,7 @@ var GetConfigCmd = &cobra.Command{ Long: "Get deployment configuration for an Environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/getdeployments.go b/cmd/env/getdeployments.go index f576f3846..7b2c46d2b 100644 --- a/cmd/env/getdeployments.go +++ b/cmd/env/getdeployments.go @@ -29,6 +29,7 @@ var GetDeployCmd = &cobra.Command{ Long: "Get deployments for an Environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/getenv.go b/cmd/env/getenv.go index 6921e4563..ff05871fe 100644 --- a/cmd/env/getenv.go +++ b/cmd/env/getenv.go @@ -29,6 +29,7 @@ var GetCmd = &cobra.Command{ Long: "Get properties of an environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/getiam.go b/cmd/env/getiam.go index 00b7bfd26..495b89b7c 100644 --- a/cmd/env/getiam.go +++ b/cmd/env/getiam.go @@ -29,6 +29,7 @@ var GetIamCmd = &cobra.Command{ Long: "Gets the IAM policy on an Environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/getsecactions.go b/cmd/env/getsecactions.go index fd4a20ee3..1f2f649d6 100644 --- a/cmd/env/getsecactions.go +++ b/cmd/env/getsecactions.go @@ -28,6 +28,7 @@ var GetSecActCmd = &cobra.Command{ Long: "Get a SecurityAction by name", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/getsecactionscfg.go b/cmd/env/getsecactionscfg.go index d1b25fb67..0f5c55e6f 100644 --- a/cmd/env/getsecactionscfg.go +++ b/cmd/env/getsecactionscfg.go @@ -29,6 +29,7 @@ var GetSecActCfgCmd = &cobra.Command{ Long: "Returns the current SecurityActions configuration", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/getsecin.go b/cmd/env/getsecin.go index 565cc53ff..18661dd3e 100644 --- a/cmd/env/getsecin.go +++ b/cmd/env/getsecin.go @@ -28,6 +28,7 @@ var GetSecInCmd = &cobra.Command{ Long: "Returns a security incidents by name", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/getsecreport.go b/cmd/env/getsecreport.go index 11daeeda7..f2b120716 100644 --- a/cmd/env/getsecreport.go +++ b/cmd/env/getsecreport.go @@ -28,6 +28,7 @@ var GetSecReportCmd = &cobra.Command{ Long: "Returns a security reports by name", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/gettracecfg.go b/cmd/env/gettracecfg.go index a951f20ad..06b208140 100644 --- a/cmd/env/gettracecfg.go +++ b/cmd/env/gettracecfg.go @@ -29,6 +29,7 @@ var GetTraceConfigCmd = &cobra.Command{ Long: "Get Distributed Trace config for the environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/gettraceoverrides.go b/cmd/env/gettraceoverrides.go index 29f3099e8..a618eb28b 100644 --- a/cmd/env/gettraceoverrides.go +++ b/cmd/env/gettraceoverrides.go @@ -29,6 +29,7 @@ var GetTraceOverridesCmd = &cobra.Command{ Long: "Get Distributed Trace config overrides", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/listarchives.go b/cmd/env/listarchives.go index e435912b8..6682080b5 100644 --- a/cmd/env/listarchives.go +++ b/cmd/env/listarchives.go @@ -29,6 +29,7 @@ var ListArchiveCmd = &cobra.Command{ Long: "List archives deployed to the environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/env/listsecact.go b/cmd/env/listsecact.go index 83832aa67..b6f2fd07d 100644 --- a/cmd/env/listsecact.go +++ b/cmd/env/listsecact.go @@ -37,9 +37,9 @@ var ListSecActCmd = &cobra.Command{ } func init() { - ListSecActCmd.Flags().IntVarP(&pageSize, "pageSize", "", + ListSecActCmd.Flags().IntVarP(&pageSize, "page-size", "", -1, "The maximum number of versions to return") - ListSecActCmd.Flags().StringVarP(&pageToken, "pageToken", "", + ListSecActCmd.Flags().StringVarP(&pageToken, "page-token", "", "", "A page token, received from a previous call") ListSecActCmd.Flags().StringVarP(&filter, "filter", "", "", "Filter results") diff --git a/cmd/env/listsecin.go b/cmd/env/listsecin.go index 086aa7d4e..8cf270cbb 100644 --- a/cmd/env/listsecin.go +++ b/cmd/env/listsecin.go @@ -42,9 +42,9 @@ var ( ) func init() { - ListSecInCmd.Flags().IntVarP(&pageSize, "pageSize", "", + ListSecInCmd.Flags().IntVarP(&pageSize, "page-size", "", -1, "The maximum number of versions to return") - ListSecInCmd.Flags().StringVarP(&pageToken, "pageToken", "", + ListSecInCmd.Flags().StringVarP(&pageToken, "page-token", "", "", "A page token, received from a previous call") ListSecInCmd.Flags().StringVarP(&filter, "filter", "", "", "Filter results") diff --git a/cmd/env/listsecreports.go b/cmd/env/listsecreports.go index ec42846f5..e2b315109 100644 --- a/cmd/env/listsecreports.go +++ b/cmd/env/listsecreports.go @@ -40,9 +40,9 @@ var ListSecReportCmd = &cobra.Command{ var from, to, dataset, status, submittedBy string func init() { - ListSecReportCmd.Flags().IntVarP(&pageSize, "pageSize", "", + ListSecReportCmd.Flags().IntVarP(&pageSize, "page-size", "", -1, "The maximum number of versions to return") - ListSecReportCmd.Flags().StringVarP(&pageToken, "pageToken", "", + ListSecReportCmd.Flags().StringVarP(&pageToken, "page-token", "", "", "A page token, received from a previous call") ListSecReportCmd.Flags().StringVarP(&from, "from", "f", "", "Filter response list by returning security reports that created after this date time") diff --git a/cmd/env/removerole.go b/cmd/env/removerole.go index fcd491654..8010f5d32 100644 --- a/cmd/env/removerole.go +++ b/cmd/env/removerole.go @@ -45,7 +45,7 @@ var RemoveRoleCmd = &cobra.Command{ func init() { RemoveRoleCmd.Flags().StringVarP(&memberName, "name", "n", "", "Member name. Prefix the member role as role:name. Ex: user:foo@acme.com") - RemoveRoleCmd.Flags().StringVarP(&role, "role", "r", + RemoveRoleCmd.Flags().StringVarP(&role, "role", "", "", "IAM Role") _ = RemoveRoleCmd.MarkFlagRequired("name") diff --git a/cmd/env/setadmin.go b/cmd/env/setadmin.go index 56141efce..c65fdd52a 100644 --- a/cmd/env/setadmin.go +++ b/cmd/env/setadmin.go @@ -45,7 +45,7 @@ var SetAdminCmd = &cobra.Command{ func init() { SetAdminCmd.Flags().StringVarP(&memberName, "name", "n", "", "Member Name, example Service Account Name") - SetAdminCmd.Flags().StringVarP(&memberType, "memberType", "m", + SetAdminCmd.Flags().StringVarP(&memberType, "member-type", "m", "serviceAccount", "memberType must be serviceAccount, user or group") _ = SetAdminCmd.MarkFlagRequired("name") diff --git a/cmd/env/setax.go b/cmd/env/setax.go index 6e393ae76..96838fb48 100644 --- a/cmd/env/setax.go +++ b/cmd/env/setax.go @@ -50,9 +50,9 @@ var SetAxCmd = &cobra.Command{ func init() { SetAxCmd.Flags().StringVarP(&memberName, "name", "n", "", "Member Name, example Service Account Name") - SetAxCmd.Flags().StringVarP(&memberType, "memberType", "m", + SetAxCmd.Flags().StringVarP(&memberType, "member-type", "m", "serviceAccount", "memberType must be serviceAccount, user or group") - SetAxCmd.Flags().StringVarP(&role, "memberRole", "r", + SetAxCmd.Flags().StringVarP(&role, "member-role", "", "analyticsAgent", "memberRole must be analyticsViewer or analyticsAgent") _ = SetAxCmd.MarkFlagRequired("name") } diff --git a/cmd/env/setcustom.go b/cmd/env/setcustom.go index 5755c6c00..290b29194 100644 --- a/cmd/env/setcustom.go +++ b/cmd/env/setcustom.go @@ -53,9 +53,9 @@ var SetCustCmd = &cobra.Command{ func init() { SetCustCmd.Flags().StringVarP(&memberName, "name", "n", "", "Member Name, example Service Account Name") - SetCustCmd.Flags().StringVarP(&role, "role", "r", + SetCustCmd.Flags().StringVarP(&role, "role", "", "", "Custom IAM role in the format projects/{project-id}/roles/{role}") - SetCustCmd.Flags().StringVarP(&memberType, "memberType", "m", + SetCustCmd.Flags().StringVarP(&memberType, "member-type", "m", "serviceAccount", "memberType must be serviceAccount, user or group") _ = SetCustCmd.MarkFlagRequired("name") diff --git a/cmd/env/setdeploy.go b/cmd/env/setdeploy.go index ab825ee77..b9fbecde0 100644 --- a/cmd/env/setdeploy.go +++ b/cmd/env/setdeploy.go @@ -45,7 +45,7 @@ var SetDepCmd = &cobra.Command{ func init() { SetDepCmd.Flags().StringVarP(&memberName, "name", "n", "", "Member Name, example Service Account Name") - SetDepCmd.Flags().StringVarP(&memberType, "memberType", "m", + SetDepCmd.Flags().StringVarP(&memberType, "member-type", "m", "serviceAccount", "memberType must be serviceAccount, user or group") _ = SetDepCmd.MarkFlagRequired("name") diff --git a/cmd/env/setsync.go b/cmd/env/setsync.go index 8d9f5b1db..1c6d97bde 100644 --- a/cmd/env/setsync.go +++ b/cmd/env/setsync.go @@ -45,7 +45,7 @@ var SetSyncCmd = &cobra.Command{ func init() { SetSyncCmd.Flags().StringVarP(&memberName, "name", "n", "", "Member Name, example Service Account Name") - SetSyncCmd.Flags().StringVarP(&memberType, "memberType", "m", + SetSyncCmd.Flags().StringVarP(&memberType, "member-type", "m", "serviceAccount", "memberType must be serviceAccount, user or group") _ = SetSyncCmd.MarkFlagRequired("name") diff --git a/cmd/env/testiam.go b/cmd/env/testiam.go index f8866b508..ba82810e8 100644 --- a/cmd/env/testiam.go +++ b/cmd/env/testiam.go @@ -42,6 +42,6 @@ var verb, resource string func init() { TestIamCmd.Flags().StringVarP(&verb, "verb", "v", "get", "resource verb") - TestIamCmd.Flags().StringVarP(&resource, "res", "r", + TestIamCmd.Flags().StringVarP(&resource, "res", "s", "environment", "resource") } diff --git a/cmd/env/updatetracecfg.go b/cmd/env/updatetracecfg.go index 6016917ea..0ea2cfe6f 100644 --- a/cmd/env/updatetracecfg.go +++ b/cmd/env/updatetracecfg.go @@ -42,11 +42,11 @@ var exporter, endpoint, sampler, sampleRate string func init() { UpdateTraceConfigCmd.Flags().StringVarP(&exporter, "exporter", "x", "", "Trace exporter can be JAEGER or CLOUD_TRACE") - UpdateTraceConfigCmd.Flags().StringVarP(&endpoint, "endpoint", "p", + UpdateTraceConfigCmd.Flags().StringVarP(&endpoint, "endpoint-uri", "p", "", "Trace endpoint, used only with JAEGER") UpdateTraceConfigCmd.Flags().StringVarP(&sampler, "sampler", "s", "PROBABILITY", "Sampler can be set to PROBABILITY or OFF") - UpdateTraceConfigCmd.Flags().StringVarP(&sampleRate, "rate", "r", + UpdateTraceConfigCmd.Flags().StringVarP(&sampleRate, "rate", "", "", "Sampler Rate") _ = UpdateTraceConfigCmd.MarkFlagRequired("exporter") diff --git a/cmd/envgroup/attachenv.go b/cmd/envgroup/attachenv.go index b4b38b85f..8ef549a10 100644 --- a/cmd/envgroup/attachenv.go +++ b/cmd/envgroup/attachenv.go @@ -28,6 +28,7 @@ var AttachCmd = &cobra.Command{ Short: "Attach an env to an Environment Group", Long: "Attach an env to an Environment Group", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/envgroup/crtenvgroup.go b/cmd/envgroup/crtenvgroup.go index 8ce4fb852..86eaa451a 100644 --- a/cmd/envgroup/crtenvgroup.go +++ b/cmd/envgroup/crtenvgroup.go @@ -28,6 +28,7 @@ var CreateCmd = &cobra.Command{ Short: "Create an Environment Group", Long: "Create an Environment Group", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/envgroup/delenvgroup.go b/cmd/envgroup/delenvgroup.go index dc21629d6..0422e688b 100644 --- a/cmd/envgroup/delenvgroup.go +++ b/cmd/envgroup/delenvgroup.go @@ -28,6 +28,7 @@ var DelCmd = &cobra.Command{ Short: "Deletes an Environment Group", Long: "Deletes an Environment Group", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/envgroup/detachenv.go b/cmd/envgroup/detachenv.go index aba617620..f376f222a 100644 --- a/cmd/envgroup/detachenv.go +++ b/cmd/envgroup/detachenv.go @@ -28,6 +28,7 @@ var DetachCmd = &cobra.Command{ Short: "Detach an env from an Environment Group", Long: "Detach an env from an Environment Group", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/envgroup/envgroup.go b/cmd/envgroup/envgroup.go index 0044327ad..a4fae1cfa 100644 --- a/cmd/envgroup/envgroup.go +++ b/cmd/envgroup/envgroup.go @@ -26,13 +26,15 @@ var Cmd = &cobra.Command{ } var ( - org, name, environment string - hostnames []string + org, name, environment, region string + hostnames []string ) func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(AttachCmd) Cmd.AddCommand(CreateCmd) diff --git a/cmd/envgroup/getenvgroup.go b/cmd/envgroup/getenvgroup.go index 81b745c12..e0d3df9f2 100644 --- a/cmd/envgroup/getenvgroup.go +++ b/cmd/envgroup/getenvgroup.go @@ -28,6 +28,7 @@ var GetCmd = &cobra.Command{ Short: "Gets an Environment Group", Long: "Gets an Environment Group", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/envgroup/listattach.go b/cmd/envgroup/listattach.go index e6f3c78d4..58f743f8f 100644 --- a/cmd/envgroup/listattach.go +++ b/cmd/envgroup/listattach.go @@ -28,6 +28,7 @@ var ListAttachCmd = &cobra.Command{ Short: "List attachments of an Environment Group", Long: "List attachments of an Environment Group", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/envgroup/listenvgroup.go b/cmd/envgroup/listenvgroup.go index 9d9a0cc68..f66a4d374 100644 --- a/cmd/envgroup/listenvgroup.go +++ b/cmd/envgroup/listenvgroup.go @@ -28,6 +28,7 @@ var ListCmd = &cobra.Command{ Short: "Returns a list of environment groups", Long: "Returns a list of environment groups", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/envgroup/updateenvgroup.go b/cmd/envgroup/updateenvgroup.go index 46f97aa96..53dc0e734 100644 --- a/cmd/envgroup/updateenvgroup.go +++ b/cmd/envgroup/updateenvgroup.go @@ -28,6 +28,7 @@ var UpdateCmd = &cobra.Command{ Short: "Update hostnames in an Environment Group", Long: "Update hostnames in an Environment Group", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/eptattachment/crteptattachment.go b/cmd/eptattachment/crteptattachment.go index a12e99d34..2ea1cc011 100644 --- a/cmd/eptattachment/crteptattachment.go +++ b/cmd/eptattachment/crteptattachment.go @@ -31,6 +31,7 @@ var CreateCmd = &cobra.Command{ Short: "Create a new service endpoint", Long: "Create a new service endpoint in Apigee for a service attachment", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/eptattachment/deleptattachment.go b/cmd/eptattachment/deleptattachment.go index e677ff1e7..0fd713139 100644 --- a/cmd/eptattachment/deleptattachment.go +++ b/cmd/eptattachment/deleptattachment.go @@ -28,6 +28,7 @@ var RemoveCmd = &cobra.Command{ Short: "Delete a service endpoint", Long: "Delete a service endpoint", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/eptattachment/eptattachment.go b/cmd/eptattachment/eptattachment.go index ab9900030..f6831f4e5 100644 --- a/cmd/eptattachment/eptattachment.go +++ b/cmd/eptattachment/eptattachment.go @@ -26,11 +26,13 @@ var Cmd = &cobra.Command{ Long: "Manage Service Endpoints for PSC Consumers in Apigee", } -var org, name string +var org, name, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(CreateCmd) Cmd.AddCommand(ListCmd) diff --git a/cmd/eptattachment/geteptattachment.go b/cmd/eptattachment/geteptattachment.go index f19ff0cf7..4cd11829b 100644 --- a/cmd/eptattachment/geteptattachment.go +++ b/cmd/eptattachment/geteptattachment.go @@ -28,6 +28,7 @@ var GetCmd = &cobra.Command{ Short: "Get a service endpoint", Long: "Get a service endpoint", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/eptattachment/listeptattachment.go b/cmd/eptattachment/listeptattachment.go index 355e28575..cdc134bb2 100644 --- a/cmd/eptattachment/listeptattachment.go +++ b/cmd/eptattachment/listeptattachment.go @@ -28,6 +28,7 @@ var ListCmd = &cobra.Command{ Short: "List of service endpoints", Long: "Lists of service endpoints", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/flowhooks/crtfh.go b/cmd/flowhooks/crtfh.go index c190f50e3..d859ac137 100644 --- a/cmd/flowhooks/crtfh.go +++ b/cmd/flowhooks/crtfh.go @@ -29,6 +29,7 @@ var CreateCmd = &cobra.Command{ Long: "Attach a flowhook", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/flowhooks/delfh.go b/cmd/flowhooks/delfh.go index 4bfaa66a9..16d3c8612 100644 --- a/cmd/flowhooks/delfh.go +++ b/cmd/flowhooks/delfh.go @@ -29,6 +29,7 @@ var DelCmd = &cobra.Command{ Long: "Detach a flowhook", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/flowhooks/flowhooks.go b/cmd/flowhooks/flowhooks.go index 969165f42..0afb00b51 100644 --- a/cmd/flowhooks/flowhooks.go +++ b/cmd/flowhooks/flowhooks.go @@ -26,13 +26,15 @@ var Cmd = &cobra.Command{ Long: "Manage Flowhooks", } -var org, env, name string +var org, env, name, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") Cmd.PersistentFlags().StringVarP(&env, "env", "e", "", "Apigee environment name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") _ = Cmd.MarkPersistentFlagRequired("env") diff --git a/cmd/flowhooks/getfh.go b/cmd/flowhooks/getfh.go index 163614a02..5db167764 100644 --- a/cmd/flowhooks/getfh.go +++ b/cmd/flowhooks/getfh.go @@ -29,6 +29,7 @@ var GetCmd = &cobra.Command{ Long: "Get a flowhook", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/flowhooks/listfh.go b/cmd/flowhooks/listfh.go index c6727a6d5..30b95a760 100644 --- a/cmd/flowhooks/listfh.go +++ b/cmd/flowhooks/listfh.go @@ -29,6 +29,7 @@ var ListCmd = &cobra.Command{ Long: "List Flowhooks", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/iam/create.go b/cmd/iam/create.go index f7a0bae17..e7de6506a 100644 --- a/cmd/iam/create.go +++ b/cmd/iam/create.go @@ -53,7 +53,7 @@ func init() { "", "Service Account Name") CallCmd.Flags().BoolVarP(&generateName, "gen", "g", false, "Generate account name") - CallCmd.Flags().StringVarP(&roleType, "role", "r", + CallCmd.Flags().StringVarP(&roleType, "role", "", "", "IAM Role Type, must be one of: "+strings.Join(roles, ", ")) _ = CallCmd.MarkFlagRequired("prj") diff --git a/cmd/instances/activatenat.go b/cmd/instances/activatenat.go index 19f987674..2a290bf42 100644 --- a/cmd/instances/activatenat.go +++ b/cmd/instances/activatenat.go @@ -29,6 +29,7 @@ var ActivateNatCmd = &cobra.Command{ Long: "Activate NAT IP for an Apigee instance", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/instances/crtattachment.go b/cmd/instances/crtattachment.go index 49d5e0059..4829cf5a6 100644 --- a/cmd/instances/crtattachment.go +++ b/cmd/instances/crtattachment.go @@ -29,6 +29,7 @@ var CreateAttachCmd = &cobra.Command{ Long: "Attach an environment to an instance", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/instances/crtinstance.go b/cmd/instances/crtinstance.go index 42eee0651..e72096b5a 100644 --- a/cmd/instances/crtinstance.go +++ b/cmd/instances/crtinstance.go @@ -32,6 +32,7 @@ var CreateCmd = &cobra.Command{ Short: "Create an Instance", Long: "Create an Instance", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/instances/delattachment.go b/cmd/instances/delattachment.go index 6fd5725b4..c8606c3be 100644 --- a/cmd/instances/delattachment.go +++ b/cmd/instances/delattachment.go @@ -29,6 +29,7 @@ var DeleteAttachCmd = &cobra.Command{ Long: "Detach an environment from an instance", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/instances/deletenat.go b/cmd/instances/deletenat.go index d90c9216a..b4d85184f 100644 --- a/cmd/instances/deletenat.go +++ b/cmd/instances/deletenat.go @@ -29,6 +29,7 @@ var DeleteNatCmd = &cobra.Command{ Long: "Delete a NAT IP for an Apigee instance", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/instances/delinstance.go b/cmd/instances/delinstance.go index 3666ed0e2..9e246407d 100644 --- a/cmd/instances/delinstance.go +++ b/cmd/instances/delinstance.go @@ -28,6 +28,7 @@ var DeleteCmd = &cobra.Command{ Short: "Delete an Instance", Long: "Delete an Instance", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/instances/getattachment.go b/cmd/instances/getattachment.go index 9d14a8441..994c4686f 100644 --- a/cmd/instances/getattachment.go +++ b/cmd/instances/getattachment.go @@ -29,6 +29,7 @@ var GetAttachCmd = &cobra.Command{ Long: "Get attachment details for an instance", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/instances/getinstance.go b/cmd/instances/getinstance.go index 74b71742a..3b17262b3 100644 --- a/cmd/instances/getinstance.go +++ b/cmd/instances/getinstance.go @@ -28,6 +28,7 @@ var GetCmd = &cobra.Command{ Short: "Get an Instance", Long: "Get an Instance", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/instances/instances.go b/cmd/instances/instances.go index 9cc139596..853864ff5 100644 --- a/cmd/instances/instances.go +++ b/cmd/instances/instances.go @@ -25,11 +25,13 @@ var Cmd = &cobra.Command{ Long: "Manage Apigee runtime instances", } -var org, name, location string +var org, name, location, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(CreateCmd) Cmd.AddCommand(ListCmd) diff --git a/cmd/instances/listattachments.go b/cmd/instances/listattachments.go index 9af26b593..06783745c 100644 --- a/cmd/instances/listattachments.go +++ b/cmd/instances/listattachments.go @@ -29,6 +29,7 @@ var ListAttachCmd = &cobra.Command{ Long: "List attachment details for an instance", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/instances/listintance.go b/cmd/instances/listintance.go index 10b5fddca..0f5438e64 100644 --- a/cmd/instances/listintance.go +++ b/cmd/instances/listintance.go @@ -28,6 +28,7 @@ var ListCmd = &cobra.Command{ Short: "Returns a list of environment groups", Long: "Returns a list of environment groups", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/instances/listnat.go b/cmd/instances/listnat.go index ac6872940..aa41b82ba 100644 --- a/cmd/instances/listnat.go +++ b/cmd/instances/listnat.go @@ -29,6 +29,7 @@ var ListNatCmd = &cobra.Command{ Long: "List NAT IPs for an Apigee instance", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/instances/reservenat.go b/cmd/instances/reservenat.go index bc8d8959e..1986db8d3 100644 --- a/cmd/instances/reservenat.go +++ b/cmd/instances/reservenat.go @@ -29,6 +29,7 @@ var ReserveNatCmd = &cobra.Command{ Long: "Reserve a NAT IP for an Apigeee instance", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/instances/updtinstance.go b/cmd/instances/updtinstance.go index c244af71b..eaa48f953 100644 --- a/cmd/instances/updtinstance.go +++ b/cmd/instances/updtinstance.go @@ -28,6 +28,7 @@ var UpdateCmd = &cobra.Command{ Short: "Update an Instance", Long: "Update an Instance", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/keyaliases/crtka.go b/cmd/keyaliases/crtka.go index c58d8c5bd..c30ec7eaf 100644 --- a/cmd/keyaliases/crtka.go +++ b/cmd/keyaliases/crtka.go @@ -47,6 +47,7 @@ var CreateCmd = &cobra.Command{ if selfFile != "" && !utils.FileExists(selfFile) { return fmt.Errorf("selfsigned JSON file was not found") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -100,13 +101,13 @@ func init() { false, "Ignore expiry validation") CreateCmd.Flags().BoolVarP(&ignoreNewLine, "nl", "w", false, "Ignore new line in cert chain") - CreateCmd.Flags().StringVarP(&certFile, "certFilePath", "", + CreateCmd.Flags().StringVarP(&certFile, "cert-filepath", "", "", "Path to the X509 certificate in PEM format") - CreateCmd.Flags().StringVarP(&keyFile, "keyFilePath", "", + CreateCmd.Flags().StringVarP(&keyFile, "key-filepath", "", "", "Path to the X509 key in PEM format") - CreateCmd.Flags().StringVarP(&pfxFile, "pfxFilePath", "", + CreateCmd.Flags().StringVarP(&pfxFile, "pfx-filepath", "", "", "Path to the PFX file") - CreateCmd.Flags().StringVarP(&selfFile, "selfsignedFilePath", "", + CreateCmd.Flags().StringVarP(&selfFile, "selfsigned-filepath", "", "", "Path to a JSON file containing details for a self signed certificate") _ = CreateCmd.MarkFlagRequired("alias") diff --git a/cmd/keyaliases/csr.go b/cmd/keyaliases/csr.go index 5ae5c71a4..fc98306b6 100644 --- a/cmd/keyaliases/csr.go +++ b/cmd/keyaliases/csr.go @@ -29,6 +29,7 @@ var CsrCmd = &cobra.Command{ Long: "Generates a PKCS #10 Certificate Signing Request for the private key in an alias", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/keyaliases/delka.go b/cmd/keyaliases/delka.go index ace83aa34..09ec0117c 100644 --- a/cmd/keyaliases/delka.go +++ b/cmd/keyaliases/delka.go @@ -29,6 +29,7 @@ var DelCmd = &cobra.Command{ Long: "Delete a Key Alias", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/keyaliases/getcert.go b/cmd/keyaliases/getcert.go index 4cb9005e1..c70589a21 100644 --- a/cmd/keyaliases/getcert.go +++ b/cmd/keyaliases/getcert.go @@ -29,6 +29,7 @@ var GetctCmd = &cobra.Command{ Long: "Get a Key alias certificate", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/keyaliases/getka.go b/cmd/keyaliases/getka.go index e3f9d00cb..e4f24362b 100644 --- a/cmd/keyaliases/getka.go +++ b/cmd/keyaliases/getka.go @@ -29,6 +29,7 @@ var GetCmd = &cobra.Command{ Long: "Get a Key Alias", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/keyaliases/keyaliases.go b/cmd/keyaliases/keyaliases.go index aa3bfbb6e..70a18d486 100644 --- a/cmd/keyaliases/keyaliases.go +++ b/cmd/keyaliases/keyaliases.go @@ -26,13 +26,15 @@ var Cmd = &cobra.Command{ Long: "Manage Key Aliases", } -var org, env, name, keystoreName, aliasName string +var org, env, name, keystoreName, aliasName, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") Cmd.PersistentFlags().StringVarP(&env, "env", "e", "", "Apigee environment name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") _ = Cmd.MarkPersistentFlagRequired("env") diff --git a/cmd/keyaliases/listka.go b/cmd/keyaliases/listka.go index 2788ba2d7..cd4ddaf15 100644 --- a/cmd/keyaliases/listka.go +++ b/cmd/keyaliases/listka.go @@ -29,6 +29,7 @@ var ListCmd = &cobra.Command{ Long: "List Key Alises", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/keyaliases/updateka.go b/cmd/keyaliases/updateka.go index 50d538286..df55666fe 100644 --- a/cmd/keyaliases/updateka.go +++ b/cmd/keyaliases/updateka.go @@ -35,6 +35,7 @@ var UpdateCmd = &cobra.Command{ if certFile != "" && !utils.FileExists(certFile) { return fmt.Errorf("certFile was not found") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -61,7 +62,7 @@ func init() { false, "Ignore expiry validation") UpdateCmd.Flags().BoolVarP(&ignoreNewLine, "nl", "w", false, "Ignore new line in cert chain") - UpdateCmd.Flags().StringVarP(&certFile, "certFilePath", "", + UpdateCmd.Flags().StringVarP(&certFile, "cert-filepath", "", "", "Path to the X509 certificate in PEM format") _ = UpdateCmd.MarkFlagRequired("alias") diff --git a/cmd/keystores/crtks.go b/cmd/keystores/crtks.go index 09c439e66..e8f7b3598 100644 --- a/cmd/keystores/crtks.go +++ b/cmd/keystores/crtks.go @@ -29,6 +29,7 @@ var CreateCmd = &cobra.Command{ Long: "Create a Key Store", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/keystores/delks.go b/cmd/keystores/delks.go index 7f4649041..b3313131b 100644 --- a/cmd/keystores/delks.go +++ b/cmd/keystores/delks.go @@ -29,6 +29,7 @@ var DelCmd = &cobra.Command{ Long: "Delete a Key Store", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/keystores/getks.go b/cmd/keystores/getks.go index 4922978cd..dbc474c1f 100644 --- a/cmd/keystores/getks.go +++ b/cmd/keystores/getks.go @@ -29,6 +29,7 @@ var GetCmd = &cobra.Command{ Long: "Get a Key Store", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/keystores/impks.go b/cmd/keystores/impks.go index 5ed7099c7..8adfe7e11 100644 --- a/cmd/keystores/impks.go +++ b/cmd/keystores/impks.go @@ -29,6 +29,7 @@ var ImpCmd = &cobra.Command{ Long: "Import a file containing keystores", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/keystores/keystores.go b/cmd/keystores/keystores.go index 55e092589..1480e7a3e 100644 --- a/cmd/keystores/keystores.go +++ b/cmd/keystores/keystores.go @@ -26,13 +26,15 @@ var Cmd = &cobra.Command{ Long: "Manage Key Stores", } -var org, env, name string +var org, env, name, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") Cmd.PersistentFlags().StringVarP(&env, "env", "e", "", "Apigee environment name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") _ = Cmd.MarkPersistentFlagRequired("env") diff --git a/cmd/keystores/listks.go b/cmd/keystores/listks.go index 320497014..f3f890f3e 100644 --- a/cmd/keystores/listks.go +++ b/cmd/keystores/listks.go @@ -29,6 +29,7 @@ var ListCmd = &cobra.Command{ Long: "List Key Stores", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/kvm/crtentry.go b/cmd/kvm/crtentry.go index 7b8accd05..ed2cd206e 100644 --- a/cmd/kvm/crtentry.go +++ b/cmd/kvm/crtentry.go @@ -36,6 +36,7 @@ var CreateEntryCmd = &cobra.Command{ if env != "" && proxyName != "" { return fmt.Errorf("proxy and env flags cannot be used together") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/kvm/crtkvm.go b/cmd/kvm/crtkvm.go index a5b8802c7..fc3a2c48f 100644 --- a/cmd/kvm/crtkvm.go +++ b/cmd/kvm/crtkvm.go @@ -36,6 +36,7 @@ var CreateCmd = &cobra.Command{ if env != "" && proxyName != "" { return fmt.Errorf("proxy and env flags cannot be used together") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/kvm/delentry.go b/cmd/kvm/delentry.go index 7f8599ae7..c2e9ed695 100644 --- a/cmd/kvm/delentry.go +++ b/cmd/kvm/delentry.go @@ -36,6 +36,7 @@ var DelEntryCmd = &cobra.Command{ if env != "" && proxyName != "" { return fmt.Errorf("proxy and env flags cannot be used together") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/kvm/delkvm.go b/cmd/kvm/delkvm.go index a6a8bb3c6..1dffd9735 100644 --- a/cmd/kvm/delkvm.go +++ b/cmd/kvm/delkvm.go @@ -36,6 +36,7 @@ var DelCmd = &cobra.Command{ if env != "" && proxyName != "" { return fmt.Errorf("proxy and env flags cannot be used together") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/kvm/expentries.go b/cmd/kvm/expentries.go index 9906e79f8..28e34b400 100644 --- a/cmd/kvm/expentries.go +++ b/cmd/kvm/expentries.go @@ -38,6 +38,7 @@ var ExpEntryCmd = &cobra.Command{ if env != "" && proxyName != "" { return fmt.Errorf("proxy and env flags cannot be used together") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/kvm/expkvm.go b/cmd/kvm/expkvm.go index e22dc9ad0..ae9445b2d 100644 --- a/cmd/kvm/expkvm.go +++ b/cmd/kvm/expkvm.go @@ -40,6 +40,7 @@ var ExpCmd = &cobra.Command{ if env != "" && proxyName != "" { return fmt.Errorf("proxy and env flags cannot be used together") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/kvm/getentry.go b/cmd/kvm/getentry.go index 75abfb53c..1667bbd75 100644 --- a/cmd/kvm/getentry.go +++ b/cmd/kvm/getentry.go @@ -36,6 +36,7 @@ var GetEntryCmd = &cobra.Command{ if env != "" && proxyName != "" { return fmt.Errorf("proxy and env flags cannot be used together") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/kvm/impentries.go b/cmd/kvm/impentries.go index 07e0415a6..0aa1f53b7 100644 --- a/cmd/kvm/impentries.go +++ b/cmd/kvm/impentries.go @@ -36,6 +36,7 @@ var ImpEntryCmd = &cobra.Command{ if env != "" && proxyName != "" { return fmt.Errorf("proxy and env flags cannot be used together") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/kvm/impkvms.go b/cmd/kvm/impkvms.go index 3e2d79a05..41c4ceb1b 100644 --- a/cmd/kvm/impkvms.go +++ b/cmd/kvm/impkvms.go @@ -33,6 +33,7 @@ var ImpCmd = &cobra.Command{ Short: "Import KVM Entries from a folder containing KVM files", Long: "Import KVM Entries from a folder containing KVM files", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/kvm/kvm.go b/cmd/kvm/kvm.go index adedfe39f..0d9597a5e 100644 --- a/cmd/kvm/kvm.go +++ b/cmd/kvm/kvm.go @@ -25,11 +25,13 @@ var Cmd = &cobra.Command{ Long: "Manage Key Value Maps", } -var org, env, name, proxyName string +var org, env, name, proxyName, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(ListCmd) Cmd.AddCommand(DelCmd) diff --git a/cmd/kvm/listentry.go b/cmd/kvm/listentry.go index 9aa94052c..f0bbe22aa 100644 --- a/cmd/kvm/listentry.go +++ b/cmd/kvm/listentry.go @@ -36,6 +36,7 @@ var ListEntryCmd = &cobra.Command{ if env != "" && proxyName != "" { return fmt.Errorf("proxy and env flags cannot be used together") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/kvm/listkvm.go b/cmd/kvm/listkvm.go index d79e56f84..305810fee 100644 --- a/cmd/kvm/listkvm.go +++ b/cmd/kvm/listkvm.go @@ -36,6 +36,7 @@ var ListCmd = &cobra.Command{ if env != "" && proxyName != "" { return fmt.Errorf("proxy and env flags cannot be used together") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/ops/getops.go b/cmd/ops/getops.go index a7f96376c..c69749fc7 100644 --- a/cmd/ops/getops.go +++ b/cmd/ops/getops.go @@ -28,6 +28,7 @@ var GetCmd = &cobra.Command{ Short: "Get operation of an org", Long: "Get operation of an org", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/ops/listops.go b/cmd/ops/listops.go index ee8240393..baff29293 100644 --- a/cmd/ops/listops.go +++ b/cmd/ops/listops.go @@ -39,6 +39,7 @@ var ListCmd = &cobra.Command{ if state != "IN_PROGRESS" && state != "FINISHED" && state != "ERROR" { return fmt.Errorf("state must be oneOf IN_PROGRESS, FINISHED or ERROR") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -61,6 +62,6 @@ var ( func init() { ListCmd.Flags().StringVarP(&state, "state", "s", "", "filter by operation state: FINISHED, ERROR, IN_PROGRESS") - ListCmd.Flags().StringVarP(&completeState, "completeState", "c", + ListCmd.Flags().StringVarP(&completeState, "complete-state", "c", "", "filter by operation compeleted state: Success, Failed or Both") } diff --git a/cmd/ops/ops.go b/cmd/ops/ops.go index d22ef7dcd..0d3a4375a 100644 --- a/cmd/ops/ops.go +++ b/cmd/ops/ops.go @@ -26,11 +26,13 @@ var Cmd = &cobra.Command{ Long: "View Apigee Operations", } -var org string +var org, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(ListCmd) Cmd.AddCommand(GetCmd) diff --git a/cmd/org/createorg.go b/cmd/org/createorg.go index 10feb9b8b..731555a3a 100644 --- a/cmd/org/createorg.go +++ b/cmd/org/createorg.go @@ -66,7 +66,7 @@ var ( func init() { CreateCmd.Flags().StringVarP(&description, "desc", "d", "", "Apigee org description") - CreateCmd.Flags().StringVarP(&analyticsRegion, "reg", "r", + CreateCmd.Flags().StringVarP(&analyticsRegion, "reg", "", "", "Analytics region name") CreateCmd.Flags().BoolVarP(&disableVpcPeering, "disable-vpc-peering", "", true, "Disable VPC Peering; default true") diff --git a/cmd/org/delorg.go b/cmd/org/delorg.go index ec4ba4d6d..da61f8505 100644 --- a/cmd/org/delorg.go +++ b/cmd/org/delorg.go @@ -41,6 +41,6 @@ var retention string func init() { DelCmd.Flags().StringVarP(&org, "org", "o", "", "Apigee organization name") - DelCmd.Flags().StringVarP(&retention, "retension", "r", + DelCmd.Flags().StringVarP(&retention, "retension", "", "", "Retention period for soft-delete; Must be MINIMUM or DELETION_RETENTION_UNSPECIFIED") } diff --git a/cmd/org/export.go b/cmd/org/export.go index 2aa5912dd..faf9c03ce 100644 --- a/cmd/org/export.go +++ b/cmd/org/export.go @@ -304,14 +304,14 @@ func init() { 4, "Number of connections") /*ExportCmd.Flags().StringVarP(&folder, "folder", "f", "", "Folder to export org data")*/ - ExportCmd.Flags().BoolVarP(&exportEntries, "exportEntries", "", + ExportCmd.Flags().BoolVarP(&exportEntries, "export-entries", "", true, "Export all KVM entries") ExportCmd.Flags().BoolVarP(&cleanPath, "clean", "", false, "clean folder or files and directories before export") ExportCmd.Flags().BoolVarP(&allRevisions, "all", "", false, "Export all revisions, default=false. Exports the latest revision."+ "Applies to proxies, sf and sec profiles") - ExportCmd.Flags().BoolVarP(&continueOnErr, "continueOnError", "", + ExportCmd.Flags().BoolVarP(&continueOnErr, "continue-on-error", "", false, "Ignore errors and continue exporting data") } diff --git a/cmd/org/import.go b/cmd/org/import.go index ea564a781..b9eb16f2a 100644 --- a/cmd/org/import.go +++ b/cmd/org/import.go @@ -228,9 +228,9 @@ func init() { 4, "Number of connections") ImportCmd.Flags().StringVarP(&folder, "folder", "f", "", "folder containing API proxy bundles") - ImportCmd.Flags().BoolVarP(&importTrace, "importTrace", "", + ImportCmd.Flags().BoolVarP(&importTrace, "import-trace", "", false, "Import distributed trace configuration; default false") - ImportCmd.Flags().BoolVarP(&importDebugmask, "importDebugmask", "", + ImportCmd.Flags().BoolVarP(&importDebugmask, "import-debugmask", "", false, "Import debugmask configuration; default false") _ = ImportCmd.MarkFlagRequired("folder") diff --git a/cmd/preferences/setpref.go b/cmd/preferences/setpref.go index 9c6a63fdd..bf4001f1f 100644 --- a/cmd/preferences/setpref.go +++ b/cmd/preferences/setpref.go @@ -44,13 +44,19 @@ var SetCmd = &cobra.Command{ } } - return apiclient.SetStaging(usestage) + if region != "" { + if err = apiclient.WriteDefaultRegion(region); err != nil { + return err + } + } + + return nil }, } var ( - org, proxyURL, gitHubURL string - usestage, nocheck bool + org, region, proxyURL, gitHubURL string + usestage, nocheck bool ) func init() { @@ -68,4 +74,7 @@ func init() { SetCmd.Flags().StringVarP(&gitHubURL, "github", "g", "", "On premises Github URL") + + SetCmd.Flags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region") } diff --git a/cmd/products/crtprod.go b/cmd/products/crtprod.go index 470428dd5..b55cf96f4 100644 --- a/cmd/products/crtprod.go +++ b/cmd/products/crtprod.go @@ -28,6 +28,7 @@ var CreateCmd = &cobra.Command{ Short: "Create an API product", Long: "Create an API product", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -72,7 +73,7 @@ var operationGroupFile, gqlOperationGroupFile, grpcOperationGroupFile string func init() { CreateCmd.Flags().StringVarP(&name, "name", "n", "", "Name of the API Product") - CreateCmd.Flags().StringVarP(&displayName, "displayname", "m", + CreateCmd.Flags().StringVarP(&displayName, "display-name", "m", "", "Display Name of the API Product") CreateCmd.Flags().StringVarP(&description, "desc", "d", "", "Description for the API Product") diff --git a/cmd/products/crtrateplan.go b/cmd/products/crtrateplan.go index 541c5d85b..c36321706 100644 --- a/cmd/products/crtrateplan.go +++ b/cmd/products/crtrateplan.go @@ -32,6 +32,7 @@ var CreateRateplanCmd = &cobra.Command{ Short: "Create a rate plan for an API product", Long: "Create a rate plan for an API product", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/products/delattrprod.go b/cmd/products/delattrprod.go index f5e74c933..8d88b9f18 100644 --- a/cmd/products/delattrprod.go +++ b/cmd/products/delattrprod.go @@ -28,6 +28,7 @@ var DelAttrCmd = &cobra.Command{ Short: "Deletes an attribute from an API product", Long: "Deletes an attribute from an API product", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/products/delprod.go b/cmd/products/delprod.go index 9505ffe03..678d33094 100644 --- a/cmd/products/delprod.go +++ b/cmd/products/delprod.go @@ -28,6 +28,7 @@ var DelCmd = &cobra.Command{ Short: "Deletes an API product from an organization", Long: "Deletes an API product from an organization", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/products/delrateplan.go b/cmd/products/delrateplan.go index 6c707c16c..3ea0d7dfd 100644 --- a/cmd/products/delrateplan.go +++ b/cmd/products/delrateplan.go @@ -28,6 +28,7 @@ var DelRatePlanCmd = &cobra.Command{ Short: "Delete rate plan associated with the API Product", Long: "Delete rate plan associated with the API Product", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -39,7 +40,7 @@ var DelRatePlanCmd = &cobra.Command{ func init() { DelRatePlanCmd.Flags().StringVarP(&name, "name", "n", "", "name of the API Product") - DelRatePlanCmd.Flags().StringVarP(&rateplan, "rateplan", "r", + DelRatePlanCmd.Flags().StringVarP(&rateplan, "rateplan", "p", "", "name of the API Product") _ = DelRatePlanCmd.MarkFlagRequired("name") diff --git a/cmd/products/expprod.go b/cmd/products/expprod.go index ddadd04e0..f369396c4 100644 --- a/cmd/products/expprod.go +++ b/cmd/products/expprod.go @@ -28,6 +28,7 @@ var ExpCmd = &cobra.Command{ Short: "Export API products to a file", Long: "Export API products to a file", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/products/exprateplan.go b/cmd/products/exprateplan.go index 8ee0f4caa..ffc7b3e91 100644 --- a/cmd/products/exprateplan.go +++ b/cmd/products/exprateplan.go @@ -28,6 +28,7 @@ var ExpRateplanCmd = &cobra.Command{ Short: "Export the rate plans of an API product to a file", Long: "Export the rate plans of an API product to a file", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/products/getattrprod.go b/cmd/products/getattrprod.go index c9fdb3843..e1ae2899b 100644 --- a/cmd/products/getattrprod.go +++ b/cmd/products/getattrprod.go @@ -28,6 +28,7 @@ var GetAttrCmd = &cobra.Command{ Short: "Get an attribute of an API product", Long: "Get an attribute of an API product", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/products/getprod.go b/cmd/products/getprod.go index 97f31dea9..b507dd99a 100644 --- a/cmd/products/getprod.go +++ b/cmd/products/getprod.go @@ -28,6 +28,7 @@ var GetCmd = &cobra.Command{ Short: "Gets an API product from an organization", Long: "Gets an API product from an organization", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/products/getrateplan.go b/cmd/products/getrateplan.go index f22411fef..a01953a2a 100644 --- a/cmd/products/getrateplan.go +++ b/cmd/products/getrateplan.go @@ -28,6 +28,7 @@ var GetRatePlanCmd = &cobra.Command{ Short: "Get a rate plan associated with an API Product", Long: "Get a rate plan associated with an API Product", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -39,7 +40,7 @@ var GetRatePlanCmd = &cobra.Command{ func init() { GetRatePlanCmd.Flags().StringVarP(&name, "name", "n", "", "name of the API Product") - GetRatePlanCmd.Flags().StringVarP(&rateplan, "rateplan", "r", + GetRatePlanCmd.Flags().StringVarP(&rateplan, "rateplan", "p", "", "name of the API Product") _ = GetRatePlanCmd.MarkFlagRequired("name") diff --git a/cmd/products/impprod.go b/cmd/products/impprod.go index 7e1857f43..1499fc23e 100644 --- a/cmd/products/impprod.go +++ b/cmd/products/impprod.go @@ -28,6 +28,7 @@ var ImpCmd = &cobra.Command{ Short: "Import a file containing API products", Long: "Import a file containing API products", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/products/listattrprod.go b/cmd/products/listattrprod.go index 3d44b3c86..c60bf8346 100644 --- a/cmd/products/listattrprod.go +++ b/cmd/products/listattrprod.go @@ -28,6 +28,7 @@ var ListAttrCmd = &cobra.Command{ Short: "List attributes of an API product", Long: "List attributes of an API product", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/products/listproducts.go b/cmd/products/listproducts.go index 14062a763..f9f31fb5d 100644 --- a/cmd/products/listproducts.go +++ b/cmd/products/listproducts.go @@ -37,6 +37,7 @@ var ListCmd = &cobra.Command{ return fmt.Errorf("invalid filter options. Filter option must be proxies, " + "expand must be set to true and count cannot be set") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/products/listrateplan.go b/cmd/products/listrateplan.go index 5d9e227e3..4cd6e0e64 100644 --- a/cmd/products/listrateplan.go +++ b/cmd/products/listrateplan.go @@ -28,6 +28,7 @@ var ListRatePlanCmd = &cobra.Command{ Short: "List rate plans associated with an API Product", Long: "List rate plans associated with an API Product", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/products/products.go b/cmd/products/products.go index 8c80bb65e..a35567fca 100644 --- a/cmd/products/products.go +++ b/cmd/products/products.go @@ -34,8 +34,8 @@ var Cmd = &cobra.Command{ } var ( - org, name string - conn int + org, name, region string + conn int ) var ( @@ -47,6 +47,8 @@ var ( func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(ListCmd) Cmd.AddCommand(GetCmd) diff --git a/cmd/products/updattrprod.go b/cmd/products/updattrprod.go index a9f21b386..5ddc4f917 100644 --- a/cmd/products/updattrprod.go +++ b/cmd/products/updattrprod.go @@ -28,6 +28,7 @@ var UpdAttrCmd = &cobra.Command{ Short: "Update an attribute of an API product", Long: "Update an attribute of an API product", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/products/updprod.go b/cmd/products/updprod.go index 18013ea83..10ef40885 100644 --- a/cmd/products/updprod.go +++ b/cmd/products/updprod.go @@ -28,6 +28,7 @@ var UpdateCmd = &cobra.Command{ Short: "Update an API product", Long: "Update an API product", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -70,7 +71,7 @@ var UpdateCmd = &cobra.Command{ func init() { UpdateCmd.Flags().StringVarP(&name, "name", "n", "", "Name of the API Product") - UpdateCmd.Flags().StringVarP(&displayName, "displayname", "m", + UpdateCmd.Flags().StringVarP(&displayName, "display-name", "m", "", "Display Name of the API Product") UpdateCmd.Flags().StringVarP(&description, "desc", "d", "", "Description for the API Product") diff --git a/cmd/references/crtref.go b/cmd/references/crtref.go index 300881145..8d40300a5 100644 --- a/cmd/references/crtref.go +++ b/cmd/references/crtref.go @@ -50,7 +50,7 @@ func init() { "", "Description for the reference") CreateCmd.Flags().StringVarP(&resourceType, "restype", "s", "", "Resource type must be KeyStore or TrustStore") - CreateCmd.Flags().StringVarP(&refers, "refers", "r", + CreateCmd.Flags().StringVarP(&refers, "refers", "", "", "The id of the resource to which this reference refers") _ = CreateCmd.MarkFlagRequired("name") diff --git a/cmd/references/references.go b/cmd/references/references.go index 278817b05..3f0699f7a 100644 --- a/cmd/references/references.go +++ b/cmd/references/references.go @@ -26,7 +26,7 @@ var Cmd = &cobra.Command{ Long: "Manage References. References must refer to a keystore that also exists in the env.", } -var org, env, name, description, refers, resourceType string +var org, env, name, description, refers, resourceType, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", @@ -35,6 +35,9 @@ func init() { Cmd.PersistentFlags().StringVarP(&env, "env", "e", "", "Apigee environment name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") + _ = Cmd.MarkPersistentFlagRequired("env") Cmd.AddCommand(ListCmd) diff --git a/cmd/references/updateref.go b/cmd/references/updateref.go index f61fd075a..af6bad002 100644 --- a/cmd/references/updateref.go +++ b/cmd/references/updateref.go @@ -49,7 +49,7 @@ func init() { "", "Description for the reference") UpdateCmd.Flags().StringVarP(&resourceType, "restype", "s", "", "Resource type must be KeyStore or TrustStore") - UpdateCmd.Flags().StringVarP(&refers, "refers", "r", + UpdateCmd.Flags().StringVarP(&refers, "refers", "", "", "The id of the resource to which this reference refers") _ = UpdateCmd.MarkFlagRequired("name") diff --git a/cmd/registry/apis/apis.go b/cmd/registry/apis/apis.go new file mode 100644 index 000000000..8e29d8c3b --- /dev/null +++ b/cmd/registry/apis/apis.go @@ -0,0 +1,44 @@ +// 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 apis + +import ( + "github.com/apigee/apigeecli/cmd/registry/apis/artifacts" + "github.com/apigee/apigeecli/cmd/registry/apis/deployments" + "github.com/apigee/apigeecli/cmd/registry/apis/versions" + "github.com/spf13/cobra" +) + +// APICmd to manage apis +var APICmd = &cobra.Command{ + Use: "apis", + Short: "Manage APIs in Apigee Registry", + Long: "Manage APIs in Apigee Registry", +} + +var ( + name string + labels, annotations map[string]string +) + +func init() { + APICmd.AddCommand(CreateAPICmd) + APICmd.AddCommand(GetAPICmd) + APICmd.AddCommand(DelAPICmd) + APICmd.AddCommand(ListAPICmd) + APICmd.AddCommand(deployments.APIDeploymentCmd) + APICmd.AddCommand(versions.APIVersionCmd) + APICmd.AddCommand(artifacts.APIArtifactCmd) +} diff --git a/cmd/registry/apis/artifacts/artifacts.go b/cmd/registry/apis/artifacts/artifacts.go new file mode 100644 index 000000000..676d905e6 --- /dev/null +++ b/cmd/registry/apis/artifacts/artifacts.go @@ -0,0 +1,33 @@ +// 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 artifacts + +import ( + "github.com/spf13/cobra" +) + +// APIArtifactCmd to manage apis +var APIArtifactCmd = &cobra.Command{ + Use: "artifacts", + Short: "Manage artifacts for an API", + Long: "Manage artifacts for an API in Apigee Registry", +} + +func init() { + APIArtifactCmd.AddCommand(ListAPIArtifactCmd) + APIArtifactCmd.AddCommand(CreateArtifactCmd) + APIArtifactCmd.AddCommand(DelArtifactCmd) + APIArtifactCmd.AddCommand(GetArtifactCmd) +} diff --git a/cmd/registry/apis/artifacts/crtartifact.go b/cmd/registry/apis/artifacts/crtartifact.go new file mode 100644 index 000000000..714e892cc --- /dev/null +++ b/cmd/registry/apis/artifacts/crtartifact.go @@ -0,0 +1,70 @@ +// 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 artifacts + +import ( + "encoding/base64" + + "internal/apiclient" + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// CreateArtifactCmd to create a new instance +var CreateArtifactCmd = &cobra.Command{ + Use: "create", + Short: "Create an artifact for an API", + Long: "Create an artifact for an API Apigee Registry Instance", + 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) { + var payload []byte + if payload, err = utils.ReadFile(contentsFile); err != nil { + return err + } + contents := base64.StdEncoding.EncodeToString(payload) + _, err = apis.CreateArtifact(apiName, artifactID, name, contents, labels, annotations) + return err + }, +} + +var ( + name, artifactID, contentsFile string + labels, annotations map[string]string +) + +func init() { + CreateArtifactCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "Apigee Registry API Name") + CreateArtifactCmd.Flags().StringVarP(&artifactID, "id", "i", + "", "Apigee Registry Artifact ID") + CreateArtifactCmd.Flags().StringVarP(&name, "name", "n", + "", "Name of the Artifact") + CreateArtifactCmd.Flags().StringVarP(&contentsFile, "file", "f", + "", "Path to a file containing Artifact Contents") + CreateArtifactCmd.Flags().StringToStringVar(&labels, "labels", + nil, "Labels attach identifying metadata to resources") + CreateArtifactCmd.Flags().StringToStringVar(&annotations, "annotations", + nil, "Annotations attach non-identifying metadata to resources") + + _ = CreateArtifactCmd.MarkFlagRequired("id") + _ = CreateArtifactCmd.MarkFlagRequired("name") + _ = CreateArtifactCmd.MarkFlagRequired("file") +} diff --git a/cmd/registry/apis/artifacts/delartifact.go b/cmd/registry/apis/artifacts/delartifact.go new file mode 100644 index 000000000..55c7bd4ce --- /dev/null +++ b/cmd/registry/apis/artifacts/delartifact.go @@ -0,0 +1,51 @@ +// 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 artifacts + +import ( + "internal/apiclient" + + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// DelArtifactCmd to get instance +var DelArtifactCmd = &cobra.Command{ + Use: "delete", + Short: "Delete artifact for an API from Apigee Registry", + Long: "Delete artifact for an API from 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) { + _, err = apis.DeleteArtifact(apiName, name) + return + }, +} +var apiName string + +func init() { + DelArtifactCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + DelArtifactCmd.Flags().StringVarP(&name, "name", "n", + "", "Artifact Name") + + _ = DelArtifactCmd.MarkFlagRequired("api-name") + _ = DelArtifactCmd.MarkFlagRequired("name") +} diff --git a/cmd/registry/apis/artifacts/getartifact.go b/cmd/registry/apis/artifacts/getartifact.go new file mode 100644 index 000000000..49995a0b3 --- /dev/null +++ b/cmd/registry/apis/artifacts/getartifact.go @@ -0,0 +1,57 @@ +// 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 artifacts + +import ( + "internal/apiclient" + + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// GetArtifactCmd to get instance +var GetArtifactCmd = &cobra.Command{ + Use: "get", + Short: "Get Artifact details for an API", + Long: "Get Artifact details for an API", + 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) { + if content { + return apis.GetArtifactContents(apiName, name) + } + _, err = apis.GetArtifact(apiName, name) + return + }, +} + +var content bool + +func init() { + GetArtifactCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "Apigee Registry API Name") + GetArtifactCmd.Flags().StringVarP(&name, "name", "n", + "", "Artifact Name") + GetArtifactCmd.Flags().BoolVarP(&content, "content", "c", + false, "If set to true, returns artifact contents") + + _ = GetArtifactCmd.MarkFlagRequired("api-name") + _ = GetArtifactCmd.MarkFlagRequired("name") +} diff --git a/cmd/registry/apis/artifacts/listartifacts.go b/cmd/registry/apis/artifacts/listartifacts.go new file mode 100644 index 000000000..9c8273fb6 --- /dev/null +++ b/cmd/registry/apis/artifacts/listartifacts.go @@ -0,0 +1,58 @@ +// 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 artifacts + +import ( + "internal/apiclient" + + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// ListAPIArtifactCmd to get instance +var ListAPIArtifactCmd = &cobra.Command{ + Use: "list", + Short: "List all artifacts for an API", + Long: "List all artifacts for an API 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) { + _, err = apis.ListArtifacts(apiName, pageSize, pageToken, filter, orderBy) + return + }, +} + +var ( + pageToken, filter, orderBy string + pageSize int +) + +func init() { + ListAPIArtifactCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "Apigee Registry API Name") + ListAPIArtifactCmd.Flags().StringVarP(&pageToken, "page-token", "", + "", "A page token, received from a previous list call") + ListAPIArtifactCmd.Flags().StringVarP(&filter, "filter", "", + "", "An expression that can be used to filter the list") + ListAPIArtifactCmd.Flags().StringVarP(&orderBy, "order-by", "", + "", "A comma-separated list of fields to be sorted; ex: foo desc") + + _ = ListAPIArtifactCmd.MarkFlagRequired("api-name") +} diff --git a/cmd/registry/apis/crtapis.go b/cmd/registry/apis/crtapis.go new file mode 100644 index 000000000..d7bb65a1e --- /dev/null +++ b/cmd/registry/apis/crtapis.go @@ -0,0 +1,67 @@ +// 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 apis + +import ( + "internal/apiclient" + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// CreateAPICmd to create a new instance +var CreateAPICmd = &cobra.Command{ + Use: "create", + Short: "Create an Apigee Registry API entity", + Long: "Create an Apigee Registry API entity", + 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) { + _, err = apis.Create(apiID, name, displayName, description, + availability, recommendedVersion, recommendedDeployment, + labels, annotations) + return err + }, +} + +var apiID, availability, recommendedDeployment, recommendedVersion, description, displayName string + +func init() { + CreateAPICmd.Flags().StringVarP(&apiID, "id", "i", + "", "Apigee Registry API ID") + CreateAPICmd.Flags().StringVarP(&name, "name", "n", + "", "Name of the API") + CreateAPICmd.Flags().StringVarP(&displayName, "display-name", "d", + "", "Human friendly display name of the API") + CreateAPICmd.Flags().StringVarP(&description, "desc", "", + "", "Description of the API") + CreateAPICmd.Flags().StringVarP(&recommendedVersion, "version", "v", + "", "The recommended version of the API; Format: projects/{project}/"+ + "locations/{location}/apis/{api}/versions/{version}") + CreateAPICmd.Flags().StringVarP(&recommendedDeployment, "deployment", "", + "", "The recommended deployment of the API; Format: projects/{project}/"+ + "locations/{location}/apis/{api}/deployments/{deployment}") + CreateAPICmd.Flags().StringToStringVar(&labels, "labels", + nil, "Labels attach identifying metadata to resources") + CreateAPICmd.Flags().StringToStringVar(&annotations, "annotations", + nil, "Annotations attach non-identifying metadata to resources") + + _ = CreateAPICmd.MarkFlagRequired("id") + _ = CreateAPICmd.MarkFlagRequired("name") +} diff --git a/cmd/registry/apis/delapis.go b/cmd/registry/apis/delapis.go new file mode 100644 index 000000000..144b2577c --- /dev/null +++ b/cmd/registry/apis/delapis.go @@ -0,0 +1,45 @@ +// 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 apis + +import ( + "internal/apiclient" + + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// DelAPICmd to get instance +var DelAPICmd = &cobra.Command{ + Use: "delete", + Short: "Delete Apigee Registry API", + Long: "Delete Apigee Registry API", + 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) { + _, err = apis.Delete(name) + return + }, +} + +func init() { + DelAPICmd.Flags().StringVarP(&name, "name", "n", + "", "Apigee Registry API Name") +} diff --git a/cmd/registry/apis/deployments/crtdeploy.go b/cmd/registry/apis/deployments/crtdeploy.go new file mode 100644 index 000000000..2071b2146 --- /dev/null +++ b/cmd/registry/apis/deployments/crtdeploy.go @@ -0,0 +1,75 @@ +// 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 deployments + +import ( + "internal/apiclient" + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// CreateDeployCmd to create a new instance +var CreateDeployCmd = &cobra.Command{ + Use: "create", + Short: "Create an Apigee Registry API entity", + Long: "Create an Apigee Registry API entity", + 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) { + _, err = apis.CreateDeployment(apiDeploymentID, name, displayName, description, + apiSpecRevision, endpointURI, externalChannelURI, intendedAudience, + accessGuidance, labels, annotations) + return err + }, +} + +var ( + apiDeploymentID, apiSpecRevision, endpointURI, externalChannelURI string + name, description, displayName, intendedAudience, accessGuidance string + labels, annotations map[string]string +) + +func init() { + CreateDeployCmd.Flags().StringVarP(&apiDeploymentID, "id", "i", + "", "Apigee Registry Deployment ID") + CreateDeployCmd.Flags().StringVarP(&name, "name", "n", + "", "Name of the Deployment") + CreateDeployCmd.Flags().StringVarP(&displayName, "display-name", "d", + "", "Human friendly display name of the Deployment") + CreateDeployCmd.Flags().StringVarP(&description, "desc", "", + "", "Description of the Deployment") + CreateDeployCmd.Flags().StringVarP(&apiSpecRevision, "spec-revision", "", + "", "API Spec Revision") + CreateDeployCmd.Flags().StringVarP(&endpointURI, "endpoint-uri", "", + "", "Endpoint URI for the API") + CreateDeployCmd.Flags().StringVarP(&apiSpecRevision, "external-channel-uri", "", + "", "External Channle URI") + CreateDeployCmd.Flags().StringVarP(&apiSpecRevision, "intended-audience", "", + "", "Intended Audience for the API") + CreateDeployCmd.Flags().StringVarP(&accessGuidance, "access-guidance", "", + "", "Guidance for accessing the API") + CreateDeployCmd.Flags().StringToStringVar(&labels, "labels", + nil, "Labels attach identifying metadata to resources") + CreateDeployCmd.Flags().StringToStringVar(&annotations, "annotations", + nil, "Annotations attach non-identifying metadata to resources") + + _ = CreateDeployCmd.MarkFlagRequired("id") + _ = CreateDeployCmd.MarkFlagRequired("name") +} diff --git a/cmd/registry/apis/deployments/deldeploy.go b/cmd/registry/apis/deployments/deldeploy.go new file mode 100644 index 000000000..431e14f12 --- /dev/null +++ b/cmd/registry/apis/deployments/deldeploy.go @@ -0,0 +1,60 @@ +// 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 deployments + +import ( + "internal/apiclient" + + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// DelDeployCmd to get instance +var DelDeployCmd = &cobra.Command{ + Use: "delete", + Short: "Delete deployment associated with an API", + Long: "Delete deployment associated with an API", + 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) { + if revision { + _, err = apis.DeleteDeploymentRevision(apiName, name) + return + } + _, err = apis.DeleteDeployment(apiName, name, force) + return + }, +} + +var force, revision bool + +func init() { + DelDeployCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + DelDeployCmd.Flags().StringVarP(&name, "name", "n", + "", "Deployment name") + DelDeployCmd.Flags().BoolVarP(&force, "force", "f", + false, "Deployment name") + DelDeployCmd.Flags().BoolVarP(&revision, "revision", "v", + false, "Delete a revision") + + _ = DelDeployCmd.MarkFlagRequired("api-name") + _ = DelDeployCmd.MarkFlagRequired("name") +} diff --git a/cmd/registry/apis/deployments/deployments.go b/cmd/registry/apis/deployments/deployments.go new file mode 100644 index 000000000..34442569f --- /dev/null +++ b/cmd/registry/apis/deployments/deployments.go @@ -0,0 +1,35 @@ +// 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 deployments + +import ( + "github.com/spf13/cobra" +) + +// APIDeploymentCmd to manage apis +var APIDeploymentCmd = &cobra.Command{ + Use: "deployments", + Short: "Manage API Deployments in Apigee Registry", + Long: "Manage API Deployments in Apigee Registry", +} + +func init() { + APIDeploymentCmd.AddCommand(ListDeployCmd) + APIDeploymentCmd.AddCommand(CreateDeployCmd) + APIDeploymentCmd.AddCommand(GetDeployCmd) + APIDeploymentCmd.AddCommand(DelDeployCmd) + APIDeploymentCmd.AddCommand(TagDeployCmd) + APIDeploymentCmd.AddCommand(RollbackDeployCmd) +} diff --git a/cmd/registry/apis/deployments/getdeploy.go b/cmd/registry/apis/deployments/getdeploy.go new file mode 100644 index 000000000..d547d9cc7 --- /dev/null +++ b/cmd/registry/apis/deployments/getdeploy.go @@ -0,0 +1,49 @@ +// 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 deployments + +import ( + "internal/apiclient" + + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// GetDeployCmd to get instance +var GetDeployCmd = &cobra.Command{ + Use: "get", + Short: "Get deployment details for an API", + Long: "Get deployment details for an API", + 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) { + _, err = apis.GetDeployment(apiName, name) + return + }, +} + +func init() { + GetDeployCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + GetDeployCmd.Flags().StringVarP(&name, "name", "n", + "", "Deployment name") + + _ = GetDeployCmd.MarkFlagRequired("api-name") +} diff --git a/cmd/registry/apis/deployments/listdeploy.go b/cmd/registry/apis/deployments/listdeploy.go new file mode 100644 index 000000000..cd2776702 --- /dev/null +++ b/cmd/registry/apis/deployments/listdeploy.go @@ -0,0 +1,64 @@ +// 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 deployments + +import ( + "internal/apiclient" + + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// ListDeployCmd to get instance +var ListDeployCmd = &cobra.Command{ + Use: "list", + Short: "List deployments for an API in Apigee Registry", + Long: "List deployments for an API 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) { + if name != "" { + _, err = apis.ListDeploymentRevisions(apiName, name, pageSize, pageToken, filter, orderBy) + return err + } + _, err = apis.ListDeployments(apiName, pageSize, pageToken, filter, orderBy) + return + }, +} + +var ( + apiName, pageToken, filter, orderBy string + pageSize int +) + +func init() { + ListDeployCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + ListDeployCmd.Flags().StringVarP(&name, "name", "n", + "", "Deployment Name") + ListDeployCmd.Flags().StringVarP(&pageToken, "page-token", "", + "", "A page token, received from a previous list call") + ListDeployCmd.Flags().StringVarP(&filter, "filter", "", + "", "An expression that can be used to filter the list") + ListDeployCmd.Flags().StringVarP(&orderBy, "order-by", "", + "", "A comma-separated list of fields to be sorted; ex: foo desc") + + _ = ListDeployCmd.MarkFlagRequired("api-name") +} diff --git a/cmd/registry/apis/deployments/rollbackdeploy.go b/cmd/registry/apis/deployments/rollbackdeploy.go new file mode 100644 index 000000000..f5c4f65b5 --- /dev/null +++ b/cmd/registry/apis/deployments/rollbackdeploy.go @@ -0,0 +1,55 @@ +// 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 deployments + +import ( + "internal/apiclient" + + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// RollbackDeployCmd to get instance +var RollbackDeployCmd = &cobra.Command{ + Use: "rollback", + Short: "Rollback deployment revision for an API", + Long: "Rollback deployment revision for an API", + 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) { + _, err = apis.Rollback(apiName, name, revisionID) + return + }, +} + +var revisionID string + +func init() { + RollbackDeployCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + RollbackDeployCmd.Flags().StringVarP(&name, "name", "n", + "", "Deployment name") + RollbackDeployCmd.Flags().StringVarP(&revisionID, "revision-id", "", + "", "The tag to apply") + + _ = RollbackDeployCmd.MarkFlagRequired("api-name") + _ = RollbackDeployCmd.MarkFlagRequired("name") + _ = RollbackDeployCmd.MarkFlagRequired("revision-id") +} diff --git a/cmd/registry/apis/deployments/tagdeploy.go b/cmd/registry/apis/deployments/tagdeploy.go new file mode 100644 index 000000000..8af397043 --- /dev/null +++ b/cmd/registry/apis/deployments/tagdeploy.go @@ -0,0 +1,55 @@ +// 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 deployments + +import ( + "internal/apiclient" + + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// TagDeployCmd to get instance +var TagDeployCmd = &cobra.Command{ + Use: "tag", + Short: "Tag deployment revision for an API", + Long: "Tag deployment revision for an API", + 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) { + _, err = apis.Tag(apiName, name, tag) + return + }, +} + +var tag string + +func init() { + TagDeployCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + TagDeployCmd.Flags().StringVarP(&name, "name", "n", + "", "Deployment name") + TagDeployCmd.Flags().StringVarP(&tag, "tag", "", + "", "The tag to apply") + + _ = TagDeployCmd.MarkFlagRequired("api-name") + _ = TagDeployCmd.MarkFlagRequired("name") + _ = TagDeployCmd.MarkFlagRequired("tag") +} diff --git a/cmd/registry/apis/getapis.go b/cmd/registry/apis/getapis.go new file mode 100644 index 000000000..8cd8d05ea --- /dev/null +++ b/cmd/registry/apis/getapis.go @@ -0,0 +1,45 @@ +// 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 apis + +import ( + "internal/apiclient" + + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// GetAPICmd to get instance +var GetAPICmd = &cobra.Command{ + Use: "get", + Short: "Get Apigee Registry API details", + Long: "Get Apigee Registry API details", + 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) { + _, err = apis.Get(name) + return + }, +} + +func init() { + GetAPICmd.Flags().StringVarP(&name, "name", "n", + "", "Apigee Registry API Name") +} diff --git a/cmd/registry/apis/listapis.go b/cmd/registry/apis/listapis.go new file mode 100644 index 000000000..8bed566a2 --- /dev/null +++ b/cmd/registry/apis/listapis.go @@ -0,0 +1,54 @@ +// 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 apis + +import ( + "internal/apiclient" + + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// ListAPICmd to get instance +var ListAPICmd = &cobra.Command{ + Use: "list", + Short: "List all APIs in Apigee Registry", + Long: "List all APIs 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) { + _, err = apis.List(pageSize, pageToken, filter, orderBy) + return + }, +} + +var ( + pageToken, filter, orderBy string + pageSize int +) + +func init() { + ListAPICmd.Flags().StringVarP(&pageToken, "page-token", "", + "", "A page token, received from a previous list call") + ListAPICmd.Flags().StringVarP(&filter, "filter", "", + "", "An expression that can be used to filter the list") + ListAPICmd.Flags().StringVarP(&orderBy, "order-by", "", + "", "A comma-separated list of fields to be sorted; ex: foo desc") +} diff --git a/cmd/registry/apis/versions/artifacts/artifacts.go b/cmd/registry/apis/versions/artifacts/artifacts.go new file mode 100644 index 000000000..4e5db0cea --- /dev/null +++ b/cmd/registry/apis/versions/artifacts/artifacts.go @@ -0,0 +1,35 @@ +// 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 artifacts + +import ( + "github.com/spf13/cobra" +) + +// ArtifactCmd to manage apis +var ArtifactCmd = &cobra.Command{ + Use: "artifacts", + Short: "Manage artifacts for an API version", + Long: "Manage artifacts for an API version in Apigee Registry", +} + +var labels, annotations map[string]string + +func init() { + ArtifactCmd.AddCommand(CreateArtifactCmd) + ArtifactCmd.AddCommand(ListArtifactCmd) + ArtifactCmd.AddCommand(GetArtifactCmd) + ArtifactCmd.AddCommand(DelArtifactCmd) +} diff --git a/cmd/registry/apis/versions/artifacts/crtartifact.go b/cmd/registry/apis/versions/artifacts/crtartifact.go new file mode 100644 index 000000000..9dd38d0ed --- /dev/null +++ b/cmd/registry/apis/versions/artifacts/crtartifact.go @@ -0,0 +1,70 @@ +// 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 artifacts + +import ( + "encoding/base64" + + "internal/apiclient" + "internal/client/registry/apis/versions" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// CreateArtifactCmd to create a new instance +var CreateArtifactCmd = &cobra.Command{ + Use: "create", + Short: "Create an artifact for an API version", + Long: "Create an artifact for an API version", + Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetProjectID(utils.ProjectID) + return apiclient.SetApigeeOrg(utils.Org) + }, + RunE: func(cmd *cobra.Command, args []string) (err error) { + var payload []byte + if payload, err = utils.ReadFile(contentsFile); err != nil { + return err + } + contents := base64.StdEncoding.EncodeToString(payload) + _, err = versions.CreateArtifact(apiName, apiVersion, artifactID, name, contents, labels, annotations) + return err + }, +} + +var apiName, apiVersion, name, artifactID, contentsFile string + +func init() { + CreateArtifactCmd.Flags().StringVarP(&apiVersion, "api-version", "", + "", "API Version ID") + CreateArtifactCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "Name of the API") + CreateArtifactCmd.Flags().StringVarP(&artifactID, "id", "i", + "", "Apigee Registry Artifact ID") + CreateArtifactCmd.Flags().StringVarP(&name, "name", "n", + "", "Name of the Artifact") + CreateArtifactCmd.Flags().StringVarP(&contentsFile, "file", "f", + "", "Path to a file containing Artifact Contents") + CreateArtifactCmd.Flags().StringToStringVar(&labels, "labels", + nil, "Labels attach identifying metadata to resources") + CreateArtifactCmd.Flags().StringToStringVar(&annotations, "annotations", + nil, "Annotations attach non-identifying metadata to resources") + + _ = CreateArtifactCmd.MarkFlagRequired("id") + _ = CreateArtifactCmd.MarkFlagRequired("api-name") + _ = CreateArtifactCmd.MarkFlagRequired("api-version") + _ = CreateArtifactCmd.MarkFlagRequired("name") + _ = CreateArtifactCmd.MarkFlagRequired("file") +} diff --git a/cmd/registry/apis/versions/artifacts/delartifact.go b/cmd/registry/apis/versions/artifacts/delartifact.go new file mode 100644 index 000000000..e2dd6a0fa --- /dev/null +++ b/cmd/registry/apis/versions/artifacts/delartifact.go @@ -0,0 +1,53 @@ +// 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 artifacts + +import ( + "internal/apiclient" + + "internal/client/registry/apis/versions" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// DelArtifactCmd to get instance +var DelArtifactCmd = &cobra.Command{ + Use: "delete", + Short: "Delete artifact for an API version", + Long: "Delete artifact for an API version", + 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) { + _, err = versions.DeleteArtifact(apiName, apiVersion, name) + return + }, +} + +func init() { + DelArtifactCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + DelArtifactCmd.Flags().StringVarP(&apiVersion, "api-version", "", + "", "API Version") + DelArtifactCmd.Flags().StringVarP(&name, "name", "n", + "", "Artifact Name") + + _ = DelArtifactCmd.MarkFlagRequired("api-name") + _ = DelArtifactCmd.MarkFlagRequired("api-version") + _ = DelArtifactCmd.MarkFlagRequired("name") +} diff --git a/cmd/registry/apis/versions/artifacts/getartifact.go b/cmd/registry/apis/versions/artifacts/getartifact.go new file mode 100644 index 000000000..c7814631c --- /dev/null +++ b/cmd/registry/apis/versions/artifacts/getartifact.go @@ -0,0 +1,59 @@ +// 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 artifacts + +import ( + "internal/apiclient" + + "internal/client/registry/apis/versions" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// GetArtifactCmd to get instance +var GetArtifactCmd = &cobra.Command{ + Use: "get", + Short: "Get Artifact details for an API version", + Long: "Get Artifact details for an API version", + Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetProjectID(utils.ProjectID) + return apiclient.SetApigeeOrg(utils.Org) + }, + RunE: func(cmd *cobra.Command, args []string) (err error) { + if content { + return versions.GetArtifactContents(apiName, apiVersion, name) + } + _, err = versions.GetArtifact(apiName, apiVersion, name) + return + }, +} + +var content bool + +func init() { + GetArtifactCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + GetArtifactCmd.Flags().StringVarP(&apiVersion, "api-version", "", + "", "API Version") + GetArtifactCmd.Flags().StringVarP(&name, "name", "n", + "", "Artifact Name") + GetArtifactCmd.Flags().BoolVarP(&content, "content", "c", + false, "If set to true, returns artifact contents") + + _ = GetArtifactCmd.MarkFlagRequired("api-name") + _ = GetArtifactCmd.MarkFlagRequired("api-version") + _ = GetArtifactCmd.MarkFlagRequired("name") +} diff --git a/cmd/registry/apis/versions/artifacts/listartifacts.go b/cmd/registry/apis/versions/artifacts/listartifacts.go new file mode 100644 index 000000000..521d888f1 --- /dev/null +++ b/cmd/registry/apis/versions/artifacts/listartifacts.go @@ -0,0 +1,61 @@ +// 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 artifacts + +import ( + "internal/apiclient" + + "internal/client/registry/apis/versions" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// ListArtifactCmd to get instance +var ListArtifactCmd = &cobra.Command{ + Use: "list", + Short: "List all artifacts in Apigee Registry", + Long: "List all artifacts 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) { + _, err = versions.ListArtifacts(apiName, apiVersion, pageSize, pageToken, filter, orderBy) + return + }, +} + +var ( + pageToken, filter, orderBy string + pageSize int +) + +func init() { + ListArtifactCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + ListArtifactCmd.Flags().StringVarP(&apiVersion, "api-version", "", + "", "API Version") + ListArtifactCmd.Flags().StringVarP(&pageToken, "page-token", "", + "", "A page token, received from a previous list call") + ListArtifactCmd.Flags().StringVarP(&filter, "filter", "", + "", "An expression that can be used to filter the list") + ListArtifactCmd.Flags().StringVarP(&orderBy, "order-by", "", + "", "A comma-separated list of fields to be sorted; ex: foo desc") + + _ = ListArtifactCmd.MarkFlagRequired("api-name") + _ = ListArtifactCmd.MarkFlagRequired("api-version") +} diff --git a/cmd/registry/apis/versions/crtversion.go b/cmd/registry/apis/versions/crtversion.go new file mode 100644 index 000000000..1f73e79ec --- /dev/null +++ b/cmd/registry/apis/versions/crtversion.go @@ -0,0 +1,66 @@ +// 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 versions + +import ( + "internal/apiclient" + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// CreateVersionCmd to create a new instance +var CreateVersionCmd = &cobra.Command{ + Use: "create", + Short: "Create a version for an API", + Long: "Create a version for an API Apigee Registry Instance", + 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) { + _, err = apis.CreateVersion(apiVersionID, name, displayName, + description, state, labels, annotations, primarySpec) + return err + }, +} + +var ( + apiVersionID, description, displayName, state, primarySpec string + labels, annotations map[string]string +) + +func init() { + CreateVersionCmd.Flags().StringVarP(&apiVersionID, "api-version", "", + "", "The ID to use for the version") + CreateVersionCmd.Flags().StringVarP(&name, "name", "n", + "", "Name of the version") + CreateVersionCmd.Flags().StringVarP(&displayName, "display-name", "", + "", "Human friendly display name of the version") + CreateVersionCmd.Flags().StringVarP(&description, "desc", "d", + "", "A detailed description") + CreateVersionCmd.Flags().StringVarP(&state, "state", "s", + "", "A user-definable description of the lifecycle phase of this API version") + CreateVersionCmd.Flags().StringVarP(&primarySpec, "primary-spec", "", + "", "The primary spec for this version; ex: projects/*/locations/*/apis/*/versions/*/specs/*") + CreateVersionCmd.Flags().StringToStringVar(&labels, "labels", + nil, "Labels attach identifying metadata to resources") + CreateVersionCmd.Flags().StringToStringVar(&annotations, "annotations", + nil, "Annotations attach non-identifying metadata to resources") + + _ = CreateVersionCmd.MarkFlagRequired("id") +} diff --git a/cmd/registry/apis/versions/deleteversion.go b/cmd/registry/apis/versions/deleteversion.go new file mode 100644 index 000000000..de084a99f --- /dev/null +++ b/cmd/registry/apis/versions/deleteversion.go @@ -0,0 +1,54 @@ +// 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 versions + +import ( + "internal/apiclient" + + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// DelVersionCmd to get instance +var DelVersionCmd = &cobra.Command{ + Use: "delete", + Short: "Delete an API Version for an API", + Long: "Delete an API Version for an API 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) { + _, err = apis.DeleteVersion(name, version, force) + return + }, +} + +var force bool + +func init() { + DelVersionCmd.Flags().StringVarP(&name, "name", "n", + "", "Apigee Registry API Name") + DelVersionCmd.Flags().StringVarP(&version, "version", "v", + "", "API Version name") + DelVersionCmd.Flags().BoolVarP(&force, "force", "f", + false, "Deployment name") + + _ = DelVersionCmd.MarkFlagRequired("name") + _ = DelVersionCmd.MarkFlagRequired("version") +} diff --git a/cmd/registry/apis/versions/getversion.go b/cmd/registry/apis/versions/getversion.go new file mode 100644 index 000000000..df1d62f65 --- /dev/null +++ b/cmd/registry/apis/versions/getversion.go @@ -0,0 +1,52 @@ +// 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 versions + +import ( + "internal/apiclient" + + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// GetVersionCmd to get instance +var GetVersionCmd = &cobra.Command{ + Use: "get", + Short: "Get API Version details for an API", + Long: "Get API Version details for an API 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) { + _, err = apis.GetVersion(name, version) + return + }, +} + +var version string + +func init() { + GetVersionCmd.Flags().StringVarP(&name, "name", "n", + "", "Apigee Registry API Name") + GetVersionCmd.Flags().StringVarP(&version, "version", "v", + "", "API Version name") + + _ = GetVersionCmd.MarkFlagRequired("name") + _ = GetVersionCmd.MarkFlagRequired("version") +} diff --git a/cmd/registry/apis/versions/listversion.go b/cmd/registry/apis/versions/listversion.go new file mode 100644 index 000000000..38cb51c77 --- /dev/null +++ b/cmd/registry/apis/versions/listversion.go @@ -0,0 +1,58 @@ +// 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 versions + +import ( + "internal/apiclient" + + "internal/client/registry/apis" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// ListVersionCmd to get instance +var ListVersionCmd = &cobra.Command{ + Use: "list", + Short: "List all API Versions for an API", + Long: "List all API Versions for an API 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) { + _, err = apis.ListVersions(name, pageSize, pageToken, filter, orderBy) + return + }, +} + +var ( + name, pageToken, filter, orderBy string + pageSize int +) + +func init() { + ListVersionCmd.Flags().StringVarP(&name, "name", "n", + "", "Apigee Registry API Name") + ListVersionCmd.Flags().StringVarP(&pageToken, "page-token", "", + "", "A page token, received from a previous list call") + ListVersionCmd.Flags().StringVarP(&filter, "filter", "", + "", "An expression that can be used to filter the list") + ListVersionCmd.Flags().StringVarP(&orderBy, "order-by", "", + "", "A comma-separated list of fields to be sorted; ex: foo desc") + + _ = ListVersionCmd.MarkFlagRequired("name") +} diff --git a/cmd/registry/apis/versions/specs/artifacts/artifacts.go b/cmd/registry/apis/versions/specs/artifacts/artifacts.go new file mode 100644 index 000000000..02d7b861d --- /dev/null +++ b/cmd/registry/apis/versions/specs/artifacts/artifacts.go @@ -0,0 +1,35 @@ +// 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 artifacts + +import ( + "github.com/spf13/cobra" +) + +// ArtifactCmd to manage apis +var ArtifactCmd = &cobra.Command{ + Use: "artifacts", + Short: "Manage artifacts for an API version's spec", + Long: "Manage artifacts for an API version in Apigee Registry", +} + +var apiName, apiVersion, specName, name string + +func init() { + ArtifactCmd.AddCommand(DelArtifactCmd) + ArtifactCmd.AddCommand(GetArtifactCmd) + ArtifactCmd.AddCommand(ListArtifactCmd) + ArtifactCmd.AddCommand(CreateArtifactCmd) +} diff --git a/cmd/registry/apis/versions/specs/artifacts/crtartifact.go b/cmd/registry/apis/versions/specs/artifacts/crtartifact.go new file mode 100644 index 000000000..af30b0406 --- /dev/null +++ b/cmd/registry/apis/versions/specs/artifacts/crtartifact.go @@ -0,0 +1,75 @@ +// 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 artifacts + +import ( + "encoding/base64" + + "internal/apiclient" + "internal/client/registry/apis/versions" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// CreateArtifactCmd to create a new instance +var CreateArtifactCmd = &cobra.Command{ + Use: "create", + Short: "Create an artifact for an API version", + Long: "Create an artifact for an API version", + Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetProjectID(utils.ProjectID) + return apiclient.SetApigeeOrg(utils.Org) + }, + RunE: func(cmd *cobra.Command, args []string) (err error) { + var payload []byte + if payload, err = utils.ReadFile(contentsFile); err != nil { + return err + } + contents := base64.StdEncoding.EncodeToString(payload) + _, err = versions.CreateSpecArtifact(apiName, apiVersion, specName, artifactID, name, contents, labels, annotations) + return err + }, +} + +var labels, annotations map[string]string + +var artifactID, contentsFile string + +func init() { + CreateArtifactCmd.Flags().StringVarP(&apiVersion, "api-version", "", + "", "API Version ID") + CreateArtifactCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "Name of the API") + CreateArtifactCmd.Flags().StringVarP(&artifactID, "id", "i", + "", "Apigee Registry Artifact ID") + CreateArtifactCmd.Flags().StringVarP(&specName, "spec-name", "", + "", "API Version Spec name") + CreateArtifactCmd.Flags().StringVarP(&name, "name", "n", + "", "Name of the Artifact") + CreateArtifactCmd.Flags().StringVarP(&contentsFile, "file", "f", + "", "Path to a file containing Artifact Contents") + CreateArtifactCmd.Flags().StringToStringVar(&labels, "labels", + nil, "Labels attach identifying metadata to resources") + CreateArtifactCmd.Flags().StringToStringVar(&annotations, "annotations", + nil, "Annotations attach non-identifying metadata to resources") + + _ = CreateArtifactCmd.MarkFlagRequired("id") + _ = CreateArtifactCmd.MarkFlagRequired("api-name") + _ = CreateArtifactCmd.MarkFlagRequired("api-version") + _ = CreateArtifactCmd.MarkFlagRequired("spec-name") + _ = CreateArtifactCmd.MarkFlagRequired("name") + _ = CreateArtifactCmd.MarkFlagRequired("file") +} diff --git a/cmd/registry/apis/versions/specs/artifacts/delartifact.go b/cmd/registry/apis/versions/specs/artifacts/delartifact.go new file mode 100644 index 000000000..2eac000b4 --- /dev/null +++ b/cmd/registry/apis/versions/specs/artifacts/delartifact.go @@ -0,0 +1,56 @@ +// 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 artifacts + +import ( + "internal/apiclient" + + "internal/client/registry/apis/versions" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// DelArtifactCmd to get instance +var DelArtifactCmd = &cobra.Command{ + Use: "delete", + Short: "Delete artifact for a spec in an API version", + Long: "Delete artifact for a spec in 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) { + _, err = versions.DeleteSpecArtifact(apiName, apiVersion, specName, name) + return + }, +} + +func init() { + DelArtifactCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + DelArtifactCmd.Flags().StringVarP(&apiVersion, "api-version", "", + "", "API Version") + DelArtifactCmd.Flags().StringVarP(&specName, "spec-name", "", + "", "API Version Spec name") + DelArtifactCmd.Flags().StringVarP(&name, "name", "n", + "", "API Version Spec Artifact name") + + _ = DelArtifactCmd.MarkFlagRequired("api-name") + _ = DelArtifactCmd.MarkFlagRequired("api-version") + _ = DelArtifactCmd.MarkFlagRequired("spec-name") + _ = DelArtifactCmd.MarkFlagRequired("name") +} diff --git a/cmd/registry/apis/versions/specs/artifacts/getartifact.go b/cmd/registry/apis/versions/specs/artifacts/getartifact.go new file mode 100644 index 000000000..037e4bdcd --- /dev/null +++ b/cmd/registry/apis/versions/specs/artifacts/getartifact.go @@ -0,0 +1,56 @@ +// 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 artifacts + +import ( + "internal/apiclient" + + "internal/client/registry/apis/versions" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// GetArtifactCmd to get instance +var GetArtifactCmd = &cobra.Command{ + Use: "get", + Short: "Get artifact details for a spec in an API version", + Long: "Get artifact details for a spec in 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) { + _, err = versions.GetSpecArtifact(apiName, apiVersion, specName, name) + return + }, +} + +func init() { + GetArtifactCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + GetArtifactCmd.Flags().StringVarP(&apiVersion, "api-version", "", + "", "API Version") + GetArtifactCmd.Flags().StringVarP(&specName, "spec-name", "", + "", "API Version Spec name") + GetArtifactCmd.Flags().StringVarP(&name, "name", "n", + "", "API Version Spec Artifact name") + + _ = GetArtifactCmd.MarkFlagRequired("api-name") + _ = GetArtifactCmd.MarkFlagRequired("api-version") + _ = GetArtifactCmd.MarkFlagRequired("spec-name") + _ = GetArtifactCmd.MarkFlagRequired("name") +} diff --git a/cmd/registry/apis/versions/specs/artifacts/listartifacts.go b/cmd/registry/apis/versions/specs/artifacts/listartifacts.go new file mode 100644 index 000000000..541b0d5e8 --- /dev/null +++ b/cmd/registry/apis/versions/specs/artifacts/listartifacts.go @@ -0,0 +1,64 @@ +// 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 artifacts + +import ( + "internal/apiclient" + + "internal/client/registry/apis/versions" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// ListArtifactCmd to get instance +var ListArtifactCmd = &cobra.Command{ + Use: "list", + Short: "List all artifacts in Apigee Registry", + Long: "List all artifacts 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) { + _, err = versions.ListSpecArtifacts(apiName, apiVersion, specName, pageSize, pageToken, filter, orderBy) + return + }, +} + +var ( + pageToken, filter, orderBy string + pageSize int +) + +func init() { + ListArtifactCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + ListArtifactCmd.Flags().StringVarP(&apiVersion, "api-version", "", + "", "API Version") + ListArtifactCmd.Flags().StringVarP(&specName, "spec-name", "", + "", "API Version Spec name") + ListArtifactCmd.Flags().StringVarP(&pageToken, "page-token", "", + "", "A page token, received from a previous list call") + ListArtifactCmd.Flags().StringVarP(&filter, "filter", "", + "", "An expression that can be used to filter the list") + ListArtifactCmd.Flags().StringVarP(&orderBy, "order-by", "", + "", "A comma-separated list of fields to be sorted; ex: foo desc") + + _ = ListArtifactCmd.MarkFlagRequired("api-name") + _ = ListArtifactCmd.MarkFlagRequired("api-version") + _ = ListArtifactCmd.MarkFlagRequired("spec-name") +} diff --git a/cmd/registry/apis/versions/specs/crtspec.go b/cmd/registry/apis/versions/specs/crtspec.go new file mode 100644 index 000000000..160316e0e --- /dev/null +++ b/cmd/registry/apis/versions/specs/crtspec.go @@ -0,0 +1,81 @@ +// 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 ( + "encoding/base64" + "path/filepath" + + "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 + } + fileName := filepath.Base(filePath) + contents := base64.URLEncoding.EncodeToString(fileContents) + _, err = versions.CreateSpec(apiName, apiVersion, apiSpecID, + name, fileName, description, sourceURI, contents, labels, annotations) + return + }, +} + +var ( + labels, annotations map[string]string + apiSpecID, description, sourceURI, filePath string +) + +func init() { + CreateSpecCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + CreateSpecCmd.Flags().StringVarP(&apiVersion, "api-version", "", + "", "API Version") + CreateSpecCmd.Flags().StringVarP(&apiSpecID, "api-specid", "", + "", "API Spec Id") + CreateSpecCmd.Flags().StringVarP(&name, "name", "n", + "", "API Version Spec name") + 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") +} diff --git a/cmd/registry/apis/versions/specs/delspec.go b/cmd/registry/apis/versions/specs/delspec.go new file mode 100644 index 000000000..f8b096c97 --- /dev/null +++ b/cmd/registry/apis/versions/specs/delspec.go @@ -0,0 +1,53 @@ +// 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" +) + +// DeleteSpecCmd to get instance +var DeleteSpecCmd = &cobra.Command{ + Use: "delete", + Short: "Delete a spec associated with an API version", + Long: "Delete 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) { + _, err = versions.DeleteSpec(apiName, apiVersion, name) + return + }, +} + +func init() { + DeleteSpecCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + DeleteSpecCmd.Flags().StringVarP(&apiVersion, "api-version", "", + "", "API Version") + DeleteSpecCmd.Flags().StringVarP(&name, "name", "n", + "", "Name of the Spec") + + _ = DeleteSpecCmd.MarkFlagRequired("api-name") + _ = DeleteSpecCmd.MarkFlagRequired("api-version") + _ = DeleteSpecCmd.MarkFlagRequired("name") +} diff --git a/cmd/registry/apis/versions/specs/getspec.go b/cmd/registry/apis/versions/specs/getspec.go new file mode 100644 index 000000000..2c5da01e3 --- /dev/null +++ b/cmd/registry/apis/versions/specs/getspec.go @@ -0,0 +1,64 @@ +// 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" +) + +// GetSpecCmd to get instance +var GetSpecCmd = &cobra.Command{ + Use: "get", + Short: "Get the spec details for an API version", + Long: "Get the spec details for 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) { + if content { + err = versions.GetSpecContents(apiName, apiVersion, name) + return err + } + _, err = versions.GetSpec(apiName, apiVersion, name) + return + }, +} + +var ( + name string + content bool +) + +func init() { + GetSpecCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + GetSpecCmd.Flags().StringVarP(&apiVersion, "api-version", "", + "", "API Version") + GetSpecCmd.Flags().StringVarP(&name, "name", "n", + "", "Name of the Spec") + GetSpecCmd.Flags().BoolVarP(&content, "content", "c", + false, "If set to true, returns artifact contents") + + _ = GetSpecCmd.MarkFlagRequired("api-name") + _ = GetSpecCmd.MarkFlagRequired("api-version") + _ = GetSpecCmd.MarkFlagRequired("name") +} diff --git a/cmd/registry/apis/versions/specs/listspecs.go b/cmd/registry/apis/versions/specs/listspecs.go new file mode 100644 index 000000000..d24806c33 --- /dev/null +++ b/cmd/registry/apis/versions/specs/listspecs.go @@ -0,0 +1,61 @@ +// 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" +) + +// ListSpecCmd to get instance +var ListSpecCmd = &cobra.Command{ + Use: "list", + Short: "List all specs for an API version", + Long: "List all artifacts for 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) { + _, err = versions.ListSpecs(apiName, apiVersion, pageSize, pageToken, filter, orderBy) + return + }, +} + +var ( + apiName, apiVersion, pageToken, filter, orderBy string + pageSize int +) + +func init() { + ListSpecCmd.Flags().StringVarP(&apiName, "api-name", "", + "", "API Name") + ListSpecCmd.Flags().StringVarP(&apiVersion, "api-version", "", + "", "API Version") + ListSpecCmd.Flags().StringVarP(&pageToken, "page-token", "", + "", "A page token, received from a previous list call") + ListSpecCmd.Flags().StringVarP(&filter, "filter", "", + "", "An expression that can be used to filter the list") + ListSpecCmd.Flags().StringVarP(&orderBy, "order-by", "", + "", "A comma-separated list of fields to be sorted; ex: foo desc") + + _ = ListSpecCmd.MarkFlagRequired("api-name") + _ = ListSpecCmd.MarkFlagRequired("api-version") +} diff --git a/cmd/registry/apis/versions/specs/specs.go b/cmd/registry/apis/versions/specs/specs.go new file mode 100644 index 000000000..9c3e4e791 --- /dev/null +++ b/cmd/registry/apis/versions/specs/specs.go @@ -0,0 +1,35 @@ +// 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 ( + "github.com/apigee/apigeecli/cmd/registry/apis/versions/specs/artifacts" + "github.com/spf13/cobra" +) + +// SpecCmd to manage apis +var SpecCmd = &cobra.Command{ + Use: "specs", + Short: "Manage specs for an API version", + Long: "Manage specs for an API version in Apigee Registry", +} + +func init() { + SpecCmd.AddCommand(ListSpecCmd) + SpecCmd.AddCommand(GetSpecCmd) + SpecCmd.AddCommand(DeleteSpecCmd) + SpecCmd.AddCommand(CreateSpecCmd) + SpecCmd.AddCommand(artifacts.ArtifactCmd) +} diff --git a/cmd/registry/apis/versions/versions.go b/cmd/registry/apis/versions/versions.go new file mode 100644 index 000000000..8afc6213c --- /dev/null +++ b/cmd/registry/apis/versions/versions.go @@ -0,0 +1,37 @@ +// 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 versions + +import ( + "github.com/apigee/apigeecli/cmd/registry/apis/versions/artifacts" + "github.com/apigee/apigeecli/cmd/registry/apis/versions/specs" + "github.com/spf13/cobra" +) + +// APIVersionCmd to manage apis +var APIVersionCmd = &cobra.Command{ + Use: "versions", + Short: "Manage API Versions in Apigee Registry", + Long: "Manage API Versions in Apigee Registry", +} + +func init() { + APIVersionCmd.AddCommand(ListVersionCmd) + APIVersionCmd.AddCommand(CreateVersionCmd) + APIVersionCmd.AddCommand(GetVersionCmd) + APIVersionCmd.AddCommand(DelVersionCmd) + APIVersionCmd.AddCommand(artifacts.ArtifactCmd) + APIVersionCmd.AddCommand(specs.SpecCmd) +} diff --git a/cmd/registry/artifacts/artifacts.go b/cmd/registry/artifacts/artifacts.go new file mode 100644 index 000000000..f801d2e3a --- /dev/null +++ b/cmd/registry/artifacts/artifacts.go @@ -0,0 +1,35 @@ +// 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 artifacts + +import ( + "github.com/spf13/cobra" +) + +// ArtifactCmd to manage apis +var ArtifactCmd = &cobra.Command{ + Use: "artifacts", + Short: "Manage artifacts in Apigee Registry", + Long: "Manage artifacts in Apigee Registry", +} + +var labels, annotations map[string]string + +func init() { + ArtifactCmd.AddCommand(CreateArtifactCmd) + ArtifactCmd.AddCommand(GetArtifactCmd) + ArtifactCmd.AddCommand(ListArtifactCmd) + ArtifactCmd.AddCommand(DelArtifactCmd) +} diff --git a/cmd/registry/artifacts/crtartifact.go b/cmd/registry/artifacts/crtartifact.go new file mode 100644 index 000000000..bfe2e7177 --- /dev/null +++ b/cmd/registry/artifacts/crtartifact.go @@ -0,0 +1,65 @@ +// 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 artifacts + +import ( + "encoding/base64" + + "internal/apiclient" + "internal/client/registry/artifacts" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// CreateArtifactCmd to create a new instance +var CreateArtifactCmd = &cobra.Command{ + Use: "create", + Short: "Create an Apigee Registry Artifact", + Long: "Create an Apigee Registry Artifact", + 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) { + var payload []byte + if payload, err = utils.ReadFile(contentsFile); err != nil { + return err + } + contents := base64.StdEncoding.EncodeToString(payload) + _, err = artifacts.Create(artifactID, name, contents, labels, annotations) + return err + }, +} + +var name, artifactID, contentsFile string + +func init() { + CreateArtifactCmd.Flags().StringVarP(&artifactID, "id", "i", + "", "Apigee Registry Artifact ID") + CreateArtifactCmd.Flags().StringVarP(&name, "name", "n", + "", "Name of the Artifact") + CreateArtifactCmd.Flags().StringVarP(&contentsFile, "file", "f", + "", "Path to a file containing Artifact Contents") + CreateArtifactCmd.Flags().StringToStringVar(&labels, "labels", + nil, "Labels attach identifying metadata to resources") + CreateArtifactCmd.Flags().StringToStringVar(&annotations, "annotations", + nil, "Annotations attach non-identifying metadata to resources") + + _ = CreateArtifactCmd.MarkFlagRequired("id") + _ = CreateArtifactCmd.MarkFlagRequired("name") + _ = CreateArtifactCmd.MarkFlagRequired("file") +} diff --git a/cmd/registry/artifacts/delartifact.go b/cmd/registry/artifacts/delartifact.go new file mode 100644 index 000000000..31318dc3c --- /dev/null +++ b/cmd/registry/artifacts/delartifact.go @@ -0,0 +1,45 @@ +// 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 artifacts + +import ( + "internal/apiclient" + + "internal/client/registry/artifacts" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// DelArtifactCmd to get instance +var DelArtifactCmd = &cobra.Command{ + Use: "delete", + Short: "Delete artifact from Apigee Registry", + Long: "Delete artifact from 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) { + _, err = artifacts.Delete(name) + return + }, +} + +func init() { + DelArtifactCmd.Flags().StringVarP(&name, "name", "n", + "", "Artifact Name") +} diff --git a/cmd/registry/artifacts/getartifact.go b/cmd/registry/artifacts/getartifact.go new file mode 100644 index 000000000..f3d25ce18 --- /dev/null +++ b/cmd/registry/artifacts/getartifact.go @@ -0,0 +1,52 @@ +// 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 artifacts + +import ( + "internal/apiclient" + + "internal/client/registry/artifacts" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// GetArtifactCmd to get instance +var GetArtifactCmd = &cobra.Command{ + Use: "get", + Short: "Get Artifact details", + Long: "Get Artifact details", + 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) { + if content { + return artifacts.GetContents(name) + } + _, err = artifacts.Get(name) + return + }, +} + +var content bool + +func init() { + GetArtifactCmd.Flags().StringVarP(&name, "name", "n", + "", "Artifact Name") + GetArtifactCmd.Flags().BoolVarP(&content, "content", "c", + false, "If set to true, returns artifact contents") +} diff --git a/cmd/registry/artifacts/listartifact.go b/cmd/registry/artifacts/listartifact.go new file mode 100644 index 000000000..978aa3d32 --- /dev/null +++ b/cmd/registry/artifacts/listartifact.go @@ -0,0 +1,54 @@ +// 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 artifacts + +import ( + "internal/apiclient" + + "internal/client/registry/artifacts" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// ListArtifactCmd to get instance +var ListArtifactCmd = &cobra.Command{ + Use: "list", + Short: "List all artifacts in Apigee Registry", + Long: "List all artifacts 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) { + _, err = artifacts.List(pageSize, pageToken, filter, orderBy) + return + }, +} + +var ( + pageToken, filter, orderBy string + pageSize int +) + +func init() { + ListArtifactCmd.Flags().StringVarP(&pageToken, "page-token", "", + "", "A page token, received from a previous list call") + ListArtifactCmd.Flags().StringVarP(&filter, "filter", "", + "", "An expression that can be used to filter the list") + ListArtifactCmd.Flags().StringVarP(&orderBy, "order-by", "", + "", "A comma-separated list of fields to be sorted; ex: foo desc") +} diff --git a/cmd/registry/instances/crtinstance.go b/cmd/registry/instances/crtinstance.go new file mode 100644 index 000000000..b460fb16a --- /dev/null +++ b/cmd/registry/instances/crtinstance.go @@ -0,0 +1,48 @@ +// 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 instances + +import ( + "internal/apiclient" + "internal/client/registry/instances" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// CreateInstanceCmd to create a new instance +var CreateInstanceCmd = &cobra.Command{ + Use: "create", + Short: "Create an Apigee Registry Instance", + Long: "Create an Apigee Registry Instance", + 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) { + _, err = instances.Create(cmekName) + return err + }, +} + +var cmekName string + +func init() { + CreateInstanceCmd.Flags().StringVarP(&cmekName, "cmek", "k", + "", "Cloud KMS Key Resource ID") + + _ = CreateInstanceCmd.MarkFlagRequired("cmek") +} diff --git a/cmd/registry/instances/delinstance.go b/cmd/registry/instances/delinstance.go new file mode 100644 index 000000000..289bc20dc --- /dev/null +++ b/cmd/registry/instances/delinstance.go @@ -0,0 +1,43 @@ +// 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 instances + +import ( + "internal/apiclient" + + "internal/client/registry/instances" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// DeleteInstanceCmd to delete instance +var DeleteInstanceCmd = &cobra.Command{ + Use: "delete", + Short: "Delete an Apigee Registry Instance", + Long: "Delete an Apigee Registry Instance", + 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) { + _, err = instances.Delete() + return + }, +} + +func init() { +} diff --git a/cmd/registry/instances/getinstance.go b/cmd/registry/instances/getinstance.go new file mode 100644 index 000000000..0e69adca7 --- /dev/null +++ b/cmd/registry/instances/getinstance.go @@ -0,0 +1,43 @@ +// 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 instances + +import ( + "internal/apiclient" + + "internal/client/registry/instances" + + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// GetInstanceCmd to get instance +var GetInstanceCmd = &cobra.Command{ + Use: "get", + Short: "Get an Apigee Registry Instance", + Long: "Get an Apigee Registry Instance", + 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) { + _, err = instances.Get() + return + }, +} + +func init() { +} diff --git a/cmd/registry/instances/instances.go b/cmd/registry/instances/instances.go new file mode 100644 index 000000000..4a0aa36ae --- /dev/null +++ b/cmd/registry/instances/instances.go @@ -0,0 +1,32 @@ +// 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 instances + +import ( + "github.com/spf13/cobra" +) + +// InstanceCmd to manage apis +var InstanceCmd = &cobra.Command{ + Use: "instances", + Short: "Manage Apigee Registry Instances", + Long: "Manage Apigee Registry Instances", +} + +func init() { + InstanceCmd.AddCommand(CreateInstanceCmd) + InstanceCmd.AddCommand(GetInstanceCmd) + InstanceCmd.AddCommand(DeleteInstanceCmd) +} diff --git a/cmd/registry/registry.go b/cmd/registry/registry.go new file mode 100644 index 000000000..972b3f9bf --- /dev/null +++ b/cmd/registry/registry.go @@ -0,0 +1,43 @@ +// 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 registry + +import ( + "github.com/apigee/apigeecli/cmd/registry/apis" + "github.com/apigee/apigeecli/cmd/registry/artifacts" + "github.com/apigee/apigeecli/cmd/registry/instances" + "github.com/apigee/apigeecli/cmd/utils" + "github.com/spf13/cobra" +) + +// Cmd to manage apis +var Cmd = &cobra.Command{ + Use: "registry", + Short: "Manage Apigee API Registry APIs", + Long: "Manage Apigee API Registry APIs", +} + +func init() { + Cmd.AddCommand(apis.APICmd) + Cmd.AddCommand(artifacts.ArtifactCmd) + Cmd.AddCommand(instances.InstanceCmd) + + Cmd.PersistentFlags().StringVarP(&utils.Org, "org", "o", + "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(&utils.Region, "region", "", + "", "Region where Apigee Registry is provisioned") + Cmd.PersistentFlags().StringVarP(&utils.ProjectID, "projectID", "p", + "", "Apigee Registry Project ID; Use if Apigee Orgniazation not provisioned in this project") +} diff --git a/cmd/res/crtres.go b/cmd/res/crtres.go index 84051a315..764248685 100644 --- a/cmd/res/crtres.go +++ b/cmd/res/crtres.go @@ -29,6 +29,7 @@ var CreateCmd = &cobra.Command{ Long: "Create a resource file", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -44,7 +45,7 @@ func init() { "", "Name of the resource file") CreateCmd.Flags().StringVarP(&resType, "type", "p", "", "Resource type; Valid types include java, js, jsc, properties, py, wsdl, xsd, or xsl.") - CreateCmd.Flags().StringVarP(&resPath, "respath", "r", + CreateCmd.Flags().StringVarP(&resPath, "respath", "", "", "Resource Path") _ = CreateCmd.MarkFlagRequired("name") diff --git a/cmd/res/delres.go b/cmd/res/delres.go index 9601ea24c..cf5688861 100644 --- a/cmd/res/delres.go +++ b/cmd/res/delres.go @@ -29,6 +29,7 @@ var DelCmd = &cobra.Command{ Long: "Delete a resource file", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/res/getres.go b/cmd/res/getres.go index f11c6ecfc..9c3d6674e 100644 --- a/cmd/res/getres.go +++ b/cmd/res/getres.go @@ -29,6 +29,7 @@ var GetCmd = &cobra.Command{ Long: "Get a resource file", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/res/listres.go b/cmd/res/listres.go index 5d61e9347..0e56c6ac6 100644 --- a/cmd/res/listres.go +++ b/cmd/res/listres.go @@ -29,6 +29,7 @@ var ListCmd = &cobra.Command{ Long: "List all resources in your environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/res/res.go b/cmd/res/res.go index bcd692919..7f3404b89 100644 --- a/cmd/res/res.go +++ b/cmd/res/res.go @@ -26,7 +26,7 @@ var Cmd = &cobra.Command{ Long: "Manage resources within an Apigee environment", } -var name, org, env, resType string +var name, org, env, resType, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", @@ -35,6 +35,9 @@ func init() { Cmd.PersistentFlags().StringVarP(&env, "env", "e", "", "Apigee environment name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") + _ = Cmd.MarkPersistentFlagRequired("env") Cmd.AddCommand(CreateCmd) diff --git a/cmd/res/updres.go b/cmd/res/updres.go index b90b9298f..61fb12545 100644 --- a/cmd/res/updres.go +++ b/cmd/res/updres.go @@ -29,6 +29,7 @@ var UpdateCmd = &cobra.Command{ Long: "Update a resource file", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -41,7 +42,7 @@ func init() { "", "Name of the resource file") UpdateCmd.Flags().StringVarP(&resType, "type", "p", "", "Resource type. Valid types include java, js, jsc, properties, py, wsdl, xsd, or xsl.") - UpdateCmd.Flags().StringVarP(&resPath, "respath", "r", + UpdateCmd.Flags().StringVarP(&resPath, "respath", "", "", "Resource Path") _ = UpdateCmd.MarkFlagRequired("name") diff --git a/cmd/root.go b/cmd/root.go index 38e0b296f..cb2488827 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -51,6 +51,7 @@ import ( "github.com/apigee/apigeecli/cmd/products" "github.com/apigee/apigeecli/cmd/projects" "github.com/apigee/apigeecli/cmd/references" + "github.com/apigee/apigeecli/cmd/registry" res "github.com/apigee/apigeecli/cmd/res" "github.com/apigee/apigeecli/cmd/securityprofiles" "github.com/apigee/apigeecli/cmd/sharedflows" @@ -182,6 +183,7 @@ func init() { RootCmd.AddCommand(datastores.Cmd) RootCmd.AddCommand(securityprofiles.Cmd) RootCmd.AddCommand(sites.Cmd) + RootCmd.AddCommand(registry.Cmd) } func initConfig() { diff --git a/cmd/securityprofiles/attach.go b/cmd/securityprofiles/attach.go index 225fb8018..4cea430aa 100644 --- a/cmd/securityprofiles/attach.go +++ b/cmd/securityprofiles/attach.go @@ -28,6 +28,7 @@ var AttachCmd = &cobra.Command{ Long: "Attach a security profile to an environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -43,7 +44,7 @@ func init() { "", "Name of the security profile") AttachCmd.Flags().StringVarP(&environment, "env", "e", "", "Apigee environment name") - AttachCmd.Flags().StringVarP(&revision, "rev", "r", + AttachCmd.Flags().StringVarP(&revision, "rev", "v", "", "Security Profile revision id") _ = AttachCmd.MarkFlagRequired("name") _ = AttachCmd.MarkFlagRequired("env") diff --git a/cmd/securityprofiles/compute.go b/cmd/securityprofiles/compute.go index 1f050ae92..30b854c98 100644 --- a/cmd/securityprofiles/compute.go +++ b/cmd/securityprofiles/compute.go @@ -41,6 +41,7 @@ var ComputeCmd = &cobra.Command{ } } apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/securityprofiles/create.go b/cmd/securityprofiles/create.go index c9c80320c..662f474b0 100644 --- a/cmd/securityprofiles/create.go +++ b/cmd/securityprofiles/create.go @@ -28,6 +28,7 @@ var CreateCmd = &cobra.Command{ Short: "Create a new Security Profile", Long: "Create a new Security Profile", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/securityprofiles/delete.go b/cmd/securityprofiles/delete.go index 37d7b1ca4..1e7eb10fc 100644 --- a/cmd/securityprofiles/delete.go +++ b/cmd/securityprofiles/delete.go @@ -27,6 +27,7 @@ var DeleteCmd = &cobra.Command{ Short: "Deletes a security profile", Long: "Deletes a security profile", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/securityprofiles/detach.go b/cmd/securityprofiles/detach.go index ace61c770..c481a42c2 100644 --- a/cmd/securityprofiles/detach.go +++ b/cmd/securityprofiles/detach.go @@ -28,6 +28,7 @@ var DetachCmd = &cobra.Command{ Long: "Detach a security profile from an environment", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(environment) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/securityprofiles/export.go b/cmd/securityprofiles/export.go index be155866b..f24879e91 100644 --- a/cmd/securityprofiles/export.go +++ b/cmd/securityprofiles/export.go @@ -30,6 +30,7 @@ var ExpCmd = &cobra.Command{ Short: "Export Security Profiles to a file", Long: "Export Security Profiles to a file", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/securityprofiles/get.go b/cmd/securityprofiles/get.go index 93a23a78b..5bcecf119 100644 --- a/cmd/securityprofiles/get.go +++ b/cmd/securityprofiles/get.go @@ -27,6 +27,7 @@ var GetCmd = &cobra.Command{ Short: "Returns a security profile by name", Long: "Returns a security profile by name", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -40,7 +41,7 @@ var name string func init() { GetCmd.Flags().StringVarP(&name, "name", "n", "", "Name of the security profile") - GetCmd.Flags().StringVarP(&revision, "revision", "r", + GetCmd.Flags().StringVarP(&revision, "revision", "v", "", "Revision of the security profile") _ = GetCmd.MarkFlagRequired("name") } diff --git a/cmd/securityprofiles/import.go b/cmd/securityprofiles/import.go index 4e83a800e..f5575c594 100644 --- a/cmd/securityprofiles/import.go +++ b/cmd/securityprofiles/import.go @@ -31,6 +31,7 @@ var ImpCmd = &cobra.Command{ Short: "Import a folder containing Security Profiles", Long: "Import a folder containing Security Profiles", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/securityprofiles/list.go b/cmd/securityprofiles/list.go index 95d020b5b..bf36f85f7 100644 --- a/cmd/securityprofiles/list.go +++ b/cmd/securityprofiles/list.go @@ -27,6 +27,7 @@ var ListCmd = &cobra.Command{ Short: "Returns the security profiles in the org", Long: "Returns the security profiles in the org", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/securityprofiles/listrevisions.go b/cmd/securityprofiles/listrevisions.go index bf00283c4..adec98d57 100644 --- a/cmd/securityprofiles/listrevisions.go +++ b/cmd/securityprofiles/listrevisions.go @@ -27,6 +27,7 @@ var ListRevisionsCmd = &cobra.Command{ Short: "Returns the revisions of a security profile", Long: "Returns the revisions of a security profile", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/securityprofiles/securityprofiles.go b/cmd/securityprofiles/securityprofiles.go index e3ff2910f..c00bd7845 100644 --- a/cmd/securityprofiles/securityprofiles.go +++ b/cmd/securityprofiles/securityprofiles.go @@ -26,11 +26,13 @@ var Cmd = &cobra.Command{ Long: "Manage Adv API Security Profiles", } -var org string +var org, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(ListCmd) Cmd.AddCommand(GetCmd) diff --git a/cmd/securityprofiles/update.go b/cmd/securityprofiles/update.go index ac1a3cd0a..9137e8426 100644 --- a/cmd/securityprofiles/update.go +++ b/cmd/securityprofiles/update.go @@ -28,6 +28,7 @@ var UpdateCmd = &cobra.Command{ Short: "Update an existing Security Profile", Long: "Update an existing Security Profile", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/sharedflows/bundlecrtsf.go b/cmd/sharedflows/bundlecrtsf.go index 697d5cc74..907aa85be 100644 --- a/cmd/sharedflows/bundlecrtsf.go +++ b/cmd/sharedflows/bundlecrtsf.go @@ -51,6 +51,7 @@ var BundleCreateCmd = &cobra.Command{ if env != "" { apiclient.SetApigeeEnv(env) } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -109,7 +110,7 @@ func init() { "", "Path to the Sharedflow Bundle; ex: ./test/sharedflowbundle") BundleCreateCmd.Flags().StringVarP(&env, "env", "e", "", "Apigee environment name") - BundleCreateCmd.Flags().BoolVarP(&overrides, "ovr", "r", + BundleCreateCmd.Flags().BoolVarP(&overrides, "ovr", "", false, "Forces deployment of the new revision") BundleCreateCmd.Flags().BoolVarP(&wait, "wait", "", false, "Waits for the deployment to finish, with success or error") diff --git a/cmd/sharedflows/cleansf.go b/cmd/sharedflows/cleansf.go index f2267e4b3..838c919f8 100644 --- a/cmd/sharedflows/cleansf.go +++ b/cmd/sharedflows/cleansf.go @@ -28,6 +28,7 @@ var CleanCmd = &cobra.Command{ Short: "Deletes undeployed/unused reivisions of a Sharedflow", Long: "Deletes undeployed/unused reivisions of a Sharedflow", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/sharedflows/delsf.go b/cmd/sharedflows/delsf.go index 99dbbf37d..0b2be2fac 100644 --- a/cmd/sharedflows/delsf.go +++ b/cmd/sharedflows/delsf.go @@ -29,6 +29,7 @@ var DelCmd = &cobra.Command{ Long: "Deletes a shared flow and all associated policies, resources, and revisions." + "The flow must be undeployed first.", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) apiclient.SetApigeeEnv(env) return apiclient.SetApigeeOrg(org) }, diff --git a/cmd/sharedflows/depsf.go b/cmd/sharedflows/depsf.go index 289c73b42..583535bcb 100644 --- a/cmd/sharedflows/depsf.go +++ b/cmd/sharedflows/depsf.go @@ -29,6 +29,7 @@ var DepCmd = &cobra.Command{ Long: "Deploys a revision of an existing Sharedflow to an environment in an organization", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -62,7 +63,7 @@ func init() { "", "Apigee environment name") DepCmd.Flags().IntVarP(&revision, "rev", "v", -1, "Sharedflow revision. If not set, the highest revision is used") - DepCmd.Flags().BoolVarP(&overrides, "ovr", "r", + DepCmd.Flags().BoolVarP(&overrides, "ovr", "", false, "Forces deployment of the new revision") DepCmd.Flags().BoolVarP(&wait, "wait", "", false, "Waits for the deployment to finish, with success or error") diff --git a/cmd/sharedflows/expsf.go b/cmd/sharedflows/expsf.go index 84dbbe955..2003e4b25 100644 --- a/cmd/sharedflows/expsf.go +++ b/cmd/sharedflows/expsf.go @@ -29,6 +29,7 @@ var ExpCmd = &cobra.Command{ Long: "export Sharedflow bundles from an org", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/sharedflows/fetchsf.go b/cmd/sharedflows/fetchsf.go index 69c0c9611..4d7fa11fa 100644 --- a/cmd/sharedflows/fetchsf.go +++ b/cmd/sharedflows/fetchsf.go @@ -29,6 +29,7 @@ var FetCmd = &cobra.Command{ Long: "Returns a zip-formatted shared flow bundle of code and config files", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/sharedflows/getsf.go b/cmd/sharedflows/getsf.go index 1b439474c..04be480ca 100644 --- a/cmd/sharedflows/getsf.go +++ b/cmd/sharedflows/getsf.go @@ -29,6 +29,7 @@ var GetCmd = &cobra.Command{ Long: "Gets a shared flow by name, including a list of its revisions.", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/sharedflows/ghcrtsf.go b/cmd/sharedflows/ghcrtsf.go index 905e41fe8..41416fd04 100644 --- a/cmd/sharedflows/ghcrtsf.go +++ b/cmd/sharedflows/ghcrtsf.go @@ -40,7 +40,7 @@ var GhCreateCmd = &cobra.Command{ if ok := re.Match([]byte(ghPath)); !ok { return fmt.Errorf("github path must end with /sharedflowbundle") } - + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -67,7 +67,7 @@ func init() { "", "Sharedflow name") GhCreateCmd.Flags().StringVarP(&ghOwner, "owner", "u", "", "The github organization or username. ex: In https://github.com/apigee, apigee is the owner name") - GhCreateCmd.Flags().StringVarP(&ghRepo, "repo", "r", + GhCreateCmd.Flags().StringVarP(&ghRepo, "repo", "", "", "The github repo name. ex: https://github.com/apigee/api-platform-samples, api-platform-samples is the repo") GhCreateCmd.Flags().StringVarP(&ghPath, "sf-path", "p", "", "The path in the repo to the sharedflowbundle folder. ex: sample-proxies/security/sharedflowbundle") diff --git a/cmd/sharedflows/impsfs.go b/cmd/sharedflows/impsfs.go index 2668ef183..102a2adc9 100644 --- a/cmd/sharedflows/impsfs.go +++ b/cmd/sharedflows/impsfs.go @@ -32,6 +32,7 @@ var ImpCmd = &cobra.Command{ Long: "Import a folder containing sharedflow bundles", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/sharedflows/listdeploy.go b/cmd/sharedflows/listdeploy.go index a9c265a52..e29974f4b 100644 --- a/cmd/sharedflows/listdeploy.go +++ b/cmd/sharedflows/listdeploy.go @@ -40,6 +40,7 @@ var ListDepCmd = &cobra.Command{ if name != "" && revision == -1 && apiclient.GetApigeeEnv() != "" { return fmt.Errorf("revision must be supplied with sharedflow name and env") } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -61,6 +62,6 @@ func init() { "", "Shareflow name") ListDepCmd.Flags().StringVarP(&env, "env", "e", "", "Apigee environment name") - ListDepCmd.Flags().IntVarP(&revision, "rev", "r", + ListDepCmd.Flags().IntVarP(&revision, "rev", "v", -1, "Shareflow revision") } diff --git a/cmd/sharedflows/listsf.go b/cmd/sharedflows/listsf.go index 1e55647f2..d429142a4 100644 --- a/cmd/sharedflows/listsf.go +++ b/cmd/sharedflows/listsf.go @@ -29,6 +29,7 @@ var ListCmd = &cobra.Command{ Long: "Lists all shared flows in the organization.", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -42,6 +43,6 @@ var includeRevisions bool func init() { ListCmd.Flags().StringVarP(&env, "env", "e", "", "Apigee environment name") - ListCmd.Flags().BoolVarP(&includeRevisions, "rev", "r", + ListCmd.Flags().BoolVarP(&includeRevisions, "rev", "v", false, "Include revisions") } diff --git a/cmd/sharedflows/sharedflows.go b/cmd/sharedflows/sharedflows.go index 3d656803f..147799b16 100644 --- a/cmd/sharedflows/sharedflows.go +++ b/cmd/sharedflows/sharedflows.go @@ -26,13 +26,15 @@ var Cmd = &cobra.Command{ } var ( - name, org, env string - conn, revision int + name, org, env, region string + conn, revision int ) func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(ListCmd) Cmd.AddCommand(GetCmd) diff --git a/cmd/sharedflows/undepsf.go b/cmd/sharedflows/undepsf.go index a8e6cb889..fd9b50d81 100644 --- a/cmd/sharedflows/undepsf.go +++ b/cmd/sharedflows/undepsf.go @@ -29,6 +29,7 @@ var UndepCmd = &cobra.Command{ Long: "Undeploys a revision of an existing API proxy to an environment in an organization", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/sites/list.go b/cmd/sites/list.go index 7ea7b1924..6803ed781 100644 --- a/cmd/sites/list.go +++ b/cmd/sites/list.go @@ -27,6 +27,7 @@ var ListCmd = &cobra.Command{ Short: "Returns the API Portals associated with the org", Long: "Returns the API Portals associated with the org", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/sites/sites.go b/cmd/sites/sites.go index 2774ffd9a..f0cc0cb81 100644 --- a/cmd/sites/sites.go +++ b/cmd/sites/sites.go @@ -25,12 +25,15 @@ var Cmd = &cobra.Command{ Long: "Manage Apigee API Portals", } -var org string +var org, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") + Cmd.AddCommand(ListCmd) _ = Cmd.MarkFlagRequired("org") diff --git a/cmd/sync/getsync.go b/cmd/sync/getsync.go index b6d2b735f..d4371c647 100644 --- a/cmd/sync/getsync.go +++ b/cmd/sync/getsync.go @@ -28,6 +28,7 @@ var GetCmd = &cobra.Command{ Short: "Show the list of identities with access to control plane resources", Long: "Show the list of identities with access to control plane resources", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/sync/removesync.go b/cmd/sync/removesync.go index 9c0fc6707..a43ba1431 100644 --- a/cmd/sync/removesync.go +++ b/cmd/sync/removesync.go @@ -35,6 +35,7 @@ var RemoveCmd = &cobra.Command{ return fmt.Errorf("identity[0] must have .iam.gserviceaccount.com suffix"+ " and should not be a Google managed service account: %s", identity) } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/sync/resetsync.go b/cmd/sync/resetsync.go index 7f2d2acdb..a7e44ae0c 100644 --- a/cmd/sync/resetsync.go +++ b/cmd/sync/resetsync.go @@ -28,6 +28,7 @@ var ResetCmd = &cobra.Command{ Short: "Reset identities with access to control plane resources", Long: "Reset identities with access to control plane resources", Args: func(cmd *cobra.Command, args []string) (err error) { + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/sync/setsync.go b/cmd/sync/setsync.go index 0e01402e0..f94ed4719 100644 --- a/cmd/sync/setsync.go +++ b/cmd/sync/setsync.go @@ -35,6 +35,7 @@ var SetCmd = &cobra.Command{ return fmt.Errorf("identity[0] must have .iam.gserviceaccount.com suffix"+ " and should not be a Google managed service account: %s", identity) } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/sync/sync.go b/cmd/sync/sync.go index 999987bbc..42e11948f 100644 --- a/cmd/sync/sync.go +++ b/cmd/sync/sync.go @@ -25,11 +25,13 @@ var Cmd = &cobra.Command{ Long: "Manage identities with grant access to control plane resources", } -var org, identity string +var org, identity, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") Cmd.AddCommand(SetCmd) Cmd.AddCommand(GetCmd) diff --git a/cmd/targetservers/crtts.go b/cmd/targetservers/crtts.go index 731ccd70d..99c75c7fd 100644 --- a/cmd/targetservers/crtts.go +++ b/cmd/targetservers/crtts.go @@ -47,6 +47,7 @@ var CreateCmd = &cobra.Command{ return fmt.Errorf("ignoreValidationErrors must be set to true or false") } } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -80,18 +81,18 @@ func init() { CreateCmd.Flags().BoolVarP(&enable, "enable", "b", true, "Enabling/disabling a TargetServer") - CreateCmd.Flags().StringVarP(&keyStore, "keyStore", "", + CreateCmd.Flags().StringVarP(&keyStore, "keystore", "", "", "Key store for the target server") - CreateCmd.Flags().StringVarP(&keyAlias, "keyAlias", "", + CreateCmd.Flags().StringVarP(&keyAlias, "keyalias", "", "", "Key alias for the target server") - CreateCmd.Flags().StringVarP(&trustStore, "trustStore", "", + CreateCmd.Flags().StringVarP(&trustStore, "truststore", "", "", "Trust store for the target server") CreateCmd.Flags().StringVarP(&tlsenabled, "tls", "", "", "Enable TLS for the target server") - CreateCmd.Flags().StringVarP(&clientAuthEnabled, "clientAuth", "c", + CreateCmd.Flags().StringVarP(&clientAuthEnabled, "client-auth", "c", "", "Enable mTLS for the target server") - CreateCmd.Flags().StringVarP(&ignoreValidationErrors, "ignoreErr", "i", + CreateCmd.Flags().StringVarP(&ignoreValidationErrors, "ignore-err", "i", "", "Ignore TLS validation errors for the target server") CreateCmd.Flags().IntVarP(&port, "port", "p", diff --git a/cmd/targetservers/delts.go b/cmd/targetservers/delts.go index 5a9ecee1b..f87759a15 100644 --- a/cmd/targetservers/delts.go +++ b/cmd/targetservers/delts.go @@ -29,6 +29,7 @@ var DelCmd = &cobra.Command{ Long: "Delete a Target Server", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/targetservers/expts.go b/cmd/targetservers/expts.go index 2996c2e2a..753f0ff78 100644 --- a/cmd/targetservers/expts.go +++ b/cmd/targetservers/expts.go @@ -29,6 +29,7 @@ var ExpCmd = &cobra.Command{ Long: "Export target servers to a file", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/targetservers/getts.go b/cmd/targetservers/getts.go index b103d7e44..a99202357 100644 --- a/cmd/targetservers/getts.go +++ b/cmd/targetservers/getts.go @@ -29,6 +29,7 @@ var GetCmd = &cobra.Command{ Long: "Get a Target Server", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/targetservers/impts.go b/cmd/targetservers/impts.go index 8ee5c749c..54ab7f8a5 100644 --- a/cmd/targetservers/impts.go +++ b/cmd/targetservers/impts.go @@ -29,6 +29,7 @@ var ImpCmd = &cobra.Command{ Long: "Import a file containing target servers", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/targetservers/listts.go b/cmd/targetservers/listts.go index db78233d8..740c2b490 100644 --- a/cmd/targetservers/listts.go +++ b/cmd/targetservers/listts.go @@ -29,6 +29,7 @@ var ListCmd = &cobra.Command{ Long: "List Target Servers", Args: func(cmd *cobra.Command, args []string) (err error) { apiclient.SetApigeeEnv(env) + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/cmd/targetservers/targetservers.go b/cmd/targetservers/targetservers.go index 19fc52885..697248e33 100644 --- a/cmd/targetservers/targetservers.go +++ b/cmd/targetservers/targetservers.go @@ -26,13 +26,15 @@ var Cmd = &cobra.Command{ Long: "Manage Target Servers", } -var org, env, name string +var org, env, name, region string func init() { Cmd.PersistentFlags().StringVarP(&org, "org", "o", "", "Apigee organization name") Cmd.PersistentFlags().StringVarP(&env, "env", "e", "", "Apigee environment name") + Cmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "Apigee control plane region name; default is https://apigee.googleapis.com") _ = Cmd.MarkPersistentFlagRequired("env") diff --git a/cmd/targetservers/updatets.go b/cmd/targetservers/updatets.go index b4853fec6..3d2aef9b2 100644 --- a/cmd/targetservers/updatets.go +++ b/cmd/targetservers/updatets.go @@ -47,6 +47,7 @@ var UpdateCmd = &cobra.Command{ return fmt.Errorf("ignoreValidationErrors must be set to true or false") } } + apiclient.SetRegion(region) return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { @@ -73,18 +74,18 @@ func init() { UpdateCmd.Flags().BoolVarP(&enable, "enable", "b", true, "Enabling/disabling a TargetServer") - UpdateCmd.Flags().StringVarP(&keyStore, "keyStore", "", + UpdateCmd.Flags().StringVarP(&keyStore, "keystore", "", "", "Key store for the target server") - UpdateCmd.Flags().StringVarP(&keyAlias, "keyAlias", "", + UpdateCmd.Flags().StringVarP(&keyAlias, "keyalias", "", "", "Key alias for the target server") - UpdateCmd.Flags().StringVarP(&trustStore, "trustStore", "", + UpdateCmd.Flags().StringVarP(&trustStore, "truststore", "", "", "Trust store for the target server") UpdateCmd.Flags().StringVarP(&tlsenabled, "tls", "", "", "Enable TLS for the target server") - UpdateCmd.Flags().StringVarP(&clientAuthEnabled, "clientAuth", "c", + UpdateCmd.Flags().StringVarP(&clientAuthEnabled, "client-auth", "c", "", "Enable mTLS for the target server") - UpdateCmd.Flags().StringVarP(&ignoreValidationErrors, "ignoreErr", "i", + UpdateCmd.Flags().StringVarP(&ignoreValidationErrors, "ignore-err", "i", "", "Ignore TLS validation errors for the target server") UpdateCmd.Flags().IntVarP(&port, "port", "p", diff --git a/cmd/utils/utils.go b/cmd/utils/utils.go index 459eaf02e..7ea63da46 100644 --- a/cmd/utils/utils.go +++ b/cmd/utils/utils.go @@ -25,6 +25,15 @@ import ( "internal/clilog" ) +// Org variable is used within the registry cmd +var Org string + +// ProjectID variable is used within the registry cmd +var ProjectID string + +// Region variable is used within the registry cmd +var Region string + func ListKVMFiles(folder string) (orgKVMFileList map[string]string, envKVMFileList map[string]string, proxyKVMFileList map[string]string, err error, ) { diff --git a/internal/apiclient/bundles.go b/internal/apiclient/bundles.go index 59d449697..38bd491bb 100644 --- a/internal/apiclient/bundles.go +++ b/internal/apiclient/bundles.go @@ -205,7 +205,7 @@ func FetchAsyncBundle(entityType string, folder string, name string, revision st func FetchBundle(entityType string, folder string, name string, revision string, allRevisions bool) error { var proxyName string - u, _ := url.Parse(BaseURL) + u, _ := url.Parse(GetApigeeBaseURL()) q := u.Query() q.Set("format", "bundle") u.RawQuery = q.Encode() @@ -252,7 +252,7 @@ func ImportBundle(entityType string, name string, bundlePath string) (respBody [ name = names[0] } - u, _ := url.Parse(BaseURL) + u, _ := url.Parse(GetApigeeBaseURL()) u.Path = path.Join(u.Path, GetApigeeOrg(), entityType) q := u.Query() diff --git a/internal/apiclient/clifile.go b/internal/apiclient/clifile.go index 669e02588..0027e5f5d 100644 --- a/internal/apiclient/clifile.go +++ b/internal/apiclient/clifile.go @@ -35,10 +35,10 @@ type apigeeCLI struct { Token string `json:"token,omitempty"` LastCheck string `json:"lastCheck,omitempty"` Org string `json:"defaultOrg,omitempty"` - Staging bool `json:"staging,omitempty"` ProxyURL string `json:"proxyUrl,omitempty"` GithubURL string `json:"githubURL,omitempty"` Nocheck bool `json:"nocheck,omitempty" default:"false"` + Region string `json:"region,omitempty"` } var cliPref *apigeeCLI //= apigeeCLI{} @@ -66,10 +66,6 @@ func ReadPreferencesFile() (err error) { return DeletePreferencesFile() } - if cliPref.Staging { - UseStaging() - } - if cliPref.ProxyURL != "" { SetProxyURL(cliPref.ProxyURL) } @@ -78,9 +74,15 @@ func ReadPreferencesFile() (err error) { SetGithubURL(cliPref.GithubURL) } + if cliPref.Region != "" { + SetRegion(cliPref.Region) + } + if cliPref.Org != "" { + SetProjectID(cliPref.Org) return SetApigeeOrg(cliPref.Org) } + return nil } @@ -177,24 +179,6 @@ func WriteDefaultOrg(org string) (err error) { return WritePerferencesFile(data) } -func SetStaging(usestage bool) (err error) { - if usestage == cliPref.Staging { - return nil - } - cliPref.Staging = usestage - data, err := json.Marshal(&cliPref) - if err != nil { - clilog.Debug.Printf("Error marshalling: %v\n", err) - return err - } - clilog.Debug.Println("Writing ", string(data)) - return WritePerferencesFile(data) -} - -func GetStaging() bool { - return cliPref.Staging -} - func SetProxy(url string) (err error) { if url == "" { return nil @@ -229,6 +213,18 @@ func GetGithubURL() string { return cliPref.GithubURL } +func WriteDefaultRegion(r string) (err error) { + clilog.Debug.Println("Default control plane region: ", r) + cliPref.Region = r + data, err := json.Marshal(&cliPref) + if err != nil { + clilog.Debug.Printf("Error marshalling: %v\n", err) + return err + } + clilog.Debug.Println("Writing ", string(data)) + return WritePerferencesFile(data) +} + func GetPreferences() (err error) { output, err := json.Marshal(&cliPref) if err != nil { diff --git a/internal/apiclient/httpclient.go b/internal/apiclient/httpclient.go index 7bbef918f..fb6e09085 100644 --- a/internal/apiclient/httpclient.go +++ b/internal/apiclient/httpclient.go @@ -275,21 +275,21 @@ func HttpClient(params ...string) (respBody []byte, err error) { return nil, err } - clilog.Debug.Println("Connecting to: ", params[0]) - switch paramLen := len(params); paramLen { case 1: + clilog.Debug.Printf("Connecting to: %s - %s", http.MethodGet, params[0]) req, err = http.NewRequest(http.MethodGet, params[0], nil) case 2: + clilog.Debug.Printf("Connecting to: %s - %s", http.MethodPost, params[0]) payload := []byte(params[1]) if len(payload) > 0 { - //attempt to convert to json + // attempt to convert to json jsonPayload, err := PrettifyJSON([]byte(params[1])) if err != nil { - //payload is not json, print as-is + // payload is not json, print as-is clilog.Debug.Println("Payload: ", string(payload)) } else { - //print json + // print json clilog.Debug.Println("Payload: ", string(jsonPayload)) } } @@ -356,7 +356,7 @@ func PrettifyJSON(body []byte) ([]byte, error) { var prettyJSON bytes.Buffer err := json.Indent(&prettyJSON, body, "", "\t") if err != nil { - //fail silently + // fail silently return nil, err } return prettyJSON.Bytes(), nil @@ -415,6 +415,7 @@ func GetHttpClient() (err error) { } func getRequest(params []string) (req *http.Request, err error) { + clilog.Debug.Printf("Connecting to: %s - %s", params[2], params[0]) if params[2] == "DELETE" { req, err = http.NewRequest(http.MethodDelete, params[0], nil) } else if params[2] == "PUT" { diff --git a/internal/apiclient/iam.go b/internal/apiclient/iam.go index 84d105726..165be0fa7 100644 --- a/internal/apiclient/iam.go +++ b/internal/apiclient/iam.go @@ -263,7 +263,7 @@ func SetIAMPermission(memberName string, iamRole string, memberType string) (err ClientPrintHttpResponse.Set(false) defer ClientPrintHttpResponse.Set(GetCmdPrintHttpResponseSetting()) - u, _ := url.Parse(BaseURL) + u, _ := url.Parse(GetApigeeBaseURL()) u.Path = path.Join(u.Path, GetApigeeOrg(), "environments", GetApigeeEnv()+":getIamPolicy") getIamPolicyBody, err := HttpClient(u.String()) if err != nil { @@ -296,7 +296,7 @@ func SetIAMPermission(memberName string, iamRole string, memberType string) (err getIamPolicy.Bindings = append(getIamPolicy.Bindings, binding) } - u, _ = url.Parse(BaseURL) + u, _ = url.Parse(GetApigeeBaseURL()) u.Path = path.Join(u.Path, GetApigeeOrg(), "environments", GetApigeeEnv()+":setIamPolicy") setIamPolicy := setIamPolicy{} @@ -318,7 +318,7 @@ func RemoveIAMPermission(memberName string, iamRole string) (err error) { ClientPrintHttpResponse.Set(false) defer ClientPrintHttpResponse.Set(GetCmdPrintHttpResponseSetting()) - u, _ := url.Parse(BaseURL) + u, _ := url.Parse(GetApigeeBaseURL()) u.Path = path.Join(u.Path, GetApigeeOrg(), "environments", GetApigeeEnv()+":getIamPolicy") getIamPolicyBody, err := HttpClient(u.String()) clilog.Debug.Println(string(getIamPolicyBody)) @@ -417,7 +417,7 @@ func RemoveIAMPermission(memberName string, iamRole string) (err error) { } } - u, _ = url.Parse(BaseURL) + u, _ = url.Parse(GetApigeeBaseURL()) u.Path = path.Join(u.Path, GetApigeeOrg(), "environments", GetApigeeEnv()+":setIamPolicy") removeIamPolicyBody, err := json.Marshal(removeIamPolicy) diff --git a/internal/apiclient/options.go b/internal/apiclient/options.go index 7f32584d7..878608fff 100644 --- a/internal/apiclient/options.go +++ b/internal/apiclient/options.go @@ -22,11 +22,14 @@ import ( "internal/clilog" ) -// BaseURL is the Apigee control plane endpoint -var ( - BaseURL = "https://apigee.googleapis.com/v1/organizations/" - StageBaseURL = "https://staging-apigee.sandbox.googleapis.com/v1/organizations/" -) +// baseURL is the Apigee control plane endpoint +const baseURL = "https://apigee.googleapis.com/v1/organizations/" + +// registryBaseURL is the Apigee API Hub control plane endpoint +const registryBaseURL = "https://apigeeregistry.googleapis.com/v1/projects/%s/locations/%s" + +// baseDRZURL is the Apigee control plane endpoint +const baseDRZURL = "https://%s-apigee.googleapis.com/v1/organizations/" // ApigeeClientOptions is the base struct to hold all command arguments type ApigeeClientOptions struct { @@ -43,6 +46,7 @@ type ApigeeClientOptions struct { ProxyUrl string // use a proxy url MetadataToken bool // use metadata outh2 token APIRate Rate // throttle api calls to Apigee + Region string // control plane region } var options *ApigeeClientOptions @@ -66,6 +70,8 @@ type clientPrintHttpResponse struct { var ClientPrintHttpResponse = &clientPrintHttpResponse{enable: true} +const registryRegion = "global" + // NewApigeeClient sets up options to invoke Apigee APIs func NewApigeeClient(o ApigeeClientOptions) { if options == nil { @@ -81,9 +87,13 @@ func NewApigeeClient(o ApigeeClientOptions) { if o.ServiceAccount != "" { options.ServiceAccount = o.ServiceAccount } + // if a project is not explicitly set, use the org name as project id if o.ProjectID != "" { options.ProjectID = o.ProjectID + } else { + options.ProjectID = o.Org } + if o.Env != "" { options.Env = o.Env } @@ -101,11 +111,6 @@ func NewApigeeClient(o ApigeeClientOptions) { _ = ReadPreferencesFile() } -// UseStaging -func UseStaging() { - BaseURL = StageBaseURL -} - // SetApigeeOrg sets the org variable func SetApigeeOrg(org string) (err error) { if org == "" { @@ -115,6 +120,9 @@ func SetApigeeOrg(org string) (err error) { return nil } options.Org = org + if options.ProjectID == "" { + options.ProjectID = org + } return nil } @@ -143,6 +151,18 @@ func GetApigeeToken() string { return options.Token } +// GetRegion gets the control plane region +func GetRegion() string { + return options.Region +} + +// SetRegion +func SetRegion(r string) { + if r != "" { + options.Region = r + } +} + // SetProjectID sets the project id func SetProjectID(projectID string) { options.ProjectID = projectID @@ -261,3 +281,24 @@ func SetRate(r Rate) { func GetRate() Rate { return apiRate } + +// GetRegistryRegion +func GetRegistryRegion() string { + return registryRegion +} + +// GetApigeeRegistryURL +func GetApigeeRegistryURL() (registryURL string) { + if options.ProjectID == "" { + options.ProjectID = options.Org + } + return fmt.Sprintf(registryBaseURL, options.ProjectID, registryRegion) +} + +// GetApigeeBaseURL +func GetApigeeBaseURL() string { + if options.Region != "" { + return fmt.Sprintf(baseDRZURL, options.Region) + } + return baseURL +} diff --git a/internal/client/apicategories/apicategories.go b/internal/client/apicategories/apicategories.go index 8cbb6c5fc..d6d9b1805 100644 --- a/internal/client/apicategories/apicategories.go +++ b/internal/client/apicategories/apicategories.go @@ -55,7 +55,7 @@ func Create(siteid string, name string) (respBody []byte, err error) { apicategories = append(apicategories, "\"siteId\":"+"\""+siteid+"\"") apicategories = append(apicategories, "\"name\":"+"\""+name+"\"") payload := "{" + strings.Join(apicategories, ",") + "}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites", siteid, "apicategories") respBody, err = apiclient.HttpClient(u.String(), payload) return respBody, err @@ -63,7 +63,7 @@ func Create(siteid string, name string) (respBody []byte, err error) { // Get func Get(siteid string, name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites", siteid, "apicategories", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -71,7 +71,7 @@ func Get(siteid string, name string) (respBody []byte, err error) { // List func List(siteid string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites", siteid, "apicategories") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -79,7 +79,7 @@ func List(siteid string) (respBody []byte, err error) { // Delete func Delete(siteid string, name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites", siteid, "apicategories", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -91,7 +91,7 @@ func Update(siteid string, name string) (respBody []byte, err error) { apicategories = append(apicategories, "\"siteId\":"+"\""+siteid+"\"") apicategories = append(apicategories, "\"name\":"+"\""+name+"\"") payload := "{" + strings.Join(apicategories, ",") + "}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites", siteid, "apicategories") respBody, err = apiclient.HttpClient(u.String(), payload, "PATCH") return respBody, err @@ -108,7 +108,7 @@ func GetIDByName(siteid string, name string) (id string, err error) { if err != nil { return "", err } - var apicatResp = map[string]string{} + apicatResp := map[string]string{} err = json.Unmarshal(outBytes, &apicatResp) if err != nil { return "", err diff --git a/internal/client/apidocs/apidocs.go b/internal/client/apidocs/apidocs.go index 9de5654b1..5b457ec1a 100644 --- a/internal/client/apidocs/apidocs.go +++ b/internal/client/apidocs/apidocs.go @@ -124,7 +124,7 @@ func createOrUpdate(siteid string, id string, title string, description string, anonAllowed string, apiProductName string, requireCallbackUrl string, imageUrl string, categoryIds []string, action Action, ) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) apidoc := []string{} @@ -171,7 +171,7 @@ func createOrUpdate(siteid string, id string, title string, description string, // GetDocumentation func GetDocumentation(siteid string, id string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites", siteid, "apidocs", id, "documentation") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -179,7 +179,7 @@ func GetDocumentation(siteid string, id string) (respBody []byte, err error) { // Get func Get(siteid string, id string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites", siteid, "apidocs", id) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -220,7 +220,7 @@ func GetByTitle(siteid string, title string) (respBody []byte, err error) { // List func List(siteid string, pageSize int, pageToken string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites", siteid, "apidocs") q := u.Query() if pageSize != -1 { @@ -237,7 +237,7 @@ func List(siteid string, pageSize int, pageToken string) (respBody []byte, err e // Delete func Delete(siteid string, id string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites", siteid, "apidocs", id) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -279,7 +279,7 @@ func UpdateDocumentation(siteid string, id string, displayName string, } payload := string(jsonData) - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites", siteid, "apidocs", id, "documentation") respBody, err = apiclient.HttpClient(u.String(), payload, "PATCH") diff --git a/internal/client/apis/apis.go b/internal/client/apis/apis.go index 7a94ba873..dab19a211 100644 --- a/internal/client/apis/apis.go +++ b/internal/client/apis/apis.go @@ -86,7 +86,7 @@ func CreateProxy(name string, proxy string) (respBody []byte, err error) { respBody, err = apiclient.ImportBundle("apis", name, proxy) return respBody, err } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apis") proxyName := "{\"name\":\"" + name + "\"}" respBody, err = apiclient.HttpClient(u.String(), proxyName) @@ -95,7 +95,7 @@ func CreateProxy(name string, proxy string) (respBody []byte, err error) { // DeleteProxy func DeleteProxy(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apis", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -103,7 +103,7 @@ func DeleteProxy(name string) (respBody []byte, err error) { // DeleteProxyRevision func DeleteProxyRevision(name string, revision int) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apis", name, "revisions", strconv.Itoa(revision)) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -127,7 +127,7 @@ func DeployProxy(name string, revision int, overrides bool, sequencedRollout boo } } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) q := u.Query() q.Set("sequencedRollout", strconv.FormatBool(sequencedRollout)) @@ -156,7 +156,7 @@ func FetchProxy(name string, revision int) (err error) { // GetProxy func GetProxy(name string, revision int) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if revision != -1 { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apis", name, "revisions", strconv.Itoa(revision)) } else { @@ -171,7 +171,7 @@ func GetHighestProxyRevision(name string) (version int, err error) { apiclient.ClientPrintHttpResponse.Set(false) defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apis", name) respBody, err := apiclient.HttpClient(u.String()) if err != nil { @@ -191,7 +191,7 @@ func GetHighestProxyRevision(name string) (version int, err error) { // GenerateDeployChangeReport func GenerateDeployChangeReport(name string, revision int, overrides bool) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if apiclient.GetApigeeEnv() == "" { return respBody, fmt.Errorf("environment name missing") } @@ -212,7 +212,7 @@ func GenerateDeployChangeReport(name string, revision int, overrides bool) (resp // GenerateUndeployChangeReport func GenerateUndeployChangeReport(name string, revision int) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if apiclient.GetApigeeEnv() == "" { return respBody, fmt.Errorf("environment name missing") } @@ -225,7 +225,7 @@ func GenerateUndeployChangeReport(name string, revision int) (respBody []byte, e // ListProxies func ListProxies(includeRevisions bool) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if includeRevisions { q := u.Query() q.Set("includeRevisions", strconv.FormatBool(includeRevisions)) @@ -238,7 +238,7 @@ func ListProxies(includeRevisions bool) (respBody []byte, err error) { // ListEnvDeployments func ListEnvDeployments() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if apiclient.GetApigeeEnv() == "" { return respBody, fmt.Errorf("environment name missing") } @@ -249,7 +249,7 @@ func ListEnvDeployments() (respBody []byte, err error) { // ListProxyDeployments func ListProxyDeployments(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apis", name, "deployments") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -257,7 +257,7 @@ func ListProxyDeployments(name string) (respBody []byte, err error) { // ListProxyRevisionDeployments func ListProxyRevisionDeployments(name string, revision int) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if apiclient.GetApigeeEnv() == "" { return respBody, fmt.Errorf("environment name missing") } @@ -284,7 +284,7 @@ func UndeployProxy(name string, revision int, safeUndeploy bool) (respBody []byt return nil, fmt.Errorf("Undeployment conflicts detected. Here are the conflicts: %s", string(safeResp)) } } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "apis", name, "revisions", strconv.Itoa(revision), "deployments") respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") @@ -294,7 +294,7 @@ func UndeployProxy(name string, revision int, safeUndeploy bool) (respBody []byt // Update func Update(name string, labels map[string]string) (respBody []byte, err error) { if len(labels) != 0 { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) q := u.Query() q.Set("updateMask", "labels") u.RawQuery = q.Encode() @@ -415,7 +415,7 @@ func CleanProxy(name string, reportOnly bool, keepList []string) (err error) { // ExportProxies func ExportProxies(conn int, folder string, allRevisions bool) (err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) q := u.Query() q.Set("includeRevisions", "true") u.RawQuery = q.Encode() @@ -571,7 +571,7 @@ func importAPIProxies(wg *sync.WaitGroup, jobs <-chan string, errs chan<- error) return } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) q := u.Query() q.Set("name", strings.TrimSuffix(filepath.Base(job), ".zip")) q.Set("action", "import") diff --git a/internal/client/apis/kvm.go b/internal/client/apis/kvm.go index c3ad97605..62809375d 100644 --- a/internal/client/apis/kvm.go +++ b/internal/client/apis/kvm.go @@ -24,7 +24,7 @@ import ( // CreateProxyKVM func CreateProxyKVM(proxyName string, name string, encrypted bool) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apis", proxyName, "keyvaluemaps") payload := "{\"name\":\"" + name + "\", \"encrypted\": \"" + strconv.FormatBool(encrypted) + "\"}" respBody, err = apiclient.HttpClient(u.String(), payload) @@ -33,7 +33,7 @@ func CreateProxyKVM(proxyName string, name string, encrypted bool) (respBody []b // DeleteProxyKVM func DeleteProxyKVM(proxyName string, name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apis", name, "keyvaluemaps", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -41,7 +41,7 @@ func DeleteProxyKVM(proxyName string, name string) (respBody []byte, err error) // ListProxyKVM func ListProxyKVM(proxyName string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apis", proxyName, "keyvaluemaps") respBody, err = apiclient.HttpClient(u.String()) return respBody, err diff --git a/internal/client/apis/trace.go b/internal/client/apis/trace.go index 3513c8236..0854467ee 100644 --- a/internal/client/apis/trace.go +++ b/internal/client/apis/trace.go @@ -34,7 +34,7 @@ func getFilterStr(filter map[string]string) string { // CreateTraceSession func CreateTraceSession(name string, revision int, filter map[string]string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "apis", name, "revisions", strconv.Itoa(revision), "debugsessions") q := u.Query() @@ -53,7 +53,7 @@ func CreateTraceSession(name string, revision int, filter map[string]string) (re // GetTraceSession func GetTraceSession(name string, revision int, sessionID string, messageID string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if messageID == "" { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "apis", name, "revisions", strconv.Itoa(revision), "debugsessions", sessionID, "data") @@ -71,7 +71,7 @@ func GetTraceSession(name string, revision int, sessionID string, messageID stri // ListTracceSession func ListTracceSession(name string, revision int) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "apis", name, "revisions", strconv.Itoa(revision), "debugsessions") respBody, err = apiclient.HttpClient(u.String()) diff --git a/internal/client/appgroups/app.go b/internal/client/appgroups/app.go index 2b6ca8024..727be1995 100644 --- a/internal/client/appgroups/app.go +++ b/internal/client/appgroups/app.go @@ -90,7 +90,7 @@ func createAppNoKey(name string, appName string, expires string, callback string // DeleteApp func DeleteApp(name string, appName string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "appgroups", name, "apps", appName) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -98,7 +98,7 @@ func DeleteApp(name string, appName string) (respBody []byte, err error) { // GetApp func GetApp(name string, appName string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "appgroups", name, "apps", appName) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -106,7 +106,7 @@ func GetApp(name string, appName string) (respBody []byte, err error) { // ListApps func ListApps(name string, pageSize int, pageToken string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "appgroups", name, "apps") q := u.Query() if pageSize != -1 { @@ -127,7 +127,7 @@ func UpdateApp(name string, appName string, expires string, callback string, api } func createOrUpdate(name string, appName string, expires string, callback string, apiProducts []string, scopes []string, attrs map[string]string, action Action) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) app := []string{} app = append(app, "\"name\":\""+appName+"\"") @@ -175,7 +175,7 @@ func ManageApp(name string, appName string, action string) (respBody []byte, err return nil, fmt.Errorf("invalid action. action must be revoke or approve") } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "appgroups", name, "apps", appName) q := u.Query() q.Set("action", action) diff --git a/internal/client/appgroups/appgroups.go b/internal/client/appgroups/appgroups.go index db9d5de93..c22389e25 100644 --- a/internal/client/appgroups/appgroups.go +++ b/internal/client/appgroups/appgroups.go @@ -60,7 +60,7 @@ var maxPageSize = 1000 // Create func Create(name string, channelURI string, channelID string, displayName string, attrs map[string]string, devs map[string]string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) app := []string{} @@ -157,7 +157,7 @@ func Update(name string, channelURI string, channelID string, displayName string return nil, err } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "appgroups", name) respBody, err = apiclient.HttpClient(u.String(), string(reqBody), "PUT") return respBody, err @@ -165,7 +165,7 @@ func Update(name string, channelURI string, channelID string, displayName string // Get func Get(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "appgroups", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -173,7 +173,7 @@ func Get(name string) (respBody []byte, err error) { // Delete func Delete(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "appgroups", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -185,7 +185,7 @@ func Manage(name string, action string) (respBody []byte, err error) { return nil, fmt.Errorf("invalid action. action must be active or inactive") } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "appgroups", name) q := u.Query() q.Set("action", action) @@ -197,7 +197,7 @@ func Manage(name string, action string) (respBody []byte, err error) { // List func List(pageSize int, pageToken string, filter string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "appgroups") q := u.Query() if pageSize != -1 { diff --git a/internal/client/appgroups/keys.go b/internal/client/appgroups/keys.go index 99a29f9b4..bae1a00b1 100644 --- a/internal/client/appgroups/keys.go +++ b/internal/client/appgroups/keys.go @@ -25,7 +25,7 @@ import ( // CreateKey func CreateKey(name string, appName string, consumerKey string, consumerSecret string, expiresInSeconds string, apiProducts []string, scopes []string, attrs map[string]string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) key := []string{} @@ -74,7 +74,7 @@ func CreateKey(name string, appName string, consumerKey string, consumerSecret s // GetKey func GetKey(name string, appName string, key string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "appgroups", name, "apps", appName, "keys", key) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -82,7 +82,7 @@ func GetKey(name string, appName string, key string) (respBody []byte, err error // DeleteKey func DeleteKey(name string, appName string, key string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "appgroups", name, "apps", appName, "keys", key) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -94,7 +94,7 @@ func ManageKey(name string, appName string, consumerKey string, action string) ( return nil, fmt.Errorf("invalid action. action must be revoke or approve") } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "appgroups", name, "apps", appName, "keys", consumerKey) q := u.Query() q.Set("action", action) @@ -106,7 +106,7 @@ func ManageKey(name string, appName string, consumerKey string, action string) ( // UpdateKeyProducts func UpdateKeyProducts(name string, appName string, consumerKey string, apiProducts []string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) key := []string{} key = append(key, "\"apiProducts\":[\""+getArrayStr(apiProducts)+"\"]") @@ -121,7 +121,7 @@ func UpdateKeyProducts(name string, appName string, consumerKey string, apiProdu // DeleteKeyProduct func DeleteKeyProduct(name string, appName string, consumerKey string, productName string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "appgroups", name, "apps", appName, "keys", consumerKey, "apiproducts", productName) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err diff --git a/internal/client/apps/apps.go b/internal/client/apps/apps.go index 83e2aa812..48631c67c 100644 --- a/internal/client/apps/apps.go +++ b/internal/client/apps/apps.go @@ -93,7 +93,7 @@ func Create(name string, email string, expires string, callback string, apiProdu // Delete func Delete(name string, developerID string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", developerID, "apps", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -101,7 +101,7 @@ func Delete(name string, developerID string) (respBody []byte, err error) { // Get func Get(appID string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apps", appID) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -113,7 +113,7 @@ func Update(name string, email string, expires string, callback string, apiProdu } func createOrUpdate(name string, email string, expires string, callback string, apiProducts []string, scopes []string, attrs map[string]string, action Action) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) app := []string{} @@ -163,7 +163,7 @@ func Manage(appID string, developerEmail string, action string) (respBody []byte return nil, fmt.Errorf("invalid action. action must be revoke or approve") } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", developerEmail, "apps", appID) q := u.Query() q.Set("action", action) @@ -178,7 +178,7 @@ func SearchApp(name string) (respBody []byte, err error) { apiclient.ClientPrintHttpResponse.Set(false) defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apps") q := u.Query() q.Set("filter", "appName="+name) @@ -202,7 +202,7 @@ func List(includeCred bool, expand bool, count int, status string, startKey stri ids string, keyStatus string, apiProduct string, pageSize int, pageToken string, filter string, ) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apps") q := u.Query() if expand { @@ -247,7 +247,7 @@ func List(includeCred bool, expand bool, count int, status string, startKey stri // ListApps func ListApps(productName string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apps") q := u.Query() q.Set("apiProduct", productName) @@ -258,7 +258,7 @@ func ListApps(productName string) (respBody []byte, err error) { // GenerateKey func GenerateKey(name string, developerID string, apiProducts []string, callback string, expires string, scopes []string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) key := []string{} @@ -293,7 +293,7 @@ func Export(conn int) (payload [][]byte, err error) { var mu sync.Mutex const entityType = "apps" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), entityType) respBody, err := apiclient.HttpClient(u.String()) @@ -421,7 +421,7 @@ func batchExport(entities []app, entityType string, pwg *sync.WaitGroup, mu *syn bwg.Add(len(entities)) for _, entity := range entities { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), entityType, entity.AppID) go apiclient.GetAsyncEntity(u.String(), &bwg, mu) } @@ -448,7 +448,7 @@ func createAsyncApp(app application, developerEntities developers.Appdevelopers, // importing an app will be a two step process. // 1. create the app without the credential // 2. create/import the credential - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if app.DeveloperID == nil { clilog.Error.Println("developer id was not found") return @@ -499,7 +499,7 @@ func createAsyncApp(app application, developerEntities developers.Appdevelopers, return } - createDeveloperAppUrl, _ := url.Parse(apiclient.BaseURL) + createDeveloperAppUrl, _ := url.Parse(apiclient.GetApigeeBaseURL()) createDeveloperAppUrl.Path = path.Join(createDeveloperAppUrl.Path, apiclient.GetApigeeOrg(), "developers", developerID, "apps", app.Name, "keys") for _, credential := range credentials { @@ -529,7 +529,7 @@ func createAsyncApp(app application, developerEntities developers.Appdevelopers, if len(products) > 0 { // updateDeveloperApp - updateDeveloperAppUrl, _ := url.Parse(apiclient.BaseURL) + updateDeveloperAppUrl, _ := url.Parse(apiclient.GetApigeeBaseURL()) updateDeveloperAppUrl.Path = path.Join(updateDeveloperAppUrl.Path, apiclient.GetApigeeOrg(), "developers", developerID, "apps", app.Name, "keys", credential.ConsumerKey) updateCred := importCredential{} diff --git a/internal/client/apps/keys.go b/internal/client/apps/keys.go index ed5db6ac6..43e99dfe6 100644 --- a/internal/client/apps/keys.go +++ b/internal/client/apps/keys.go @@ -15,6 +15,7 @@ package apps import ( + "encoding/json" "fmt" "net/url" "path" @@ -24,8 +25,11 @@ import ( ) // CreateKey -func CreateKey(developerEmail string, appID string, consumerKey string, consumerSecret string, apiProducts []string, scopes []string, expires string, attrs map[string]string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) +func CreateKey(developerEmail string, appID string, consumerKey string, consumerSecret string, + apiProducts []string, scopes []string, expires string, + attrs map[string]string, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) key := []string{} @@ -63,7 +67,8 @@ func CreateKey(developerEmail string, appID string, consumerKey string, consumer if len(apiProducts) > 0 { // restore client output setting apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) - respBody, err = UpdateKeyProducts(developerEmail, appID, consumerKey, apiProducts, scopes) + respBody, err = UpdateKey(developerEmail, appID, consumerKey, apiProducts, scopes, nil) + // UpdateKeyProducts(developerEmail, appID, consumerKey, apiProducts, scopes) } return respBody, err @@ -71,7 +76,7 @@ func CreateKey(developerEmail string, appID string, consumerKey string, consumer // DeleteKey func DeleteKey(developerEmail string, appName string, key string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", developerEmail, "apps", appName, "keys", key) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -79,7 +84,7 @@ func DeleteKey(developerEmail string, appName string, key string) (respBody []by // GetKey func GetKey(developerEmail string, appID string, key string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", developerEmail, "apps", appID, "keys", key) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -89,7 +94,31 @@ func GetKey(developerEmail string, appID string, key string) (respBody []byte, e func UpdateKey(developerEmail string, appID string, consumerKey string, apiProducts []string, scopes []string, attrs map[string]string, ) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + curCred := credential{} + + apiclient.ClientPrintHttpResponse.Set(false) + credRespBody, err := GetKey(developerEmail, appID, consumerKey) + if err != nil { + return nil, err + } + + if err = json.Unmarshal(credRespBody, &curCred); err != nil { + return nil, err + } + + // remove all products from the app + for _, p := range curCred.APIProducts { + _, err = deleteKeyProduct(developerEmail, appID, consumerKey, p.Name) + if err != nil { + return nil, err + } + } + + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) + + // add the products set in the function + + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) key := []string{} @@ -115,13 +144,13 @@ func UpdateKey(developerEmail string, appID string, consumerKey string, payload := "{" + strings.Join(key, ",") + "}" u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", developerEmail, "apps", appID, "keys", consumerKey) - respBody, err = apiclient.HttpClient(u.String(), payload) + respBody, err = apiclient.HttpClient(u.String(), payload, "PUT") return respBody, err } -func UpdateKeyProducts(developerEmail string, appID string, consumerKey string, apiProducts []string, scopes []string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) +/*func UpdateKeyProducts(developerEmail string, appID string, consumerKey string, apiProducts []string, scopes []string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) key := []string{} key = append(key, "\"apiProducts\":[\""+getArrayStr(apiProducts)+"\"]") @@ -136,14 +165,14 @@ func UpdateKeyProducts(developerEmail string, appID string, consumerKey string, respBody, err = apiclient.HttpClient(u.String(), payload) return respBody, err -} +}*/ func ManageKey(developerEmail string, appID string, consumerKey string, action string) (respBody []byte, err error) { if action != "revoke" && action != "approve" { return nil, fmt.Errorf("invalid action. action must be revoke or approve") } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", developerEmail, "apps", appID, "keys", consumerKey) q := u.Query() q.Set("action", action) @@ -152,3 +181,11 @@ func ManageKey(developerEmail string, appID string, consumerKey string, action s return respBody, err } + +func deleteKeyProduct(developerEmail string, appID string, consumerKey string, product string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) + u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", + developerEmail, "apps", appID, "keys", consumerKey, "apiproducts", product) + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} diff --git a/internal/client/cache/cache.go b/internal/client/cache/cache.go index e696e3b80..a2cb473c5 100644 --- a/internal/client/cache/cache.go +++ b/internal/client/cache/cache.go @@ -23,7 +23,7 @@ import ( // Delete func Delete(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "caches", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -31,7 +31,7 @@ func Delete(name string) (respBody []byte, err error) { // List func List() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "caches") respBody, err = apiclient.HttpClient(u.String()) return respBody, err diff --git a/internal/client/datacollectors/datacollectors.go b/internal/client/datacollectors/datacollectors.go index 4b4605b85..e4c096f80 100644 --- a/internal/client/datacollectors/datacollectors.go +++ b/internal/client/datacollectors/datacollectors.go @@ -49,7 +49,7 @@ func Create(name string, description string, collectorType string) (respBody []b payload := "{" + strings.Join(datacollector, ",") + "}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "datacollectors") respBody, err = apiclient.HttpClient(u.String(), payload) return respBody, err @@ -57,7 +57,7 @@ func Create(name string, description string, collectorType string) (respBody []b // Get func Get(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "datacollectors", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -65,7 +65,7 @@ func Get(name string) (respBody []byte, err error) { // Delete func Delete(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "datacollectors", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -73,7 +73,7 @@ func Delete(name string) (respBody []byte, err error) { // List func List() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "datacollectors") respBody, err = apiclient.HttpClient(u.String()) return respBody, err diff --git a/internal/client/datastores/datastores.go b/internal/client/datastores/datastores.go index 57218f710..0adebd962 100644 --- a/internal/client/datastores/datastores.go +++ b/internal/client/datastores/datastores.go @@ -85,7 +85,7 @@ func createOrTestorUpdate(id string, displayName string, targetType string, proj bucketName string, gcsPath string, datasetName string, tablePrefix string, action Action, ) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) ds := []string{} @@ -129,7 +129,7 @@ func createOrTestorUpdate(id string, displayName string, targetType string, proj // Delete func Delete(id string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "analytics", "datastores", id) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -137,7 +137,7 @@ func Delete(id string) (respBody []byte, err error) { // Get func Get(id string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "analytics", "datastores", id) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -200,7 +200,7 @@ func GetVersion(name string) (version string, err error) { // List func List(targetType string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "analytics", "datastores") if (targetType != "") && (targetType != "gcs" && targetType != "bigquery") { return nil, fmt.Errorf("invalid targetType. Must be gcs or bigquery") diff --git a/internal/client/developers/balance.go b/internal/client/developers/balance.go index 6fa5b03d5..ff6481aa0 100644 --- a/internal/client/developers/balance.go +++ b/internal/client/developers/balance.go @@ -43,7 +43,7 @@ func Adjust(email string, adjust string) (respBody []byte, err error) { return nil, err } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email), "balance:adjust") respBody, err = apiclient.HttpClient(u.String(), adjust) return respBody, err @@ -55,7 +55,7 @@ func Credit(email string, transact string) (respBody []byte, err error) { return nil, err } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email), "balance:credit") respBody, err = apiclient.HttpClient(u.String(), transact) return respBody, err diff --git a/internal/client/developers/developers.go b/internal/client/developers/developers.go index 55ecfcea3..b6ae419e4 100644 --- a/internal/client/developers/developers.go +++ b/internal/client/developers/developers.go @@ -37,9 +37,13 @@ type Appdeveloper struct { FirstName string `json:"firstName,omitempty"` LastName string `json:"lastName,omitempty"` Attributes []Attribute `json:"attributes,omitempty"` + Apps []string `json:"apps,omitempty"` + Companies []string `json:"companies,omitempty"` Username string `json:"userName,omitempty"` DeveloperId string `json:"developerId,omitempty"` Status *string `json:"status,omitempty"` + AccessType string `json:"accessType,omitempty"` + AppFamily string `json:"appFamily,omitempty"` } // Appdevelopers hold an array of developers @@ -55,7 +59,7 @@ type Attribute struct { // Create func Create(email string, firstName string, lastName string, username string, attrs map[string]string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) developer := []string{} @@ -81,7 +85,7 @@ func Create(email string, firstName string, lastName string, username string, at // Delete func Delete(email string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email)) // since developer emails can have + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -89,7 +93,7 @@ func Delete(email string) (respBody []byte, err error) { // Get func Get(email string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email)) // since developer emails can have + respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -147,14 +151,14 @@ func Update(email string, firstName string, lastName string, username string, st return nil, err } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email)) respBody, err = apiclient.HttpClient(u.String(), string(reqBody), "PUT") return respBody, err } func setDeveloperStatus(email string, action string) (err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email)) q := u.Query() q.Set("action", action) @@ -169,7 +173,7 @@ func GetDeveloperId(email string) (developerId string, err error) { apiclient.ClientPrintHttpResponse.Set(false) defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) var developerMap map[string]interface{} - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email)) // since developer emails can have + respBody, err := apiclient.HttpClient(u.String()) if err != nil { @@ -185,7 +189,7 @@ func GetDeveloperId(email string) (developerId string, err error) { // GetApps func GetApps(name string, expand bool) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if expand { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", name, "apps") q := u.Query() @@ -199,8 +203,9 @@ func GetApps(name string, expand bool) (respBody []byte, err error) { } // List -func List(count int, expand bool, ids string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) +func List(count int, expand bool, ids string, startKey string, + app string, includeCompany bool) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers") q := u.Query() if expand { @@ -214,6 +219,12 @@ func List(count int, expand bool, ids string) (respBody []byte, err error) { if ids != "" { q.Set("ids", ids) } + if includeCompany { + q.Set("includeCompany", "true") + } + if startKey != "" { + q.Set("startKey", startKey) + } u.RawQuery = q.Encode() respBody, err = apiclient.HttpClient(u.String()) @@ -222,17 +233,35 @@ func List(count int, expand bool, ids string) (respBody []byte, err error) { // Export func Export() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) - u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers") - q := u.Query() - q.Set("expand", "true") - - u.RawQuery = q.Encode() // don't print to sysout apiclient.ClientPrintHttpResponse.Set(false) - defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) - respBody, err = apiclient.HttpClient(u.String()) + devs := Appdevelopers{} + startKey := "" + for { + d := Appdevelopers{} + respBody, err := List(-1, true, "", startKey, "", false) + if err != nil { + return nil, err + } + err = json.Unmarshal(respBody, &d) + if err != nil { + return nil, err + } + if len(d.Developer) > 1 { + devs.Developer = append(devs.Developer, d.Developer...) + startKey = devs.Developer[len(devs.Developer)-1].EMail + } else { + break + } + } + + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) + respBody, err = json.Marshal(&devs) + if err != nil { + return nil, err + } + respBody, err = apiclient.PrettifyJSON(respBody) return respBody, err } @@ -288,7 +317,7 @@ func Import(conn int, filePath string) error { func createAsyncDeveloper(wg *sync.WaitGroup, jobs <-chan Appdeveloper, errs chan<- error) { defer wg.Done() - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers") for { diff --git a/internal/client/developers/subscriptions.go b/internal/client/developers/subscriptions.go index 7c2c0eb7a..9e2dc7146 100644 --- a/internal/client/developers/subscriptions.go +++ b/internal/client/developers/subscriptions.go @@ -23,7 +23,7 @@ import ( ) func CreateSubscription(email string, name string, apiproduct string, startTime string, endTime string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) subscription := []string{} @@ -40,7 +40,7 @@ func CreateSubscription(email string, name string, apiproduct string, startTime // ExpireSubscriptions func ExpireSubscriptions(email string, subscription string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email), "subscriptions", subscription, ":expire") // since developer emails can have + respBody, err = apiclient.HttpClient(u.String(), "") return respBody, err @@ -48,7 +48,7 @@ func ExpireSubscriptions(email string, subscription string) (respBody []byte, er // GetSubscriptions func GetSubscriptions(email string, subscription string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email), "subscriptions", subscription) // since developer emails can have + respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -56,7 +56,7 @@ func GetSubscriptions(email string, subscription string) (respBody []byte, err e // ListSubscriptions func ListSubscriptions(email string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email), "subscriptions") // since developer emails can have + respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -64,7 +64,7 @@ func ListSubscriptions(email string) (respBody []byte, err error) { // ExportSubscriptions func ExportSubscriptions(email string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email), "subscriptions") // don't print to sysout diff --git a/internal/client/env/archives.go b/internal/client/env/archives.go index f0e5043fc..3c9620e04 100644 --- a/internal/client/env/archives.go +++ b/internal/client/env/archives.go @@ -28,7 +28,7 @@ import ( func generateUploadURL() (respBody []byte, err error) { apiclient.ClientPrintHttpResponse.Set(false) defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "archiveDeployments:generateUploadUrl") respBody, err = apiclient.HttpClient(u.String(), "") return respBody, err @@ -71,7 +71,7 @@ func CreateArchive(name string, zipfile string) (respBody []byte, err error) { payload := "{" + strings.Join(archive, ",") + "}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "archiveDeployments") respBody, err = apiclient.HttpClient(u.String(), payload) return respBody, err @@ -79,7 +79,7 @@ func CreateArchive(name string, zipfile string) (respBody []byte, err error) { // GetArchive func GetArchive(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "archiveDeployments", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -87,7 +87,7 @@ func GetArchive(name string) (respBody []byte, err error) { // ListArchives func ListArchives() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "archiveDeployments") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -95,7 +95,7 @@ func ListArchives() (respBody []byte, err error) { // DeleteArchive func DeleteArchive(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "archiveDeployments", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err diff --git a/internal/client/env/debugmask.go b/internal/client/env/debugmask.go index f535f1371..60d9523ad 100644 --- a/internal/client/env/debugmask.go +++ b/internal/client/env/debugmask.go @@ -24,7 +24,7 @@ import ( // GetDebug func GetDebug() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "debugmask") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -38,7 +38,7 @@ func SetDebug(maskConfig string) (respBody []byte, err error) { if err != nil { return respBody, err } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "debugmask") respBody, err = apiclient.HttpClient(u.String(), maskConfig) return respBody, err diff --git a/internal/client/env/env.go b/internal/client/env/env.go index b57a9e016..1c2900251 100644 --- a/internal/client/env/env.go +++ b/internal/client/env/env.go @@ -43,7 +43,7 @@ func Create(deploymentType string, fwdProxyURI string) (respBody []byte, err err payload := "{" + strings.Join(environment, ",") + "}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments") respBody, err = apiclient.HttpClient(u.String(), payload) return respBody, err @@ -51,7 +51,7 @@ func Create(deploymentType string, fwdProxyURI string) (respBody []byte, err err // Delete func Delete() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv()) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -59,7 +59,7 @@ func Delete() (respBody []byte, err error) { // Get func Get(config bool) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if config { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "deployedConfig") } else { @@ -71,7 +71,7 @@ func Get(config bool) (respBody []byte, err error) { // List func List() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -79,7 +79,7 @@ func List() (respBody []byte, err error) { // GetDeployments func GetDeployments(sharedflows bool) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if sharedflows { q := u.Query() q.Set("sharedFlows", "true") @@ -115,7 +115,7 @@ func GetAllDeployments() (respBody []byte, err error) { // GetDeployedConfig func GetDeployedConfig() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "deployedConfig") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -142,7 +142,7 @@ func SetEnvProperty(name string, value string) (err error) { Properties envProperties `json:"properties,omitempty"` } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv()) // get env details apiclient.ClientPrintHttpResponse.Set(false) @@ -183,7 +183,7 @@ func SetEnvProperty(name string, value string) (err error) { return err } - u, _ = url.Parse(apiclient.BaseURL) + u, _ = url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv()) _, err = apiclient.HttpClient(u.String(), string(newEnvBody), "PUT") @@ -211,7 +211,7 @@ func ClearEnvProperties() (err error) { Properties envProperties `json:"-,omitempty"` } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv()) // get env details apiclient.ClientPrintHttpResponse.Set(false) @@ -235,7 +235,7 @@ func ClearEnvProperties() (err error) { return err } - u, _ = url.Parse(apiclient.BaseURL) + u, _ = url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv()) _, err = apiclient.HttpClient(u.String(), string(newEnvBody), "PUT") @@ -244,7 +244,7 @@ func ClearEnvProperties() (err error) { // GetSecurityActionsConfig func GetSecurityActionsConfig() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "securityActionsConfig") respBody, err = apiclient.HttpClient(u.String()) @@ -253,7 +253,7 @@ func GetSecurityActionsConfig() (respBody []byte, err error) { // GetSecurityRuntimeConfig func GetSecurityRuntimeConfig() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "apiSecurityRuntimeConfig") respBody, err = apiclient.HttpClient(u.String()) @@ -262,7 +262,7 @@ func GetSecurityRuntimeConfig() (respBody []byte, err error) { // UpdateSecurityActionsConfig func UpdateSecurityActionsConfig(action bool) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "apiSecurityRuntimeConfig") diff --git a/internal/client/env/iam.go b/internal/client/env/iam.go index e73688176..745d3ca1a 100644 --- a/internal/client/env/iam.go +++ b/internal/client/env/iam.go @@ -27,7 +27,7 @@ var validMemberTypes = []string{"serviceAccount", "group", "user", "domain"} // GetIAM func GetIAM() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv()+":getIamPolicy") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -53,7 +53,7 @@ func RemoveIAM(memberName string, role string) (err error) { // TestIAM func TestIAM(resource string, verb string) (respBody []byte, err error) { permission := "apigee." + resource + "." + verb - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv()+":testIamPermissions") payload := "{\"permissions\":[\"" + permission + "\"]}" respBody, err = apiclient.HttpClient(u.String(), payload) diff --git a/internal/client/env/reports.go b/internal/client/env/reports.go index ab5f49f32..b8eeca518 100644 --- a/internal/client/env/reports.go +++ b/internal/client/env/reports.go @@ -88,7 +88,7 @@ func TotalAPICallsInMonth(environment string, month int, year int) (total int, e apiclient.SetRate(apiclient.ApigeeAnalyticsAPI) defer apiclient.SetRate(getDefaultRate) - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) timeRange := fmt.Sprintf("%d/01/%d 00:00~%d/%d/%d 23:59", month, year, month, daysIn(time.Month(month), year), year) diff --git a/internal/client/env/securityactions.go b/internal/client/env/securityactions.go index 83ebe0b2c..e77541503 100644 --- a/internal/client/env/securityactions.go +++ b/internal/client/env/securityactions.go @@ -61,7 +61,7 @@ func CreateSecurityAction(name string, content []byte) (respBody []byte, err err if err = json.Unmarshal(content, &sa); err != nil { return nil, err } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "securityActions") respBody, err = apiclient.HttpClient(u.String(), string(content)) @@ -70,7 +70,7 @@ func CreateSecurityAction(name string, content []byte) (respBody []byte, err err // DisableSecurityAction func DisableSecurityAction(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "securityActions", name+":disable") respBody, err = apiclient.HttpClient(u.String(), "") @@ -79,7 +79,7 @@ func DisableSecurityAction(name string) (respBody []byte, err error) { // EnableSecurityAction func EnableSecurityAction(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "securityActions", name+":enable") respBody, err = apiclient.HttpClient(u.String(), "") @@ -88,7 +88,7 @@ func EnableSecurityAction(name string) (respBody []byte, err error) { // GetSecurityAction func GetSecurityAction(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "securityActions", name) respBody, err = apiclient.HttpClient(u.String()) @@ -97,7 +97,7 @@ func GetSecurityAction(name string) (respBody []byte, err error) { // ListSecurityActions func ListSecurityActions(pageSize int, pageToken string, filter string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "securityActions") q := u.Query() diff --git a/internal/client/env/securityincidents.go b/internal/client/env/securityincidents.go index 1087544d4..947c9cebb 100644 --- a/internal/client/env/securityincidents.go +++ b/internal/client/env/securityincidents.go @@ -24,7 +24,7 @@ import ( // GetSecurityIncident func GetSecurityIncident(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "securityIncidents", name) respBody, err = apiclient.HttpClient(u.String()) @@ -33,7 +33,7 @@ func GetSecurityIncident(name string) (respBody []byte, err error) { // ListSecurityIncidents func ListSecurityIncidents(pageSize int, pageToken string, filter string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "securityIncidents") q := u.Query() diff --git a/internal/client/env/securityreports.go b/internal/client/env/securityreports.go index 72070080b..2f064338c 100644 --- a/internal/client/env/securityreports.go +++ b/internal/client/env/securityreports.go @@ -24,7 +24,7 @@ import ( // GetSecurityReportView func GetSecurityReportView(reportID string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "securityReports", reportID, "resultView") respBody, err = apiclient.HttpClient(u.String()) @@ -33,7 +33,7 @@ func GetSecurityReportView(reportID string) (respBody []byte, err error) { // GetSecurityReportResult func GetSecurityReportResult(reportID string, name string) (err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "securityReports", reportID, "result") err = apiclient.DownloadResource(u.String(), name, ".zip", true) @@ -42,7 +42,7 @@ func GetSecurityReportResult(reportID string, name string) (err error) { // GetSecurityReport func GetSecurityReport(reportID string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "securityReports", reportID) respBody, err = apiclient.HttpClient(u.String()) @@ -53,7 +53,7 @@ func GetSecurityReport(reportID string) (respBody []byte, err error) { func ListSecurityReports(pageSize int, pageToken string, dataset string, to string, from string, status string, submittedBy string, ) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "securityReports") q := u.Query() diff --git a/internal/client/env/traceconfig.go b/internal/client/env/traceconfig.go index 6d257b82b..37ff5e145 100644 --- a/internal/client/env/traceconfig.go +++ b/internal/client/env/traceconfig.go @@ -37,7 +37,7 @@ type samplingCfg struct { // GetTraceConfig func GetTraceConfig() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "traceConfig") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -63,14 +63,14 @@ func UpdateTraceConfig(exporter string, endpoint string, sampler string, sample_ payload := "{" + strings.Join(traceConfig, ",") + "}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "traceConfig") respBody, err = apiclient.HttpClient(u.String(), payload, "PATCH") return respBody, err } func ImportTraceConfig(payload string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "traceConfig") respBody, err = apiclient.HttpClient(u.String(), payload, "PATCH") return respBody, err @@ -102,7 +102,7 @@ func DisableTraceConfig() (respBody []byte, err error) { return nil, err } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "traceConfig") respBody, err = apiclient.HttpClient(u.String(), string(payload), "PATCH") return respBody, err diff --git a/internal/client/env/traceoverrides.go b/internal/client/env/traceoverrides.go index f190db31c..c4b1e053f 100644 --- a/internal/client/env/traceoverrides.go +++ b/internal/client/env/traceoverrides.go @@ -34,28 +34,28 @@ func CreateTraceOverrides(apiproxy string, exporter string, endpoint string, sam payload := "{" + strings.Join(traceConfig, ",") + "}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "traceConfig", "overrides") respBody, err = apiclient.HttpClient(u.String(), payload) return respBody, err } func GetTraceOverrides(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "traceConfig", "overrides", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err } func DeleteTraceOverrides(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "traceConfig", "overrides", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err } func ListTraceOverrides() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "traceConfig", "overrides") respBody, err = apiclient.HttpClient(u.String()) return respBody, err diff --git a/internal/client/envgroups/envgroups.go b/internal/client/envgroups/envgroups.go index d49addda5..6ad3b786e 100644 --- a/internal/client/envgroups/envgroups.go +++ b/internal/client/envgroups/envgroups.go @@ -47,7 +47,7 @@ func Create(name string, hostnames []string) (respBody []byte, err error) { payload := "{" + strings.Join(envgroup, ",") + "}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "envgroups") respBody, err = apiclient.HttpClient(u.String(), payload) return respBody, err @@ -55,7 +55,7 @@ func Create(name string, hostnames []string) (respBody []byte, err error) { // Get func Get(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "envgroups", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -63,7 +63,7 @@ func Get(name string) (respBody []byte, err error) { // Delete func Delete(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "envgroups", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -71,7 +71,7 @@ func Delete(name string) (respBody []byte, err error) { // List func List() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "envgroups") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -79,7 +79,7 @@ func List() (respBody []byte, err error) { // PatchHosts func PatchHosts(name string, hostnames []string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "envgroups", name) q := u.Query() q.Set("updateMask", "hostnames") @@ -99,7 +99,7 @@ func Attach(name string, environment string) (respBody []byte, err error) { envgroup = append(envgroup, "\"environment\":\""+environment+"\"") payload := "{" + strings.Join(envgroup, ",") + "}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "envgroups", name, "attachments") respBody, err = apiclient.HttpClient(u.String(), payload) return respBody, err @@ -141,7 +141,7 @@ func DetachEnvironment(name string, environment string) (respBody []byte, err er // Detach func Detach(name string, attachment string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "envgroups", name, "attachments", attachment) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -149,7 +149,7 @@ func Detach(name string, attachment string) (respBody []byte, err error) { // ListAttach func ListAttach(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "envgroups", name, "attachments") respBody, err = apiclient.HttpClient(u.String()) return respBody, err diff --git a/internal/client/eptattachment/eptattchment.go b/internal/client/eptattachment/eptattchment.go index abe273c4d..8ec2a8441 100644 --- a/internal/client/eptattachment/eptattchment.go +++ b/internal/client/eptattachment/eptattchment.go @@ -31,7 +31,7 @@ func Create(name string, serviceAttachment string, location string) (respBody [] payload := "{" + strings.Join(endpointAttachment, ",") + "}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "endpointAttachments") q := u.Query() @@ -44,7 +44,7 @@ func Create(name string, serviceAttachment string, location string) (respBody [] // Get func Get(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "endpointAttachments", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -52,7 +52,7 @@ func Get(name string) (respBody []byte, err error) { // Delete func Delete(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "endpointAttachments", name) respBody, err = apiclient.HttpClient(u.String(), "DELETE") return respBody, err @@ -60,7 +60,7 @@ func Delete(name string) (respBody []byte, err error) { // List func List() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "endpointAttachments") respBody, err = apiclient.HttpClient(u.String()) return respBody, err diff --git a/internal/client/flowhooks/flowhooks.go b/internal/client/flowhooks/flowhooks.go index 83ca1a589..ecc286921 100644 --- a/internal/client/flowhooks/flowhooks.go +++ b/internal/client/flowhooks/flowhooks.go @@ -25,7 +25,7 @@ import ( // Attach func Attach(name string, description string, sharedflow string, continueOnErr bool) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) flowhook := []string{} @@ -49,7 +49,7 @@ func Attach(name string, description string, sharedflow string, continueOnErr bo // Detach func Detach(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "flowhooks", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -57,7 +57,7 @@ func Detach(name string) (respBody []byte, err error) { // Get func Get(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "flowhooks", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -65,7 +65,7 @@ func Get(name string) (respBody []byte, err error) { // List func List() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "flowhooks") respBody, err = apiclient.HttpClient(u.String()) return respBody, err diff --git a/internal/client/instances/attachments.go b/internal/client/instances/attachments.go index f5001f79a..a34ba5397 100644 --- a/internal/client/instances/attachments.go +++ b/internal/client/instances/attachments.go @@ -30,7 +30,7 @@ func Attach(name string, environment string) (respBody []byte, err error) { envgroup = append(envgroup, "\"environment\":\""+environment+"\"") payload := "{" + strings.Join(envgroup, ",") + "}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "instances", name, "attachments") respBody, err = apiclient.HttpClient(u.String(), payload) return respBody, err @@ -39,7 +39,7 @@ func Attach(name string, environment string) (respBody []byte, err error) { // DetachEnv func DetachEnv(instance string) (respBody []byte, err error) { var attachmentName string - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if attachmentName, err = getAttachmentName(instance); err != nil { return nil, err @@ -57,7 +57,7 @@ func DetachEnv(instance string) (respBody []byte, err error) { // func GetEnv func GetEnv(instance string) (respBody []byte, err error) { var attachmentName string - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if attachmentName, err = getAttachmentName(instance); err != nil { return nil, err @@ -74,7 +74,7 @@ func GetEnv(instance string) (respBody []byte, err error) { // Detach func Detach(name string, instanceName string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "instances", instanceName, "attachments", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -82,7 +82,7 @@ func Detach(name string, instanceName string) (respBody []byte, err error) { // GetAttach func GetAttach(name string, instanceName string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "instances", instanceName, "attachments", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -90,7 +90,7 @@ func GetAttach(name string, instanceName string) (respBody []byte, err error) { // ListAttach func ListAttach(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "instances", name, "attachments") respBody, err = apiclient.HttpClient(u.String()) return respBody, err diff --git a/internal/client/instances/instances.go b/internal/client/instances/instances.go index bb7207f19..1ef907db7 100644 --- a/internal/client/instances/instances.go +++ b/internal/client/instances/instances.go @@ -47,7 +47,7 @@ func Create(name string, location string, diskEncryptionKeyName string, ipRange payload := "{" + strings.Join(instance, ",") + "}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "instances") respBody, err = apiclient.HttpClient(u.String(), payload) return respBody, err @@ -55,7 +55,7 @@ func Create(name string, location string, diskEncryptionKeyName string, ipRange // Get func Get(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "instances", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -63,7 +63,7 @@ func Get(name string) (respBody []byte, err error) { // Delete func Delete(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "instances", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -71,7 +71,7 @@ func Delete(name string) (respBody []byte, err error) { // List func List() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "instances") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -81,7 +81,7 @@ func List() (respBody []byte, err error) { func Update(name string, consumerAcceptList []string) (respBody []byte, err error) { instance := []string{} - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "instances", name) if len(consumerAcceptList) > 0 { diff --git a/internal/client/instances/nat.go b/internal/client/instances/nat.go index 0bfd90177..3d6c93297 100644 --- a/internal/client/instances/nat.go +++ b/internal/client/instances/nat.go @@ -28,7 +28,7 @@ func ReserveNatIP(name string, natid string) (respBody []byte, err error) { reserveNat = append(reserveNat, "\"name\":\""+natid+"\"") payload := "{" + strings.Join(reserveNat, ",") + "}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "instances", name, "natAddresses") respBody, err = apiclient.HttpClient(u.String(), payload) return respBody, err @@ -37,7 +37,7 @@ func ReserveNatIP(name string, natid string) (respBody []byte, err error) { // ActivateNatIP func ActivateNatIP(name string, natid string) (respBody []byte, err error) { payload := "{}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "instances", name, "natAddresses", natid, ":activate") respBody, err = apiclient.HttpClient(u.String(), payload) return respBody, err @@ -45,7 +45,7 @@ func ActivateNatIP(name string, natid string) (respBody []byte, err error) { // DeleteNatIP func DeleteNatIP(name string, natid string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "instances", name, "natAddresses", natid) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -53,7 +53,7 @@ func DeleteNatIP(name string, natid string) (respBody []byte, err error) { // ListNatIPs func ListNatIPs(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "instances", name, "natAddresses") respBody, err = apiclient.HttpClient(u.String()) return respBody, err diff --git a/internal/client/keyaliases/keyaliases.go b/internal/client/keyaliases/keyaliases.go index f96c0c06e..031218bb3 100644 --- a/internal/client/keyaliases/keyaliases.go +++ b/internal/client/keyaliases/keyaliases.go @@ -44,7 +44,7 @@ type subject struct { } func CreateOrUpdateSelfSigned(keystoreName string, name string, update bool, ignoreExpiry bool, ignoreNewLine bool, selfsignedFile string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keystores", keystoreName, "aliases") @@ -134,7 +134,7 @@ func CreateOrUpdateKeyCert(keystoreName string, name string, update bool, ignore } func createOrUpdate(keystoreName string, name string, format string, password string, update bool, ignoreExpiry bool, ignoreNewLine bool, formParams map[string]string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) q := u.Query() q.Set("format", format) @@ -164,7 +164,7 @@ func createOrUpdate(keystoreName string, name string, format string, password st // CreateCSR func CreateCSR(keystoreName string, name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keystores", keystoreName, "aliases", name, "csr") respBody, err = apiclient.HttpClient(u.String()) @@ -173,7 +173,7 @@ func CreateCSR(keystoreName string, name string) (respBody []byte, err error) { // GetCert func GetCert(keystoreName string, name string) (err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keystores", keystoreName, "aliases", name, "certificate") err = apiclient.DownloadResource(u.String(), name+".crt", "", true) @@ -182,7 +182,7 @@ func GetCert(keystoreName string, name string) (err error) { // Get func Get(keystoreName string, name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keystores", keystoreName, "aliases", name) respBody, err = apiclient.HttpClient(u.String()) @@ -191,7 +191,7 @@ func Get(keystoreName string, name string) (respBody []byte, err error) { // Delete func Delete(keystoreName string, name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keystores", keystoreName, "aliases", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") @@ -200,7 +200,7 @@ func Delete(keystoreName string, name string) (respBody []byte, err error) { // List func List(keystoreName string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keystores", keystoreName, "aliases") respBody, err = apiclient.HttpClient(u.String()) diff --git a/internal/client/keystores/keystores.go b/internal/client/keystores/keystores.go index 7ca35287f..790cd29ff 100644 --- a/internal/client/keystores/keystores.go +++ b/internal/client/keystores/keystores.go @@ -32,7 +32,7 @@ import ( // Create func Create(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keystores") payload := "{\"name\":\"" + name + "\"}" respBody, err = apiclient.HttpClient(u.String(), payload) @@ -41,7 +41,7 @@ func Create(name string) (respBody []byte, err error) { // Get func Get(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keystores", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -49,7 +49,7 @@ func Get(name string) (respBody []byte, err error) { // Delete func Delete(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keystores", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -57,7 +57,7 @@ func Delete(name string) (respBody []byte, err error) { // List func List() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keystores") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -121,7 +121,7 @@ func importKeystores(wg *sync.WaitGroup, jobs <-chan string, errs chan<- error) return } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keystores") u.RawQuery = fmt.Sprintf("name=%s", job) diff --git a/internal/client/kvm/entries.go b/internal/client/kvm/entries.go index 300f9c29d..faa753d8f 100644 --- a/internal/client/kvm/entries.go +++ b/internal/client/kvm/entries.go @@ -42,7 +42,7 @@ type keyvalueentries struct { // CreateEntry func CreateEntry(proxyName string, mapName string, keyName string, value string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if apiclient.GetApigeeEnv() != "" { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keyvaluemaps", mapName, "entries") } else if proxyName != "" { @@ -57,7 +57,7 @@ func CreateEntry(proxyName string, mapName string, keyName string, value string) // DeleteEntry func DeleteEntry(proxyName string, mapName string, keyName string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if apiclient.GetApigeeEnv() != "" { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keyvaluemaps", mapName, "entries", keyName) } else if proxyName != "" { @@ -71,7 +71,7 @@ func DeleteEntry(proxyName string, mapName string, keyName string) (respBody []b // GetEntry func GetEntry(proxyName string, mapName string, keyName string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if apiclient.GetApigeeEnv() != "" { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keyvaluemaps", mapName, "entries", keyName) } else if proxyName != "" { @@ -85,7 +85,7 @@ func GetEntry(proxyName string, mapName string, keyName string) (respBody []byte // ListEntries func ListEntries(proxyName string, mapName string, pageSize int, pageToken string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if pageToken != "" || pageSize != -1 { q := u.Query() @@ -209,7 +209,7 @@ func ExportEntries(proxyName string, mapName string) (payload [][]byte, err erro func ImportEntries(proxyName string, mapName string, conn int, filePath string) (err error) { var pwg sync.WaitGroup - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if apiclient.GetApigeeEnv() != "" { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keyvaluemaps", mapName, "entries") } else if proxyName != "" { diff --git a/internal/client/kvm/kvm.go b/internal/client/kvm/kvm.go index b3223868e..936c0132d 100644 --- a/internal/client/kvm/kvm.go +++ b/internal/client/kvm/kvm.go @@ -25,7 +25,7 @@ import ( // Create func Create(proxyName string, name string, encrypt bool) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) kvm := []string{} kvm = append(kvm, "\"name\":\""+name+"\"") @@ -48,7 +48,7 @@ func Create(proxyName string, name string, encrypt bool) (respBody []byte, err e // Delete func Delete(proxyName string, name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if apiclient.GetApigeeEnv() != "" { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keyvaluemaps", name) @@ -64,7 +64,7 @@ func Delete(proxyName string, name string) (respBody []byte, err error) { // List func List(proxyName string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if apiclient.GetApigeeEnv() != "" { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "keyvaluemaps") } else if proxyName != "" { diff --git a/internal/client/operations/operations.go b/internal/client/operations/operations.go index eccf34d5d..32f7a25e0 100644 --- a/internal/client/operations/operations.go +++ b/internal/client/operations/operations.go @@ -61,7 +61,7 @@ const ( // Get func Get(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "operations", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -69,7 +69,7 @@ func Get(name string) (respBody []byte, err error) { // List func List(state string, completeState OperationCompleteState) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "operations") if state != "" { apiclient.ClientPrintHttpResponse.Set(false) diff --git a/internal/client/orgs/orgs.go b/internal/client/orgs/orgs.go index 94ef0d676..0d168c104 100644 --- a/internal/client/orgs/orgs.go +++ b/internal/client/orgs/orgs.go @@ -95,20 +95,12 @@ func Create(description string, analyticsRegion string, authorizedNetwork string portalDisabled bool, apiConsumerDataEncryptionKeyName string, controlPlaneEncryptionKeyName string, apiConsumerDataLocation string, ) (respBody []byte, err error) { - const baseURL = "https://apigee.googleapis.com/v1/organizations" - stageBaseURL := "https://staging-apigee.sandbox.googleapis.com/v1/organizations/" - if !validRegion(analyticsRegion) { return respBody, fmt.Errorf("invalid analytics region."+ " Analytics region must be one of : %v", analyticsRegions) } - var u *url.URL - if apiclient.GetStaging() { - u, _ = url.Parse(stageBaseURL) - } else { - u, _ = url.Parse(baseURL) - } + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path) q := u.Query() @@ -162,7 +154,7 @@ func Create(description string, analyticsRegion string, authorizedNetwork string // Get func Get() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -170,7 +162,7 @@ func Get() (respBody []byte, err error) { // Delete func Delete(retension string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if retension != "" { q := u.Query() q.Set("retention", retension) @@ -183,7 +175,7 @@ func Delete(retension string) (respBody []byte, err error) { // GetOrgField func GetOrgField(key string) (value string, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()) orgBody, err := apiclient.HttpClient(u.String()) @@ -201,7 +193,7 @@ func GetOrgField(key string) (value string, err error) { // GetAddOn func GetAddOn(addon string) (enabled bool) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()) apiclient.DisableCmdPrintHttpResponse() @@ -234,14 +226,14 @@ func GetAddOn(addon string) (enabled bool) { // List func List() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) respBody, err = apiclient.HttpClient(u.String()) return respBody, err } // GetDeployedIngressConfig func GetDeployedIngressConfig(view bool) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if view { q := u.Query() q.Set("view", "full") @@ -254,7 +246,7 @@ func GetDeployedIngressConfig(view bool) (respBody []byte, err error) { // GetlDeployments func GetDeployments(sharedflows bool) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if sharedflows { q := u.Query() q.Set("sharedFlows", "true") @@ -291,7 +283,7 @@ func GetAllDeployments() (respBody []byte, err error) { // SetOrgProperty is used to set org properties func SetOrgProperty(name string, value string) (err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()) // get org details apiclient.ClientPrintHttpResponse.Set(false) @@ -332,7 +324,7 @@ func SetOrgProperty(name string, value string) (err error) { return err } - u, _ = url.Parse(apiclient.BaseURL) + u, _ = url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()) _, err = apiclient.HttpClient(u.String(), string(newOrgBody), "PUT") @@ -367,7 +359,7 @@ func Update(description string, authorizedNetwork string) (respBody []byte, err return nil, err } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()) respBody, err = apiclient.HttpClient(u.String(), string(newOrgBody), "PUT") @@ -420,7 +412,7 @@ func SetAddons(advancedApiOpsConfig bool, integrationConfig bool, monetizationCo payload := "{\"addonsConfig\":{" + strings.Join(addonPayload, ",") + "}}" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":setAddons") respBody, err = apiclient.HttpClient(u.String(), payload) diff --git a/internal/client/products/products.go b/internal/client/products/products.go index 30041b337..8e956e874 100644 --- a/internal/client/products/products.go +++ b/internal/client/products/products.go @@ -129,7 +129,7 @@ func Update(p APIProduct) (respBody []byte, err error) { // Get func Get(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -137,7 +137,7 @@ func Get(name string) (respBody []byte, err error) { // Delete func Delete(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -145,7 +145,7 @@ func Delete(name string) (respBody []byte, err error) { // upsert - use Action to control if upsert is enabled func upsert(p APIProduct, a Action) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) var createNew bool // default false @@ -182,7 +182,7 @@ func upsert(p APIProduct, a Action) (respBody []byte, err error) { // UpdateAttribute func UpdateAttribute(name string, key string, value string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", name, "attributes", key) payload := "{ \"name\":\"" + key + "\",\"value\":\"" + value + "\"}" respBody, err = apiclient.HttpClient(u.String(), payload) @@ -191,7 +191,7 @@ func UpdateAttribute(name string, key string, value string) (respBody []byte, er // DeleteAttribute func DeleteAttribute(name string, key string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", name, "attributes", key) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -199,7 +199,7 @@ func DeleteAttribute(name string, key string) (respBody []byte, err error) { // GetAttribute func GetAttribute(name string, key string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", name, "attributes", key) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -207,7 +207,7 @@ func GetAttribute(name string, key string) (respBody []byte, err error) { // ListAttributes func ListAttributes(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", name, "attributes") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -215,7 +215,7 @@ func ListAttributes(name string) (respBody []byte, err error) { // List func List(count int, startKey string, expand bool) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts") q := u.Query() if expand { @@ -312,7 +312,7 @@ func Export(conn int) (payload [][]byte, err error) { var mu sync.Mutex const entityType = "apiproducts" - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), entityType) // don't print to sysout apiclient.ClientPrintHttpResponse.Set(false) @@ -422,7 +422,7 @@ func batchExport(entities []APIProduct, entityType string, pwg *sync.WaitGroup, bwg.Add(len(entities)) for _, entity := range entities { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), entityType, url.PathEscape(entity.Name)) go apiclient.GetAsyncEntity(u.String(), &bwg, mu) } diff --git a/internal/client/products/rateplans.go b/internal/client/products/rateplans.go index fdb0139d0..7140f941e 100644 --- a/internal/client/products/rateplans.go +++ b/internal/client/products/rateplans.go @@ -23,7 +23,7 @@ import ( // CreateRatePlan func CreateRatePlan(productName string, rateplan []byte) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", productName, "rateplans") respBody, err = apiclient.HttpClient(u.String(), string(rateplan)) return respBody, err @@ -31,7 +31,7 @@ func CreateRatePlan(productName string, rateplan []byte) (respBody []byte, err e // DeleteRatePlan func DeleteRatePlan(productName string, rateplan string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", productName, "rateplans", rateplan) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -39,7 +39,7 @@ func DeleteRatePlan(productName string, rateplan string) (respBody []byte, err e // GetRatePlan func GetRatePlan(productName string, rateplan string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", productName, "rateplans", rateplan) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -47,7 +47,7 @@ func GetRatePlan(productName string, rateplan string) (respBody []byte, err erro // ListRatePlan func ListRatePlan(productName string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", productName, "rateplans") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -55,7 +55,7 @@ func ListRatePlan(productName string) (respBody []byte, err error) { // ExportRateplan func ExportRateplan(productName string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", productName, "rateplans") // don't print to sysout diff --git a/internal/client/references/references.go b/internal/client/references/references.go index 2654017e2..72bf83f26 100644 --- a/internal/client/references/references.go +++ b/internal/client/references/references.go @@ -40,7 +40,7 @@ type ref struct { // Create references func Create(name string, description string, resourceType string, refers string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) reference := []string{} @@ -62,7 +62,7 @@ func Create(name string, description string, resourceType string, refers string) // Get a reference func Get(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "references", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -70,7 +70,7 @@ func Get(name string) (respBody []byte, err error) { // DeleteĀ a reference func Delete(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "references", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -78,7 +78,7 @@ func Delete(name string) (respBody []byte, err error) { // List references func List() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "references") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -86,7 +86,7 @@ func List() (respBody []byte, err error) { // Update references func Update(name string, description string, resourceType string, refers string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) reference := []string{} @@ -212,7 +212,7 @@ func Import(conn int, filePath string) (err error) { clilog.Debug.Printf("Found %d references in the file\n", len(references)) clilog.Debug.Printf("Create references with %d connections\n", conn) - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "references") err = apiclient.GetHttpClient() if err != nil { @@ -304,7 +304,7 @@ func importReferences(knownRefs map[string]bool, wg *sync.WaitGroup, jobs <-chan continue } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "references") method := http.MethodPost if knownRefs[job.Name] { diff --git a/internal/client/registry/apis/apis.go b/internal/client/registry/apis/apis.go new file mode 100644 index 000000000..07b1ada31 --- /dev/null +++ b/internal/client/registry/apis/apis.go @@ -0,0 +1,113 @@ +// 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 apis + +import ( + "net/url" + "path" + "strconv" + "strings" + + "internal/apiclient" +) + +// Create +func Create(apiID string, name string, displayName string, description string, + availability string, recommendedVersion string, recommendedDeployment string, + labels map[string]string, annotations map[string]string, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis") + q := u.Query() + q.Set("apiId", apiID) + u.RawQuery = q.Encode() + + apiContent := []string{} + apiContent = append(apiContent, "\"name\":"+"\""+name+"\"") + if displayName != "" { + apiContent = append(apiContent, "\"displayName\":"+"\""+displayName+"\"") + } + if description != "" { + apiContent = append(apiContent, "\"description\":"+"\""+description+"\"") + } + if availability != "" { + apiContent = append(apiContent, "\"availability\":"+"\""+availability+"\"") + } + if recommendedVersion != "" { + apiContent = append(apiContent, "\"recommendedVersion\":"+"\""+recommendedVersion+"\"") + } + if recommendedDeployment != "" { + apiContent = append(apiContent, "\"recommendedDeployment\":"+"\""+recommendedDeployment+"\"") + } + if len(labels) > 0 { + l := []string{} + for key, value := range labels { + l = append(l, "\""+key+"\":\""+value+"\"") + } + labelStr := "\"labels\":{" + strings.Join(l, ",") + "}" + apiContent = append(apiContent, labelStr) + } + + if len(annotations) > 0 { + a := []string{} + for key, value := range annotations { + a = append(a, "\""+key+"\":\""+value+"\"") + } + annotationStr := "\"annotations\":{" + strings.Join(a, ",") + "}" + apiContent = append(apiContent, annotationStr) + } + payload := "{" + strings.Join(apiContent, ",") + "}" + respBody, err = apiclient.HttpClient(u.String(), payload) + return respBody, err +} + +// Get +func Get(name string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", name) + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +// Delete +func Delete(name string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", name) + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} + +// List +func List(pageSize int, pageToken string, filter string, orderBy string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis") + q := u.Query() + if pageSize != -1 { + q.Set("pageSize", strconv.Itoa(pageSize)) + } + if pageToken != "" { + q.Set("pageToken", pageToken) + } + if filter != "" { + q.Set("filter", filter) + } + if orderBy != "" { + q.Set("orderBy", orderBy) + } + + u.RawQuery = q.Encode() + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} diff --git a/internal/client/registry/apis/artifacts.go b/internal/client/registry/apis/artifacts.go new file mode 100644 index 000000000..a2a0be47e --- /dev/null +++ b/internal/client/registry/apis/artifacts.go @@ -0,0 +1,94 @@ +// 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 apis + +import ( + "net/url" + "path" + + "internal/apiclient" + "internal/client/registry/common" +) + +type Action uint8 + +const ( + CREATE Action = iota + UPDATE +) + +// CreateArtifact +func CreateArtifact(apiName string, artifactID string, name string, contents string, + labels map[string]string, annotations map[string]string, +) (respBody []byte, err error) { + return createOrReplace(apiName, artifactID, name, contents, labels, annotations, CREATE) +} + +// ReplaceArtifact +func ReplaceArtifact(apiName string, artifactID string, name string, contents string, + labels map[string]string, annotations map[string]string, +) (respBody []byte, err error) { + return createOrReplace(apiName, artifactID, name, contents, labels, annotations, UPDATE) +} + +// DeleteArtifact +func DeleteArtifact(apiName string, name string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "artifacts", name) + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} + +// GetArtifact +func GetArtifact(apiName string, name string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "artifacts", name) + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +// GetArtifactContents +func GetArtifactContents(apiName string, name string) (err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "artifacts", name+":getContents") + return apiclient.DownloadResource(u.String(), name+".txt", "", true) +} + +// ListArtifacts +func ListArtifacts(name string, pageSize int, pageToken string, filter string, orderBy string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", name, "artifacts") + return common.ListArtifacts(u, pageSize, pageToken, filter, orderBy) +} + +// createOrReplace +func createOrReplace(apiName string, artifactID string, name string, contents string, + labels map[string]string, annotations map[string]string, action Action, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + payload := common.GetArtifactPayload(name, contents, labels, annotations) + + if action == CREATE { + u.Path = path.Join(u.Path, "apis", apiName, "artifacts") + q := u.Query() + q.Set("artifactId", artifactID) + u.RawQuery = q.Encode() + respBody, err = apiclient.HttpClient(u.String(), payload) + } else { + u.Path = path.Join(u.Path, "apis", apiName, "artifacts", artifactID) + respBody, err = apiclient.HttpClient(u.String(), payload, "PUT") + } + return respBody, err +} diff --git a/internal/client/registry/apis/deployments.go b/internal/client/registry/apis/deployments.go new file mode 100644 index 000000000..3ba6464f7 --- /dev/null +++ b/internal/client/registry/apis/deployments.go @@ -0,0 +1,173 @@ +// 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 apis + +import ( + "net/url" + "path" + "strconv" + "strings" + + "internal/apiclient" +) + +// CreateDeployment +func CreateDeployment(apiDeploymentID string, name string, displayName string, description string, + apiSpecRevsion string, endpointURI string, externalChannelURI string, intendedAudience string, + accessGuidance string, labels map[string]string, annotations map[string]string, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiDeploymentID, "deployment") + apiDeployment := []string{} + apiDeployment = append(apiDeployment, "\"name\":"+"\""+name+"\"") + if displayName != "" { + apiDeployment = append(apiDeployment, "\"displayName\":"+"\""+displayName+"\"") + } + if description != "" { + apiDeployment = append(apiDeployment, "\"description\":"+"\""+description+"\"") + } + if apiSpecRevsion != "" { + apiDeployment = append(apiDeployment, "\"apiSpecRevsion\":"+"\""+apiSpecRevsion+"\"") + } + if endpointURI != "" { + apiDeployment = append(apiDeployment, "\"endpointUri\":"+"\""+endpointURI+"\"") + } + if externalChannelURI != "" { + apiDeployment = append(apiDeployment, "\"externalChannelUri\":"+"\""+externalChannelURI+"\"") + } + if intendedAudience != "" { + apiDeployment = append(apiDeployment, "\"intendedAudience\":"+"\""+intendedAudience+"\"") + } + if accessGuidance != "" { + apiDeployment = append(apiDeployment, "\"accessGuidance\":"+"\""+accessGuidance+"\"") + } + if len(labels) > 0 { + l := []string{} + for key, value := range labels { + l = append(l, "\""+key+"\":\""+value+"\"") + } + labelStr := "\"labels\":{" + strings.Join(l, ",") + "}" + apiDeployment = append(apiDeployment, labelStr) + } + + if len(annotations) > 0 { + a := []string{} + for key, value := range annotations { + a = append(a, "\""+key+"\":\""+value+"\"") + } + annotationStr := "\"annotations\":{" + strings.Join(a, ",") + "}" + apiDeployment = append(apiDeployment, annotationStr) + } + payload := "{" + strings.Join(apiDeployment, ",") + "}" + respBody, err = apiclient.HttpClient(u.String(), payload) + return respBody, err +} + +// Tag +func Tag(name string, deployment string, tag string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", name, "deployments", deployment+":tagRevision") + payload := "{\"tag\":\"" + tag + "\"}" + respBody, err = apiclient.HttpClient(u.String(), payload) + return respBody, err +} + +// Rollback +func Rollback(name string, deployment string, revisionID string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", name, "deployments", deployment+":rollback") + payload := "{\"revisionId\":\"" + revisionID + "\"}" + respBody, err = apiclient.HttpClient(u.String(), payload) + return respBody, err +} + +// DeleteDeployment +func DeleteDeployment(name string, deployment string, force bool) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", name, "deployments", deployment) + if force { + q := u.Query() + q.Set("force", strconv.FormatBool(force)) + u.RawQuery = q.Encode() + } + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} + +// DeleteDeploymentRevision +func DeleteDeploymentRevision(name string, deployment string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", name, "deployments", deployment+":deleteRevision") + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} + +// GetDeployment +func GetDeployment(name string, deployment string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", name, "deployments", deployment) + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +// ListDeploymentRevisions +func ListDeploymentRevisions(apiName string, name string, pageSize int, pageToken string, + filter string, orderBy string, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "deployments", name+":listRevisions") + q := u.Query() + if pageSize != -1 { + q.Set("pageSize", strconv.Itoa(pageSize)) + } + if pageToken != "" { + q.Set("pageToken", pageToken) + } + if filter != "" { + q.Set("filter", filter) + } + if orderBy != "" { + q.Set("orderBy", orderBy) + } + + u.RawQuery = q.Encode() + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +// ListDeployments +func ListDeployments(name string, pageSize int, pageToken string, + filter string, orderBy string, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", name, "deployments") + q := u.Query() + if pageSize != -1 { + q.Set("pageSize", strconv.Itoa(pageSize)) + } + if pageToken != "" { + q.Set("pageToken", pageToken) + } + if filter != "" { + q.Set("filter", filter) + } + if orderBy != "" { + q.Set("orderBy", orderBy) + } + + u.RawQuery = q.Encode() + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} diff --git a/internal/client/registry/apis/deployments/artifacts.go b/internal/client/registry/apis/deployments/artifacts.go new file mode 100644 index 000000000..30f580180 --- /dev/null +++ b/internal/client/registry/apis/deployments/artifacts.go @@ -0,0 +1,95 @@ +// 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 deployments + +import ( + "net/url" + "path" + + "internal/apiclient" + "internal/client/registry/common" +) + +type Action uint8 + +const ( + CREATE Action = iota + UPDATE +) + +// CreateArtifact +func CreateArtifact(apiName string, deploymentName string, artifactID string, name string, contents string, + labels map[string]string, annotations map[string]string, +) (respBody []byte, err error) { + createOrReplace(apiName, deploymentName, artifactID, name, contents, labels, annotations, CREATE) +} + +// ReplaceArtifact +func ReplaceArtifact(apiName string, deploymentName string, artifactID string, name string, contents string, + labels map[string]string, annotations map[string]string, +) (respBody []byte, err error) { + return createOrReplace(apiName, deploymentName, artifactID, name, contents, labels, annotations, UPDATE) +} + +// DeleteArtifact +func DeleteArtifact(apiName string, deploymentName string, name string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "deployments", deploymentName, "artifacts", name) + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} + +// GetArtifact +func GetArtifact(apiName string, deploymentName string, name string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "deployments", deploymentName, "artifacts", name) + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +// GetArtifactContents +func GetArtifactContents(apiName string, deploymentName string, name string) (err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "deployments", deploymentName, "artifacts", name+":getContents") + return apiclient.DownloadResource(u.String(), name+".txt", "", true) +} + +// ListArtifacts +func ListArtifacts(apiName string, deploymentName string, pageSize int, + pageToken string, filter string, orderBy string, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "deployments", deploymentName, "artifacts") + return common.ListArtifacts(u, pageSize, pageToken, filter, orderBy) +} + +func createOrReplace(apiName string, deploymentName string, artifactID string, name string, contents string, + labels map[string]string, annotations map[string]string, action Action, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + payload := common.GetArtifactPayload(name, contents, labels, annotations) + + if action == CREATE { + u.Path = path.Join(u.Path, "apis", apiName, "deployments", deploymentName, "artifacts") + q := u.Query() + q.Set("artifactId", artifactID) + u.RawQuery = q.Encode() + respBody, err = apiclient.HttpClient(u.String(), payload) + } else { + u.Path = path.Join(u.Path, "apis", apiName, "deployments", deploymentName, "artifacts", artifactID) + respBody, err = apiclient.HttpClient(u.String(), payload, "PUT") + } + return respBody, err +} diff --git a/internal/client/registry/apis/versions.go b/internal/client/registry/apis/versions.go new file mode 100644 index 000000000..5f285f511 --- /dev/null +++ b/internal/client/registry/apis/versions.go @@ -0,0 +1,115 @@ +// 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 apis + +import ( + "net/url" + "path" + "strconv" + "strings" + + "internal/apiclient" +) + +// CreateVersion +func CreateVersion(apiVersionId string, name string, displayName string, + description string, state string, labels map[string]string, + annotations map[string]string, primarySpec string, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", name, "versions") + apiVersionContent := []string{} + apiVersionContent = append(apiVersionContent, "\"name\":"+"\""+name+"\"") + if displayName != "" { + apiVersionContent = append(apiVersionContent, "\"displayName\":"+"\""+displayName+"\"") + } + if description != "" { + apiVersionContent = append(apiVersionContent, "\"description\":"+"\""+description+"\"") + } + if state != "" { + apiVersionContent = append(apiVersionContent, "\"state\":"+"\""+state+"\"") + } + if len(labels) > 0 { + l := []string{} + for key, value := range labels { + l = append(l, "\""+key+"\":\""+value+"\"") + } + labelStr := "\"labels\":{" + strings.Join(l, ",") + "}" + apiVersionContent = append(apiVersionContent, labelStr) + } + + if len(annotations) > 0 { + a := []string{} + for key, value := range annotations { + a = append(a, "\""+key+"\":\""+value+"\"") + } + annotationStr := "\"annotations\":{" + strings.Join(a, ",") + "}" + apiVersionContent = append(apiVersionContent, annotationStr) + } + payload := "{" + strings.Join(apiVersionContent, ",") + "}" + + q := u.Query() + q.Set("apiVersionId", apiVersionId) + u.RawQuery = q.Encode() + + respBody, err = apiclient.HttpClient(u.String(), payload) + return respBody, err +} + +// GetVersion +func GetVersion(name string, version string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", name, "versions", version) + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +// DeleteVersion +func DeleteVersion(name string, version string, force bool) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", name, "versions", version) + if force { + q := u.Query() + q.Set("force", strconv.FormatBool(force)) + u.RawQuery = q.Encode() + } + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} + +// ListVersions +func ListVersions(name string, pageSize int, pageToken string, + filter string, orderBy string, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", name, "versions") + q := u.Query() + if pageSize != -1 { + q.Set("pageSize", strconv.Itoa(pageSize)) + } + if pageToken != "" { + q.Set("pageToken", pageToken) + } + if filter != "" { + q.Set("filter", filter) + } + if orderBy != "" { + q.Set("orderBy", orderBy) + } + + u.RawQuery = q.Encode() + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} diff --git a/internal/client/registry/apis/versions/artifacts.go b/internal/client/registry/apis/versions/artifacts.go new file mode 100644 index 000000000..c73d8e419 --- /dev/null +++ b/internal/client/registry/apis/versions/artifacts.go @@ -0,0 +1,95 @@ +// 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 versions + +import ( + "net/url" + "path" + + "internal/apiclient" + "internal/client/registry/common" +) + +type Action uint8 + +const ( + CREATE Action = iota + UPDATE +) + +// CreateArtifact +func CreateArtifact(apiName string, apiVersion string, artifactID string, name string, contents string, + labels map[string]string, annotations map[string]string, +) (respBody []byte, err error) { + return createOrReplaceArtifact(apiName, apiVersion, artifactID, name, contents, labels, annotations, CREATE) +} + +// ReaplceArtifact +func ReplaceArtifact(apiName string, apiVersion string, artifactID string, name string, contents string, + labels map[string]string, annotations map[string]string, +) (respBody []byte, err error) { + return createOrReplaceArtifact(apiName, apiVersion, artifactID, name, contents, labels, annotations, UPDATE) +} + +// DeleteArtifact +func DeleteArtifact(apiName string, apiVersion string, name string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "artifacts", name) + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} + +// GetArtifact +func GetArtifact(apiName string, apiVersion string, name string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "artifacts", name) + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +// GetArtifactContents +func GetArtifactContents(apiName string, apiVersion string, name string) (err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "artifacts", name+":getContents") + return apiclient.DownloadResource(u.String(), name+".txt", "", true) +} + +// ListArtifacts +func ListArtifacts(apiName string, apiVersion string, pageSize int, + pageToken string, filter string, orderBy string, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "artifacts") + return common.ListArtifacts(u, pageSize, pageToken, filter, orderBy) +} + +func createOrReplaceArtifact(apiName, apiVersion, artifactID string, name string, contents string, + labels map[string]string, annotations map[string]string, action Action, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + payload := common.GetArtifactPayload(name, contents, labels, annotations) + + if action == CREATE { + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "artifacts") + q := u.Query() + q.Set("artifactId", artifactID) + u.RawQuery = q.Encode() + respBody, err = apiclient.HttpClient(u.String(), payload) + } else { + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "artifacts", artifactID) + respBody, err = apiclient.HttpClient(u.String(), payload, "PUT") + } + return respBody, err +} diff --git a/internal/client/registry/apis/versions/specartifacts.go b/internal/client/registry/apis/versions/specartifacts.go new file mode 100644 index 000000000..67ed4679b --- /dev/null +++ b/internal/client/registry/apis/versions/specartifacts.go @@ -0,0 +1,100 @@ +// 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 versions + +import ( + "net/url" + "path" + + "internal/apiclient" + "internal/client/registry/common" +) + +// CreateSpecArtifact +func CreateSpecArtifact(apiName string, apiVersion string, specName string, artifactId string, + name string, contents string, labels map[string]string, + annotations map[string]string, +) (respBody []byte, err error) { + return createOrReplaceSpecArtifact(apiName, apiVersion, specName, artifactId, name, contents, labels, annotations, CREATE) +} + +// ReplaceSpecArtifact +func ReplaceSpecArtifact(apiName string, apiVersion string, specName string, artifactId string, + name string, contents string, labels map[string]string, + annotations map[string]string, +) (respBody []byte, err error) { + return createOrReplaceSpecArtifact(apiName, apiVersion, specName, artifactId, name, contents, labels, annotations, UPDATE) +} + +// DeleteSpecArtifact +func DeleteSpecArtifact(apiName string, apiVersion string, specName string, + name string, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "specs", + specName, "artifacts", name) + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} + +// GetSpecArtifact +func GetSpecArtifact(apiName string, apiVersion string, specName string, + name string, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "specs", + specName, "artifacts", name) + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +// GetSpecArtifactContents +func GetSpecArtifactContents(apiName string, apiVersion string, specName string, + name string, +) (err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, + "specs", specName, "artifacts", name+":getContents") + return apiclient.DownloadResource(u.String(), name+".txt", "", true) +} + +// ListSpecArtifacts +func ListSpecArtifacts(apiName string, apiVersion string, specName string, pageSize int, + pageToken string, filter string, orderBy string, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "specs", + specName, "artifacts") + return common.ListArtifacts(u, pageSize, pageToken, filter, orderBy) +} + +func createOrReplaceSpecArtifact(apiName string, apiVersion string, specName string, artifactID string, + name string, contents string, labels map[string]string, + annotations map[string]string, action Action, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + payload := common.GetArtifactPayload(name, contents, labels, annotations) + if action == CREATE { + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "specs", specName, "artifacts") + q := u.Query() + q.Set("artifactId", artifactID) + u.RawQuery = q.Encode() + respBody, err = apiclient.HttpClient(u.String(), payload) + } else { + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "specs", specName, "artifacts", artifactID) + respBody, err = apiclient.HttpClient(u.String(), payload, "PUT") + } + return respBody, err +} diff --git a/internal/client/registry/apis/versions/specs.go b/internal/client/registry/apis/versions/specs.go new file mode 100644 index 000000000..9b234dd73 --- /dev/null +++ b/internal/client/registry/apis/versions/specs.go @@ -0,0 +1,164 @@ +// 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 versions + +import ( + "encoding/json" + "fmt" + "net/url" + "path" + "strconv" + "strings" + + "internal/apiclient" +) + +// CreateSpec +func CreateSpec(apiName string, apiVersion string, apiSpecId string, name string, fileName string, + description string, sourceURI string, contents string, labels map[string]string, + annotations map[string]string, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "specs") + q := u.Query() + q.Set("apiSpecId", apiSpecId) + u.RawQuery = q.Encode() + + specContent := []string{} + specContent = append(specContent, "\"name\":"+"\""+name+"\"") + if description != "" { + specContent = append(specContent, "\"description\":"+"\""+description+"\"") + } + if fileName != "" { + specContent = append(specContent, "\"filename\":"+"\""+fileName+"\"") + } + if sourceURI != "" { + specContent = append(specContent, "\"sourceUri\":"+"\""+sourceURI+"\"") + } + if contents != "" { + specContent = append(specContent, "\"contents\":"+"\""+contents+"\"") + } + if len(labels) > 0 { + l := []string{} + for key, value := range labels { + l = append(l, "\""+key+"\":\""+value+"\"") + } + labelStr := "\"labels\":{" + strings.Join(l, ",") + "}" + specContent = append(specContent, labelStr) + } + + if len(annotations) > 0 { + a := []string{} + for key, value := range annotations { + a = append(a, "\""+key+"\":\""+value+"\"") + } + annotationStr := "\"annotations\":{" + strings.Join(a, ",") + "}" + specContent = append(specContent, annotationStr) + } + payload := "{" + strings.Join(specContent, ",") + "}" + respBody, err = apiclient.HttpClient(u.String(), payload) + return respBody, err +} + +// TagSpec +func TagSpec(apiName string, apiVersion string, name string, tag string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "specs", name+":tagRevision") + payload := "{\"tag\":\"" + tag + "\"}" + respBody, err = apiclient.HttpClient(u.String(), payload) + return respBody, err +} + +// RollbackSpec +func RollbackSpec(apiName string, apiVersion string, name string, revisionID string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "specs", name+":rollback") + payload := "{\"revisionId\":\"" + revisionID + "\"}" + respBody, err = apiclient.HttpClient(u.String(), payload) + return respBody, err +} + +// DeleteSpec +func DeleteSpec(apiName string, apiVersion string, name string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "specs", name) + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} + +// DeleteSpecRevision +func DeleteSpecRevision(apiName string, apiVersion string, name string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "specs", name+":deleteRevision") + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} + +// GetSpec +func GetSpec(apiName string, apiVersion string, name string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "specs", name) + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +// 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(), specFileName, "", true) +} + +// ListSpecs +func ListSpecs(apiName string, apiVersion string, pageSize int, + pageToken string, filter string, orderBy string, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "apis", apiName, "versions", apiVersion, "specs") + q := u.Query() + if pageSize != -1 { + q.Set("pageSize", strconv.Itoa(pageSize)) + } + if pageToken != "" { + q.Set("pageToken", pageToken) + } + if filter != "" { + q.Set("filter", filter) + } + if orderBy != "" { + q.Set("orderBy", orderBy) + } + + u.RawQuery = q.Encode() + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} diff --git a/internal/client/registry/artifacts/artifacts.go b/internal/client/registry/artifacts/artifacts.go new file mode 100644 index 000000000..23770d940 --- /dev/null +++ b/internal/client/registry/artifacts/artifacts.go @@ -0,0 +1,94 @@ +// 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 artifacts + +import ( + "net/url" + "path" + + "internal/apiclient" + "internal/client/registry/common" +) + +type Action uint8 + +const ( + CREATE Action = iota + UPDATE +) + +// Create +func Create(artifactID string, name string, contents string, + labels map[string]string, annotations map[string]string, +) (respBody []byte, err error) { + return createOrReplace(artifactID, name, contents, labels, annotations, CREATE) +} + +// Delete +func Delete(name string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "artifacts", name) + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} + +// Get +func Get(name string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "artifacts", name) + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +// GetContents +func GetContents(name string) (err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "artifacts", name+":getContents") + return apiclient.DownloadResource(u.String(), name+".txt", "", true) +} + +// List +func List(pageSize int, pageToken string, filter string, orderBy string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "artifacts") + return common.ListArtifacts(u, pageSize, pageToken, filter, orderBy) +} + +// Replace +func Replace(artifactID string, name string, contents string, + labels map[string]string, annotations map[string]string, +) (respBody []byte, err error) { + return createOrReplace(artifactID, name, contents, labels, annotations, UPDATE) +} + +// createOrReplace +func createOrReplace(artifactID string, name string, contents string, + labels map[string]string, annotations map[string]string, action Action, +) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + payload := common.GetArtifactPayload(name, contents, labels, annotations) + + if action == CREATE { + u.Path = path.Join(u.Path, "artifacts") + q := u.Query() + q.Set("artifactId", artifactID) + u.RawQuery = q.Encode() + respBody, err = apiclient.HttpClient(u.String(), payload) + } else { + u.Path = path.Join(u.Path, "artifacts", artifactID) + respBody, err = apiclient.HttpClient(u.String(), payload, "PUT") + } + return respBody, err +} diff --git a/internal/client/registry/common/common.go b/internal/client/registry/common/common.go new file mode 100644 index 000000000..32e868744 --- /dev/null +++ b/internal/client/registry/common/common.go @@ -0,0 +1,74 @@ +// 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 common + +import ( + "net/url" + "strconv" + "strings" + + "internal/apiclient" +) + +// GetArtifactPayload +func GetArtifactPayload(name string, contents string, labels map[string]string, annotations map[string]string) string { + artifact := []string{} + artifact = append(artifact, "\"name\":"+"\""+name+"\"") + artifact = append(artifact, "\"contents\":"+"\""+contents+"\"") + + if len(labels) > 0 { + l := []string{} + for key, value := range labels { + l = append(l, "\""+key+"\":\""+value+"\"") + } + labelStr := "\"labels\":{" + strings.Join(l, ",") + "}" + artifact = append(artifact, labelStr) + } + + if len(annotations) > 0 { + a := []string{} + for key, value := range annotations { + a = append(a, "\""+key+"\":\""+value+"\"") + } + annotationStr := "\"annotations\":{" + strings.Join(a, ",") + "}" + artifact = append(artifact, annotationStr) + } + + payload := "{" + strings.Join(artifact, ",") + "}" + return payload +} + +// ListArtifacts +func ListArtifacts(u *url.URL, pageSize int, + pageToken string, filter string, orderBy string, +) (respBody []byte, err error) { + q := u.Query() + if pageSize != -1 { + q.Set("pageSize", strconv.Itoa(pageSize)) + } + if pageToken != "" { + q.Set("pageToken", pageToken) + } + if filter != "" { + q.Set("filter", filter) + } + if orderBy != "" { + q.Set("orderBy", orderBy) + } + + u.RawQuery = q.Encode() + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} diff --git a/internal/client/registry/instances/instances.go b/internal/client/registry/instances/instances.go new file mode 100644 index 000000000..6ce42637b --- /dev/null +++ b/internal/client/registry/instances/instances.go @@ -0,0 +1,63 @@ +// 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 instances + +import ( + "fmt" + "net/url" + "path" + "strings" + + "internal/apiclient" +) + +// Create +func Create(cmekName string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "instances") + q := u.Query() + q.Set("instanceId", "default") + u.RawQuery = q.Encode() + + instance := []string{} + config := []string{} + + name := fmt.Sprintf("projects/%s/locations/%s/instance", apiclient.GetProjectID(), apiclient.GetRegistryRegion()) + instance = append(instance, "\"name\":"+"\""+name+"\"") + + config = append(config, "\"cmekKeyName\":"+"\""+cmekName+"\"") + configJson := "{" + strings.Join(config, ",") + "}" + instance = append(instance, "\"config\":"+configJson) + + payload := "{" + strings.Join(instance, ",") + "}" + respBody, err = apiclient.HttpClient(u.String(), payload) + return respBody, err +} + +// Delete +func Delete() (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "instances", "default") + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} + +// Get +func Get() (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetApigeeRegistryURL()) + u.Path = path.Join(u.Path, "instances", "default") + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} diff --git a/internal/client/res/res.go b/internal/client/res/res.go index ddb414f57..f593769fd 100644 --- a/internal/client/res/res.go +++ b/internal/client/res/res.go @@ -27,7 +27,7 @@ func Create(name string, resPath string, resourceType string) (respBody []byte, if !validate(resourceType) { return respBody, fmt.Errorf("invalid resource type") } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "resourcefiles") if resourceType != "" { q := u.Query() @@ -47,7 +47,7 @@ func Delete(name string, resourceType string) (respBody []byte, err error) { if !validate(resourceType) { return respBody, fmt.Errorf("invalid resource type") } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "resourcefiles", resourceType, name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -58,7 +58,7 @@ func Get(name string, resourceType string) (err error) { if !validate(resourceType) { return fmt.Errorf("invalid resource type") } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "resourcefiles", resourceType, name) err = apiclient.DownloadResource(u.String(), name, resourceType, true) return @@ -69,7 +69,7 @@ func Update(name string, resPath string, resourceType string) (err error) { if !validate(resourceType) { return fmt.Errorf("invalid resource type") } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "resourcefiles", resourceType, name) formParams := map[string]string{ "file": resPath, @@ -86,7 +86,7 @@ func List(resourceType string) (respBody []byte, err error) { } } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "resourcefiles") if resourceType != "" { diff --git a/internal/client/securityprofiles/securityprofiles.go b/internal/client/securityprofiles/securityprofiles.go index a3ff31b48..422d029c2 100644 --- a/internal/client/securityprofiles/securityprofiles.go +++ b/internal/client/securityprofiles/securityprofiles.go @@ -125,7 +125,7 @@ func Create(name string, content []byte) (respBody []byte, err error) { if err = json.Unmarshal(content, &sc); err != nil { return nil, err } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "securityProfiles") q := u.Query() q.Set("securityProfileId", name) @@ -136,7 +136,7 @@ func Create(name string, content []byte) (respBody []byte, err error) { // Attach func Attach(name string, revision string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "securityProfiles", name, "environments") attachProfile := []string{} attachProfile = append(attachProfile, "\"name\":"+"\""+apiclient.GetApigeeEnv()+"\"") @@ -148,7 +148,7 @@ func Attach(name string, revision string) (respBody []byte, err error) { // Detach func Detach(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "securityProfiles", name, "environments", apiclient.GetApigeeEnv()) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") @@ -157,7 +157,7 @@ func Detach(name string) (respBody []byte, err error) { // Delete func Delete(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "securityProfiles", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -165,7 +165,7 @@ func Delete(name string) (respBody []byte, err error) { // Get func Get(name string, revision string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if revision != "" { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "securityProfiles", name+"@"+revision) } else { @@ -177,7 +177,7 @@ func Get(name string, revision string) (respBody []byte, err error) { // ListRevisions func ListRevisions(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "securityProfiles", name+":listRevisions") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -185,7 +185,7 @@ func ListRevisions(name string) (respBody []byte, err error) { // List func List(pageSize int, pageToken string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "securityProfiles") q := u.Query() if pageSize != -1 { @@ -206,7 +206,7 @@ func Update(name string, content []byte) (respBody []byte, err error) { if err = json.Unmarshal(content, &sc); err != nil { return nil, err } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "securityProfiles", name) q := u.Query() q.Set("updateMask", "description,profileConfig") @@ -247,7 +247,7 @@ func Compute(name string, startTime string, endTime string, filters []string, return nil, err } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "securityProfiles", name, "environments", apiclient.GetApigeeEnv()+":computeEnvironmentScores") diff --git a/internal/client/sharedflows/sharedflows.go b/internal/client/sharedflows/sharedflows.go index 0340ac3b9..43186c0a4 100644 --- a/internal/client/sharedflows/sharedflows.go +++ b/internal/client/sharedflows/sharedflows.go @@ -55,7 +55,7 @@ func Create(name string, proxy string) (respBody []byte, err error) { respBody, err = apiclient.ImportBundle("sharedflows", name, proxy) return respBody, err } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sharedflows") proxyName := "{\"name\":\"" + name + "\"}" respBody, err = apiclient.HttpClient(u.String(), proxyName) @@ -64,7 +64,7 @@ func Create(name string, proxy string) (respBody []byte, err error) { // Get func Get(name string, revision int) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if revision != -1 { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sharedflows", name, "revisions", strconv.Itoa(revision)) } else { @@ -77,7 +77,7 @@ func Get(name string, revision int) (respBody []byte, err error) { // GetHighestSfRevision func GetHighestSfRevision(name string) (version int, err error) { apiclient.ClientPrintHttpResponse.Set(false) - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sharedflows", name) respBody, err := apiclient.HttpClient(u.String()) apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) @@ -98,7 +98,7 @@ func GetHighestSfRevision(name string) (version int, err error) { // Delete func Delete(name string, revision int) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if revision != -1 { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sharedflows", name, "revisions", strconv.Itoa(revision)) } else { @@ -110,7 +110,7 @@ func Delete(name string, revision int) (respBody []byte, err error) { // List func List(includeRevisions bool) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if includeRevisions { q := u.Query() q.Set("includeRevisions", strconv.FormatBool(includeRevisions)) @@ -123,7 +123,7 @@ func List(includeRevisions bool) (respBody []byte, err error) { // ListEnvDeployments func ListEnvDeployments() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if apiclient.GetApigeeEnv() == "" { return respBody, fmt.Errorf("environment name missing") @@ -140,7 +140,7 @@ func ListEnvDeployments() (respBody []byte, err error) { // ListDeployments func ListDeployments(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sharedflows", name, "deployments") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -148,7 +148,7 @@ func ListDeployments(name string) (respBody []byte, err error) { // ListRevisionDeployments func ListRevisionDeployments(name string, revision int) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if apiclient.GetApigeeEnv() == "" { return respBody, fmt.Errorf("environment name missing") } @@ -160,7 +160,7 @@ func ListRevisionDeployments(name string, revision int) (respBody []byte, err er // Deploy func Deploy(name string, revision int, overrides bool, serviceAccountName string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if overrides || serviceAccountName != "" { q := u.Query() if overrides { @@ -276,7 +276,7 @@ func Clean(name string, reportOnly bool) (err error) { // Undeploy func Undeploy(name string, revision int) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "sharedflows", name, "revisions", strconv.Itoa(revision), "deployments") respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") @@ -290,7 +290,7 @@ func Fetch(name string, revision int) (err error) { // Export func Export(conn int, folder string, allRevisions bool) (err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) q := u.Query() q.Set("includeRevisions", "true") u.RawQuery = q.Encode() @@ -441,7 +441,7 @@ func importSharedFlows(wg *sync.WaitGroup, jobs <-chan string, errs chan<- error return } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) q := u.Query() q.Set("name", strings.TrimSuffix(filepath.Base(job), ".zip")) q.Set("action", "import") diff --git a/internal/client/sites/sites.go b/internal/client/sites/sites.go index 07a158d79..e7435163d 100644 --- a/internal/client/sites/sites.go +++ b/internal/client/sites/sites.go @@ -25,7 +25,7 @@ import ( // List func List() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites") respBody, err = apiclient.HttpClient(u.String()) return respBody, err diff --git a/internal/client/sync/sync.go b/internal/client/sync/sync.go index ea063bd10..ef1bd7b83 100644 --- a/internal/client/sync/sync.go +++ b/internal/client/sync/sync.go @@ -42,7 +42,7 @@ func validate(i string) string { // Get func Get() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":getSyncAuthorization") respBody, err = apiclient.HttpClient(u.String(), "") return respBody, err @@ -50,7 +50,7 @@ func Get() (respBody []byte, err error) { // Reset func Reset() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":setSyncAuthorization") payload := "{\"identities\":[]}" respBody, err = apiclient.HttpClient(u.String(), payload) @@ -59,7 +59,7 @@ func Reset() (respBody []byte, err error) { // Set func Set(identity interface{}) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":getSyncAuthorization") apiclient.ClientPrintHttpResponse.Set(false) respBody, err = apiclient.HttpClient(u.String(), "") @@ -100,7 +100,7 @@ func Set(identity interface{}) (respBody []byte, err error) { } apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) - u, _ = url.Parse(apiclient.BaseURL) + u, _ = url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":setSyncAuthorization") respBody, err = apiclient.HttpClient(u.String(), string(payload)) @@ -109,7 +109,7 @@ func Set(identity interface{}) (respBody []byte, err error) { // SetList func SetList(identities []string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":getSyncAuthorization") apiclient.ClientPrintHttpResponse.Set(false) respBody, err = apiclient.HttpClient(u.String(), "") @@ -137,7 +137,7 @@ func SetList(identities []string) (respBody []byte, err error) { } apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) - u, _ = url.Parse(apiclient.BaseURL) + u, _ = url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":setSyncAuthorization") respBody, err = apiclient.HttpClient(u.String(), string(payload)) @@ -146,7 +146,7 @@ func SetList(identities []string) (respBody []byte, err error) { // Remove func Remove(identity string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":getSyncAuthorization") apiclient.ClientPrintHttpResponse.Set(false) respBody, err = apiclient.HttpClient(u.String(), "") @@ -189,7 +189,7 @@ func Remove(identity string) (respBody []byte, err error) { } apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) - u, _ = url.Parse(apiclient.BaseURL) + u, _ = url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":setSyncAuthorization") respBody, err = apiclient.HttpClient(u.String(), string(payload)) diff --git a/internal/client/targetservers/targetservers.go b/internal/client/targetservers/targetservers.go index 50d57fbf0..9ff4d5b78 100644 --- a/internal/client/targetservers/targetservers.go +++ b/internal/client/targetservers/targetservers.go @@ -131,7 +131,7 @@ func createOrUpdate(action string, targetsvr targetserver, name string, descript return nil, err } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) if action == "create" { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "targetservers") respBody, err = apiclient.HttpClient(u.String(), string(reqBody)) @@ -145,7 +145,7 @@ func createOrUpdate(action string, targetsvr targetserver, name string, descript // Get func Get(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "targetservers", name) respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -153,7 +153,7 @@ func Get(name string) (respBody []byte, err error) { // Delete func Delete(name string) (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "targetservers", name) respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") return respBody, err @@ -161,7 +161,7 @@ func Delete(name string) (respBody []byte, err error) { // List func List() (respBody []byte, err error) { - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "targetservers") respBody, err = apiclient.HttpClient(u.String()) return respBody, err @@ -269,7 +269,7 @@ func Import(conn int, filePath string) (err error) { clilog.Debug.Printf("Found %d target servers in the file\n", len(targetservers)) clilog.Debug.Printf("Create target servers with %d connections\n", conn) - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "targetservers") err = apiclient.GetHttpClient() if err != nil { @@ -360,7 +360,7 @@ func importServers(knownServers map[string]bool, wg *sync.WaitGroup, jobs <-chan continue } - u, _ := url.Parse(apiclient.BaseURL) + u, _ := url.Parse(apiclient.GetApigeeBaseURL()) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "targetservers") method := http.MethodPost if knownServers[job.Name] {