Skip to content

Commit

Permalink
fix: read and pass NetApp key
Browse files Browse the repository at this point in the history
  • Loading branch information
Artonus committed Feb 27, 2024
1 parent e1d9c03 commit 9aa6161
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ FETCH_DIR=./fetch
POST_DIR=./post
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=
AWS_REGION=
NETAPP_KEY=
5 changes: 3 additions & 2 deletions cmd/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ var fetchCmd = &cobra.Command{
region := os.Getenv("AWS_REGION")
bucket := os.Getenv("AWS_BUCKET")
fetchDir := os.Getenv("FETCH_DIR")
cfg := config.NewConfig(accessKey, secretKey, config.WithFetchDir(fetchDir), config.WithBucket(bucket), config.WithRegion(region))
key := os.Getenv("NETAPP_KEY")
cfg := config.NewConfig(accessKey, secretKey, config.WithFetchDir(fetchDir), config.WithBucket(bucket), config.WithRegion(region), config.WithKey(key))

fetchClient, err := cmdutil.CreateFetchClient(cfg)
if err != nil {
panic(err)
}

err = fetchClient.Fetch("", fetchDir)
err = fetchClient.Fetch(cfg.Key, fetchDir)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ var postCmd = &cobra.Command{
region := os.Getenv("AWS_REGION")
bucket := os.Getenv("AWS_BUCKET")
postDir := os.Getenv("POST_DIR")
cfg := config.NewConfig(accessKey, secretKey, config.WithPostDir(postDir), config.WithBucket(bucket), config.WithRegion(region))
key := os.Getenv("NETAPP_KEY")
cfg := config.NewConfig(accessKey, secretKey, config.WithPostDir(postDir), config.WithBucket(bucket), config.WithRegion(region), config.WithKey(key))

postClient, err := cmdutil.CreatePostClient(cfg)
if err != nil {
Expand All @@ -39,7 +40,7 @@ var postCmd = &cobra.Command{
// Notify the channel when a SIGTERM signal is received
fmt.Printf("Received signal: %v\n", sigReceived)
// Upload the data to S3
err = postClient.Post("", postDir)
err = postClient.Post(cfg.Key, postDir)
if err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type HermesConfig struct {
AwsBucket string
FetchDir string
PostDir string
Key string
}

type HermesOption func(*HermesConfig)
Expand All @@ -32,6 +33,11 @@ func WithPostDir(postDir string) HermesOption {
c.PostDir = postDir
}
}
func WithKey(key string) HermesOption {
return func(c *HermesConfig) {
c.Key = key
}
}

func NewConfig(awsAccessKeyId, awsAccessSecretKey string, opts ...HermesOption) *HermesConfig {
if awsAccessKeyId == "" || awsAccessSecretKey == "" {
Expand Down

0 comments on commit 9aa6161

Please sign in to comment.