Skip to content

Commit

Permalink
Display JSON on list commands properly [CLI-191] (#327)
Browse files Browse the repository at this point in the history
* Display JSON on list commands properly

* Fix rules

* Fix actions

* Remove unused logic
  • Loading branch information
Widcket authored Jul 8, 2021
1 parent 53f029c commit 4685f26
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 262 deletions.
24 changes: 12 additions & 12 deletions commander.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ tests:
exit-code: 0
stdout:
json:
Email: "[email protected]"
Connection: "Username-Password-Authentication"
email: "[email protected]"
connection: "Username-Password-Authentication"

users create and check output:
command: auth0 users create --name integration-test-user-new2 --connection Username-Password-Authentication --email [email protected] --password testUser12 --no-input
Expand All @@ -423,8 +423,8 @@ tests:
command: auth0 users show $(cat ./integration/identifiers/user-id) --format json
stdout:
json:
Email: "[email protected]"
Connection: "Username-Password-Authentication"
email: "[email protected]"
connection: "Username-Password-Authentication"
exit-code: 0

users show:
Expand All @@ -440,14 +440,14 @@ tests:
command: auth0 users update $(cat ./integration/identifiers/user-id) --email [email protected] --format json --no-input
stdout:
json:
Email: [email protected]
email: [email protected]
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: [email protected] # Name is not being displayed, hence using email
email: [email protected] # Name is not being displayed, hence using email
exit-code: 0

# Test 'roles create'
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion integration/get-role-id.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion integration/get-user-id.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
user=$( auth0 users create -n integration-test-user-better -c Username-Password-Authentication -e [email protected] -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
16 changes: 8 additions & 8 deletions integration/test-cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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-* ]]
Expand All @@ -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-* ]]
Expand All @@ -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
Expand All @@ -60,13 +60,13 @@ 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-* ]]
then
echo deleting "$name"
$( auth0 roles delete "$id")
fi
done
done
19 changes: 1 addition & 18 deletions internal/display/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions internal/display/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func makeApiTableView(api *management.ResourceServer) *apiTableView {
type scopeView struct {
Scope string
Description string
raw interface{}
}

func (v *scopeView) AsTableHeader() []string {
Expand All @@ -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"

Expand All @@ -173,6 +178,7 @@ func makeScopeView(scope *management.ResourceServerScope) *scopeView {
return &scopeView{
Scope: auth0.StringValue(scope.Value),
Description: auth0.StringValue(scope.Description),
raw: scope,
}
}

Expand Down
126 changes: 14 additions & 112 deletions internal/display/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ", "),
}
}

Expand Down Expand Up @@ -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"

Expand All @@ -177,44 +119,19 @@ 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)
}

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) {
Expand All @@ -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))

Expand All @@ -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),
Expand All @@ -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.
Expand Down
Loading

0 comments on commit 4685f26

Please sign in to comment.