Skip to content

Commit

Permalink
https://github.com/kedacore/keda/issues/2214
Browse files Browse the repository at this point in the history
Signed-off-by: Siva Guruvareddiar <gurusiva@gmail.com>
Signed-off-by: Siva Guruvareddiar <sivagurunath@gmail.com>
  • Loading branch information
Siva Guruvareddiar authored and sguruvar committed Jan 15, 2024
1 parent 68e52fe commit ebaa539
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
22 changes: 4 additions & 18 deletions pkg/scalers/aws_sigv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ import (

v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
"github.com/aws/aws-sdk-go-v2/service/amp"

awsutils "github.com/kedacore/keda/v2/pkg/scalers/aws"
httputils "github.com/kedacore/keda/v2/pkg/util"
)

// SigV4Config configures signing requests with SigV4.
type SigV4Config struct {
Enabled bool `yaml:"enabled,omitempty"`
Region string `yaml:"region,omitempty"`
}

type awsConfigMetadata struct {
awsRegion string
awsAuthorization awsutils.AuthorizationMetadata
Expand Down Expand Up @@ -51,7 +47,7 @@ func (rt *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
return nil, err
}
// Create default transport
transport := &http.Transport{}
transport := httputils.CreateHTTPTransport(false)

// Send signed request
return transport.RoundTrip(req)
Expand All @@ -60,12 +56,6 @@ func (rt *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
func parseAwsAMPMetadata(config *ScalerConfig) (*awsConfigMetadata, error) {
meta := awsConfigMetadata{}

if val, ok := config.TriggerMetadata["awsRegion"]; ok && val != "" {
meta.awsRegion = val
} else {
return nil, ErrAwsAMPNoAwsRegion
}

auth, err := awsutils.GetAwsAuthorization(config.TriggerUniqueKey, config.PodIdentity, config.TriggerMetadata, config.AuthParams, config.ResolvedEnv)
if err != nil {
return nil, err
Expand Down Expand Up @@ -97,14 +87,10 @@ func NewSigV4RoundTripper(config *ScalerConfig) (http.RoundTripper, error) {
return nil, fmt.Errorf("trigger metadata cannot be nil")
}

awsRegion := triggerMetadata["awsRegion"]
if awsRegion == "" {
return nil, fmt.Errorf("awsRegion not configured in trigger metadata")
}
client := amp.NewFromConfig(*awsCfg, func(o *amp.Options) {})
rt := &roundTripper{
client: client,
region: awsRegion,
region: metadata.awsRegion,
}

return rt, nil
Expand Down
7 changes: 2 additions & 5 deletions pkg/scalers/aws_sigv4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import (
"strings"
"testing"

"github.com/kedacore/keda/v2/pkg/util"
"github.com/stretchr/testify/require"

"github.com/kedacore/keda/v2/pkg/util"
)

func TestSigV4RoundTripper(t *testing.T) {
// rt := &roundTripper{
// client: amp.New(nil),
// region: "us-west-2",
// }

transport := util.CreateHTTPTransport(false)

Expand Down

0 comments on commit ebaa539

Please sign in to comment.