Skip to content

Commit

Permalink
Merge pull request #24 from ConradKurth/aws-credentials
Browse files Browse the repository at this point in the history
Use AWS sdk to parse credentials
  • Loading branch information
hypnoglow authored Jan 9, 2018
2 parents 649ecb7 + 2d940df commit 40c3ccf
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 200 deletions.
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
name = "github.com/aws/aws-sdk-go"
version = "1.12.1"

[[constraint]]
name = "github.com/go-ini/ini"
version = "1.28.2"

[[constraint]]
name = "github.com/pkg/errors"
version = "0.8.0"
Expand Down
8 changes: 1 addition & 7 deletions cmd/helms3/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/pkg/errors"

"github.com/hypnoglow/helm-s3/pkg/awss3"
"github.com/hypnoglow/helm-s3/pkg/awsutil"
"github.com/hypnoglow/helm-s3/pkg/helmutil"
"github.com/hypnoglow/helm-s3/pkg/index"
)
Expand All @@ -18,12 +17,7 @@ func runDelete(name, version, repoName string) error {
return err
}

awsConfig, err := awsutil.Config()
if err != nil {
return errors.Wrap(err, "get aws config")
}

storage := awss3.NewStorage(awsConfig)
storage := awss3.New()

// Fetch current index.

Expand Down
8 changes: 1 addition & 7 deletions cmd/helms3/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/pkg/errors"

"github.com/hypnoglow/helm-s3/pkg/awss3"
"github.com/hypnoglow/helm-s3/pkg/awsutil"
"github.com/hypnoglow/helm-s3/pkg/index"
)

Expand All @@ -16,12 +15,7 @@ func runInit(uri string) error {
return errors.WithMessage(err, "get index reader")
}

awsConfig, err := awsutil.Config()
if err != nil {
return errors.WithMessage(err, "get aws config")
}

storage := awss3.NewStorage(awsConfig)
storage := awss3.New()

ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()
Expand Down
7 changes: 1 addition & 6 deletions cmd/helms3/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ import (
"github.com/pkg/errors"

"github.com/hypnoglow/helm-s3/pkg/awss3"
"github.com/hypnoglow/helm-s3/pkg/awsutil"
)

func runProxy(uri string) error {
awsConfig, err := awsutil.Config()
if err != nil {
return errors.WithMessage(err, "get aws config")
}

storage := awss3.NewStorage(awsConfig)
storage := awss3.New()

ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()
Expand Down
8 changes: 1 addition & 7 deletions cmd/helms3/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"k8s.io/helm/pkg/provenance"

"github.com/hypnoglow/helm-s3/pkg/awss3"
"github.com/hypnoglow/helm-s3/pkg/awsutil"
"github.com/hypnoglow/helm-s3/pkg/helmutil"
"github.com/hypnoglow/helm-s3/pkg/index"
)
Expand All @@ -38,12 +37,7 @@ func runPush(chartPath string, repoName string) error {
return errors.Wrapf(err, "change dir to %s", dir)
}

awsConfig, err := awsutil.Config()
if err != nil {
return errors.Wrap(err, "get aws config")
}

storage := awss3.NewStorage(awsConfig)
storage := awss3.New()

// Load chart, calculate required params like hash,
// and upload the chart right away.
Expand Down
13 changes: 6 additions & 7 deletions pkg/awss3/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ import (
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/pkg/errors"

"github.com/hypnoglow/helm-s3/pkg/awsutil"
)

// NewStorage returns a new Storage.
func NewStorage(awsConfig *aws.Config) *Storage {
return &Storage{
config: awsConfig,
}
// New returns a new Storage.
func New() *Storage {
return &Storage{}
}

// Storage provides an interface to work with AWS S3 objects by s3 protocol.
type Storage struct {
config *aws.Config
session *session.Session
}

Expand Down Expand Up @@ -111,7 +110,7 @@ func (s *Storage) initSession() (err error) {
return nil
}

s.session, err = session.NewSession(s.config)
s.session, err = awsutil.Session()
return errors.Wrap(err, "init aws session")
}

Expand Down
58 changes: 0 additions & 58 deletions pkg/awsutil/config.go

This file was deleted.

28 changes: 28 additions & 0 deletions pkg/awsutil/session.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package awsutil

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session"
)

var (
// awsDisableSSL can be set to true by build tag.
awsDisableSSL = "false"

// awsEndpoint can be set to a custom endpoint by build tag.
awsEndpoint = ""
)

// Session returns an AWS session as described http://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html
func Session() (*session.Session, error) {
return session.NewSessionWithOptions(session.Options{
Config: aws.Config{
DisableSSL: aws.Bool(awsDisableSSL == "true"),
S3ForcePathStyle: aws.Bool(true),
Endpoint: aws.String(awsEndpoint),
},
SharedConfigState: session.SharedConfigEnable,
AssumeRoleTokenProvider: stscreds.StdinTokenProvider,
})
}
46 changes: 0 additions & 46 deletions pkg/dotaws/config.go

This file was deleted.

55 changes: 0 additions & 55 deletions pkg/dotaws/credentials.go

This file was deleted.

0 comments on commit 40c3ccf

Please sign in to comment.