Skip to content

Commit

Permalink
fix(cdsctl): env token usage (#4867)
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
  • Loading branch information
yesnault authored and sguiheux committed Jan 8, 2020
1 parent 2fbfe2c commit 489f5d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions cli/cdsctl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func loadConfig(cmd *cobra.Command) (string, *cdsclient.Config, error) {
if cdsctxEnv.Session != "" {
cdsctx.Session = cdsctxEnv.Session
}
if cdsctxEnv.Token != "" {
cdsctx.Token = cdsctxEnv.Token
}

// if there is no session token, but if we have a sign in token, recreate a session token
if cdsctxEnv.Session == "" && cdsctxEnv.Token != "" {
Expand Down
10 changes: 7 additions & 3 deletions cli/cdsctl/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var loginCmd = cli.Command{
},
{
Name: "driver",
Usage: "An enabled auth driver to login with. This should be local, github, gitlab, ldap, builtin or corporate-sso",
Usage: "An enabled auth driver to login with. This should be local, GitHub, GitLab, Ldap, builtin or corporate-sso",
ShortHand: "d",
},
{
Expand All @@ -52,6 +52,10 @@ var loginCmd = cli.Command{
Usage: "A CDS init token that can be used for first connection",
ShortHand: "i",
},
{
Name: "token",
Usage: "A CDS token that can be used to login with a builtin auth driver.",
},
},
}

Expand Down Expand Up @@ -179,7 +183,7 @@ func loginRunLDAP(v cli.Values) (sdk.AuthConsumerSigninRequest, error) {

func loginRunBuiltin(v cli.Values) (sdk.AuthConsumerSigninRequest, error) {
req := sdk.AuthConsumerSigninRequest{
"token": v.GetString("signin-token"),
"token": v.GetString("token"),
}

if req["token"] == "" && !v.GetBool("no-interactive") {
Expand Down Expand Up @@ -238,7 +242,7 @@ func doAfterLogin(client cdsclient.Interface, v cli.Values, apiURL string, drive

var signinToken, sessionToken string
if driverType == sdk.ConsumerBuiltin {
signinToken = v.GetString("signin-token")
signinToken = v.GetString("token")
sessionToken = res.Token
} else {
var err error
Expand Down
10 changes: 5 additions & 5 deletions cli/cdsctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,9 @@ Per default, the command line ` + "`cdsctl`" + ` uses your keychain on your os:
* OSX: Keychain Access
* Linux System: Secret-tool (libsecret)
You can bypass keychain tools by using environment variables:
CDS_API_URL="https://instance.cds.api" CDS_USER="username" CDS_SESSION_TOKEN="yourtoken" cdsctl [command]
You can use a "sign in" token attached to a consumer:
CDS_API_URL="https://instance.cds.api" CDS_SIGNIN_TOKEN="token-consumer" cdsctl [command]
CDS_API_URL="https://instance.cds.api" CDS_TOKEN="token-consumer" cdsctl [command]
Want to debug something? You can use ` + "`CDS_VERBOSE`" + ` environment variable.
Expand All @@ -121,6 +117,10 @@ If you're using a self-signed certificate on CDS API, you probably want to use `
CDS_INSECURE=true cdsctl [command]
For advanced usage, you can use a session-token instead of a token:
CDS_API_URL="https://instance.cds.api" CDS_USER="username" CDS_SESSION_TOKEN="yourtoken" cdsctl [command]
`,
}

Expand Down

0 comments on commit 489f5d6

Please sign in to comment.