Skip to content

Commit

Permalink
Merge pull request #11180 from juanvallejo/jvallejo/add-means-of-gett…
Browse files Browse the repository at this point in the history
…ing-url-rest-api

Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored Oct 4, 2016
2 parents 00625c0 + 341f89a commit 02751ff
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contrib/completions/bash/oc
Original file line number Diff line number Diff line change
Expand Up @@ -13715,6 +13715,8 @@ _oc_whoami()
flags+=("--show-context")
flags+=("-c")
local_nonpersistent_flags+=("--show-context")
flags+=("--show-server")
local_nonpersistent_flags+=("--show-server")
flags+=("--show-token")
flags+=("-t")
local_nonpersistent_flags+=("--show-token")
Expand Down
2 changes: 2 additions & 0 deletions contrib/completions/bash/openshift
Original file line number Diff line number Diff line change
Expand Up @@ -18267,6 +18267,8 @@ _openshift_cli_whoami()
flags+=("--show-context")
flags+=("-c")
local_nonpersistent_flags+=("--show-context")
flags+=("--show-server")
local_nonpersistent_flags+=("--show-server")
flags+=("--show-token")
flags+=("-t")
local_nonpersistent_flags+=("--show-token")
Expand Down
2 changes: 2 additions & 0 deletions contrib/completions/zsh/oc
Original file line number Diff line number Diff line change
Expand Up @@ -13876,6 +13876,8 @@ _oc_whoami()
flags+=("--show-context")
flags+=("-c")
local_nonpersistent_flags+=("--show-context")
flags+=("--show-server")
local_nonpersistent_flags+=("--show-server")
flags+=("--show-token")
flags+=("-t")
local_nonpersistent_flags+=("--show-token")
Expand Down
2 changes: 2 additions & 0 deletions contrib/completions/zsh/openshift
Original file line number Diff line number Diff line change
Expand Up @@ -18428,6 +18428,8 @@ _openshift_cli_whoami()
flags+=("--show-context")
flags+=("-c")
local_nonpersistent_flags+=("--show-context")
flags+=("--show-server")
local_nonpersistent_flags+=("--show-server")
flags+=("--show-token")
flags+=("-t")
local_nonpersistent_flags+=("--show-token")
Expand Down
4 changes: 4 additions & 0 deletions docs/man/man1/oc-whoami.1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ user context.
\fB\-c\fP, \fB\-\-show\-context\fP=false
Print the current user context name

.PP
\fB\-\-show\-server\fP=false
Print the current server's REST API URL

.PP
\fB\-t\fP, \fB\-\-show\-token\fP=false
Print the token the current session is using. This will return an error if you are using a different form of authentication.
Expand Down
4 changes: 4 additions & 0 deletions docs/man/man1/openshift-cli-whoami.1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ user context.
\fB\-c\fP, \fB\-\-show\-context\fP=false
Print the current user context name

.PP
\fB\-\-show\-server\fP=false
Print the current server's REST API URL

.PP
\fB\-t\fP, \fB\-\-show\-token\fP=false
Print the token the current session is using. This will return an error if you are using a different form of authentication.
Expand Down
12 changes: 12 additions & 0 deletions pkg/cmd/cli/cmd/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func NewCmdWhoAmI(name, fullName string, f *clientcmd.Factory, out io.Writer) *c

cmd.Flags().BoolP("show-token", "t", false, "Print the token the current session is using. This will return an error if you are using a different form of authentication.")
cmd.Flags().BoolP("show-context", "c", false, "Print the current user context name")
cmd.Flags().Bool("show-server", false, "Print the current server's REST API URL")

return cmd
}
Expand Down Expand Up @@ -89,6 +90,17 @@ func RunWhoAmI(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []s
fmt.Fprintf(out, "%s\n", cfg.CurrentContext)
return nil
}
if kcmdutil.GetFlagBool(cmd, "show-server") {
cfg, err := f.OpenShiftClientConfig.RawConfig()
if err != nil {
return err
}
for _, c := range cfg.Clusters {
fmt.Fprintf(out, "%s\n", c.Server)
return nil
}
return fmt.Errorf("unable to get clusters. Cannot retrieve server URL.")
}

client, _, err := f.Clients()
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions test/cmd/whoami.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
source "$(dirname "${BASH_SOURCE}")/../../hack/lib/init.sh"
trap os::test::junit::reconcile_output EXIT

# Cleanup cluster resources created by this test
(
set +e
oc delete all,templates --all
exit 0
) &>/dev/null


os::test::junit::declare_suite_start "cmd/whoami"
# This test validates the whoami command's --show-server flag
os::cmd::expect_success_and_text 'oc whoami --show-server' 'http(s)?:\/\/[0-9\.]+\:[0-9]+'

echo "whoami: ok"
os::test::junit::declare_suite_end

0 comments on commit 02751ff

Please sign in to comment.