bcgov / api-services-portal

API Services Portal provides a multi-tenant frontend integrating API Gateway and Authorization services from Kong CE and Keycloak.
https://api.gov.bc.ca
Apache License 2.0
22 stars 7 forks source link

Namespace to gateway - feature testing #1070

Closed ikethecoder closed 4 months ago

ikethecoder commented 5 months ago

Related to:

As a Github user logging into the portal..

As an IDIR user with existing gateways logging into the portal..

Steps:

image

As an IDIR user with no gateways logging into the portal..

As an IDIR user I want to delete a gateway

rustyjux commented 5 months ago

The pile of HTML returned from some gwa commands is the result of trying to hit a /v2/ endpoint that doesn't exist, e.g. https://api-gov-bc-ca.dev.api.gov.bc.ca/ds/api/v2/gateways. This is resolved by changing GWA_VERSION in .env to v3.

Should improving the handling of this type of error happen in the cli or in the API? or neither since it isn't easy for users to users to alter the API version?

ikethecoder commented 5 months ago

Yeah, I think on the CLI if content-type: text/html is returned then there's no point in showing the output as it is most certainly garbage. But the Portal should also use the Accept header to return JSON if it is set to application/json.

ikethecoder commented 5 months ago

Also to consider for gateway services, gwa-api does not have a v3 of its API, so https://github.com/bcgov/api-services-portal/blob/feature/ns-to-gw/src/api-proxy.js#L20 will need to map /gw/api/v3 to /v2. Otherwise it will probably give a 404 error.

ikethecoder commented 5 months ago

The pile of HTML returned from some gwa commands is the result of trying to hit a /v2/ endpoint that doesn't exist, e.g. https://api-gov-bc-ca.dev.api.gov.bc.ca/ds/api/v2/gateways. This is resolved by changing GWA_VERSION in .env to v3.

Should improving the handling of this type of error happen in the cli or in the API? or neither since it isn't easy for users to users to alter the API version?

If people upgrade their gwa, are they going to have to manually edit the .env file to v3? Perhaps the gwa command line should update this for you.

rustyjux commented 5 months ago

If people upgrade their gwa, are they going to have to manually edit the .env file to v3? Perhaps the gwa command line should update this for you.

I haven't done any builds yet but I'm guessing the .env contents get packed up somewhere. I'll see if I can add general handling for content-type: text/html - the HTML response you'd have seen isn't actually total junk (it includes a 404 message), but we should be able to handle that much more cleanly.

rustyjux commented 5 months ago

Fixed the http error handling to give Error: received HTML error page (status code 404) instead of a wall of text - https://github.com/bcgov/gwa-cli/commit/5b6c3cc9c1726a260d530cd38a09b9779691918d

And I checked out just release locally and can confirm the executables created point to the API set in .env. For production releases, we set the .env defaults in the GHA - https://github.com/bcgov/gwa-cli/blob/5b6c3cc9c1726a260d530cd38a09b9779691918d/.github/workflows/main.yml#L11

env:
  GWA_API_HOST: api.gov.bc.ca
  GWA_CLIENT_ID: gwa-cli
  GWA_VERSION: v2
ikethecoder commented 4 months ago

Regression testing update