-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In #20, I was only testing single policies however it is more likely you'll encounter multiple policies for tokens as there are varying resource levels. This takes into account all the policy options and fixes overwriting environment variables instead of just appending it.
- Loading branch information
1 parent
9b7322f
commit 847ec0f
Showing
3 changed files
with
67 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cmd | ||
|
||
import "strings" | ||
|
||
// environ is a slice of strings representing the environment, in the form | ||
// "key=value". | ||
type environ []string | ||
|
||
// Unset an environment variable by key | ||
func (e *environ) Unset(key string) { | ||
for i := range *e { | ||
if strings.HasPrefix((*e)[i], key+"=") { | ||
(*e)[i] = (*e)[len(*e)-1] | ||
*e = (*e)[:len(*e)-1] | ||
break | ||
} | ||
} | ||
} | ||
|
||
// Set adds an environment variable, replacing any existing ones of the same key | ||
func (e *environ) Set(key, val string) { | ||
e.Unset(key) | ||
*e = append(*e, key+"="+val) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters