From 3b2648bd5eb97fb5a0d6cc51a1cbe4d596f1c249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Szczygie=C5=82?= Date: Wed, 5 Jul 2017 16:19:25 +0200 Subject: [PATCH 1/2] iam instance profile --- src/restic/backend/s3/s3.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/restic/backend/s3/s3.go b/src/restic/backend/s3/s3.go index 2de495403..70535ecec 100644 --- a/src/restic/backend/s3/s3.go +++ b/src/restic/backend/s3/s3.go @@ -14,6 +14,7 @@ import ( "restic/errors" "github.com/minio/minio-go" + "github.com/minio/minio-go/pkg/credentials" "restic/debug" ) @@ -38,9 +39,24 @@ func open(cfg Config) (*Backend, error) { minio.MaxRetry = int(cfg.MaxRetries) } - client, err := minio.New(cfg.Endpoint, cfg.KeyID, cfg.Secret, !cfg.UseHTTP) - if err != nil { - return nil, errors.Wrap(err, "minio.New") + var client *minio.Client + var err error + + if cfg.KeyID == "" || cfg.Secret == "" { + debug.Log("iam") + creds := credentials.NewIAM("") + client, err = minio.NewWithCredentials(cfg.Endpoint, creds, !cfg.UseHTTP, "") + + if err != nil { + return nil, errors.Wrap(err, "minio.NewWithCredentials") + } + } else { + debug.Log("key, secret") + client, err = minio.New(cfg.Endpoint, cfg.KeyID, cfg.Secret, !cfg.UseHTTP) + + if err != nil { + return nil, errors.Wrap(err, "minio.New") + } } sem, err := backend.NewSemaphore(cfg.Connections) From d651d9b427a88d2661f8dfc31a6a93b0b34f33fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Szczygie=C5=82?= Date: Wed, 5 Jul 2017 19:21:57 +0200 Subject: [PATCH 2/2] more verbose debug --- src/restic/backend/s3/s3.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/restic/backend/s3/s3.go b/src/restic/backend/s3/s3.go index 70535ecec..3dc8aef9f 100644 --- a/src/restic/backend/s3/s3.go +++ b/src/restic/backend/s3/s3.go @@ -43,7 +43,7 @@ func open(cfg Config) (*Backend, error) { var err error if cfg.KeyID == "" || cfg.Secret == "" { - debug.Log("iam") + debug.Log("key/secret not found, trying to get them from IAM") creds := credentials.NewIAM("") client, err = minio.NewWithCredentials(cfg.Endpoint, creds, !cfg.UseHTTP, "") @@ -51,7 +51,7 @@ func open(cfg Config) (*Backend, error) { return nil, errors.Wrap(err, "minio.NewWithCredentials") } } else { - debug.Log("key, secret") + debug.Log("key/secret found") client, err = minio.New(cfg.Endpoint, cfg.KeyID, cfg.Secret, !cfg.UseHTTP) if err != nil {