Skip to content

Commit

Permalink
Use ReadAuthSettings instead
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltanbedi committed Oct 17, 2024
1 parent 7cf9949 commit 2a317c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
6 changes: 1 addition & 5 deletions pkg/infinity/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ func NewClient(ctx context.Context, settings models.InfinitySettings) (client *C
httpClient = ApplyDigestAuth(ctx, httpClient, settings)
httpClient = ApplyOAuthClientCredentials(ctx, httpClient, settings)
httpClient = ApplyOAuthJWT(ctx, httpClient, settings)
httpClient, err = ApplyAWSAuth(ctx, httpClient, settings)
if err != nil {
logger.Error("error applying aws auth", "datasource uid", settings.UID, "datasource name", settings.Name)
return client, err
}
httpClient = ApplyAWSAuth(ctx, httpClient, settings)

httpClient, err = ApplySecureSocksProxyConfiguration(ctx, httpClient, settings)
if err != nil {
Expand Down
10 changes: 3 additions & 7 deletions pkg/infinity/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package infinity

import (
"context"
"errors"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -89,7 +88,7 @@ func ApplyDigestAuth(ctx context.Context, httpClient *http.Client, settings mode
func IsDigestAuthConfigured(settings models.InfinitySettings) bool {
return settings.AuthenticationMethod == models.AuthenticationMethodDigestAuth
}
func ApplyAWSAuth(ctx context.Context, httpClient *http.Client, settings models.InfinitySettings) (*http.Client, error) {
func ApplyAWSAuth(ctx context.Context, httpClient *http.Client, settings models.InfinitySettings) *http.Client {
ctx, span := tracing.DefaultTracer().Start(ctx, "ApplyAWSAuth")
defer span.End()
if IsAwsAuthConfigured(settings) {
Expand All @@ -113,18 +112,15 @@ func ApplyAWSAuth(ctx context.Context, httpClient *http.Client, settings models.
AccessKey: settings.AWSAccessKey,
SecretKey: settings.AWSSecretKey,
}
authSettings, found := awsds.ReadAuthSettingsFromContext(ctx)
if !found {
return nil, errors.New("AWS auth settings not found in context")
}

authSettings := awsds.ReadAuthSettings(ctx)
rt, _ := sigv4.New(conf, *authSettings, sigv4.RoundTripperFunc(func(req *http.Request) (*http.Response, error) {
req.Header.Add("Accept", "application/json")
return tempHttpClient.Do(req)
}))
httpClient.Transport = rt
}
return httpClient, nil
return httpClient
}

func IsAwsAuthConfigured(settings models.InfinitySettings) bool {
Expand Down

0 comments on commit 2a317c6

Please sign in to comment.