Skip to content

Commit

Permalink
added s3 options
Browse files Browse the repository at this point in the history
  • Loading branch information
verzcar committed Oct 15, 2023
1 parent 2ab0eea commit c16cbe8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 26 deletions.
19 changes: 15 additions & 4 deletions options.go → auth_options.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
package awsx

type AuthOption func(bd *AuthRequestConfig)

func applyAuthOptions(options []AuthOption) *AuthRequestConfig {
req := &AuthRequestConfig{}

for _, option := range options {
option(req)
}
return req
}

// UserPoolId sets the userPoolId
func UserPoolId(id string) Option {
func UserPoolId(id string) AuthOption {
return func(req *AuthRequestConfig) {
req.userPoolID = id
}
}

// AppClientId sets the client id
func AppClientId(appClientID string) Option {
func AppClientId(appClientID string) AuthOption {
return func(req *AuthRequestConfig) {
req.appClientID = appClientID
}
}

// ClientSecret sets the client secret
func ClientSecret(clientSecret string) Option {
func ClientSecret(clientSecret string) AuthOption {
return func(req *AuthRequestConfig) {
req.clientSecret = clientSecret
}
}

// AwsDefaultRegion sets the region for aws
func AwsDefaultRegion(awsDefaultRegion string) Option {
func AwsDefaultRegion(awsDefaultRegion string) AuthOption {
return func(req *AuthRequestConfig) {
req.awsDefaultRegion = awsDefaultRegion
}
Expand Down
11 changes: 0 additions & 11 deletions aws_auth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ var formattedCognitoURL string

const publicKeyRefreshIntervall = 2880 // minutes = 2 days

type AuthOption func(bd *AuthRequestConfig)

// NewAuthService creates a new auth authService.
// The options for the app client id and user pool id needs to be set.
// If additional options are given
Expand Down Expand Up @@ -156,12 +154,3 @@ func (s *authService) applyOptions(options []AuthOption) *AuthRequestConfig {
}
return req
}

func applyAuthOptions(options []AuthOption) *AuthRequestConfig {
req := &AuthRequestConfig{}

for _, option := range options {
option(req)
}
return req
}
11 changes: 0 additions & 11 deletions aws_s3_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ type s3Service struct {
opts []S3Option
}

type S3Option func(bd *S3RequestConfig)

// NewS3Service creates a new s3 service.
// If additional options are given
// this options will be used for the upcoming requests to the aws client.
Expand Down Expand Up @@ -92,12 +90,3 @@ func (s *s3Service) applyOptions(options []S3Option) *S3RequestConfig {
}
return req
}

func applyS3Options(options []S3Option) *S3RequestConfig {
req := &S3RequestConfig{}

for _, option := range options {
option(req)
}
return req
}
48 changes: 48 additions & 0 deletions s3_options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package awsx

type S3Option func(bd *S3RequestConfig)

func applyS3Options(options []S3Option) *S3RequestConfig {
req := &S3RequestConfig{}

for _, option := range options {
option(req)
}
return req
}

func AccessKeyID(id string) S3Option {
return func(req *S3RequestConfig) {
req.accessKeyID = id
}
}

func AccessKeySecret(secret string) S3Option {
return func(req *S3RequestConfig) {
req.accessKeySecret = secret
}
}

func Region(region string) S3Option {
return func(req *S3RequestConfig) {
req.region = region
}
}

func DefaultBucketName(name string) S3Option {
return func(req *S3RequestConfig) {
req.defaultBucketName = name
}
}

func UploadTimeout(timeout int) S3Option {
return func(req *S3RequestConfig) {
req.uploadTimeout = timeout
}
}

func DefaultBaseURL(url string) S3Option {
return func(req *S3RequestConfig) {
req.defaultBaseURL = url
}
}

0 comments on commit c16cbe8

Please sign in to comment.