Merge pull request #1648 from duzvik/s3-bucketexists

Ignore s3 AccessDenied error, during creation of repository
This commit is contained in:
Alexander Neumann 2018-03-02 22:38:33 +01:00
commit 58306bfabb
2 changed files with 23 additions and 0 deletions

View file

@ -0,0 +1,6 @@
Enhancement: Ignore AWS permission denied error when creating a repository.
It's not possible to use s3 backend scoped to a subdirectory(with specific permissions).
Restic doesn't try to create repository in a subdirectory, when 'bucket exists' of parent directory check fails due to permission issues.
https://github.com/restic/restic/pull/1648

View file

@ -104,6 +104,12 @@ func Create(cfg Config, rt http.RoundTripper) (restic.Backend, error) {
return nil, errors.Wrap(err, "open") return nil, errors.Wrap(err, "open")
} }
found, err := be.client.BucketExists(cfg.Bucket) found, err := be.client.BucketExists(cfg.Bucket)
if err != nil && be.IsAccessDenied(err) {
err = nil
found = true
}
if err != nil { if err != nil {
debug.Log("BucketExists(%v) returned err %v", cfg.Bucket, err) debug.Log("BucketExists(%v) returned err %v", cfg.Bucket, err)
return nil, errors.Wrap(err, "client.BucketExists") return nil, errors.Wrap(err, "client.BucketExists")
@ -120,6 +126,17 @@ func Create(cfg Config, rt http.RoundTripper) (restic.Backend, error) {
return be, nil return be, nil
} }
// IsAccessDenied returns true if the error is caused by Access Denied.
func (be *Backend) IsAccessDenied(err error) bool {
debug.Log("IsAccessDenied(%T, %#v)", err, err)
if e, ok := errors.Cause(err).(minio.ErrorResponse); ok && e.Code == "AccessDenied" {
return true
}
return false
}
// IsNotExist returns true if the error is caused by a not existing file. // IsNotExist returns true if the error is caused by a not existing file.
func (be *Backend) IsNotExist(err error) bool { func (be *Backend) IsNotExist(err error) bool {
debug.Log("IsNotExist(%T, %#v)", err, err) debug.Log("IsNotExist(%T, %#v)", err, err)