Skip to content

Commit

Permalink
fix: only read one line from the github webhook secret file
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailswift committed Sep 13, 2024
1 parent 8e34fa2 commit 1a46d13
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions webhook/github/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package github

import (
"bufio"
"fmt"
"os"

Expand Down Expand Up @@ -53,12 +54,20 @@ func WithSecretFile(secretFilePath string) Option {
return nil
}

secret, err := os.ReadFile(secretFilePath)
file, err := os.Open(secretFilePath)
if err != nil {
return fmt.Errorf("could not open webhook secret file: %w", err)
}

defer file.Close()
scanner := bufio.NewScanner(file)
if !scanner.Scan() {
return fmt.Errorf("could not read webhook secret from file")
} else if err := scanner.Err(); err != nil {
return fmt.Errorf("could not read webhook secret from file: %w", err)
}

h.secret = secret
h.secret = []byte(scanner.Text())
return nil
}
}

0 comments on commit 1a46d13

Please sign in to comment.