Skip to content

Commit

Permalink
Use NewFromConfig to pass full config, add pretty printing for more e…
Browse files Browse the repository at this point in the history
…rrors
  • Loading branch information
lucacome committed Jul 8, 2021
1 parent 1bca335 commit 73f99f5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/nginx-ingress/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var (
productCode string
pubKeyVersion int32 = 1
pubKeyString string
nonce string
)

func init() {
Expand All @@ -43,14 +42,22 @@ func checkAWSEntitlement() error {
return fmt.Errorf("error loading AWS configuration: %w", err)
}

mpm := marketplacemetering.New(marketplacemetering.Options{Region: cfg.Region, Credentials: cfg.Credentials})
mpm := marketplacemetering.NewFromConfig(cfg)

out, err := mpm.RegisterUsage(ctx, &marketplacemetering.RegisterUsageInput{ProductCode: &productCode, PublicKeyVersion: &pubKeyVersion, Nonce: &nonce})
if err != nil {
var notEnt *types.CustomerNotEntitledException
var invRegion *types.InvalidRegionException
var platNotSup *types.PlatformNotSupportedException
if errors.As(err, &notEnt) {
return fmt.Errorf("user not entitled, code: %v, message: %v, fault: %v", notEnt.ErrorCode(), notEnt.ErrorMessage(), notEnt.ErrorFault().String())
}
if errors.As(err, &invRegion) {
return fmt.Errorf("invalid region, code: %v, message: %v, fault: %v", invRegion.ErrorCode(), invRegion.ErrorMessage(), invRegion.ErrorFault().String())
}
if errors.As(err, &platNotSup) {
return fmt.Errorf("platform not supported, code: %v, message: %v, fault: %v", platNotSup.ErrorCode(), platNotSup.ErrorMessage(), platNotSup.ErrorFault().String())
}
return err
}

Expand Down

0 comments on commit 73f99f5

Please sign in to comment.