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

Show scopes in apis subcommands instead of count #174

Merged
merged 14 commits into from
Mar 24, 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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ require (
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/zalando/go-keyring v0.1.1
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
golang.org/x/sys v0.0.0-20210305023407-0d6cb8bd5a4b // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d // indirect
golang.org/x/term v0.0.0-20210317153231-de623e64d2a6
golang.org/x/text v0.3.5 // indirect
gopkg.in/auth0.v5 v5.11.0
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,13 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210305023407-0d6cb8bd5a4b h1:zQ+/dCJWTuLZNCt92+rfDzgYfIWkoCRrcMAPBiQ6bt4=
golang.org/x/sys v0.0.0-20210305023407-0d6cb8bd5a4b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d h1:jbzgAvDZn8aEnytae+4ou0J0GwFZoHR0hOrTg4qH8GA=
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210317153231-de623e64d2a6 h1:EC6+IGYTjPpRfv9a2b/6Puw0W+hLtAhkV1tPsXhutqs=
golang.org/x/term v0.0.0-20210317153231-de623e64d2a6/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
2 changes: 2 additions & 0 deletions internal/cli/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ auth0 apis show <id>
}

cli.renderer.ApiShow(api)
cli.renderer.Newline()
cli.renderer.Infof("To see the full scope list, run %s", ansi.Faint("apis scopes list <api-id>"))
chrisscott marked this conversation as resolved.
Show resolved Hide resolved
return nil
},
}
Expand Down
49 changes: 41 additions & 8 deletions internal/display/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ package display

import (
"fmt"
"strconv"
"os"
"strings"

"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/auth0"
"golang.org/x/term"
"gopkg.in/auth0.v5/management"
)

type apiView struct {
ID string
Name string
Identifier string
Scopes int
Scopes string

raw interface{}
}
Expand All @@ -28,10 +30,10 @@ func (v *apiView) AsTableRow() []string {

func (v *apiView) KeyValues() [][]string {
return [][]string{
[]string{"ID", ansi.Faint(v.ID)},
[]string{"NAME", v.Name},
[]string{"IDENTIFIER", v.Identifier},
[]string{"SCOPES", strconv.Itoa(v.Scopes)},
{"ID", ansi.Faint(v.ID)},
{"NAME", v.Name},
{"IDENTIFIER", v.Identifier},
{"SCOPES", v.Scopes},
}
}

Expand Down Expand Up @@ -67,13 +69,12 @@ func (r *Renderer) ApiUpdate(api *management.ResourceServer) {
}

func makeApiView(api *management.ResourceServer) *apiView {
scopes := len(api.Scopes)

return &apiView{
ID: auth0.StringValue(api.ID),
Name: auth0.StringValue(api.Name),
Identifier: auth0.StringValue(api.Identifier),
Scopes: auth0.IntValue(&scopes),
Scopes: auth0.StringValue(truncateScopes(api.Scopes)),
chrisscott marked this conversation as resolved.
Show resolved Hide resolved

raw: api,
}
Expand Down Expand Up @@ -110,3 +111,35 @@ func makeScopeView(scope *management.ResourceServerScope) *scopeView {
Description: auth0.StringValue(scope.Description),
}
}

func truncateScopes(scopes []*management.ResourceServerScope) *string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Screen Shot 2021-03-22 at 13 51 50

Scopes that fit shouldn't be truncated.
Also let's not display the hint if the scopes are not truncated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦 good catch. Refactoring this now to bring the hint into the display logic instead of the cli logic.

ellipsis := "..."
padding := 16 // the longest apiView key plus two spaces before and after in the label column
width, _, err := term.GetSize(int(os.Stdin.Fd()))
if err != nil {
width = 80
}

var results []string
charactersNeeded := width - len(ellipsis) - padding

for _, scope := range scopes {
runeScope := []rune(*scope.Value)
characterLength := len(runeScope)
if charactersNeeded < characterLength {
break
}
charactersNeeded -= characterLength + 1 // add one for the space between them
results = append(results, *scope.Value)
}

var truncatedScopes string

if len(results) == 0 {
truncatedScopes = "n/a"
} else {
truncatedScopes = fmt.Sprintf("%s...", strings.NewReplacer("[", "", "]", "").Replace(fmt.Sprintf("%v", results)))
}

return &truncatedScopes
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 0 additions & 30 deletions vendor/golang.org/x/sys/unix/asm_darwin_arm.s

This file was deleted.

30 changes: 0 additions & 30 deletions vendor/golang.org/x/sys/unix/asm_darwin_arm64.s

This file was deleted.

29 changes: 0 additions & 29 deletions vendor/golang.org/x/sys/unix/asm_dragonfly_amd64.s

This file was deleted.

29 changes: 0 additions & 29 deletions vendor/golang.org/x/sys/unix/asm_freebsd_386.s

This file was deleted.

29 changes: 0 additions & 29 deletions vendor/golang.org/x/sys/unix/asm_freebsd_amd64.s

This file was deleted.

29 changes: 0 additions & 29 deletions vendor/golang.org/x/sys/unix/asm_freebsd_arm.s

This file was deleted.

Loading