@@ -12,8 +12,9 @@ import (
1212
1313// Client represents interaction with AWS S3
1414type Client interface {
15- Get (bucket , key string ) ([]byte , error )
16- BucketExists (bucket string ) (bool , error )
15+ Bucket () (string )
16+ Get (key string ) ([]byte , error )
17+ BucketExists () (bool , error )
1718}
1819
1920// Agent represents interaction with an ssh-agent process
@@ -56,12 +57,12 @@ type Config struct {
5657// functionality; secrets are downloaded from S3, and loaded into ssh-agent
5758// etc.
5859func Run (conf Config ) error {
59- bucket := conf .Bucket
60+ bucket := conf .Client . Bucket ()
6061 log := conf .Logger
6162
6263 log .Printf ("~~~ Downloading secrets from :s3: %s" , bucket )
6364
64- if ok , err := conf .Client .BucketExists (bucket ); ! ok {
65+ if ok , err := conf .Client .BucketExists (); ! ok {
6566 if err != nil {
6667 log .Printf ("+++ :warning: Bucket %q not found: %v" , bucket , err )
6768 } else {
@@ -102,7 +103,7 @@ func getSSHKeys(conf Config, results chan<- getResult) {
102103 for _ , k := range keys {
103104 conf .Logger .Printf ("- %s" , k )
104105 }
105- go GetAll (conf .Client , conf .Bucket , keys , results )
106+ go GetAll (conf .Client , conf .Client . Bucket () , keys , results )
106107}
107108
108109func getEnvs (conf Config , results chan <- getResult ) {
@@ -116,7 +117,7 @@ func getEnvs(conf Config, results chan<- getResult) {
116117 for _ , k := range keys {
117118 conf .Logger .Printf ("- %s" , k )
118119 }
119- go GetAll (conf .Client , conf .Bucket , keys , results )
120+ go GetAll (conf .Client , conf .Client . Bucket () , keys , results )
120121}
121122
122123func getGitCredentials (conf Config , results chan <- getResult ) {
@@ -128,7 +129,7 @@ func getGitCredentials(conf Config, results chan<- getResult) {
128129 for _ , k := range keys {
129130 conf .Logger .Printf ("- %s" , k )
130131 }
131- go GetAll (conf .Client , conf .Bucket , keys , results )
132+ go GetAll (conf .Client , conf .Client . Bucket () , keys , results )
132133}
133134
134135func handleSSHKeys (conf Config , results <- chan getResult ) error {
@@ -241,7 +242,7 @@ func GetAll(c Client, bucket string, keys []string, results chan<- getResult) {
241242 // goroutine immediately fetches from S3, then waits for its turn to send
242243 // to the results channel; concurrent fetch, ordered results.
243244 go func (k string , link <- chan chan <- getResult , nextLink chan <- chan <- getResult ) {
244- data , err := c .Get (bucket , k )
245+ data , err := c .Get (k )
245246 results := <- link // wait for results channel from previous goroutine
246247 results <- getResult {bucket : bucket , key : k , data : data , err : err }
247248 nextLink <- results // send results channel to the next goroutine
0 commit comments