Allow sessions without credentials
kr4ster opened this issue · 3 comments
Greetings! We are using IAM to manage connections to AWS resources. I've made a small change to this project which allows connections without credentials, but am not sure what the preferred method of submitting changes. Here's the patch:
diff --git a/config.go b/config.go
index 4b85d0d..968368f 100644
--- a/config.go
+++ b/config.go
@@ -110,11 +110,15 @@ func (r retryer) MaxRetries() int {
// newSession creates a new aws session
func newSession(c Config) (*session.Session, error) {
- //sets credentials
- creds := credentials.NewStaticCredentials(c.Key, c.Secret, "")
- _, err := creds.Get()
- if err != nil {
- return nil, ErrInvalidCreds.Context(err)
+ var creds *credentials.Credentials
+
+ // If Key/Secret are supplied, create static credentials
+ if c.Key != "" && c.Secret != "" {
+ creds = credentials.NewStaticCredentials(c.Key, c.Secret, "")
+ _, err := creds.Get()
+ if err != nil {
+ return nil, ErrInvalidCreds.Context(err)
+ }
}
r := &retryer{retryCount: c.RetryCount}
If you would like me to submit a PR, please let me know!
Thanks,
Bobby
@kr4ster this is a great improvement. I am pleased to hear you are enjoying the package and made it useful to you. Please make a PR and I will be happy to review and merge It
Instead of the above diff, I submitted a PR that solves the same problem by allowing callers to set a "SessionProvider" function in the config.
This way the caller can implement complex session setup if needed.
If a SessionProvider is not set, it will use newSession as the default.
See PR #8