Skip to content

Commit

Permalink
Add CF-prefixed variables (#38)
Browse files Browse the repository at this point in the history
Some cloudflare tools (like wrangler) expect variables prefixed with `CF_`
rather than `CLOUDFLARE_`. Add the matching variables.

Fixes issue 37
  • Loading branch information
viraptor committed Jan 14, 2021
1 parent ad1468e commit 4c50b90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ $ cf-vault exec work -- env | grep -i cloudflare
CLOUDFLARE_VAULT_SESSION=work
[email protected]
CLOUDFLARE_API_KEY=s3cr3t
[email protected]
CF_API_KEY=s3cr3t
```

If you don't provide a command, you will be dropped into a new shell with the
Expand All @@ -123,6 +125,8 @@ $ env | grep -i cloudflare
CLOUDFLARE_VAULT_SESSION=work
[email protected]
CLOUDFLARE_API_KEY=s3cr3t
[email protected]
CF_API_KEY=s3cr3t

$ exit
$ env | grep -i cloudflare
Expand Down
7 changes: 7 additions & 0 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var execCmd = &cobra.Command{
CLOUDFLARE_VAULT_SESSION=example-profile
[email protected]
CLOUDFLARE_API_KEY=s3cr3t
[email protected]
CF_API_KEY=s3cr3t
Spawn a new shell with credentials populated
Expand All @@ -39,6 +41,8 @@ var execCmd = &cobra.Command{
CLOUDFLARE_VAULT_SESSION=example-profile
[email protected]
CLOUDFLARE_API_KEY=s3cr3t
[email protected]
CF_API_KEY=s3cr3t
`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
Expand Down Expand Up @@ -105,8 +109,10 @@ var execCmd = &cobra.Command{
if profile.SessionDuration == "" {
if profile.AuthType == "api_key" {
env.Set("CLOUDFLARE_EMAIL", profile.Email)
env.Set("CF_EMAIL", profile.Email)
}
env.Set(fmt.Sprintf("CLOUDFLARE_%s", strings.ToUpper(profile.AuthType)), string(keychain.Data))
env.Set(fmt.Sprintf("CF_%s", strings.ToUpper(profile.AuthType)), string(keychain.Data))
} else {
var api *cloudflare.API
if profile.AuthType == "api_token" {
Expand Down Expand Up @@ -160,6 +166,7 @@ var execCmd = &cobra.Command{

if shortLivedToken.Value != "" {
env.Set("CLOUDFLARE_API_TOKEN", shortLivedToken.Value)
env.Set("CF_API_TOKEN", shortLivedToken.Value)
}

env.Set("CLOUDFLARE_SESSION_EXPIRY", strconv.Itoa(int(tokenExpiry.Unix())))
Expand Down

0 comments on commit 4c50b90

Please sign in to comment.