From 45549dc92bce846ab03e991e6f26ea00e17f4677 Mon Sep 17 00:00:00 2001 From: Jef LeCompte Date: Sun, 13 Jun 2021 12:56:03 -0400 Subject: [PATCH] feat: use pflag, remove docker, update ci (#83) --- .github/workflows/ci.yaml | 9 +- .github/workflows/nightly-release.yaml | 23 ----- .github/workflows/release.yaml | 69 ++++++++++---- .gitignore | 2 +- Dockerfile | 26 ----- Makefile | 41 ++++++++ README.md | 75 ++++----------- main.go => cmd/audit_org_keys/main.go | 127 ++++++++++++------------- config.go | 22 ----- go.mod | 3 +- go.sum | 70 +++++--------- logger.go | 40 -------- 12 files changed, 201 insertions(+), 306 deletions(-) delete mode 100644 .github/workflows/nightly-release.yaml delete mode 100644 Dockerfile create mode 100644 Makefile rename main.go => cmd/audit_org_keys/main.go (81%) delete mode 100644 config.go delete mode 100644 logger.go diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2852729..e1a1f14 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,7 +21,7 @@ jobs: key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: ${{ runner.os }}-go- - name: Build service - run: go build . + run: make build lint: name: Lint runs-on: ubuntu-latest @@ -39,6 +39,7 @@ jobs: key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: ${{ runner.os }}-go- - name: Lint - run: | - go get -u golang.org/x/lint/golint - golint -set_exit_status + uses: golangci/golangci-lint-action@v2 + with: + args: --enable dupl,gofmt,revive + skip-go-installation: true diff --git a/.github/workflows/nightly-release.yaml b/.github/workflows/nightly-release.yaml deleted file mode 100644 index e1922bb..0000000 --- a/.github/workflows/nightly-release.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: Nightly Release -on: - schedule: - - cron: '0 0 * * *' - workflow_dispatch: {} -jobs: - build-release: - name: Build and release Docker image - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - name: Login into GitHub Container Registry - run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin - - name: Build Docker image - run: | - docker build \ - -t "ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA:0:7}" \ - -t "ghcr.io/${GITHUB_REPOSITORY}:nightly" . - - name: Release Docker image - run: | - docker push "ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_SHA:0:7}" - docker push "ghcr.io/${GITHUB_REPOSITORY}:nightly" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 82c5c4d..396420f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -4,9 +4,12 @@ on: branches: - main jobs: - build-tag-release: - name: Build, tag, and release Docker image + release-please: + name: Build, tag, and publish assets runs-on: ubuntu-latest + outputs: + release-created: ${{ steps.release.outputs.release_created }} + upload-url: ${{ steps.release.outputs.upload_url }} steps: - name: Checkout repository uses: actions/checkout@v2 @@ -16,21 +19,51 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} release-type: simple - changelog-path: CHANGELOG.md package-name: audit-org-keys - - name: Login into GitHub Container Registry - if: ${{ steps.release.outputs.release_created }} - run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin - - name: Build Docker image - if: ${{ steps.release.outputs.release_created }} - run: | - docker build \ - -t "ghcr.io/${GITHUB_REPOSITORY}:${TAG_NAME}" \ - -t "ghcr.io/${GITHUB_REPOSITORY}:latest" . + build-publish: + name: Build and publish assets + runs-on: ubuntu-latest + needs: release-please + if: needs.release-please.outputs.release-created + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: '1.16' + - name: Setup build cache + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go- + - name: Build release assets + run: make dist + - name: Upload Windows asset + uses: actions/upload-release-asset@v1 env: - TAG_NAME: ${{ steps.release.outputs.tag_name }} - - name: Release Docker image - if: ${{ steps.release.outputs.release_created }} - run: | - docker push "ghcr.io/${GITHUB_REPOSITORY}:${TAG_NAME}" - docker push "ghcr.io/${GITHUB_REPOSITORY}:latest" + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.release-please.outputs.upload-url }} + asset_path: ./audit-org-keys-windows-amd64.exe + asset_name: audit-org-keys-windows-amd64.exe + asset_content_type: application/octet-stream + - name: Upload Linux asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.release-please.outputs.upload-url }} + asset_path: ./audit-org-keys-linux-amd64 + asset_name: audit-org-keys-linux-amd64 + asset_content_type: application/octet-stream + - name: Upload macOS asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.release-please.outputs.upload-url }} + asset_path: ./audit-org-keys-darwin-amd64 + asset_name: audit-org-keys-darwin-amd64 + asset_content_type: application/octet-stream diff --git a/.gitignore b/.gitignore index 866d2fc..c875fbd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .idea/ -audit-org-keys +bin/ diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 653b53c..0000000 --- a/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -FROM golang:1.16.4-alpine3.12 AS builder - -WORKDIR /build - -COPY go.mod go.mod -COPY go.sum go.sum - -RUN go mod download - -COPY config.go config.go -COPY logger.go logger.go -COPY main.go main.go - -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ - go build -ldflags="-s -w" - -FROM alpine:3.13.5 - -ENV GITHUB_ORGANIZATION="" -ENV GITHUB_PAT="" - -WORKDIR /opt - -COPY --from=builder /build/audit-org-keys audit-org-keys - -ENTRYPOINT ["./audit-org-keys"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4dd9048 --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +PROJECT_NAME=audit-org-keys + +GOCMD=$(shell pwd)/cmd/$(subst -,_,$(PROJECT_NAME)) +GOBIN=$(shell pwd)/bin/$(subst -,_,$(PROJECT_NAME)) +GOREPORTS=$(shell pwd)/bin +GO_MAJOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1) +GO_MINOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) +MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1 +MINIMUM_SUPPORTED_GO_MINOR_VERSION = 16 +GO_VERSION_VALIDATION_ERR_MSG = Golang version is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION) +.SILENT: + +.DEFAULT: +build: validate-go-version + go build -o $(GOBIN) $(GOCMD) + +dist: validate-go-version + GOOS=darwin GOARCH=amd64 go build -o $(PROJECT_NAME)-darwin-amd64 $(GOCMD) + GOOS=linux GOARCH=amd64 go build -o $(PROJECT_NAME)-linux-amd64 $(GOCMD) + GOOS=windows GOARCH=amd64 go build -o $(PROJECT_NAME)-windows-amd64.exe $(GOCMD) + +fmt: validate-go-version + gofmt -s -w . + +lint: validate-go-version + golangci-lint run --enable dupl,gofmt,revive + +test: validate-go-version + mkdir -p $(GOREPORTS) + go test -v ./... -coverprofile=$(GOREPORTS)/coverage.out -json > $(GOREPORTS)/report.json + +validate-go-version: + if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ + exit 0 ;\ + elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ + echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ + exit 1; \ + elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \ + echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ + exit 1; \ + fi diff --git a/README.md b/README.md index 2d592a5..cf762ad 100644 --- a/README.md +++ b/README.md @@ -4,74 +4,33 @@ The point of this project is to help demonstrate that users of GitHub could pote Programs like `ssh2john` from **John the Ripper** can best demonstrate how fast an SSH private key can be solved from a _not so_ complex algorithm with low key lengths (think RSA < 1024 bits). -## Getting started +## Installation -### Releases +`go get -u github.com/jef/audit-org-keys` -| Tag | Description | -|:---:|---| -| `latest` | Built against tagged releases; stable -| `nightly` | Built against HEAD; generally considered stable, but could have problems | - -``` -GITHUB_ORGANIZATION=actions -GITHUB_PAT=mysecrettoken - -docker run --rm -it \ - --env "GITHUB_ORGANIZATION=$GITHUB_ORGANIZATION" \ - --env "GITHUB_PAT=$GITHUB_PAT" \ - "docker.pkg.github.com/jef/audit-org-keys/audit-org-keys:" -``` - -> :point_right: View [Available arguments](#available-arguments) and [Available environment variables](#available-environment-variables) below if you'd like to customize input and output - -### Development - -#### Requirements +Also available under [GitHub Releases](https://github.com/jef/audit-org-keys/releases) as an executable. -- Go 1.14+ or Docker +## Usage -#### Running +It is required that you use a GitHub Personal Access Token (PAT). You can generate one [here](https://github.com/settings/tokens/new). The required scopes are `['read:org']`. Set your PAT to environment variable `GITHUB_TOKEN`. If `GITHUB_TOKEN` isn't set, then you may not get the results you expect. -```sh -GITHUB_ORGANIZATION=actions -GITHUB_PAT=mysecrettoken - -# Golang -go build -./audit-org-keys - -# show users with multiple keys -./audit-org-keys -show-users=multiple - -# Docker -docker build -t audit-org-keys:localhost . - -docker run --rm -it \ - --env "GITHUB_ORGANIZATION=$GITHUB_ORGANIZATION" \ - --env "GITHUB_PAT=$GITHUB_PAT" \ - audit-org-keys:localhost - -# show users without keys -docker run --rm -it \ - --env "GITHUB_ORGANIZATION=$GITHUB_ORGANIZATION" \ - --env "GITHUB_PAT=$GITHUB_PAT" \ - audit-org-keys:localhost -show-users=without +```shell +Usage of audit_org_keys: + -o, --organization string [required] GitHub organization provided to inspect + -s, --show-users all display users with filter (all, `with`, `without`, `multiple`) ``` -##### Available arguments +### Examples -- `-show-users=`: display users with filter (`all`, `with`, `without`, `multiple`) +- `audit-org-keys --organization="actions"` +- `audit-org-keys --organization="actions" --show-users="all"` -##### Available environment variables +## Releases -- `GITHUB_ORGANIZATION`*: The organization under audit -- `GITHUB_PAT`*: GitHub Personal Access Token - - [Create a PAT](https://github.com/settings/tokens) with `read:org` scope - - Some organizations have SSO; if yours does, then you also need to enable it -- `LOG_LEVEL`: Sets zap log level - -> :point_right: Required denoted by `*` +| Tag | Description | +|:---:|---| +| `latest` | Built against tagged releases; stable +| `nightly` | Built against HEAD; generally considered stable, but could have problems | ### Acknowledgments diff --git a/main.go b/cmd/audit_org_keys/main.go similarity index 81% rename from main.go rename to cmd/audit_org_keys/main.go index 1938276..a76e5c4 100644 --- a/main.go +++ b/cmd/audit_org_keys/main.go @@ -3,8 +3,6 @@ package main import ( "encoding/json" "fmt" - "github.com/olekukonko/tablewriter" - "go.uber.org/zap" "io/ioutil" "net/http" "os" @@ -12,6 +10,19 @@ import ( "strings" "sync" "sync/atomic" + + "github.com/olekukonko/tablewriter" + "github.com/rs/zerolog/log" + "github.com/spf13/pflag" +) + +const ( + gitHubURL = "https://github.com" + gitHubOrgAPI = "https://api.github.com/orgs" +) + +var ( + gitHubToken = os.Getenv("GITHUB_TOKEN") ) type member struct { @@ -19,6 +30,11 @@ type member struct { Keys []string } +type cliOptions struct { + ShowUsers string + GitHubOrg string +} + type keyTable struct { keyDsaSize uint32 keyEcdsaSize uint32 @@ -61,34 +77,29 @@ func printReport(kt keyTable) { fmt.Sprintf("%d (%.2f%%)", kt.keyRsaSize, float32(kt.keyRsaSize)/float32(kt.keySize)*100), fmt.Sprintf("%d (%.2f%%)", kt.userRsaSize, float32(kt.userRsaSize)/float32(kt.userSize)*100)}, } - withoutKey := [][]string{ {"users without keys", "", "", fmt.Sprintf("%d (%.2f%%)", kt.userWithoutKeySize, float32(kt.userWithoutKeySize)/float32(kt.userSize)*100)}, } - withMultipleKey := [][]string{{"users with multiple keys", "", "", fmt.Sprintf("%d (%.2f%%)", kt.userWithMultipleKeySize, float32(kt.userWithMultipleKeySize)/float32(kt.userSize)*100)}, } - strongKey := [][]string{ {"users with strong keys", "", fmt.Sprintf("%d (%.2f%%)", kt.strongKeySize, float32(kt.strongKeySize)/float32(kt.keySize)*100), fmt.Sprintf("%d (%.2f%%)", kt.userWithStrongKeySize, float32(kt.userWithStrongKeySize)/float32(kt.userWithKeySize)*100)}, } - weakKey := [][]string{ {"users with weak keys", "", fmt.Sprintf("%d (%.2f%%)", kt.weakKeySize, float32(kt.weakKeySize)/float32(kt.keySize)*100), fmt.Sprintf("%d (%.2f%%)", kt.userWithWeakKeySize, float32(kt.userWithWeakKeySize)/float32(kt.userWithKeySize)*100)}, } - t := tablewriter.NewWriter(os.Stdout) t.SetHeader([]string{"description", "key type", "# of keys", "# of users"}) t.SetHeaderColor(tablewriter.Colors{tablewriter.FgCyanColor}, @@ -107,28 +118,23 @@ func printReport(kt keyTable) { t.AppendBulk(strongKey) t.AppendBulk(weakKey) t.Render() - if len(kt.userWithWeakKey) > 0 { - zap.S().Info("users with weak keys:") + log.Info().Msg("users with weak keys:") for _, m := range kt.userWithWeakKey { - zap.S().Infof("%s", m.Login) + log.Info().Msgf("%s", m.Login) } } } -func generateKeyTable(ms []member) keyTable { - var wg sync.WaitGroup - +func (o cliOptions) generateKeyTable(ms []member) keyTable { var kt keyTable kt.userSize = uint32(len(ms)) - + var wg sync.WaitGroup for _, m := range ms { wg.Add(1) m := m - go func() { defer wg.Done() - var ( hasDsa bool hasEcdsa bool @@ -136,10 +142,8 @@ func generateKeyTable(ms []member) keyTable { hasRsa bool userHasStrongRsa bool ) - for _, key := range m.Keys { atomic.AddUint32(&kt.keySize, 1) - switch { case strings.Contains(key, "ssh-dsa"): hasDsa = true @@ -167,7 +171,6 @@ func generateKeyTable(ms []member) keyTable { } } } - switch { case hasDsa: atomic.AddUint32(&kt.userDsaSize, 1) @@ -189,40 +192,36 @@ func generateKeyTable(ms []member) keyTable { kt.userWithWeakKey = append(kt.userWithWeakKey, m) } } - if len(m.Keys) == 0 { atomic.AddUint32(&kt.userWithoutKeySize, 1) - if *showUsers == "without" || *showUsers == "all" { - zap.S().Infow("retrieved keys", - "user", m.Login, - "keys", m.Keys, - ) + if o.ShowUsers == "without" || o.ShowUsers == "all" { + log.Info(). + Str("user", m.Login). + Strs("keys", m.Keys). + Msg("retrieved keys") } } - if len(m.Keys) > 0 { atomic.AddUint32(&kt.userWithKeySize, 1) - if *showUsers == "with" || *showUsers == "all" { - zap.S().Infow("retrieved keys", - "user", m.Login, - "keys", m.Keys, - ) + if o.ShowUsers == "with" || o.ShowUsers == "all" { + log.Info(). + Str("user", m.Login). + Strs("keys", m.Keys). + Msg("retrieved keys") } } - if len(m.Keys) > 1 { atomic.AddUint32(&kt.userWithMultipleKeySize, 1) - if *showUsers == "multiple" || *showUsers == "all" { - zap.S().Infow("retrieved keys", - "user", m.Login, - "keys", m.Keys, - ) + if o.ShowUsers == "multiple" || o.ShowUsers == "all" { + log.Info(). + Str("user", m.Login). + Strs("keys", m.Keys). + Msg("retrieved keys") } } }() } wg.Wait() - return kt } @@ -233,13 +232,11 @@ func isRsaStrong(key string) bool { } func getKeys(ms []member) []member { - var wg sync.WaitGroup client := &http.Client{} + var wg sync.WaitGroup for i := 0; i < len(ms); i++ { wg.Add(1) - i := i - - go func() { + go func(i int) { m := &ms[i] defer wg.Done() @@ -249,66 +246,56 @@ func getKeys(ms []member) []member { nil, ) if err != nil { - zap.S().Fatal(err) + log.Fatal().Err(err) } res, err := client.Do(req) if err != nil { - zap.S().Fatal(err) + log.Fatal().Err(err) } defer res.Body.Close() key, err := ioutil.ReadAll(res.Body) if err != nil { - zap.S().Fatal(err) + log.Fatal().Err(err) } else if (len(key)) != 0 { m.Keys = strings.Split(strings.TrimSpace(string(key)), "\n") } - }() + }(i) } wg.Wait() - return ms } -func getMembers() []member { +func (o cliOptions) getMembers() []member { p := 1 - var members []member - for { client := &http.Client{} - req, err := http.NewRequest( "GET", - fmt.Sprintf("%s/%s/members?filter=all&page=%d", gitHubOrgAPI, gitHubOrg, p), + fmt.Sprintf("%s/%s/members?filter=all&page=%d", gitHubOrgAPI, o.GitHubOrg, p), nil, ) if err != nil { - zap.S().Fatal(err) + log.Fatal().Err(err) } - req.Header.Add("authorization", fmt.Sprintf("token %s", gitHubPAT)) - + req.Header.Add("authorization", fmt.Sprintf("token %s", gitHubToken)) res, err := client.Do(req) if err != nil { - zap.S().Fatal(err) + log.Fatal().Err(err) } - defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) if err != nil { - zap.S().Fatal(err) + log.Fatal().Err(err) } - var ms []member - err = json.Unmarshal(body, &ms) if err != nil { - zap.S().Fatal(err) + log.Fatal().Err(err) } - if len(ms) != 0 { members = append(members, ms...) p++ @@ -316,10 +303,20 @@ func getMembers() []member { break } } - return members } func main() { - printReport(generateKeyTable(getKeys(getMembers()))) + o := new(cliOptions) + pflag.StringVarP(&o.GitHubOrg, "organization", "o", "", "[required] GitHub organization provided to inspect") + pflag.StringVarP(&o.ShowUsers, "show-users", "s", "", "display users with filter (`all`, `with`, `without`, `multiple`)") + pflag.Parse() + if len(pflag.Args()) == 0 { + pflag.PrintDefaults() + os.Exit(1) + } + members := o.getMembers() + keys := getKeys(members) + table := o.generateKeyTable(keys) + printReport(table) } diff --git a/config.go b/config.go deleted file mode 100644 index b6c3a50..0000000 --- a/config.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "flag" - "os" -) - -const ( - gitHubURL = "https://github.com" - gitHubOrgAPI = "https://api.github.com/orgs" -) - -var ( - showUsers = flag.String("show-users", "", "display users with filter (`all`, `with`, `without`, `multiple`)") - gitHubOrg = os.Getenv("GITHUB_ORGANIZATION") - gitHubPAT = os.Getenv("GITHUB_PAT") -) - -func init() { - flag.Parse() - initLogger() -} diff --git a/go.mod b/go.mod index c83b4d5..45fe53b 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,6 @@ go 1.16 require ( github.com/olekukonko/tablewriter v0.0.5 - go.uber.org/zap v1.16.0 + github.com/rs/zerolog v1.23.0 + github.com/spf13/pflag v1.0.5 ) diff --git a/go.sum b/go.sum index 41d89c8..e860516 100644 --- a/go.sum +++ b/go.sum @@ -1,60 +1,34 @@ -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk= -go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A= -go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= -go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= -go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= -go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM= -go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= +github.com/rs/zerolog v1.23.0 h1:UskrK+saS9P9Y789yNNulYKdARjPZuS35B8gJF2x60g= +github.com/rs/zerolog v1.23.0/go.mod h1:6c7hFfxPOy7TacJc4Fcdi24/J0NKYGzjG8FWRI916Qo= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs= -golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/logger.go b/logger.go deleted file mode 100644 index 245143b..0000000 --- a/logger.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "os" -) - -func initLogger() { - var loggerConfig zap.Config - - var logLevel zapcore.Level - switch os.Getenv("LOG_LEVEL") { - case "debug": - logLevel = zap.DebugLevel - case "info": - logLevel = zap.InfoLevel - case "warn": - logLevel = zap.WarnLevel - case "error": - logLevel = zap.ErrorLevel - case "panic": - logLevel = zap.PanicLevel - case "fatal": - logLevel = zap.FatalLevel - default: - logLevel = zap.InfoLevel - } - - loggerConfig = zap.NewDevelopmentConfig() - loggerConfig.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder - loggerConfig.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder - loggerConfig.EncoderConfig.TimeKey = "timestamp" - loggerConfig.EncoderConfig.MessageKey = "message" - loggerConfig.Level = zap.NewAtomicLevelAt(logLevel) - - if logger, err := loggerConfig.Build(); err == nil { - zap.ReplaceGlobals(logger) - } -}