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

Ev/tctl #1248

Merged
merged 2 commits into from
Sep 4, 2017
Merged

Ev/tctl #1248

Show file tree
Hide file tree
Changes from all commits
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 docs/2.3/admin-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ of 30 hours and a minimum of 1 minute. Once authenticated, the account will beco
```bash
$ tctl users ls

User Allowed to Login as
---- -------------------
User Allowed Logins
---- --------------
admin admin,root
ross ross
joe joe,root
Expand Down
2 changes: 1 addition & 1 deletion e
Submodule e updated from 4c47bd to 7b682b
10 changes: 5 additions & 5 deletions lib/services/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,27 +361,27 @@ func ParseShortcut(in string) (string, error) {
return "", trace.BadParameter("missing resource name")
}
switch strings.ToLower(in) {
case "roles":
case "role", "roles":
return KindRole, nil
case "namespaces", "ns":
return KindNamespace, nil
case "auth_servers", "auth":
return KindAuthServer, nil
case "proxies":
return KindProxy, nil
case "nodes":
case "nodes", "node":
return KindNode, nil
case "oidc":
return KindOIDCConnector, nil
case "saml":
return KindSAMLConnector, nil
case "users":
case "user", "users":
return KindUser, nil
case "cert_authorities", "cas":
return KindCertAuthority, nil
case "reverse_tunnels", "rts":
return KindReverseTunnel, nil
case "trusted_cluster", "tc":
case "trusted_cluster", "tc", "cluster", "clusters":
return KindTrustedCluster, nil
case "cluster_authentication_preferences", "cap":
return KindClusterAuthPreference, nil
Expand Down Expand Up @@ -441,5 +441,5 @@ func (r *Ref) Set(v string) error {
}

func (r *Ref) String() string {
return fmt.Sprintf("%v/%v", r.Kind, r.Name)
return fmt.Sprintf("%s/%s", r.Kind, r.Name)
}
33 changes: 12 additions & 21 deletions tool/tctl/common/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/ghodss/yaml"
)

type collection interface {
type ResourceCollection interface {
writeText(w io.Writer) error
writeJSON(w io.Writer) error
writeYAML(w io.Writer) error
Expand All @@ -43,7 +43,7 @@ type roleCollection struct {

func (r *roleCollection) writeText(w io.Writer) error {
t := goterm.NewTable(0, 10, 5, ' ', 0)
printHeader(t, []string{"Role", "Allowed to login as", "Node Labels", "Access to resources"})
PrintHeader(t, []string{"Role", "Allowed to login as", "Node Labels", "Access to resources"})
if len(r.roles) == 0 {
_, err := io.WriteString(w, t.String())
return trace.Wrap(err)
Expand Down Expand Up @@ -93,7 +93,7 @@ type namespaceCollection struct {

func (n *namespaceCollection) writeText(w io.Writer) error {
t := goterm.NewTable(0, 10, 5, ' ', 0)
printHeader(t, []string{"Name"})
PrintHeader(t, []string{"Name"})
if len(n.namespaces) == 0 {
_, err := io.WriteString(w, t.String())
return trace.Wrap(err)
Expand Down Expand Up @@ -155,7 +155,7 @@ type serverCollection struct {

func (s *serverCollection) writeText(w io.Writer) error {
t := goterm.NewTable(0, 10, 5, ' ', 0)
printHeader(t, []string{"Hostname", "UUID", "Address", "Labels"})
PrintHeader(t, []string{"Hostname", "UUID", "Address", "Labels"})
if len(s.servers) == 0 {
_, err := io.WriteString(w, t.String())
return trace.Wrap(err)
Expand Down Expand Up @@ -197,17 +197,8 @@ type userCollection struct {
}

func (s *userCollection) writeText(w io.Writer) error {
t := goterm.NewTable(0, 10, 5, ' ', 0)
printHeader(t, []string{"User", "Roles", "Created By"})
if len(s.users) == 0 {
_, err := io.WriteString(w, t.String())
return trace.Wrap(err)
}
for _, u := range s.users {
fmt.Fprintf(t, "%v\t%v\t%v\n", u.GetName(), strings.Join(u.GetRoles(), ","), u.GetCreatedBy().String())
}
_, err := io.WriteString(w, t.String())
return trace.Wrap(err)
// a user collection does not need this method
return nil
}

func (s *userCollection) writeJSON(w io.Writer) error {
Expand Down Expand Up @@ -241,7 +232,7 @@ type authorityCollection struct {

func (a *authorityCollection) writeText(w io.Writer) error {
t := goterm.NewTable(0, 10, 5, ' ', 0)
printHeader(t, []string{"Cluster Name", "CA Type", "Fingerprint", "Role Map"})
PrintHeader(t, []string{"Cluster Name", "CA Type", "Fingerprint", "Role Map"})
for _, a := range a.cas {
for _, keyBytes := range a.GetCheckingKeys() {
fingerprint, err := sshutils.AuthorizedKeyFingerprint(keyBytes)
Expand Down Expand Up @@ -292,7 +283,7 @@ type reverseTunnelCollection struct {

func (r *reverseTunnelCollection) writeText(w io.Writer) error {
t := goterm.NewTable(0, 10, 5, ' ', 0)
printHeader(t, []string{"Cluster Name", "Dial Addresses"})
PrintHeader(t, []string{"Cluster Name", "Dial Addresses"})
for _, tunnel := range r.tunnels {
fmt.Fprintf(t, "%v\t%v\n", tunnel.GetClusterName(), strings.Join(tunnel.GetDialAddrs(), ","))
}
Expand Down Expand Up @@ -331,7 +322,7 @@ type oidcCollection struct {

func (c *oidcCollection) writeText(w io.Writer) error {
t := goterm.NewTable(0, 10, 5, ' ', 0)
printHeader(t, []string{"Name", "Issuer URL", "Additional Scope"})
PrintHeader(t, []string{"Name", "Issuer URL", "Additional Scope"})
for _, conn := range c.connectors {
fmt.Fprintf(t, "%v\t%v\t%v\n", conn.GetName(), conn.GetIssuerURL(), strings.Join(conn.GetScope(), ","))
}
Expand Down Expand Up @@ -370,7 +361,7 @@ type samlCollection struct {

func (c *samlCollection) writeText(w io.Writer) error {
t := goterm.NewTable(0, 10, 5, ' ', 0)
printHeader(t, []string{"Name", "SSO URL"})
PrintHeader(t, []string{"Name", "SSO URL"})
for _, conn := range c.connectors {
fmt.Fprintf(t, "%v\t%v\n", conn.GetName(), conn.GetSSO())
}
Expand Down Expand Up @@ -409,7 +400,7 @@ type trustedClusterCollection struct {

func (c *trustedClusterCollection) writeText(w io.Writer) error {
t := goterm.NewTable(0, 10, 5, ' ', 0)
printHeader(t, []string{"Name", "Enabled", "Token", "Proxy Address", "Reverse Tunnel Address", "Role Map"})
PrintHeader(t, []string{"Name", "Enabled", "Token", "Proxy Address", "Reverse Tunnel Address", "Role Map"})
for _, tc := range c.trustedClusters {
fmt.Fprintf(t, "%v\t%v\t%v\t%v\t%v\t%v\n", tc.GetName(), tc.GetEnabled(), tc.GetToken(), tc.GetProxyAddress(), tc.GetReverseTunnelAddress(), tc.CombinedMapping())
}
Expand Down Expand Up @@ -448,7 +439,7 @@ type authPreferenceCollection struct {

func (c *authPreferenceCollection) writeText(w io.Writer) error {
t := goterm.NewTable(0, 10, 5, ' ', 0)
printHeader(t, []string{"Type", "Second Factor"})
PrintHeader(t, []string{"Type", "Second Factor"})
fmt.Fprintf(t, "%v\t%v\n", c.GetType(), c.GetSecondFactor())
_, err := io.WriteString(w, t.String())
return trace.Wrap(err)
Expand Down
Loading