Skip to content

Commit

Permalink
Fixed: Writing to buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nils Lagerkvist committed Oct 20, 2016
1 parent 13b7c3f commit 6170ec1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,19 @@ func readAuthorizedKey(bucket, key string, authorizedKeys chan io.Reader) {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
info.Printf("Unable to convert authorized key to byte array: %v", err)
authorizedKeys <- bytes.NewReader([]byte{})
}
if !bytes.HasSuffix(body, []byte("\n")) {
body = append(body, []byte("\n")...)
}

if *authlog != "" {
outbuf := bytes.NewBufferString(fmt.Sprintf(logheader, *authlog, path.Base(key), bucket, key))
outbuf.Read(body)
_, err := outbuf.Write(body)
if err != nil {
info.Printf("Unable to write author key to buffer: %v", err)
authorizedKeys <- bytes.NewReader([]byte{})
}
authorizedKeys <- outbuf
return
}
Expand All @@ -212,7 +217,7 @@ func printAuthorizedKeys(bucket, authorizedKeysPath, user string) {
err := svc.ListObjectsPages(params, func(resp *s3.ListObjectsOutput, lastPage bool) (shouldContinue bool) {
for _, content := range resp.Contents {
// If it's a root key skip reading it
if *content.Key == authorizedKeysPath {
if *content.Key == authorizedKeysPath+"/" {
authorizedKeys <- bytes.NewReader([]byte{})
continue
}
Expand Down

0 comments on commit 6170ec1

Please sign in to comment.