Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add s3hub mb subcommand #8

Merged
merged 5 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [](https://github.com/nao1215/rainbow/compare/77bdf974281a...) (2023-12-24)
## [](https://github.com/nao1215/rainbow/compare/77bdf974281a...) (2023-12-26)

* Add: document for developers [#7](https://github.com/nao1215/rainbow/pull/7) ([nao1215](https://github.com/nao1215))
* Introduce s3hub command interactive UI without logic [#6](https://github.com/nao1215/rainbow/pull/6) ([nao1215](https://github.com/nao1215))
* Add: s3hub subcommand entrypoint. all subcommnads are not implemented yet [#5](https://github.com/nao1215/rainbow/pull/5) ([nao1215](https://github.com/nao1215))
* Add: s3hub command readme [#4](https://github.com/nao1215/rainbow/pull/4) ([nao1215](https://github.com/nao1215))
* Add status badge and bump actions/setup-go from 4 to 5 [#3](https://github.com/nao1215/rainbow/pull/3) ([nao1215](https://github.com/nao1215))
* Introduce project template files [#1](https://github.com/nao1215/rainbow/pull/1) ([nao1215](https://github.com/nao1215))
16 changes: 16 additions & 0 deletions app/domain/model/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ func NewAWSConfig(ctx context.Context, profile AWSProfile, region Region) (*AWSC
if err != nil {
return nil, err
}

if cfg.BaseEndpoint != nil {
opts = append(opts, config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(func(service, region string, opts ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{
PartitionID: "aws",
URL: *cfg.BaseEndpoint,
HostnameImmutable: true,
}, nil
})))

cfg, err = config.LoadDefaultConfig(ctx, opts...)
if err != nil {
return nil, err
}
}

return &AWSConfig{
Config: &cfg,
}, nil
Expand Down
21 changes: 15 additions & 6 deletions app/external/s3.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Packgae external provides external dependencies.
// Packgae external implements the external service.
nao1215 marked this conversation as resolved.
Show resolved Hide resolved
package external

import (
"context"
"fmt"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
Expand Down Expand Up @@ -40,14 +41,22 @@ func NewS3BucketCreator(client *s3.Client) *S3BucketCreator {

// CreateBucket creates a new S3 bucket.
func (c *S3BucketCreator) CreateBucket(ctx context.Context, input *service.S3BucketCreatorInput) (*service.S3BucketCreatorOutput, error) {
// If region is us-east-1, you must not specify the location constraint.
// If you specify the location constraint in this case, the following error will occur.
// [api error InvalidLocationConstraint: The specified location-constraint is not valid]
locationContstraint := &types.CreateBucketConfiguration{
LocationConstraint: types.BucketLocationConstraint(input.Region.String()),
}
if input.Region == model.RegionUSEast1 {
locationContstraint = nil
}

_, err := c.client.CreateBucket(ctx, &s3.CreateBucketInput{
Bucket: aws.String(input.Bucket.String()),
CreateBucketConfiguration: &types.CreateBucketConfiguration{
LocationConstraint: types.BucketLocationConstraint(input.Region.String()),
},
Bucket: aws.String(input.Bucket.String()),
CreateBucketConfiguration: locationContstraint,
})
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: region=%s, bucket name=%s", err, input.Region.String(), input.Bucket.String())
}
return &service.S3BucketCreatorOutput{}, nil
}
44 changes: 44 additions & 0 deletions doc/common/developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,51 @@ aws_secret_access_key=test
> Alternatively, you can also set the AWS_PROFILE=localstack environment variable, in which case the --profile localstack parameter can be omitted in the commands above.

### Run localstack
Run the following command to start localstack:
```shell
make docker
```

Check the status of localstack:
```shell
curl -s "http://127.0.0.1:4566/health" | jq .
{
"services": {
"acm": "available",
"apigateway": "available",
"cloudformation": "available",
"cloudwatch": "available",
"config": "available",
"dynamodb": "available",
"dynamodbstreams": "available",
"ec2": "available",
"es": "available",
"events": "available",
"firehose": "available",
"iam": "available",
"kinesis": "available",
"kms": "available",
"lambda": "available",
"logs": "available",
"opensearch": "available",
"redshift": "available",
"resource-groups": "available",
"resourcegroupstaggingapi": "available",
"route53": "available",
"route53resolver": "available",
"s3": "available",
"s3control": "available",
"secretsmanager": "available",
"ses": "available",
"sns": "available",
"sqs": "available",
"ssm": "available",
"stepfunctions": "available",
"sts": "available",
"support": "available",
"swf": "available",
"transcribe": "available"
},
"version": "2.1.1.dev"
}
```