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

Add custom domains CRUD #311

Merged
merged 5 commits into from
Jun 14, 2021
Merged

Add custom domains CRUD #311

merged 5 commits into from
Jun 14, 2021

Conversation

Widcket
Copy link
Contributor

@Widcket Widcket commented Jun 11, 2021

Description

This PR adds the following commands:

  • auth0 branding domains list
  • auth0 branding domains show
  • auth0 branding domains create
  • auth0 branding domains delete
  • auth0 branding domains verify

The update command cannot be added ATM because the Go SDK does not support that operation.

Screen Shot 2021-06-11 at 19 35 15

Screen Shot 2021-06-11 at 19 35 26

Testing

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not master

@Widcket Widcket requested a review from a team June 11, 2021 22:36
Copy link
Contributor

@jfatta jfatta left a comment

Choose a reason for hiding this comment

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

great work, I left some comments inline


if err := ansi.Waiting(func() error {
var err error
list, err = cli.api.CustomDomain.List()
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed we're not passing the context downstream, to handle cancelation properly, eventually support timeouts from the root CLI command.

this can be done with the option
https://github.com/go-auth0/auth0/blob/5e36f59f4a866da1c4858b650302c04235dc3508/management/management.go#L399-L404

the command holds its context at cmd.Context()

It seems we're not doing this in any of our API invocations, so feel free to ignore this for now, I can tackle the update on a separated PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that would need to be done in a separate PR.

Use: "show",
Args: cobra.MaximumNArgs(1),
Short: "Show a custom domain",
Long: "Show a custom domain.",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we really need long if its equal to short. do you know what's cobra doing differently with these values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally we'd like that to be abstracted away and just use a builder that wraps cobra's with our own conventions. But that needs to be part of a larger refactor effort. For now the focus is on just hitting the feature goals

list, err = cli.api.CustomDomain.List()
return err
}); err != nil {
return fmt.Errorf("An unexpected error occurred: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't use

func Error(e error, message string) error {
(pkg/errors under the hood)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're just using that method for panics for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(so that Sentry has a stack trace when it recovers from the panic)

return ansi.Spinner("Deleting custom domain", func() error {
_, err := cli.api.CustomDomain.Read(url.PathEscape(inputs.ID))

if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

is "not found" the only source of errors there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only do that GET to find out if the resource exists. Granted, it can fail because other reasons as well (e.g. network error), but unfortunately, we have no way to tell them apart. The delete call does not fail if the resource didn't exist, it ends successfully. That might be the worse outcome in this case.
What do you suggest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe rework the error message to mention that there are other potential reasons?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, maybe just remove the The specified Id: %v doesn't exist and add the error msg?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 8f932f2

@@ -63,7 +63,7 @@ var (
httpContentFormat = Flag{
Name: "HTTP Content Format",
LongForm: "http-format",
Help: "HTTP Content-Format header. Possible values: JSONLINES, JSONARRAY, JSONOBJECT.",
Help: "HTTP Content-Format header. Possible values: jsonlines, jsonarray, jsonobject.",
Copy link
Contributor

Choose a reason for hiding this comment

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

is this related with the domains CRUD?

Copy link
Contributor Author

@Widcket Widcket Jun 14, 2021

Choose a reason for hiding this comment

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

No, but found out about that, and seemed too small a change to create a separate PR for, and having to find a reviewer. Ideally under different circumstances, I'd have made that into a separate PR. If you'd prefer it that way I can extract it.

"gopkg.in/auth0.v5/management"
)

type customDomainView struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think about and approach like this to simplify here and there?

type customDomainView struct {
   raw *management.CustomDomain
}

func (v *customDomainView) AsTableRow() []string {
	return []string{
		ansi.Faint(v.raw.ID),
		v.raw.Domain,
		v.raw.Status,
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think keeping a separate view model that does not know about the underlying DTO is something that will make it easier and simpler to decouple the SDK in the future (if the project gets to that stage). Otherwise the data layer gets a (bigger) hard coupling with the view layer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean, both layers are already coupled, but doing that will make it worse.

@Widcket Widcket requested a review from jfatta June 14, 2021 16:39
@Widcket Widcket merged commit da352f4 into main Jun 14, 2021
@Widcket Widcket deleted the feature/custom-domains branch June 14, 2021 18:15
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