GoogleCloudPlatform / cloud-code-vscode

Cloud Code for Visual Studio Code: Issues, Documentation and more
Other
417 stars 111 forks source link

Apigee emulator: specify app credentials in test bundle #645

Open dpashkevich opened 2 years ago

dpashkevich commented 2 years ago

Use case Today, I can define an app in my test bundle's developerapps.json, e.g.:

[
  {
    "attributes": [
      {
        "name": "sample_attribute_0",
        "value": "sample_attribute_value_0"
      }
    ],
    "developerEmail": "dev@example.com",
    "name": "testapp",
    "displayName": "Test App",
    "callbackUrl": "https://localhost:3000",
    "apiProducts": [
      "Bronze"
    ],
    "expiryType": "never"
  }
]

Every time I upload the test bundle to the emulator, it automatically generates a new app with new credentials (can be viewed under "Active developer apps"), e.g.:

[
  {
    "name": "testapp",
    "appId": "2180ce12-5173-4191-96eb-869744e17c6f",
    "callbackUrl": "https://localhost:3000",
    "status": "approved",
    "attributes": [
      {
        "name": "sample_attribute_0",
        "value": "sample_attribute_value_0"
      }
    ],
    "credentials": [
      {
        "consumerKey": "RntbPoWU1Sb64a2fa89LaVt3APMQ4CoC",
        "consumerSecret": "H6OEV9siz0in8AGA",
        "apiProducts": [
          {
            "apiproduct": "Bronze",
            "status": "approved"
          }
        ],
        "status": "approved",
        "attributes": [],
        "scopes": [],
        "issuedAt": 1662065582702,
        "expiresAt": -1
      }
    ],
    "apiProducts": [],
    "scopes": [],
    "appType": "Developer",
    "developerId": "e2b25424-d901-4a4d-8290-12116cf76e4f"
  }
]

This is a nuissance, because this means that every time I have I redeploy the test bundle, I have to copy-paste new credentials into my HTTP client (e.g. Postman).

This also complicates automated testing setup that I'm hoping to achieve, where things such as API keys and client credentials are statically defined as part of automated testing environment configuration.

In addition, in our particular case, we use our own OAuth Authorization Server behind Apigee, and are planning on syncing apps & credentials to Apigee using the Admin API. Not being able to explicitly set/add our own client credentials on apps in the emulator complicates local development workflow.

Feature

Allow explicitly setting client credentials for apps in test data bundles. Possibly other values that would be undesirable to change upon every deployment.

toyopilgrim commented 1 year ago

@dpashkevich

While I vote for this feature request, there's a workaround that you can automate fetching the generated credentials.

Try hit this endpoint of your apigee emulator control origin.

GET http://localhost:8090/v1/emulator/test/developerapps

Then you'll get the generated developer apps information in the response. This can be utilized as a part of your automated testing setup when it comes to local test profile.

dpashkevich commented 1 year ago

Thanks, that helps!