Skip to content

Commit

Permalink
fix: stop using WithEndpointResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed Oct 13, 2024
1 parent ae843ec commit fd5e942
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
9 changes: 3 additions & 6 deletions internal/config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ func (s *ServerConfig) CreateGitHubClient() *github.Client {
return github.NewClient(oauthClient)
}

func (s *ServerConfig) r2CloudflareEndpointResolver(_, _ string, _ ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{
URL: fmt.Sprintf("https://%s.r2.cloudflarestorage.com", s.CloudflareAccountID),
}, nil
func (s *ServerConfig) r2CloudflareBaseEndpoint(o *s3.Options) {
o.BaseEndpoint = aws.String(fmt.Sprintf("https://%s.r2.cloudflarestorage.com", s.CloudflareAccountID))
}

func (s *ServerConfig) CreateS3Client() (*s3.Client, error) {
Expand All @@ -62,14 +60,13 @@ func (s *ServerConfig) CreateS3Client() (*s3.Client, error) {
"",
)
s3Cfg, err := awsConfig.LoadDefaultConfig(context.TODO(),
awsConfig.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(s.r2CloudflareEndpointResolver)),
awsConfig.WithCredentialsProvider(staticCredentialsProvider),
awsConfig.WithRegion("auto"),
)
if err != nil {
return nil, err
}
return s3.NewFromConfig(s3Cfg), nil
return s3.NewFromConfig(s3Cfg, s.r2CloudflareBaseEndpoint), nil
}

func (s *ServerConfig) GetBucket() *string {
Expand Down
10 changes: 3 additions & 7 deletions internal/server/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,13 @@ func createS3Client(t *testing.T) (*s3.Client, func()) {
w.WriteHeader(http.StatusOK)
}))
s3Cfg, err := awsConfig.LoadDefaultConfig(context.TODO(),
awsConfig.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(func(_, _ string, _ ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{
URL: ts.URL,
HostnameImmutable: true,
}, nil
})),
awsConfig.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("test", "test", "")),
awsConfig.WithRegion("auto"),
)
require.NoError(t, err)
return s3.NewFromConfig(s3Cfg), ts.Close
return s3.NewFromConfig(s3Cfg, func(o *s3.Options) {
o.BaseEndpoint = aws.String(ts.URL)
}), ts.Close
}

func newTestServer(t *testing.T) (*Server, *firestore.Client, func()) {
Expand Down

0 comments on commit fd5e942

Please sign in to comment.