diff --git a/commander.yaml b/commander.yaml index a7d44f3df..80081f11c 100644 --- a/commander.yaml +++ b/commander.yaml @@ -403,8 +403,8 @@ tests: exit-code: 0 stdout: json: - Email: "testuser@example.com" - Connection: "Username-Password-Authentication" + email: "testuser@example.com" + connection: "Username-Password-Authentication" users create and check output: command: auth0 users create --name integration-test-user-new2 --connection Username-Password-Authentication --email testuser2@example.com --password testUser12 --no-input @@ -423,8 +423,8 @@ tests: command: auth0 users show $(cat ./integration/identifiers/user-id) --format json stdout: json: - Email: "newuser@example.com" - Connection: "Username-Password-Authentication" + email: "newuser@example.com" + connection: "Username-Password-Authentication" exit-code: 0 users show: @@ -440,14 +440,14 @@ tests: command: auth0 users update $(cat ./integration/identifiers/user-id) --email betteruser@example.com --format json --no-input stdout: json: - Email: betteruser@example.com + email: betteruser@example.com exit-code: 0 users update name: command: auth0 users update $(cat ./integration/identifiers/user-id) --name integration-test-user-bettername --format json --no-input stdout: json: - Email: betteruser@example.com # Name is not being displayed, hence using email + email: betteruser@example.com # Name is not being displayed, hence using email exit-code: 0 # Test 'roles create' @@ -456,8 +456,8 @@ tests: exit-code: 0 stdout: json: - Name: integration-test-role-new1 - Description: testRole + name: integration-test-role-new1 + description: testRole roles create and check output: command: auth0 roles create --name integration-test-role-new2 --description testRole2 --no-input @@ -476,8 +476,8 @@ tests: command: auth0 roles show $(cat ./integration/identifiers/role-id) --format json stdout: json: - Name: integration-test-role-newRole - Description: integration-test-role + name: integration-test-role-newRole + description: integration-test-role exit-code: 0 roles show: @@ -493,12 +493,12 @@ tests: command: auth0 roles update $(cat ./integration/identifiers/role-id) --name integration-test-role-betterName --format json stdout: json: - Name: integration-test-role-betterName + name: integration-test-role-betterName exit-code: 0 roles update description: command: auth0 roles update $(cat ./integration/identifiers/role-id) --description betterDescription --format json stdout: json: - Description: betterDescription + description: betterDescription exit-code: 0 diff --git a/integration/get-role-id.sh b/integration/get-role-id.sh index 743513e2e..952b2e9c3 100755 --- a/integration/get-role-id.sh +++ b/integration/get-role-id.sh @@ -3,4 +3,4 @@ role=$( auth0 roles create -n integration-test-role-newRole -d integration-test-role --format json --no-input ) mkdir -p ./integration/identifiers -echo "$role" | jq -r '.["ID"]' > ./integration/identifiers/role-id +echo "$role" | jq -r '.["id"]' > ./integration/identifiers/role-id diff --git a/integration/get-user-id.sh b/integration/get-user-id.sh index dfbd253a0..92cff8d97 100755 --- a/integration/get-user-id.sh +++ b/integration/get-user-id.sh @@ -3,4 +3,4 @@ user=$( auth0 users create -n integration-test-user-better -c Username-Password-Authentication -e newuser@example.com -p testUser12 --format json --no-input ) mkdir -p ./integration/identifiers -echo "$user" | jq -r '.["UserID"]' > ./integration/identifiers/user-id +echo "$user" | jq -r '.["user_id"]' > ./integration/identifiers/user-id diff --git a/integration/test-cleanup.sh b/integration/test-cleanup.sh index 9d2d8ce16..9770bc878 100755 --- a/integration/test-cleanup.sh +++ b/integration/test-cleanup.sh @@ -7,8 +7,8 @@ for app in $( echo "${apps}" | jq -r '.[] | @base64' ); do echo "${app}" | base64 --decode | jq -r "${1}" } - clientid=$(_jq '.ClientID') - name=$(_jq '.Name') + clientid=$(_jq '.client_id') + name=$(_jq '.name') # TODO(jfatta): should remove only those # created during the same test session if [[ $name = integration-test-app-* ]] @@ -25,8 +25,8 @@ for api in $( echo "${apis}" | jq -r '.[] | @base64' ); do echo "${api}" | base64 --decode | jq -r "${1}" } - id=$(_jq '.ID') - name=$(_jq '.Name') + id=$(_jq '.id') + name=$(_jq '.name') # TODO(jfatta): should remove only those # created during the same test session if [[ $name = integration-test-api-* ]] @@ -44,7 +44,7 @@ for user in $( echo "${users}" | jq -r '.[] | @base64' ); do echo "${user}" | base64 --decode | jq -r "${1}" } - userid=$(_jq '.UserID') + userid=$(_jq '.user_id') # created during the same test session if [[ integration-* ]] then @@ -60,8 +60,8 @@ for role in $( echo "${roles}" | jq -r '.[] | @base64' ); do echo "${role}" | base64 --decode | jq -r "${1}" } - id=$(_jq '.ID') - name=$(_jq '.Name') + id=$(_jq '.id') + name=$(_jq '.name') # TODO(jfatta): should remove only those # created during the same test session if [[ $name = integration-test-role-* ]] @@ -69,4 +69,4 @@ for role in $( echo "${roles}" | jq -r '.[] | @base64' ); do echo deleting "$name" $( auth0 roles delete "$id") fi -done \ No newline at end of file +done diff --git a/internal/display/actions.go b/internal/display/actions.go index 72ae678e7..ea4ee449c 100644 --- a/internal/display/actions.go +++ b/internal/display/actions.go @@ -61,24 +61,7 @@ func (r *Renderer) ActionList(actions []*management.Action) { var res []View for _, a := range actions { - var triggers = make([]string, 0, len(a.SupportedTriggers)) - for _, t := range a.SupportedTriggers { - triggers = append(triggers, string(*t.ID)) - } - - isDeployed := false - if a.GetDeployedVersion() != nil { - isDeployed = a.GetDeployedVersion().Deployed - } - - res = append(res, &actionView{ - ID: a.GetID(), - Name: a.GetName(), - Type: strings.Join(triggers, ", "), - Status: actionStatus(a.GetStatus()), - Deployed: boolean(isDeployed), - raw: a, - }) + res = append(res, makeActionView(a)) } r.Results(res) diff --git a/internal/display/apis.go b/internal/display/apis.go index 450149667..a756d56a4 100644 --- a/internal/display/apis.go +++ b/internal/display/apis.go @@ -140,6 +140,7 @@ func makeApiTableView(api *management.ResourceServer) *apiTableView { type scopeView struct { Scope string Description string + raw interface{} } func (v *scopeView) AsTableHeader() []string { @@ -150,6 +151,10 @@ func (v *scopeView) AsTableRow() []string { return []string{v.Scope, v.Description} } +func (v *scopeView) Object() interface{} { + return v.raw +} + func (r *Renderer) ScopesList(api string, scopes []*management.ResourceServerScope) { resource := "scopes" @@ -173,6 +178,7 @@ func makeScopeView(scope *management.ResourceServerScope) *scopeView { return &scopeView{ Scope: auth0.StringValue(scope.Value), Description: auth0.StringValue(scope.Description), + raw: scope, } } diff --git a/internal/display/apps.go b/internal/display/apps.go index bb9d5122f..db1056238 100644 --- a/internal/display/apps.go +++ b/internal/display/apps.go @@ -40,49 +40,24 @@ type applicationView struct { func (v *applicationView) AsTableHeader() []string { if v.revealSecret { - return []string{ - "ClientID", - "Description", - "Name", - "Type", - "Client Secret", - "Callbacks", - "Allowed Origins", - "Allowed Web Origins", - "Allowed Logout URLs", - "Token Endpoint Auth", - "Grants", - } - } - return []string{ - "Client ID", - "Description", - "Name", - "Type", - "Callbacks", - "Allowed Origins", - "Allowed Web Origins", - "Allowed Logout URLs", - "Token Endpoint Auth", - "Grants", + return []string{"Client ID", "Name", "Type", "Client Secret"} } + return []string{"Client ID", "Name", "Type"} } func (v *applicationView) AsTableRow() []string { if v.revealSecret { return []string{ + ansi.Faint(v.ClientID), v.Name, applyColor(v.Type), - ansi.Faint(v.ClientID), ansi.Italic(v.ClientSecret), - strings.Join(v.Callbacks, ", "), } } return []string{ + ansi.Faint(v.ClientID), v.Name, applyColor(v.Type), - ansi.Faint(v.ClientID), - strings.Join(v.Callbacks, ", "), } } @@ -127,39 +102,6 @@ func (v *applicationView) Object() interface{} { return safeRaw(v.raw.(*management.Client), v.revealSecret) } -// applicationListView is a slimmed down view of a client for displaying -// larger numbers of applications -type applicationListView struct { - Name string - Type string - ClientID string - ClientSecret string `json:"ClientSecret,omitempty"` - revealSecret bool -} - -func (v *applicationListView) AsTableHeader() []string { - if v.revealSecret { - return []string{"Client ID", "Name", "Type", "Client Secret"} - } - return []string{"Client ID", "Name", "Type"} -} - -func (v *applicationListView) AsTableRow() []string { - if v.revealSecret { - return []string{ - ansi.Faint(v.ClientID), - v.Name, - applyColor(v.Type), - ansi.Italic(v.ClientSecret), - } - } - return []string{ - ansi.Faint(v.ClientID), - v.Name, - applyColor(v.Type), - } -} - func (r *Renderer) ApplicationList(clients []*management.Client, revealSecrets bool) { resource := "applications" @@ -177,19 +119,11 @@ func (r *Renderer) ApplicationList(clients []*management.Client, revealSecrets b continue } - // in case of format=JSON: - clientSecret := "" - if revealSecrets { - clientSecret = auth0.StringValue(c.ClientSecret) + if !revealSecrets { + c.ClientSecret = auth0.String("") } - res = append(res, &applicationListView{ - revealSecret: revealSecrets, - Name: auth0.StringValue(c.Name), - Type: appTypeFor(c.AppType), - ClientID: auth0.StringValue(c.ClientID), - ClientSecret: clientSecret, - }) + res = append(res, makeApplicationView(c, revealSecrets)) } r.Results(res) @@ -197,24 +131,7 @@ func (r *Renderer) ApplicationList(clients []*management.Client, revealSecrets b func (r *Renderer) ApplicationShow(client *management.Client, revealSecrets bool) { r.Heading("application") - - v := &applicationView{ - revealSecret: revealSecrets, - Name: auth0.StringValue(client.Name), - Description: auth0.StringValue(client.Description), - Type: appTypeFor(client.AppType), - ClientID: auth0.StringValue(client.ClientID), - ClientSecret: auth0.StringValue(client.ClientSecret), - Callbacks: interfaceSliceToString(client.Callbacks), - AllowedOrigins: interfaceSliceToString(client.AllowedOrigins), - AllowedWebOrigins: interfaceSliceToString(client.WebOrigins), - AllowedLogoutURLs: interfaceSliceToString(client.AllowedLogoutURLs), - AuthMethod: auth0.StringValue(client.TokenEndpointAuthMethod), - Grants: interfaceSliceToString(client.GrantTypes), - raw: client, - } - - r.Result(v) + r.Result(makeApplicationView(client, revealSecrets)) } func (r *Renderer) ApplicationCreate(client *management.Client, revealSecrets bool) { @@ -224,24 +141,7 @@ func (r *Renderer) ApplicationCreate(client *management.Client, revealSecrets bo client.ClientSecret = auth0.String("") } - v := &applicationView{ - revealSecret: revealSecrets, - Name: auth0.StringValue(client.Name), - Description: auth0.StringValue(client.Description), - Type: appTypeFor(client.AppType), - ClientID: auth0.StringValue(client.ClientID), - ClientSecret: auth0.StringValue(client.ClientSecret), - Callbacks: interfaceSliceToString(client.Callbacks), - AllowedOrigins: interfaceSliceToString(client.AllowedOrigins), - AllowedWebOrigins: interfaceSliceToString(client.WebOrigins), - AllowedLogoutURLs: interfaceSliceToString(client.AllowedLogoutURLs), - AuthMethod: auth0.StringValue(client.TokenEndpointAuthMethod), - Grants: interfaceSliceToString(client.GrantTypes), - raw: client, - } - - r.Result(v) - + r.Result(makeApplicationView(client, revealSecrets)) r.Newline() r.Infof("Quickstarts: %s", quickstartsURIFor(client.AppType)) @@ -263,7 +163,11 @@ func (r *Renderer) ApplicationUpdate(client *management.Client, revealSecrets bo client.ClientSecret = auth0.String("") } - v := &applicationView{ + r.Result(makeApplicationView(client, revealSecrets)) +} + +func makeApplicationView(client *management.Client, revealSecrets bool) *applicationView { + return &applicationView{ revealSecret: revealSecrets, Name: auth0.StringValue(client.Name), Description: auth0.StringValue(client.Description), @@ -278,8 +182,6 @@ func (r *Renderer) ApplicationUpdate(client *management.Client, revealSecrets bo Grants: interfaceSliceToString(client.GrantTypes), raw: client, } - - r.Result(v) } // TODO(cyx): determine if there's a better way to filter this out. diff --git a/internal/display/branding.go b/internal/display/branding.go index bde84ed2d..cb5d2ae93 100644 --- a/internal/display/branding.go +++ b/internal/display/branding.go @@ -10,6 +10,7 @@ type brandingView struct { LogoURL string FaviconURL string CustomFontURL string + raw interface{} } func (v *brandingView) AsTableHeader() []string { @@ -30,6 +31,10 @@ func (v *brandingView) KeyValues() [][]string { } } +func (v *brandingView) Object() interface{} { + return v.raw +} + func (r *Renderer) BrandingShow(data *management.Branding) { r.Heading("branding") r.Result(makeBrandingView(data)) @@ -42,10 +47,11 @@ func (r *Renderer) BrandingUpdate(data *management.Branding) { func makeBrandingView(data *management.Branding) *brandingView { return &brandingView{ - AccentColor: data.GetColors().GetPrimary(), + AccentColor: data.GetColors().GetPrimary(), BackgroundColor: data.GetColors().GetPageBackground(), - LogoURL: data.GetLogoURL(), - FaviconURL: data.GetFaviconURL(), - CustomFontURL: data.GetFont().GetURL(), + LogoURL: data.GetLogoURL(), + FaviconURL: data.GetFaviconURL(), + CustomFontURL: data.GetFont().GetURL(), + raw: data, } } diff --git a/internal/display/custom_domain.go b/internal/display/custom_domain.go index 19db9b8a4..89cba9a96 100644 --- a/internal/display/custom_domain.go +++ b/internal/display/custom_domain.go @@ -14,6 +14,7 @@ type customDomainView struct { VerificationMethod string TLSPolicy string CustomClientIPHeader string + raw interface{} } func (v *customDomainView) AsTableHeader() []string { @@ -41,6 +42,10 @@ func (v *customDomainView) KeyValues() [][]string { } } +func (v *customDomainView) Object() interface{} { + return v.raw +} + func (r *Renderer) CustomDomainList(customDomains []*management.CustomDomain) { resource := "custom domains" @@ -54,11 +59,7 @@ func (r *Renderer) CustomDomainList(customDomains []*management.CustomDomain) { var res []View for _, customDomain := range customDomains { - res = append(res, &customDomainView{ - ID: customDomain.GetID(), - Domain: customDomain.GetDomain(), - Status: customDomainStatusColor(customDomain.GetStatus()), - }) + res = append(res, makeCustomDomainView(customDomain)) } r.Results(res) @@ -66,21 +67,21 @@ func (r *Renderer) CustomDomainList(customDomains []*management.CustomDomain) { func (r *Renderer) CustomDomainShow(customDomain *management.CustomDomain) { r.Heading("custom domain") - r.customDomainResult(customDomain) + r.Result(makeCustomDomainView(customDomain)) } func (r *Renderer) CustomDomainCreate(customDomain *management.CustomDomain) { r.Heading("custom domain created") - r.customDomainResult(customDomain) + r.Result(makeCustomDomainView(customDomain)) } func (r *Renderer) CustomDomainUpdate(customDomain *management.CustomDomain) { r.Heading("custom domain updated") - r.customDomainResult(customDomain) + r.Result(makeCustomDomainView(customDomain)) } -func (r *Renderer) customDomainResult(customDomain *management.CustomDomain) { - r.Result(&customDomainView{ +func makeCustomDomainView(customDomain *management.CustomDomain) *customDomainView { + return &customDomainView{ ID: ansi.Faint(customDomain.GetID()), Domain: customDomain.GetDomain(), Status: customDomainStatusColor(customDomain.GetStatus()), @@ -89,7 +90,8 @@ func (r *Renderer) customDomainResult(customDomain *management.CustomDomain) { VerificationMethod: customDomain.GetVerificationMethod(), TLSPolicy: customDomain.GetTLSPolicy(), CustomClientIPHeader: customDomain.GetCustomClientIPHeader(), - }) + raw: customDomain, + } } func customDomainStatusColor(v string) string { diff --git a/internal/display/display.go b/internal/display/display.go index f1030e311..a8cc52513 100644 --- a/internal/display/display.go +++ b/internal/display/display.go @@ -14,12 +14,12 @@ import ( "github.com/olekukonko/tablewriter" ) -type OutputFormat string - const ( OutputFormatJSON OutputFormat = "json" ) +type OutputFormat string + type Renderer struct { Tenant string @@ -33,6 +33,12 @@ type Renderer struct { Format OutputFormat } +type View interface { + AsTableHeader() []string + AsTableRow() []string + Object() interface{} +} + func NewRenderer() *Renderer { return &Renderer{ MessageWriter: os.Stderr, @@ -68,11 +74,6 @@ func (r *Renderer) EmptyState(resource string) { fmt.Fprintf(r.MessageWriter, "No %s available.\n\n", resource) } -type View interface { - AsTableHeader() []string - AsTableRow() []string -} - func (r *Renderer) JSONResult(data interface{}) { b, err := json.MarshalIndent(data, "", " ") if err != nil { @@ -86,7 +87,11 @@ func (r *Renderer) Results(data []View) { if len(data) > 0 { switch r.Format { case OutputFormatJSON: - r.JSONResult(data) + var list []interface{} + for _, item := range data { + list = append(list, item.Object()) + } + r.JSONResult(list) default: rows := make([][]string, 0, len(data)) @@ -101,14 +106,7 @@ func (r *Renderer) Results(data []View) { func (r *Renderer) Result(data View) { switch r.Format { case OutputFormatJSON: - // TODO(cyx): we're type asserting on the fly to prevent too - // many changes in other places. In the future we should - // enforce `Object` on all `View` types. - if v, ok := data.(interface{ Object() interface{} }); ok { - r.JSONResult(v.Object()) - } else { - r.JSONResult(data) - } + r.JSONResult(data.Object()) default: // TODO(cyx): we're type asserting on the fly to prevent too diff --git a/internal/display/log_streams.go b/internal/display/log_streams.go index 9f3ad815a..f0251e7e2 100644 --- a/internal/display/log_streams.go +++ b/internal/display/log_streams.go @@ -10,6 +10,7 @@ type logStreamView struct { Name string Type string Status string + raw interface{} } func (v *logStreamView) AsTableHeader() []string { @@ -27,13 +28,17 @@ func (v *logStreamView) AsTableRow() []string { func (v *logStreamView) KeyValues() [][]string { return [][]string{ - []string{"ID", ansi.Faint(v.ID)}, - []string{"NAME", v.Name}, - []string{"TYPE", v.Type}, - []string{"STATUS", v.Status}, + {"ID", ansi.Faint(v.ID)}, + {"NAME", v.Name}, + {"TYPE", v.Type}, + {"STATUS", v.Status}, } } +func (v *logStreamView) Object() interface{} { + return v.raw +} + func (r *Renderer) LogStreamList(logs []*management.LogStream) { resource := "log streams" @@ -47,12 +52,7 @@ func (r *Renderer) LogStreamList(logs []*management.LogStream) { var res []View for _, ls := range logs { - res = append(res, &logStreamView{ - ID: ansi.Faint(ls.GetID()), - Name: ls.GetName(), - Type: ls.GetType(), - Status: ls.GetStatus(), - }) + res = append(res, makeLogStreamView(ls)) } r.Results(res) @@ -60,24 +60,25 @@ func (r *Renderer) LogStreamList(logs []*management.LogStream) { func (r *Renderer) LogStreamShow(logs *management.LogStream) { r.Heading("log streams") - r.logStreamResult(logs) + r.Result(makeLogStreamView(logs)) } func (r *Renderer) LogStreamCreate(logs *management.LogStream) { r.Heading("log streams created") - r.logStreamResult(logs) + r.Result(makeLogStreamView(logs)) } func (r *Renderer) LogStreamUpdate(logs *management.LogStream) { r.Heading("log streams updated") - r.logStreamResult(logs) + r.Result(makeLogStreamView(logs)) } -func (r *Renderer) logStreamResult(logs *management.LogStream) { - r.Result(&logStreamView{ +func makeLogStreamView(logs *management.LogStream) *logStreamView { + return &logStreamView{ ID: ansi.Faint(logs.GetID()), Name: logs.GetName(), Type: logs.GetType(), Status: logs.GetStatus(), - }) + raw: logs, + } } diff --git a/internal/display/logs.go b/internal/display/logs.go index cd2e4b618..f38804d3c 100644 --- a/internal/display/logs.go +++ b/internal/display/logs.go @@ -27,6 +27,7 @@ var _ View = &logView{} type logView struct { silent bool *management.Log + raw interface{} } func (v *logView) AsTableHeader() []string { @@ -79,6 +80,10 @@ func (v *logView) AsTableRow() []string { } } +func (v *logView) Object() interface{} { + return v.raw +} + func (v *logView) Extras() []string { if v.silent { return nil @@ -153,7 +158,7 @@ func (r *Renderer) LogList(logs []*management.Log, ch <-chan []*management.Log, var res []View for _, l := range logs { - res = append(res, &logView{Log: l, silent: silent}) + res = append(res, &logView{Log: l, silent: silent, raw: l}) } var viewChan chan View @@ -166,7 +171,7 @@ func (r *Renderer) LogList(logs []*management.Log, ch <-chan []*management.Log, for list := range ch { for _, l := range list { - viewChan <- &logView{Log: l, silent: silent} + viewChan <- &logView{Log: l, silent: silent, raw: l} } } }() diff --git a/internal/display/quickstarts.go b/internal/display/quickstarts.go index 830e233b6..8d07137a6 100644 --- a/internal/display/quickstarts.go +++ b/internal/display/quickstarts.go @@ -15,6 +15,7 @@ type quickstartView struct { Stack string AppType string URL string + raw interface{} } func (v *quickstartView) AsTableHeader() []string { @@ -25,6 +26,10 @@ func (v *quickstartView) AsTableRow() []string { return []string{v.Stack, applyColor(v.AppType), v.URL} } +func (v *quickstartView) Object() interface{} { + return v.raw +} + func (r *Renderer) QuickstartList(qs map[string][]auth0.Quickstart) { r.Heading() @@ -40,10 +45,11 @@ func (r *Renderer) QuickstartList(qs map[string][]auth0.Quickstart) { for _, key := range keys { for _, item := range qs[key] { results = append(results, &quickstartView{ - Stack: item.Name, - AppType: applyColor(qsAppTypeFor(key)), - URL: fmt.Sprintf("%s/%s/%s", qsBaseURL, key, item.Path), - }) + Stack: item.Name, + AppType: applyColor(qsAppTypeFor(key)), + URL: fmt.Sprintf("%s/%s/%s", qsBaseURL, key, item.Path), + raw: item, + }) } } diff --git a/internal/display/roles.go b/internal/display/roles.go index 93d0a598d..d0c336eff 100644 --- a/internal/display/roles.go +++ b/internal/display/roles.go @@ -9,6 +9,7 @@ type roleView struct { ID string Name string Description string + raw interface{} } func (v *roleView) AsTableHeader() []string { @@ -31,6 +32,10 @@ func (v *roleView) KeyValues() [][]string { } } +func (v *roleView) Object() interface{} { + return v.raw +} + func (r *Renderer) RoleList(roles []*management.Role) { resource := "roles" @@ -44,11 +49,7 @@ func (r *Renderer) RoleList(roles []*management.Role) { var res []View for _, role := range roles { - res = append(res, &roleView{ - Name: role.GetName(), - ID: role.GetID(), - Description: role.GetDescription(), - }) + res = append(res, makeRoleView(role)) } r.Results(res) @@ -56,23 +57,24 @@ func (r *Renderer) RoleList(roles []*management.Role) { func (r *Renderer) RoleShow(role *management.Role) { r.Heading("role") - r.roleResult(role) + r.Result(makeRoleView(role)) } func (r *Renderer) RoleCreate(role *management.Role) { r.Heading("role created") - r.roleResult(role) + r.Result(makeRoleView(role)) } func (r *Renderer) RoleUpdate(role *management.Role) { r.Heading("role updated") - r.roleResult(role) + r.Result(makeRoleView(role)) } -func (r *Renderer) roleResult(role *management.Role) { - r.Result(&roleView{ +func makeRoleView(role *management.Role) *roleView { + return &roleView{ Name: role.GetName(), ID: ansi.Faint(role.GetID()), Description: role.GetDescription(), - }) + raw: role, + } } diff --git a/internal/display/rules.go b/internal/display/rules.go index 4a5364963..4906a0943 100644 --- a/internal/display/rules.go +++ b/internal/display/rules.go @@ -60,12 +60,7 @@ func (r *Renderer) RulesList(rules []*management.Rule) { }) for _, rule := range rules { - res = append(res, &ruleView{ - Name: rule.GetName(), - ID: rule.GetID(), - Enabled: boolean(rule.GetEnabled()), - Order: rule.GetOrder(), - }) + res = append(res, makeRuleView(rule)) } r.Results(res) diff --git a/internal/display/tenants.go b/internal/display/tenants.go index e5d94555c..687e86538 100644 --- a/internal/display/tenants.go +++ b/internal/display/tenants.go @@ -2,6 +2,7 @@ package display type tenantView struct { Name string + raw interface{} } func (v *tenantView) AsTableHeader() []string { @@ -12,6 +13,10 @@ func (v *tenantView) AsTableRow() []string { return []string{v.Name} } +func (v *tenantView) Object() interface{} { + return v.raw +} + func (r *Renderer) TenantList(data []string) { r.Heading() @@ -19,6 +24,7 @@ func (r *Renderer) TenantList(data []string) { for _, item := range data { results = append(results, &tenantView{ Name: item, + raw: item, }) } diff --git a/internal/display/user_blocks.go b/internal/display/user_blocks.go index a3a7c9c1c..84d4f4f41 100644 --- a/internal/display/user_blocks.go +++ b/internal/display/user_blocks.go @@ -7,6 +7,7 @@ import ( type userBlockView struct { Identifier string IP string + raw interface{} } func (v *userBlockView) AsTableHeader() []string { @@ -24,6 +25,10 @@ func (v *userBlockView) KeyValues() [][]string { } } +func (v *userBlockView) Object() interface{} { + return v.raw +} + func (r *Renderer) UserBlocksList(userBlocks []*management.UserBlock) { resource := "user blocks" @@ -40,6 +45,7 @@ func (r *Renderer) UserBlocksList(userBlocks []*management.UserBlock) { res = append(res, &userBlockView{ Identifier: *userBlock.Identifier, IP: *userBlock.IP, + raw: userBlock, }) } diff --git a/internal/display/users.go b/internal/display/users.go index 916a9529c..c7ca0792b 100644 --- a/internal/display/users.go +++ b/internal/display/users.go @@ -15,6 +15,7 @@ type userView struct { Connection string Username string RequireUsername bool + raw interface{} } func (v *userView) AsTableHeader() []string { @@ -49,6 +50,10 @@ func (v *userView) KeyValues() [][]string { } } +func (v *userView) Object() interface{} { + return v.raw +} + func (r *Renderer) UserSearch(users []*management.User) { resource := "user" @@ -61,61 +66,37 @@ func (r *Renderer) UserSearch(users []*management.User) { } var res []View - for _, c := range users { - conn := getUserConnection(c) - res = append(res, &userView{ - UserID: ansi.Faint(auth0.StringValue(c.ID)), - Email: auth0.StringValue(c.Email), - Connection: stringSliceToCommaSeparatedString(conn), - Username: auth0.StringValue(c.Username), - }) + for _, user := range users { + res = append(res, makeUserView(user, false)) } r.Results(res) } -func (r *Renderer) UserShow(users *management.User, requireUsername bool) { +func (r *Renderer) UserShow(user *management.User, requireUsername bool) { r.Heading("user") - - conn := getUserConnection(users) - v := &userView{ - RequireUsername: requireUsername, - UserID: ansi.Faint(auth0.StringValue(users.ID)), - Email: auth0.StringValue(users.Email), - Connection: stringSliceToCommaSeparatedString(conn), - Username: auth0.StringValue(users.Username), - } - - r.Result(v) + r.Result(makeUserView(user, requireUsername)) } -func (r *Renderer) UserCreate(users *management.User, requireUsername bool) { +func (r *Renderer) UserCreate(user *management.User, requireUsername bool) { r.Heading("user created") - - v := &userView{ - RequireUsername: requireUsername, - UserID: ansi.Faint(auth0.StringValue(users.ID)), - Email: auth0.StringValue(users.Email), - Connection: auth0.StringValue(users.Connection), - Username: auth0.StringValue(users.Username), - } - - r.Result(v) + r.Result(makeUserView(user, requireUsername)) } -func (r *Renderer) UserUpdate(users *management.User, requireUsername bool) { +func (r *Renderer) UserUpdate(user *management.User, requireUsername bool) { r.Heading("user updated") + r.Result(makeUserView(user, requireUsername)) +} - conn := getUserConnection(users) - v := &userView{ +func makeUserView(user *management.User, requireUsername bool) *userView { + return &userView{ RequireUsername: requireUsername, - UserID: auth0.StringValue(users.ID), - Email: auth0.StringValue(users.Email), - Connection: stringSliceToCommaSeparatedString(conn), - Username: auth0.StringValue(users.Username), + UserID: ansi.Faint(auth0.StringValue(user.ID)), + Email: auth0.StringValue(user.Email), + Connection: stringSliceToCommaSeparatedString(getUserConnection(user)), + Username: auth0.StringValue(user.Username), + raw: user, } - - r.Result(v) } func getUserConnection(users *management.User) []string {