From a4f5e3dc3fd2dbe61a1527adbe945374d8973b94 Mon Sep 17 00:00:00 2001 From: Michael Tibben Date: Mon, 20 Mar 2023 20:06:05 +1100 Subject: [PATCH] Fix ini output to match credentials file --- cli/export.go | 2 +- cli/export_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 cli/export_test.go diff --git a/cli/export.go b/cli/export.go index 109b3958f..82dca9229 100644 --- a/cli/export.go +++ b/cli/export.go @@ -165,7 +165,7 @@ func printINI(credsProvider aws.CredentialsProvider, profilename, region string) } f := ini.Empty() - s, err := f.NewSection("profile " + profilename) + s, err := f.NewSection(profilename) if err != nil { return fmt.Errorf("Failed to create ini section: %w", err) } diff --git a/cli/export_test.go b/cli/export_test.go new file mode 100644 index 000000000..9037923df --- /dev/null +++ b/cli/export_test.go @@ -0,0 +1,25 @@ +package cli + +import ( + "github.com/alecthomas/kingpin/v2" + + "github.com/99designs/keyring" +) + +func ExampleExportCommand() { + app := kingpin.New("aws-vault", "") + awsVault := ConfigureGlobals(app) + awsVault.keyringImpl = keyring.NewArrayKeyring([]keyring.Item{ + {Key: "llamas", Data: []byte(`{"AccessKeyID":"ABC","SecretAccessKey":"XYZ"}`)}, + }) + ConfigureExportCommand(app, awsVault) + kingpin.MustParse(app.Parse([]string{ + "export", "--format=ini", "--no-session", "llamas", + })) + + // Output: + // [llamas] + // aws_access_key_id=ABC + // aws_secret_access_key=XYZ + // region=us-east-1 +}