Skip to content

Commit

Permalink
fix: breaking the client initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarsilva948 committed Sep 16, 2023
1 parent f7b1bff commit 5d662e6
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions cmd/local/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,18 @@ var Cmd = &cobra.Command{
func Run(cmd *cobra.Command, argv []string) {

// client initialization with AFT Credentials
log.Info("initializing AWS Client using AFT Account credentials")
awsClient := aws.NewClient("")
ssmClient := awsClient.GetSSMClient()

// defining the S3 key for the local execution
var tfS3Key string

// Validate input account ID
_, err := validate.CheckAWSAccountID(args.targetAccount)
awsClient, ssmClient, err := initializeAWSandSSMClients()
if err != nil {
log.Fatalf("invalid AWS Account ID: %v", err)
log.Errorf("error initializing AWS and SSM Clients: %v", err)
return
}

// Validate input terraform command
_, err = validate.CheckTerraformCommand(args.terraformCommand)
if err != nil {
log.Fatalf("invalid Terraform command: %v", err)
// defining the S3 key for the local execution
var tfS3Key string

// Validate input
if err := validateInput(); err != nil {
log.Errorf("Validation failed: %v", err)
return
}

Expand Down Expand Up @@ -334,3 +328,30 @@ func processJinjaFiles(

return nil
}

func validateInput() error {
_, err := validate.CheckAWSAccountID(args.targetAccount)
if err != nil {
return fmt.Errorf("invalid AWS Account ID: %w", err)
}
_, err = validate.CheckTerraformCommand(args.terraformCommand)
if err != nil {
return fmt.Errorf("invalid Terraform Command: %w", err)
}
return nil
}

func initializeAWSandSSMClients() (*aws.Client, aws.SSMClient, error) {
log.Info("initializing AWS Client using AFT Account credentials")
awsClient := aws.NewClient("")
if awsClient == nil {
return nil, nil, fmt.Errorf("failed to initialize AWS client")
}

ssmClient := awsClient.GetSSMClient()
if ssmClient == nil {
return nil, nil, fmt.Errorf("failed to initialize SSM client")
}

return awsClient, ssmClient, nil
}

0 comments on commit 5d662e6

Please sign in to comment.