Skip to content

Commit

Permalink
allow custom s3 endpoint (#4084)
Browse files Browse the repository at this point in the history
  • Loading branch information
humandad authored Jul 23, 2024
1 parent b083633 commit 6652885
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions apps/platform/pkg/configstore/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var configValues = map[string]string{
"uesio/core.platform_filesource_credentials": GetEnvWithDefault("UESIO_PLATFORM_FILESOURCE_CREDENTIALS", "uesio/core.aws"),
"uesio/core.platform_bundlestore_credentials": GetEnvWithDefault("UESIO_PLATFORM_BUNDLESTORE_CREDENTIALS", "uesio/core.aws"),
"uesio/core.aws_region": os.Getenv("AWS_REGION"),
"uesio/core.aws_endpoint": os.Getenv("AWS_ENDPOINT"),
"uesio/aikit.aws_region": os.Getenv("AWS_REGION"),
"uesio/core.userfiles_bucket_name": GetEnvWithDefault("UESIO_USERFILES_BUCKET_NAME", "uesio-userfiles"),
"uesio/core.db_host": GetRequiredEnv("UESIO_DB_HOST"),
Expand Down
12 changes: 9 additions & 3 deletions apps/platform/pkg/creds/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import (
"github.com/thecloudmasters/uesio/pkg/types/wire"
)

func getConfig(ctx context.Context, region, accessKeyID, secretAccessKey, sessionToken string) (aws.Config, error) {
func getConfig(ctx context.Context, region, endpoint, accessKeyID, secretAccessKey, sessionToken string) (aws.Config, error) {
if accessKeyID != "" && secretAccessKey != "" {
return config.LoadDefaultConfig(ctx, config.WithRegion(region), config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKeyID, secretAccessKey, sessionToken)))
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(region), config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKeyID, secretAccessKey, sessionToken)))
if endpoint != "" {
cfg.BaseEndpoint = aws.String(endpoint)
}
return cfg, err
}

return config.LoadDefaultConfig(ctx, config.WithRegion(region))
}

Expand All @@ -24,10 +29,11 @@ func GetAWSConfig(ctx context.Context, dbcreds *wire.Credentials) (aws.Config, e
return aws.Config{}, errors.New("No region provided in credentials")
}

endpoint := (*dbcreds)["endpoint"]
accessKeyID := (*dbcreds)["accessKeyId"]
secretAccessKey := (*dbcreds)["secretAccessKey"]
sessionToken := (*dbcreds)["sessionToken"]

return getConfig(ctx, region, accessKeyID, secretAccessKey, sessionToken)
return getConfig(ctx, region, endpoint, accessKeyID, secretAccessKey, sessionToken)

}
6 changes: 6 additions & 0 deletions apps/platform/pkg/types/credentials/aws_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type AwsKeyCredentials struct {
SecretAccessKey string `yaml:"secretAccessKey" json:"secret_access_key"`
SessionToken string `yaml:"sessionToken" json:"session_token"`
Region string `yaml:"region" json:"region"`
Endpoint string `yaml:"endpoint" json:"endpoint"`
}

func (c *AwsKeyCredentials) IsNil() bool {
Expand Down Expand Up @@ -33,4 +34,9 @@ func (c *AwsKeyCredentials) Map(mapper EntryMapper) {
Type: "configvalue",
Value: c.Region,
})
c.Endpoint = mapper(&CredentialEntry{
Name: "endpoint",
Type: "configvalue",
Value: c.Endpoint,
})
}
3 changes: 3 additions & 0 deletions libs/apps/uesio/core/bundle/configvalues/aws_endpoint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: aws_endpoint
managedBy: app
store: environment
1 change: 1 addition & 0 deletions libs/apps/uesio/core/bundle/credentials/aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: aws
type: AWS_KEY
awsKey:
region: uesio/core.aws_region
endpoint: uesio/core.aws_endpoint
accessKeyId: uesio/core.aws_access_key_id
secretAccessKey: uesio/core.aws_secret_access_key
sessionToken: uesio/core.aws_session_token

0 comments on commit 6652885

Please sign in to comment.