Skip to content

Commit

Permalink
chore: remove non printable chars from gh token.
Browse files Browse the repository at this point in the history
See falcosecurity/peribolos-syncer#17.

Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP authored and poiana committed May 6, 2024
1 parent c5f9e21 commit dd00d10
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/1Password/connect-sdk-go v1.5.3
github.com/google/go-github/v50 v50.2.0
github.com/jamesruan/sodium v1.0.14
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.2
gopkg.in/yaml.v3 v3.0.1
Expand All @@ -18,7 +19,6 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
Expand Down
27 changes: 24 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ package main
import (
"context"
"flag"
"github.com/pkg/errors"
"os"
"strings"
"unicode"

"github.com/falcosecurity/pigeon/pkg/pigeon"
"github.com/google/go-github/v50/github"
Expand All @@ -41,6 +43,26 @@ func init() {
flag.BoolVar(&verbose, "verbose", false, "enable verbose logging")
}

func getTokenFromFile(path string) (string, error) {
token, err := os.ReadFile(path)
if err != nil {
return "", errors.Wrap(err, "error reading token file")
}

return removeNonPrintableChars(string(token)), nil
}

func removeNonPrintableChars(s string) string {
return strings.Map(func(r rune) rune {
switch {
case unicode.IsPrint(r):
return r
default:
return -1
}
}, s)
}

func initOpts() {
flag.Parse()

Expand All @@ -55,12 +77,11 @@ func initOpts() {
logrus.Fatal(`Github token must be provided either through "gh-token" flag, or "GITHUB_AUTH_TOKEN" env."`)
}
}
ghTokBytes, err := os.ReadFile(ghToken)
var err error
ghToken, err = getTokenFromFile(ghToken)
if err != nil {
logrus.Fatal(err)
}
ghToken = string(ghTokBytes)
ghToken = strings.Trim(ghToken, "\n")

if confFile == "" {
logrus.Fatal(`"conf" flag must be set`)
Expand Down

0 comments on commit dd00d10

Please sign in to comment.