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

feat: include Callbacks on clients create and list #25

Merged
merged 2 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion internal/cli/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func clientsCreateCmd(cli *cli) *cobra.Command {
appType string
description string
reveal bool
callbacks []string
}
cmd := &cobra.Command{
Use: "create",
Expand All @@ -78,6 +79,7 @@ auth0 clients create --name myapp --type [native|spa|regular|m2m]
Name: &flags.name,
Description: &flags.description,
AppType: auth0.String(apiAppTypeFor(flags.appType)),
Callbacks: apiCallbacksFor(flags.callbacks),
}

err := ansi.Spinner("Creating client", func() error {
Expand All @@ -95,8 +97,9 @@ auth0 clients create --name myapp --type [native|spa|regular|m2m]
}
cmd.Flags().StringVarP(&flags.name, "name", "n", "", "Name of the client.")
cmd.Flags().StringVarP(&flags.appType, "type", "t", "", "Type of the client: [native|spa|regular|m2m]")
cmd.Flags().StringVarP(&flags.description, "description", "d", "", "Description of the client.")
cmd.Flags().StringVarP(&flags.description, "description", "d", "", "A free text description of the application. Max character count is 140.")
cmd.Flags().BoolVarP(&flags.reveal, "reveal", "r", false, "⚠️ Reveal the SECRET of the created client.")
cmd.Flags().StringSliceVarP(&flags.callbacks, "callbacks", "c", nil, "After the user authenticates we will only call back to any of these URLs. You can specify multiple valid URLs by comma-separating them (typically to handle different environments like QA or testing). Make sure to specify the protocol (https://) otherwise the callback may fail in some cases. With the exception of custom URI schemes for native clients, all callbacks should use protocol https://.")

mustRequireFlags(cmd, "name", "type")

Expand All @@ -118,3 +121,12 @@ func apiAppTypeFor(v string) string {
return v
}
}

func apiCallbacksFor(s []string) []interface{} {
res := make([]interface{}, len(s))
for i, v := range s {
res[i] = v
}
return res
Comment on lines +125 to +130
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 wonder if there is a 1-liner to convert from []string to []interface{} 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Nah there's none :) It's the reason the generics troll gets fueled :)


}
33 changes: 29 additions & 4 deletions internal/display/clients.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package display

import (
"fmt"
"strings"

"github.com/auth0/auth0-cli/internal/ansi"
"gopkg.in/auth0.v5"
"gopkg.in/auth0.v5/management"
Expand All @@ -11,22 +14,34 @@ type clientView struct {
Type string
ClientID string
ClientSecret string
Callbacks []string
revealSecret bool
}

func (v *clientView) AsTableHeader() []string {
if v.revealSecret {
return []string{"Name", "Type", "ClientID", "Client Secret"}
return []string{"Name", "Type", "ClientID", "Client Secret", "Callbacks"}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

a refactor here regarding how the columns are included/excluded will be needed at some point (probably not for the PoC)

}
return []string{"Name", "Type", "ClientID"}
return []string{"Name", "Type", "ClientID", "Callbacks"}
cyx marked this conversation as resolved.
Show resolved Hide resolved

}

func (v *clientView) AsTableRow() []string {
if v.revealSecret {
return []string{v.Name, v.Type, ansi.Faint(v.ClientID), ansi.Italic(v.ClientSecret)}
return []string{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same here, potential combinations are going to make this hard to maintain

v.Name,
v.Type,
ansi.Faint(v.ClientID),
ansi.Italic(v.ClientSecret),
strings.Join(v.Callbacks, ", "),
}
}
return []string{
v.Name,
v.Type,
ansi.Faint(v.ClientID),
strings.Join(v.Callbacks, ", "),
}
return []string{v.Name, v.Type, ansi.Faint(v.ClientID)}

}

Expand All @@ -42,6 +57,7 @@ func (r *Renderer) ClientList(clients []*management.Client) {
Type: appTypeFor(c.AppType),
ClientID: auth0.StringValue(c.ClientID),
ClientSecret: auth0.StringValue(c.ClientSecret),
Callbacks: callbacksFor(c.Callbacks),
})
}

Expand All @@ -59,6 +75,7 @@ func (r *Renderer) ClientCreate(client *management.Client, revealSecrets bool) {
Type: appTypeFor(client.AppType),
ClientID: auth0.StringValue(client.ClientID),
ClientSecret: auth0.StringValue(client.ClientSecret),
Callbacks: callbacksFor(client.Callbacks),
}

r.Results([]View{v})
Expand Down Expand Up @@ -88,3 +105,11 @@ func appTypeFor(v *string) string {
return *v
}
}

func callbacksFor(s []interface{}) []string {
res := make([]string, len(s))
for i, v := range s {
res[i] = fmt.Sprintf("%s", v)
}
return res
}
Comment on lines +109 to +115
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is there a simpler way to convert from []interface{} -> []string ?