-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from openstandia/dev
feat: support credential_process
- Loading branch information
Showing
23 changed files
with
2,087 additions
and
790 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
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,25 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/openstandia/aws-cli-oidc/lib" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var clearSecretCmd = &cobra.Command{ | ||
Use: "clear-secret", | ||
Short: "Clear OS secret store that saves AWS credentials", | ||
Long: `Clear OS secret store that saves AWS credentials.`, | ||
Run: clearSecret, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(clearSecretCmd) | ||
} | ||
|
||
func clearSecret(cmd *cobra.Command, args []string) { | ||
if err := lib.Clear(); err != nil { | ||
lib.Writeln("Failed to clear the secret store") | ||
lib.Exit(err) | ||
} | ||
lib.Write("The secret store has been cleared") | ||
} |
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,43 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/openstandia/aws-cli-oidc/lib" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var getCredCmd = &cobra.Command{ | ||
Use: "get-cred <OIDC provider name>", | ||
Short: "Get AWS credentials and out to stdout", | ||
Long: `Get AWS credentials and out to stdout through your OIDC provider authentication.`, | ||
Run: getCred, | ||
} | ||
|
||
func init() { | ||
getCredCmd.Flags().StringP("provider", "p", "", "OIDC provider name") | ||
getCredCmd.Flags().StringP("role", "r", "", "Override default assume role ARN") | ||
getCredCmd.Flags().Int64P("max-duration", "d", 0, "Override default max session duration, in seconds, of the role session [900-43200]") | ||
getCredCmd.Flags().BoolP("use-secret", "s", false, "Store AWS credentials into OS secret store, then load it without re-authentication") | ||
getCredCmd.Flags().BoolP("json", "j", false, "Print the credential as JSON format") | ||
rootCmd.AddCommand(getCredCmd) | ||
} | ||
|
||
func getCred(cmd *cobra.Command, args []string) { | ||
providerName, _ := cmd.Flags().GetString("provider") | ||
if providerName == "" { | ||
lib.Writeln("The OIDC provider name is required") | ||
lib.Exit(nil) | ||
} | ||
|
||
roleArn, _ := cmd.Flags().GetString("role") | ||
maxDurationSeconds, _ := cmd.Flags().GetInt64("max-duration") | ||
useSecret, _ := cmd.Flags().GetBool("use-secret") | ||
asJson, _ := cmd.Flags().GetBool("json") | ||
|
||
client, err := lib.CheckInstalled(providerName) | ||
if err != nil { | ||
lib.Writeln("Failed to login OIDC provider") | ||
lib.Exit(err) | ||
} | ||
|
||
lib.Authenticate(client, roleArn, maxDurationSeconds, useSecret, asJson) | ||
} |
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,5 @@ | ||
package main | ||
|
||
func main() { | ||
Execute() | ||
} |
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,33 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/openstandia/aws-cli-oidc/lib" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "aws-cli-oidc", | ||
Short: "CLI tool for retrieving AWS temporary credentials using OIDC provider", | ||
Long: `CLI tool for retrieving AWS temporary credentials using OIDC provider`, | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
lib.Writeln(err.Error()) | ||
} | ||
} | ||
|
||
func init() { | ||
cobra.OnInitialize(initConfig) | ||
} | ||
|
||
func initConfig() { | ||
viper.SetConfigFile(lib.ConfigPath() + "/config.yaml") | ||
|
||
if err := viper.ReadInConfig(); err == nil { | ||
lib.Writeln("Using config file: %s", viper.ConfigFileUsed()) | ||
} | ||
|
||
lib.IsTraceEnabled = false // TODO: configuable | ||
} |
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,21 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/openstandia/aws-cli-oidc/lib" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var setupCmd = &cobra.Command{ | ||
Use: "setup", | ||
Short: "Interactive setup of aws-cli-oidc", | ||
Long: `Interactive setup of aws-cli-oidc. Will prompt you for OIDC provider URL and other settings.`, | ||
Run: setup, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(setupCmd) | ||
} | ||
|
||
func setup(cmd *cobra.Command, args []string) { | ||
lib.RunSetup(nil) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.