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

API keys: tidy up the routes #4555

Merged
merged 13 commits into from
Sep 29, 2020
Merged

API keys: tidy up the routes #4555

merged 13 commits into from
Sep 29, 2020

Conversation

ikapelyukhin
Copy link
Contributor

@ikapelyukhin ikapelyukhin commented Sep 2, 2020

Description

A subset of API endpoints moved under /api/v1 and documented with Swagger.

Motivation and Context

#4532

How Has This Been Tested?

Tested manually & with existing test suite.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Docs update
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have followed the guidelines in CONTRIBUTING.md, including the required formatting of the commit message

@codecov-commenter
Copy link

codecov-commenter commented Sep 2, 2020

Codecov Report

Merging #4555 into master will decrease coverage by 0.09%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #4555      +/-   ##
==========================================
- Coverage   58.50%   58.41%   -0.10%     
==========================================
  Files         883      883              
  Lines       29239    29298      +59     
  Branches     4234     4252      +18     
==========================================
+ Hits        17105    17113       +8     
- Misses      12134    12185      +51     

@ikapelyukhin ikapelyukhin force-pushed the api-keys-tidy-up-routes branch 2 times, most recently from bba394c to 295a030 Compare September 3, 2020 22:31
@richard-cox richard-cox changed the base branch from master to acme September 4, 2020 09:44
@richard-cox richard-cox changed the base branch from acme to master September 4, 2020 09:44
Copy link
Contributor

@richard-cox richard-cox left a comment

Choose a reason for hiding this comment

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

Need to ...

  • associate with an issue as a breaking change, Neil or I will do this
  • decide what serves Swagger UI and how swagger.json is generated, Neil will do this
  • do a second pass to additional routes from from pp into api, I will create an issue for this
  • thoroughly test when ready to merge
    • echo update related things, lile web sockets
    • deployment mechanisms (cf push, AIO, etc) for swagger file changes

@@ -12,6 +12,16 @@ const PROXY_CONFIG = {
"ws": true,
"secure": false,
"changeOrigin": true,
},
"/api": {
"target": {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a node script ./build/dev-setup.js that copies this file to proxy.conf.js. For people who already have this their copy won't get update. The script should, if it already exists, replace "/pp" with `"/api".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not all of the /pp endpoints have been migrated to /api, just the ones outlined in #4532. So replacing /pp with /api will break the leftover endpoints.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nwmac hmm, should I add some fancy logic to ./build/dev-setup.js to add an /api section to proxy.conf.localdev.js if it's missing, or should this be left to the developer?

Copy link
Contributor

Choose a reason for hiding this comment

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

@ikapelyukhin I think we should add the fancy logic OR if that's a i real pain, a simpler option is:

  • if the file proxy.conf.js does not exist, create it as we do now
  • if proxy.conf.js exists but has not been changed (same MD5), then overwrite it with the new version
  • otherwise, warn the user that they need to update it manyally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, sounds reasonable, done.

@@ -0,0 +1,56 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

This file won't automatically be include when deployed, we'd need to ensure it gets included in container images.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't need to be deployed. There's docs/docs.go which is then served as /swagger/doc.json by the middleware.
Assuming that we want to use the middleware approach that is.

@nwmac
Copy link
Contributor

nwmac commented Sep 4, 2020

@ikapelyukhin Had a look through with Richard - he's left some comments.

I like the godoc comments for the APIs - you mentioned that it doesn't support OpenAPI V3, specifically the bearer auth - one option would be to submit a PR to swaggo with support for that feature, if that is what is needed to use it.

I think there are two main use cases for the OpenAPI:

  • Generate static API documentation for inclusion in the stratos docs site (stratos.app) - I assume this would generate from swagger.json
  • Provide a UI that the user can use to browser and experiment with the API against their Stratos backend.

@ikapelyukhin
Copy link
Contributor Author

I like the godoc comments for the APIs - you mentioned that it doesn't support OpenAPI V3, specifically the bearer auth - one option would be to submit a PR to swaggo with support for that feature, if that is what is needed to use it.

That'd probably result in a non-standard API doc (a mix of v2 and v3) -- that doesn't sound too thrilling.

Implementing a middleware for OpenAPI v3 or just bundling some front-end code to render the API doc seems like a more realistic solution.

* Provide a UI that the user can use to browser and experiment with the API against their Stratos backend.

@nwmac @richard-cox run the code from the current branch and see https://localhost:5443/swagger/index.html and https://localhost:5443/swagger/doc.json. Sorry, I should have probably mentioned that earlier.

@ikapelyukhin ikapelyukhin force-pushed the api-keys-tidy-up-routes branch from b351060 to 551d059 Compare September 5, 2020 00:43
@ikapelyukhin
Copy link
Contributor Author

I've dropped docs/docs.go from the repo, now it's generated automatically during build and tests.

@ikapelyukhin
Copy link
Contributor Author

curl commands for testing the API:

export API_SECRET='replaceme'
export USERNAME='replaceme'
export PASSWORD='replaceme'
export API_ENDPOINT='https://api.cap.explore.suse.dev/'

# add endpoint
curl -k -X POST "https://localhost:5443/api/v1/endpoints" -H  "accept: application/json" -H  "Authentication: Bearer $API_SECRET" -F "endpoint_type=cf" -F "cnsi_name=Potato" -F "api_endpoint=$API_ENDPOINT"

# list endpoints
curl -k -X GET "https://localhost:5443/api/v1/endpoints" -H  "accept: application/json" -H "Authentication: Bearer $API_SECRET"

endpoint_guid=$(curl -k -X GET "https://localhost:5443/api/v1/endpoints" -H  "accept: application/json" -H "Authentication: Bearer $API_SECRET" | jq -r '.[] | select(.name=="Potato").guid')

# login to endpoint
curl -k -X POST "https://localhost:5443/api/v1/tokens" -H  "accept: application/json"  -H "Authentication: Bearer $API_SECRET" -F "cnsi_guid=$endpoint_guid" -F "system_shared=false" -F "connect_type=creds" -F "username=$USERNAME" -F "password=$PASSWORD"

# rename endpoint
curl -k -X POST "https://localhost:5443/api/v1/endpoints/$endpoint_guid" -H  "accept: application/json" -H  "Authentication: Bearer $API_SECRET" -F "name=Endpoint McEndpointface"

# log out from endpoint
curl -k -X DELETE "https://localhost:5443/api/v1/tokens/$endpoint_guid" -H  "accept: application/json" -H  "Authentication: Bearer $API_SECRET"

# delete endpoint
curl -k -X DELETE "https://localhost:5443/api/v1/endpoints/$endpoint_guid" -H  "accept: application/json" -H  "Authentication: Bearer $API_SECRET"

@ikapelyukhin ikapelyukhin force-pushed the api-keys-tidy-up-routes branch from 3ae4726 to 9babf6a Compare September 24, 2020 10:58
@ikapelyukhin ikapelyukhin marked this pull request as ready for review September 28, 2020 09:20
@ikapelyukhin
Copy link
Contributor Author

ikapelyukhin commented Sep 28, 2020

curl commands with JSON bodies:

export API_SECRET='replaceme'
export USERNAME='replaceme'
export PASSWORD='replaceme'
export API_ENDPOINT='https://api.cap.explore.suse.dev/'

# add endpoint
curl -k -X POST "https://localhost:5443/api/v1/endpoints" -H  "accept: application/json" -H  "Authentication: Bearer $API_SECRET" -H "Content-Type: application/json" -d "{\"endpoint_type\":\"cf\",\"cnsi_name\":\"Potato\",\"api_endpoint\":\"$API_ENDPOINT\"}"

# list endpoints
curl -k -X GET "https://localhost:5443/api/v1/endpoints" -H  "accept: application/json" -H "Authentication: Bearer $API_SECRET"

endpoint_guid=$(curl -k -X GET "https://localhost:5443/api/v1/endpoints" -H  "accept: application/json" -H "Authentication: Bearer $API_SECRET" | jq -r '.[] | select(.name=="Potato").guid')

# login to endpoint
curl -k -X POST "https://localhost:5443/api/v1/tokens" -H  "accept: application/json"  -H "Authentication: Bearer $API_SECRET" -H "Content-Type: application/json" -d "{\"cnsi_guid\":\"$endpoint_guid\",\"system_shared\":\"false\",\"connect_type\":\"creds\",\"username\":\"$USERNAME\",\"password\":\"$PASSWORD\"}"

# rename endpoint
curl -k -X POST "https://localhost:5443/api/v1/endpoints/$endpoint_guid" -H  "accept: application/json" -H  "Authentication: Bearer $API_SECRET" -H "Content-Type: application/json" -d "{\"name\": \"Endpoint McEndpointface\"}"

# log out from endpoint
curl -k -X DELETE "https://localhost:5443/api/v1/tokens/$endpoint_guid" -H  "accept: application/json" -H  "Authentication: Bearer $API_SECRET"

# delete endpoint
curl -k -X DELETE "https://localhost:5443/api/v1/endpoints/$endpoint_guid" -H  "accept: application/json" -H  "Authentication: Bearer $API_SECRET"

@ikapelyukhin ikapelyukhin requested a review from nwmac September 28, 2020 13:54
Copy link
Contributor

@nwmac nwmac left a comment

Choose a reason for hiding this comment

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

LGTM

@ikapelyukhin ikapelyukhin merged commit 1d18271 into master Sep 29, 2020
@ikapelyukhin ikapelyukhin deleted the api-keys-tidy-up-routes branch September 29, 2020 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants