Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #24 from danmx/profile
Browse files Browse the repository at this point in the history
Adding AWS config profile support
  • Loading branch information
danmx authored Apr 15, 2019
2 parents 69b0276 + e1d3151 commit c32b996
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cmd/sigil/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
workDir string
cfgFilePath string
awsRegion string
awsProfile string
target string
targetType string
outputFormat string
Expand Down Expand Up @@ -98,6 +99,11 @@ func main() {
Usage: "specify AWS `region`",
Destination: &awsRegion,
}),
altsrc.NewStringFlag(cli.StringFlag{
Name: "profile",
Usage: "specify AWS `profile`",
Destination: &awsProfile,
}),
cli.StringFlag{
Name: "log-level",
Value: LogLevel,
Expand Down Expand Up @@ -152,10 +158,13 @@ func main() {
"tags": tagFilter.String(),
"output-format": outputFormat,
"region": awsRegion,
"profile": awsProfile,
"interactive": startSession,
}).Debug("List inputs")
input := &list.StartInput{
OutputFormat: &outputFormat,
AWSRegion: &awsRegion,
AWSProfile: &awsProfile,
TagFilter: &tagFilter.Map,
StartSession: &startSession,
}
Expand Down Expand Up @@ -190,14 +199,16 @@ func main() {
Flags: sessionFlags,
Action: func(c *cli.Context) error {
log.WithFields(log.Fields{
"target": target,
"type": targetType,
"region": awsRegion,
"target": target,
"type": targetType,
"region": awsRegion,
"profile": awsProfile,
}).Debug("Session inputs")
input := &session.StartInput{
Target: &target,
TargetType: &targetType,
AWSRegion: &awsRegion,
AWSProfile: &awsProfile,
}
err := session.Start(input)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions pkg/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
remoteSession "github.com/danmx/sigil/pkg/session"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ssm"
Expand All @@ -25,6 +26,7 @@ type StartInput struct {
// Define output format
OutputFormat *string
AWSRegion *string
AWSProfile *string
TagFilter *map[string]string
StartSession *bool
}
Expand Down Expand Up @@ -64,6 +66,11 @@ func Start(input *StartInput) error {
if *input.AWSRegion != "" {
awsConfig.Region = input.AWSRegion
}
if *input.AWSProfile != "" {
// Leaving empty filename because of
// https://github.com/aws/aws-sdk-go/blob/704cb4634ea23d666b1046363639d44234fb4ed2/aws/credentials/shared_credentials_provider.go#L31
awsConfig.Credentials = credentials.NewSharedCredentials("", *input.AWSProfile)
}
sess := session.Must(session.NewSession(awsConfig))
// Get the list of instances
ssmDescribeInstancesInput := &ssm.DescribeInstanceInformationInput{}
Expand Down
7 changes: 7 additions & 0 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ssm"
Expand All @@ -18,6 +19,7 @@ type StartInput struct {
Target *string
TargetType *string
AWSRegion *string
AWSProfile *string
}

// Start will start a session in chosen EC2 instance
Expand All @@ -26,6 +28,11 @@ func Start(input *StartInput) error {
if *input.AWSRegion != "" {
awsConfig.Region = input.AWSRegion
}
if *input.AWSProfile != "" {
// Leaving empty filename because of
// https://github.com/aws/aws-sdk-go/blob/704cb4634ea23d666b1046363639d44234fb4ed2/aws/credentials/shared_credentials_provider.go#L31
awsConfig.Credentials = credentials.NewSharedCredentials("", *input.AWSProfile)
}
sess := session.Must(session.NewSession(awsConfig))
var instanceID *string
switch *input.TargetType {
Expand Down

0 comments on commit c32b996

Please sign in to comment.