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

DXCDT-264: Add api command #531

Merged
merged 16 commits into from
Nov 29, 2022
Merged

DXCDT-264: Add api command #531

merged 16 commits into from
Nov 29, 2022

Conversation

sergiught
Copy link
Contributor

@sergiught sergiught commented Nov 28, 2022

🔧 Changes

With this PR we are introducing a brand new command: auth0 api. This enables making an authenticated arbitrary HTTP request to the Auth0 Management API.

One of the reasons we're introducing this right now is to be able to quickly fill the gaps that the CLI has in terms of managing certain resources.

$ auth0 help api
Makes an authenticated HTTP request to the Auth0 Management API and prints the response as JSON.

The method argument is optional, and when you don’t specify it, the command defaults to GET for requests without data
and POST for requests with data.

Auth0 Management API Docs:
  https://auth0.com/docs/api/management/v2

Available Methods:
  GET, POST, PUT, PATCH, DELETE

Usage:
  auth0 api <method> <uri> [flags]

Examples:
auth0 api "/organizations?include_totals=true"
auth0 api get "/organizations?include_totals=true"
auth0 api clients --data "{\"name\":\"apiTest\"}"


Flags:
  -d, --data string   JSON data payload to send with the request.
  -h, --help          help for api

Global Flags:
      --debug           Enable debug mode.
      --force           Skip confirmation.
      --format string   Command output format. Options: json.
      --no-color        Disable colors.
      --no-input        Disable interactivity.
      --tenant string   Specific tenant to use.
Screen.Recording.2022-11-28.at.13.51.38.mov

📚 References

🔬 Testing

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

@sergiught sergiught self-assigned this Nov 28, 2022
@sergiught sergiught marked this pull request as ready for review November 28, 2022 13:03
@sergiught sergiught requested a review from a team as a code owner November 28, 2022 13:03
Copy link
Contributor

@willvedd willvedd left a comment

Choose a reason for hiding this comment

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

Great first pass! Much of the design is sensible. Lots of little changes requested but nothing that would require a large refactor.

internal/cli/api.go Outdated Show resolved Hide resolved
internal/cli/api.go Outdated Show resolved Hide resolved
internal/cli/api.go Outdated Show resolved Hide resolved
internal/cli/api.go Outdated Show resolved Hide resolved
internal/cli/api.go Show resolved Hide resolved

func (i *apiCmdInputs) validateAndSetData() error {
if i.RawData != "" && !json.Valid([]byte(i.RawData)) {
return fmt.Errorf("invalid json data given: %+v", i.RawData)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly to other feedback, this error could be more human friendly. I think we'd have a good idea of when and how this error triggers, so we could provide clearer guidance on how to correct.

See: https://clig.dev/#errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The returned error wraps all inner errors so the final one ends up to be for example:

$auth0 api put z --data {"zz:2} 
"

=== tenat-example.auth0.com error

 ▸    failed to parse command inputs: invalid json data given: {zz:2}

exit status 1

What do you suggest so we make it more human friendly? As in this case it's particularly hard as the json.Valid just returns true or false and isn't able to tell that the input was missing a ".

internal/cli/api.go Show resolved Hide resolved
internal/cli/api.go Show resolved Hide resolved
internal/cli/api.go Outdated Show resolved Hide resolved
test/integration/test-cases.yaml Show resolved Hide resolved
docs/auth0_api.md Outdated Show resolved Hide resolved
docs/auth0_api.md Outdated Show resolved Hide resolved
docs/auth0_api.md Outdated Show resolved Hide resolved
@sergiught sergiught force-pushed the feature/DXCDT-264-api branch from 329f26c to dd53121 Compare November 29, 2022 11:25
@sergiught sergiught requested a review from Widcket November 29, 2022 12:43
@sergiught sergiught force-pushed the feature/DXCDT-264-api branch from 791c976 to b1b346e Compare November 29, 2022 13:48
internal/cli/api.go Outdated Show resolved Hide resolved
internal/cli/api.go Outdated Show resolved Hide resolved
internal/cli/api.go Outdated Show resolved Hide resolved
@sergiught sergiught requested a review from Widcket November 29, 2022 14:56
@willvedd willvedd merged commit ba9eb4d into main Nov 29, 2022
@willvedd willvedd deleted the feature/DXCDT-264-api branch November 29, 2022 15:42
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