Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Introduce the same OpenAPI client as go-cli with small changes #225

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Ricardo-Osorio
Copy link
Contributor

Introduced the same go-api implementation of our OpenAPI HTTP API and proceeded to make small changes to make it easier to use and understand.

As a result of such changes I introduced the following:

  • Rewrote comments to better reflect the methods, structs or variables
  • Renamed some variables with more intuitive names
  • Merged two interface implementations together since it only cared about overwriting one specific method and proxied all others (authenticate). Said interface was also deleted afterwards.
  • Moved custom error types and request params (body definitions) into the openapi package (related subjects and avoids a cycle dependency that way)
  • Addressed a lot of issues picked up by golangci-lint
  • Removed the codec struct so each of its methods can be called independently. There was no point in storing and passing obj around.
  • Lots of comments removed - but only those that didn't add any value to the methods.
  • Relying slightly more on an Architecture based on embedded structs:
  • apiclient.ClientWithReauth -> apiclient.client -> openapi.OpenAPI

Currently using a test cmd testapi to make simple GetAllVolumes calls and test this implementation.

Still have to do:

  • Obtain the target API endpoints and credentials through env vars or any other way we see fit.
  • Allow for the caching of a session token to be disabled through an env variable (or same method used on the point above)

@nolancon
Copy link
Collaborator

nolancon commented Jan 4, 2023

Obtain the target API endpoints and credentials through env vars or any other way we see fit.

We can get the creds via the storageos-api secret, and the endpoint via the node deployment. I'm having a play around with it now.

Other than that, the implementation looks fine to me - caveat being that I've never looked at the go-cli code before

@Ricardo-Osorio
Copy link
Contributor Author

caveat being that I've never looked at the go-cli code before

The first commit in the chain of commits of this PR shows the go-api code after having simply moved it and the commits that follow it were always trying to simplify its implementation. I removed a lot of complexity it initially had.

A good point made by Joe, one of the interfaces removed as part of that process could in fact be useful to mock the api methods. I haven't focused on unit tests to have notice this yet but it still stands.

Any updates to the code are welcomed.

@nolancon nolancon force-pushed the add-go-cli-api-client branch 2 times, most recently from e482f1b to 8df0b18 Compare January 9, 2023 08:25
@nolancon nolancon force-pushed the add-go-cli-api-client branch from 8df0b18 to 7b4bb7a Compare January 19, 2023 14:48
Ricardo-Osorio and others added 13 commits January 23, 2023 11:42
Some variables are hardcoded like username, password, apiendpoints, etc

Removed a few structs with little use/purpose or that had too many
dependencies in the go-cli project when trying to move into here

Added a testing cmd `testapi` that calls a GetAllVolumes and prints the
output
Use a chace for a single session (last one authenticated) which is still
reusable when doing multiple requests.
Removed the api client implementation when no transport layer has been
configured and would always return the same error indicating that. Now
when creating a new API client, we need to pass the transport as a
parameter thus we never fall into that scenario.
Very small changes like remove a method and update comments
Delete the codec struct and make each of its methods independent funcs
so we dont have to pass around the struct instance and instead just call
the coded method whenever needed
Moved a struct into another file with related content

Removed lots of comments that add no context or value at all. We don't
currently enforce any rules to include a go comment on every single
method thus don't need to worry about filling any "quotes" with
pointless "GetVolume returns a volume" comments
Merged the wrapper that adds session token caches with the one that adds
extra useful methods like GetVolumeByName.

Multiple comments updated to make responsabilities clearer.

Removed the Transport interface. Without this interface we rely more on
the embeded structs.

Moved structs and errors related to openapi requests (volume not found,
or request params for different endpoints) into the openapi package.

Renamed the api wrapper that adds a retry when authentication failed to
"reauth_client.go"

Renamed structs representing the api clients from Transport into Client.
@nolancon nolancon force-pushed the add-go-cli-api-client branch from 7b4bb7a to 8ce6f85 Compare January 23, 2023 11:44
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.

2 participants