Skip to content
Merged
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
88 changes: 88 additions & 0 deletions pkg/cmd/cli/describe/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
buildapi "github.com/openshift/origin/pkg/build/api"
deployapi "github.com/openshift/origin/pkg/deploy/api"
imageapi "github.com/openshift/origin/pkg/image/api"
oauthapi "github.com/openshift/origin/pkg/oauth/api"
projectapi "github.com/openshift/origin/pkg/project/api"
routeapi "github.com/openshift/origin/pkg/route/api"
templateapi "github.com/openshift/origin/pkg/template/api"
userapi "github.com/openshift/origin/pkg/user/api"
)

var (
Expand All @@ -29,6 +31,14 @@ var (
parameterColumns = []string{"NAME", "DESCRIPTION", "GENERATOR", "VALUE"}
policyColumns = []string{"NAME", "ROLES", "LAST MODIFIED"}
policyBindingColumns = []string{"NAME", "ROLE BINDINGS", "LAST MODIFIED"}

oauthClientColumns = []string{"NAME", "SECRET", "WWW-CHALLENGE", "REDIRECT URIS"}
oauthClientAuthorizationColumns = []string{"NAME", "USER NAME", "CLIENT NAME", "SCOPES"}
oauthAccessTokenColumns = []string{"NAME", "USER NAME", "CLIENT NAME", "CREATED", "EXPIRES", "REDIRECT URI", "SCOPES"}
Copy link
Contributor

Choose a reason for hiding this comment

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

lack of refresh token intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't support refresh token at this point, so yes

oauthAuthorizeTokenColumns = []string{"NAME", "USER NAME", "CLIENT NAME", "CREATED", "EXPIRES", "REDIRECT URI", "SCOPES"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Describer could add State.


userColumns = []string{"NAME", "UID", "FULL NAME"}
userIdentityMappingColumns = []string{"NAME", "IDENTITY PROVIDER", "IDENTITY USERNAME", "USER NAME"}
)

func NewHumanReadablePrinter(noHeaders bool) *kctl.HumanReadablePrinter {
Expand All @@ -54,6 +64,18 @@ func NewHumanReadablePrinter(noHeaders bool) *kctl.HumanReadablePrinter {
p.Handler(policyColumns, printPolicyList)
p.Handler(policyBindingColumns, printPolicyBinding)
p.Handler(policyBindingColumns, printPolicyBindingList)

p.Handler(oauthClientColumns, printOAuthClient)
p.Handler(oauthClientColumns, printOAuthClientList)
p.Handler(oauthClientAuthorizationColumns, printOAuthClientAuthorization)
p.Handler(oauthClientAuthorizationColumns, printOAuthClientAuthorizationList)
p.Handler(oauthAccessTokenColumns, printOAuthAccessToken)
p.Handler(oauthAccessTokenColumns, printOAuthAccessTokenList)
p.Handler(oauthAuthorizeTokenColumns, printOAuthAuthorizeToken)
p.Handler(oauthAuthorizeTokenColumns, printOAuthAuthorizeTokenList)

p.Handler(userColumns, printUser)
p.Handler(userIdentityMappingColumns, printUserIdentityMapping)
return p
}

Expand Down Expand Up @@ -251,3 +273,69 @@ func printPolicyBindingList(list *authorizationapi.PolicyBindingList, w io.Write

return nil
}

func printOAuthClient(client *oauthapi.OAuthClient, w io.Writer) error {
challenge := "FALSE"
if client.RespondWithChallenges {
challenge = "TRUE"
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%v\n", client.Name, client.Secret, challenge, strings.Join(client.RedirectURIs, ","))
return err
}
func printOAuthClientList(list *oauthapi.OAuthClientList, w io.Writer) error {
for _, item := range list.Items {
if err := printOAuthClient(&item, w); err != nil {
return err
}
}
return nil
}

func printOAuthClientAuthorization(auth *oauthapi.OAuthClientAuthorization, w io.Writer) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%v\n", auth.Name, auth.UserName, auth.ClientName, strings.Join(auth.Scopes, ","))
return err
}
func printOAuthClientAuthorizationList(list *oauthapi.OAuthClientAuthorizationList, w io.Writer) error {
for _, item := range list.Items {
if err := printOAuthClientAuthorization(&item, w); err != nil {
return err
}
}
return nil
}

func printOAuthAccessToken(token *oauthapi.OAuthAccessToken, w io.Writer) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\t%s\t%s\n", token.Name, token.UserName, token.ClientName, token.CreationTimestamp, token.ExpiresIn, token.RedirectURI, strings.Join(token.Scopes, ","))
return err
}
func printOAuthAccessTokenList(list *oauthapi.OAuthAccessTokenList, w io.Writer) error {
for _, item := range list.Items {
if err := printOAuthAccessToken(&item, w); err != nil {
return err
}
}
return nil
}

func printOAuthAuthorizeToken(token *oauthapi.OAuthAuthorizeToken, w io.Writer) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\t%s\t%s\n", token.Name, token.UserName, token.ClientName, token.CreationTimestamp, token.ExpiresIn, token.RedirectURI, strings.Join(token.Scopes, ","))
return err
}
func printOAuthAuthorizeTokenList(list *oauthapi.OAuthAuthorizeTokenList, w io.Writer) error {
for _, item := range list.Items {
if err := printOAuthAuthorizeToken(&item, w); err != nil {
return err
}
}
return nil
}

func printUser(user *userapi.User, w io.Writer) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\n", user.Name, user.UID, user.FullName)
return err
}

func printUserIdentityMapping(mapping *userapi.UserIdentityMapping, w io.Writer) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", mapping.Name, mapping.Identity.Provider, mapping.Identity.UserName, mapping.User.Name)
return err
}