apigee / apigeecli

This is a tool to interact with Apigee APIs. The tool lets you manage (create, del, get, list) environments, proxies, etc.
Apache License 2.0
51 stars 28 forks source link

feat: Enable API Hub #485

Closed srinandan closed 2 months ago

kurtkanaskie commented 2 months ago

Creating attribute with immutable fails, if removed works.

gorun --org=$ORG --region=us-central1 apihub attributes create \
    --id=apigeecli-enum \
    --display-name="Apigee CLI Enum" \
    --description="Example enum attribute" \
    --data-type=ENUM \
    --allowed-values=enum_values.json \
    --scope=DEPLOYMENT \
    --cardinality=1

{
  "error": {
    "code": 400,
    "message": "The request was invalid: Invalid value \"true\" specified for \"attribute.allowed_values[2].immutable\"",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {}
        ]
      },
      {
        "@type": "type.googleapis.com/google.rpc.RequestInfo",
        "requestId": "6d78085527332110"
      }
    ]
  }
}

Error: Bad Request - malformed request syntax
exit status 1

File for enums

[
    {
        "id": "red_color",
        "displayName": "Red",
        "immutable": true
    },
    {
        "id": "yellow_color",
        "displayName": "Yellow",
        "description": "Yellow color",
        "immutable": true
    },
    {
        "id": "green_color",
        "displayName": "Green",
        "description": "Green color",
        "immutable": true
    }
]
kurtkanaskie commented 2 months ago

gorun --org=$ORG --region=us-central1 apihub apis update --id=apigeecli-api-v1 --file=apigeecli-api-v1.json Command was incorrectly documented in update.go should be:

var UpdateCmd = &cobra.Command{
    Use:   "update",
    Short: "Update an existing API Hub API",
    Long:  "Update an existing API Hub API",
...
        _, err = hub.UpdateApi(id, apiFileBytes)

Update requires displayName and owner.

Update does not update apiStyle

{
  "name": "apigeecli-api",
  "displayName": "apigeecli-api-updated",
  "description": "API create via apigeecli updated",
  "apiStyle": {
    "enumValues": {
      "values": [
        {
          "id": "rest"
        }
      ]
    }
  },
  "owner": {
    "email": "kurtkanaskie.google.com"
  }
}
kurtkanaskie commented 2 months ago

create and update use --id get, delete use --app-id they should be consistent

kurtkanaskie commented 2 months ago

Help for apihub apis versions create shows: -f, --file string Path to a file containing the API defintion

Should be Path to a file containing the API version definition

kurtkanaskie commented 2 months ago

Got past apis, versions and looking at specs. All looks good so far, but the get returns base64 value, should we decode or maybe an option to save decoded to a file?

gorun --org=$ORG --region=us-central1 apihub apis versions specs get --api-id=apigeecli-api-v1 --version=v1_0 --spec-id=apigeecli-api-v1-spec-id --contents { "contents": "b3BlbmFwaTogMy4wLjAKaW5mbzoKICB0aXRsZTogRm9vZCBUcnVja3MgQVBJCiAgZGVzY3JpcHR

kurtkanaskie commented 2 months ago

Incorrect help for create and delete

gorun --org=$ORG --region=us-central1 apihub dependencies 
Manage dependencies between consumers and suppliers

Usage:
  apigeecli apihub dependencies [command]

Available Commands:
  create      Create a new API Deployment in API Hub
  delete      Delete a deployment
  get         Get details for a dependency
  list        List dependencies
kurtkanaskie commented 2 months ago

Deployments should have a required parameter for version(s) since it is required in the UI. image

apihub deployments create --help
Create a new API Deployment in API Hub

Usage:
  apigeecli apihub deployments create [flags]

Flags:
      --dep-type deploymentType    The type of deployment
      --description string         Deployment Description
  -d, --display-name string        Deployment Display Name
      --endpoints stringArray       The endpoints at which this deployment resource is listening for API requests
      --env-type environmentType   The environment mapping to this deployment
      --external-uri string        The uri of the externally hosted documentation
  -h, --help                       help for create
  -i, --id string                  Deployment ID
      --resource-uri string        A URI to the runtime resource
      --slo-type sloType           The SLO for this deployment

I think then we need to add --api-id and --version-id to create the apiVersion identifier: projects/apigeex-mint-kurt/locations/us-central1/apis/apigeecli-api-v1/versions/v1_0

srinandan commented 2 months ago

The UI may be forcing the user to select an API Version, however, the API does not. Deployments are set on the API Version and the other way around.

I think the UI is orchestrating two API calls. 1) Create a deployment 2) Update the API Version with the Deployment that was created.

Here is a command to create a deployment:

apigeecli apihub deployments create -n $name --dep-type apigee -d $display-name --env-type development --slo-type "99-99" --endpoints https://api.example.com --resource-uri https://apigee.googleapis.com/v1/organizations/my-project/apis/httpbin/revisions/1 -r us-central1 --default-token

For automation, I would use

deployment-name=$(apigeecli apihub deployments create -n $name --dep-type apigee -d $display-name --env-type development --slo-type "99-99" --endpoints https://api.example.com --resource-uri https://apigee.googleapis.com/v1/organizations/my-project/apis/httpbin/revisions/1 -r us-central1 --default-token | yq -r .name )

and use that variable in subsequent commands.

kurtkanaskie commented 2 months ago

Hmmm, yes, when I use the API to create a deployment and I give it a version, it doesn't use it. So versions have deployments and I can create a version with a deployment. OK then how do I "update" a version to have a deployment? I can PATCH with API. update command is missing from versions.

kurtkanaskie commented 2 months ago

I see deployments update was added. Missing "UpdateCmd" in deployments.go

Added that and tested, update command uses --name it should use --id like get and delete does.

kurtkanaskie commented 2 months ago

Pushed changes for deployments update and externalapis Only thing left is adding the missing versions update.

kurtkanaskie commented 2 months ago

This works for apihub apis versions create --id=v1_0_0_0 --api-id=apigeecli-api-v1 --file=apihub/apigee-cli-v1-version.json

{
  "displayName": "Version 1",
  "description": "Version One Zero via CLI updated with deployments",
  "deployments": [
    "projects/apigeex-mint-kurt/locations/us-central1/deployments/apigeecli-api-v1-deployment-dev-cli"
  ]
}

Update uses --id, but get and delete use --version, should be --id for all Update fails

apihub apis versions update --id=v1_0_0_0 --api-id=apigeecli-api-v1 --file=apihub/apigee-cli-v1-version-deployments.json
Error: json: cannot unmarshal array into Go struct field apiversion.deployments of type map[string]interface {}
exit status 1