Skip to content

Commit

Permalink
feat: support AWS_PROFILE (#1114)
Browse files Browse the repository at this point in the history
Signed-off-by: JuHyung-Son <sonju0427@gmail.com>
  • Loading branch information
JuHyung-Son committed May 16, 2024
1 parent fe53907 commit 882c6f5
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions pkg/integration/aws/aws.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package aws

import (
"os"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/k8sgpt-ai/k8sgpt/pkg/common"
"github.com/spf13/viper"
"os"
)

type AWS struct {
Expand All @@ -23,16 +24,28 @@ func (a *AWS) UnDeploy(namespace string) error {
}

func (a *AWS) AddAnalyzer(mergedMap *map[string]common.IAnalyzer) {
// Check for AWS credentials in the environment
// https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html
if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
panic("AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must be set in the environment")
// Retrieve AWS credentials from the environment
accessKeyID := os.Getenv("AWS_ACCESS_KEY_ID")
secretAccessKey := os.Getenv("AWS_SECRET_ACCESS_KEY")
awsProfile := os.Getenv("AWS_PROFILE")

var sess *session.Session
if accessKeyID != "" && secretAccessKey != "" {
// Use access keys if both are provided
sess = session.Must(session.NewSessionWithOptions(session.Options{
Config: aws.Config{},
}))
} else {
// Use AWS profile, default to "default" if not set
if awsProfile == "" {
awsProfile = "default"
}
sess = session.Must(session.NewSessionWithOptions(session.Options{
Profile: awsProfile,
SharedConfigState: session.SharedConfigEnable,
}))
}

sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
Config: aws.Config{},
}))
a.sess = sess
(*mergedMap)["EKS"] = &EKSAnalyzer{
session: a.sess,
Expand Down

0 comments on commit 882c6f5

Please sign in to comment.