Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "credential" parameter for the minio AK/SK setting #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
FlagScratch bool
FlagDefaultFileMode = "0664"
FlagS3Endpoint = ""
FlagS3Credential = ""
FlagDisableSSL = false
FlagPullInterval = time.Second * 5

Expand Down Expand Up @@ -107,6 +108,7 @@ func main() {
}
puller.DisableSSL = FlagDisableSSL
puller.S3Endpoint = FlagS3Endpoint
puller.Credential = FlagS3Credential
if FlagExclude != nil {
puller.AddExcludePatterns(FlagExclude)
}
Expand Down Expand Up @@ -179,7 +181,10 @@ func main() {
pullCmd.PersistentFlags().StringVarP(
&FlagS3Endpoint, "s3-endpoint", "", "", "override endpoint to use for remote object store (e.g. minio)")
pullCmd.PersistentFlags().DurationVarP(
&FlagPullInterval, "interval", "i", time.Second * 5, "Interval between remote storage pulls")
&FlagPullInterval, "interval", "i", time.Second*5, "Interval between remote storage pulls")

pullCmd.PersistentFlags().StringVarP(
&FlagS3Credential, "credential", "", "", "ACCESSKEYID/SECRETACCESSKEY for minio server, parameter format like: ak,sk. which use comma separated")

rootCmd.AddCommand(pullCmd)
rootCmd.Execute()
Expand Down
8 changes: 8 additions & 0 deletions pkg/sync/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
Expand Down Expand Up @@ -103,6 +104,7 @@ type Puller struct {
LocalDir string
DisableSSL bool
S3Endpoint string
Credential string

workingDir string
defaultMode os.FileMode
Expand Down Expand Up @@ -318,6 +320,12 @@ func (self *Puller) Pull() string {
s3Config.Endpoint = aws.String(self.S3Endpoint)
s3Config.S3ForcePathStyle = aws.Bool(true)
}
if self.Credential != "" {
var keys = strings.Split(self.Credential, ",")
s3Config.Credentials = credentials.NewStaticCredentials(keys[0], keys[1], "")
l.Infow("Set the credentials", "AK=", keys[0], "SK=", keys[1])
}

svc := s3.New(sess, s3Config)

downloader := s3manager.NewDownloaderWithClient(svc)
Expand Down