Skip to content

Commit

Permalink
allowed to use
Browse files Browse the repository at this point in the history
  • Loading branch information
saqijaan committed Dec 24, 2024
1 parent a6759d4 commit cf4203d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ func NewS3(ctx context.Context, config config.Config, disk string) (*S3, error)
region := config.GetString(fmt.Sprintf("filesystems.disks.%s.region", disk))
bucket := config.GetString(fmt.Sprintf("filesystems.disks.%s.bucket", disk))
url := config.GetString(fmt.Sprintf("filesystems.disks.%s.url", disk))
token := config.GetString(fmt.Sprintf("filesystems.disks.%s.token", disk), "")
if accessKeyId == "" || accessKeySecret == "" || region == "" || bucket == "" || url == "" {
return nil, fmt.Errorf("please set %s configuration first", disk)
}

client := s3.New(s3.Options{
Region: region,
Credentials: aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider(accessKeyId, accessKeySecret, "")),
Credentials: aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider(accessKeyId, accessKeySecret, token)),
})

return &S3{
Expand Down Expand Up @@ -201,13 +202,11 @@ func (r *S3) Directories(path string) ([]string, error) {
}

func (r *S3) Exists(file string) bool {
o, err := r.instance.HeadObject(r.ctx, &s3.HeadObjectInput{
_, err := r.instance.HeadObject(r.ctx, &s3.HeadObjectInput{
Bucket: aws.String(r.bucket),
Key: aws.String(file),
})

log.Printf("output %v:", o)

if err != nil {
log.Println("error while checking file existance:", err)
return false
Expand Down

0 comments on commit cf4203d

Please sign in to comment.