Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable API Hub #485

Merged
merged 26 commits into from
Jul 2, 2024
Merged

feat: Enable API Hub #485

merged 26 commits into from
Jul 2, 2024

Conversation

srinandan
Copy link
Collaborator

No description provided.

@srinandan srinandan linked an issue Jun 21, 2024 that may be closed by this pull request
@srinandan srinandan added the enhancement New feature or request label Jun 21, 2024
Copy link
Collaborator

@kurtkanaskie kurtkanaskie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: Non enum attribute appears to need the --allowed-values

gorun --org=$ORG --region=us-central1 apihub attributes create \
    --id=apigeecli-string \
    --display-name="Apigee CLI Simple" \
    --description="Example simple attribute" \
    --data-type=STRING \
    --scope=DEPLOYMENT

Error: open : no such file or directory
exit status 1

Adding --allowed-values=enum_values.txt gets it to work

@kurtkanaskie
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

kurtkanaskie commented Jun 28, 2024

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

@kurtkanaskie
Copy link
Collaborator

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
Copy link
Collaborator

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

@srinandan srinandan requested a review from kurtkanaskie June 30, 2024 22:05
@kurtkanaskie
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator Author

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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

@kurtkanaskie
Copy link
Collaborator

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

Copy link
Collaborator

@kurtkanaskie kurtkanaskie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@srinandan srinandan merged commit fb703da into main Jul 2, 2024
4 checks passed
@srinandan srinandan deleted the apihub branch July 2, 2024 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add new API Hub APIs
2 participants