Skip to content

Commit

Permalink
fixing ci file and refactoring create bucket pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarsilva948 committed Sep 4, 2023
1 parent e53b7e5 commit 45a1cf3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 85 deletions.
File renamed without changes.
88 changes: 3 additions & 85 deletions pkg/aws/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ package aws
import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)

Expand All @@ -36,87 +34,7 @@ func BucketExists(client S3Client, bucketName string) (bool, error) {
return false, nil
}

// CreateS3Bucket creates a new S3 bucket with the given name.
func CreateS3Bucket(bucketName string, kmsKeyID string, region string) error {
// new aws session
sess, err := session.NewSession(&aws.Config{
Region: aws.String(region),
})

if err != nil {
return err
}

svc := s3.New(sess)

_, err = svc.CreateBucket(&s3.CreateBucketInput{
Bucket: aws.String(bucketName),
})

if err != nil {
return err
}

// Ativar o versionamento
// _, err = svc.PutBucketVersioning(&s3.PutBucketVersioningInput{
// Bucket: aws.String(bucketName),
// VersioningConfiguration: &s3.VersioningConfiguration{
// Status: aws.String("Enabled"),
// },
// })

if err != nil {
return err
}

// Bloqueio de acesso público
_, err = svc.PutPublicAccessBlock(&s3.PutPublicAccessBlockInput{
Bucket: aws.String(bucketName),
PublicAccessBlockConfiguration: &s3.PublicAccessBlockConfiguration{
BlockPublicAcls: aws.Bool(true),
BlockPublicPolicy: aws.Bool(true),
},
})

if err != nil {
return err
}

// Configuração do ciclo de vida
// _, err = svc.PutBucketLifecycleConfiguration(&s3.PutBucketLifecycleConfigurationInput{
// Bucket: aws.String(bucketName),
// LifecycleConfiguration: &s3.BucketLifecycleConfiguration{
// Rules: []*s3.LifecycleRule{
// {
// Status: aws.String("Enabled"),
// // Adicione suas regras aqui
// },
// },
// },
// })

if err != nil {
return err
}

// Criptografia KMS
_, err = svc.PutBucketEncryption(&s3.PutBucketEncryptionInput{
Bucket: aws.String(bucketName),
ServerSideEncryptionConfiguration: &s3.ServerSideEncryptionConfiguration{
Rules: []*s3.ServerSideEncryptionRule{
{
ApplyServerSideEncryptionByDefault: &s3.ServerSideEncryptionByDefault{
KMSMasterKeyID: aws.String(kmsKeyID),
SSEAlgorithm: aws.String("aws:kms"),
},
},
},
},
})

if err != nil {
return err
}

return nil
// EnsureS3BucketExists creates a new S3 bucket with the given name, or returns success if it already exists.
func EnsureS3BucketExists(client S3Client, bucketName string, kmsKeyID string) (bool, error) {
return true, nil
}

0 comments on commit 45a1cf3

Please sign in to comment.