From 3d12152ac1cbe5d11c220e986d007a819224248f Mon Sep 17 00:00:00 2001 From: fdpeiter Date: Wed, 22 Jul 2020 12:46:51 -0300 Subject: [PATCH] Adding initial Gitlab provider and basic logic (#1) Adding initial structure and Gitlab provider --- .github/workflows/test.yml | 32 ++ .gitignore | 4 + Dockerfile | 15 + LICENSE | 223 ++++++++++- Makefile | 130 +++++++ Makefile.git | 18 + Makefile.golang | 57 +++ Makefile.silent | 13 + README.md | 84 +++- cmd/root.go | 69 ++++ cmd/validate.go | 40 ++ cmd/verify.go | 39 ++ go.mod | 33 ++ go.sum | 428 ++++++++++++++++++++ main.go | 7 + pkg/providers/gitlab_client.go | 93 +++++ pkg/providers/gitlab_client_mock.go | 76 ++++ pkg/providers/gitlab_client_test.go | 232 +++++++++++ pkg/providers/provider.go | 30 ++ pkg/providers/provider_test.go | 31 ++ pkg/verifier/codeowner.go | 213 ++++++++++ pkg/verifier/codeowner_test.go | 580 ++++++++++++++++++++++++++++ 22 files changed, 2425 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 Makefile.git create mode 100644 Makefile.golang create mode 100644 Makefile.silent create mode 100644 cmd/root.go create mode 100644 cmd/validate.go create mode 100644 cmd/verify.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 pkg/providers/gitlab_client.go create mode 100644 pkg/providers/gitlab_client_mock.go create mode 100644 pkg/providers/gitlab_client_test.go create mode 100644 pkg/providers/provider.go create mode 100644 pkg/providers/provider_test.go create mode 100644 pkg/verifier/codeowner.go create mode 100644 pkg/verifier/codeowner_test.go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..abc848b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,32 @@ +on: [push, pull_request] +name: Static Analysis +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.14.x + - name: Checkout code + uses: actions/checkout@v2 + - name: Lint + uses: golangci/golangci-lint-action@v1 + with: + version: v1.26 + args: --timeout=5m + test: + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.14.x + - name: Checkout code + uses: actions/checkout@v2 + - name: Go-CI Setup + uses: rkoCyrus/Go-CI@1.4.0 + - name: Fix vendor + run: go mod vendor + - name: test + run: make test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b976b06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +vendor +build +.vscode +coverage.out \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c7fe077 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM golang:1.14 as build + +WORKDIR /src + +ADD go.mod /src/ +ADD go.sum /src/ +RUN go mod download + +ADD . /src/ +RUN CGO_ENABLED=0 GOOS=linux make all + +FROM alpine:3.11.6 +COPY --from=build /src/build/codeowners-verifier /usr/local/bin + +CMD [ "codeowners-verifier", "help" ] diff --git a/LICENSE b/LICENSE index a87c2b5..38a0486 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,202 @@ -MIT License - -Copyright (c) 2020 TFG Co - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [2020] [Wildlife Studios] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9f3c796 --- /dev/null +++ b/Makefile @@ -0,0 +1,130 @@ +# Makefile for Helm Generate +# +# This Makefile makes an effort to provide standard make targets, as describe +# by https://www.gnu.org/prep/standards/html_node/Standard-Targets.html. + +# include other Makefiles +include Makefile.* + +DOCKER_IMAGE := "codeowners-verifier" +PROJECT := "codeowners-verifier" +TAG := $(shell git tag -l --points-at HEAD) +COMMIT := $(shell git describe --always --long --dirty --tags) +VERSION := $(shell [ ! -z "${TAG}" ] && echo "${TAG}" || echo "${COMMIT}") +REVISION := $(shell git rev-parse HEAD) +SHELL := /bin/sh +GITREMOTE := "https://github.com/topfreegames/codeowners-verifier" + +GOLANGCI_LINT := golangci-lint + +SOURCES := $(shell \ + find . -name '*.go' | \ + grep -Ev './(build|third_party|vendor)/' | \ + xargs) +ifdef DEBUG +$(info SOURCES = $(SOURCES)) +endif + +# Go packages to compile / test. +PACKAGES ?= ./... +ifdef DEBUG +$(info PACKAGES = $(PACKAGES)) +endif + +# Make is verbose in Linux. Make it silent. +MAKEFLAGS += --silent + +# Use linker flags to provide version settings to the target +# # Also build it with as much as possible static links. It may do the build a bit slower +LDFLAGS=-ldflags "-X=${GITREMOTE}/pkg/constants.Version=$(VERSION) -extldflags '-static'" + +################################################################################ +## Standard make targets +################################################################################ + +##- all: Run fix, build and install steps. +.DEFAULT_GOAL := all +.PHONY: all +all: fix build install + +##- build: Build go binary +.PHONY: version +version: + @echo "$(VERSION)" + +##- build: Build go binary +.PHONY: build +build: go-build + +##- install: Install binary on system +.PHONY: install +install: go-install + +##- uninstall: Uninstall binary +.PHONY: uninstall +uninstall: go-uninstall + +##- clean: Clean build files. Runs `go clean` internally. +.PHONY: clean +clean: go-clean + +##- test: Run all tests +.PHONY: test +test: go-test + +##- help: Show options +.PHONY: help +help: Makefile + @echo + @echo " Choose a command run in "$(PROJECT)":" + @echo + @sed -n 's/^##-//p' $< | column -t -s ':' | sed -e 's/^/ /' + @echo + +##- build-docker: Builds application in a docker image +.PHONY: build-docker +build-docker: + @echo " > Building docker image" + docker build -t $(DOCKER_IMAGE) . + +################################################################################ +## Go-like targets +################################################################################ + +go-build: + @echo " > Building binary" + @mkdir -p $(GOBINDIR) + $(GOBUILD) -o $(GOBINDIR) $(LDFLAGS) $(PACKAGES) + +go-install: + @echo " > Installing ${PROJECT}" + @GOBINDIR=$(GOBINDIR) $(GOINSTALL) $(PACKAGES) + +go-uninstall: + @echo " > Uninstalling ${PROJECT}" + $(RM) $(GOPATH)/bin/$(PROJECT) + +go-clean: + @echo " > Cleaning build cache" + @GOBINDIR=$(GOBINDIR) $(GOCLEAN) + +go-test: + @echo " > Executing tests" + @sh -c "${GOTEST} -cover -coverprofile coverage.out -v -tags=unit ${SILENT_CMD_SUFFIX} ${PACKAGES}" + +################################################################################ +## Linters and formatters +################################################################################ + +##- fix: Add and remove missing dependencies +.PHONY: fix +fix: + @echo " > Making sure go.mod matches the source code" + $(GOMOD) vendor + $(GOMOD) tidy + +##- lint: Run lint +.PHONY: lint +lint: + @echo " > Running lint" + $(GOLANGCI_LINT) run $(PACKAGES) --timeout=120s diff --git a/Makefile.git b/Makefile.git new file mode 100644 index 0000000..d06c2d0 --- /dev/null +++ b/Makefile.git @@ -0,0 +1,18 @@ +# Git related targets. + +include Makefile.silent + +GIT ?= git +GITDIFF ?= $(GIT) diff + +.PHONY: git/diff +git/diff: +ifeq (,$(SILENT)) + @if ! $(GITDIFF) --quiet; then \ + printf 'Found changes on local workspace. ' ; \ + printf 'Please run `make fix` and commit the changes.\n' ; \ + exit 1; \ + fi +else + $(GITDIFF) --quiet +endif diff --git a/Makefile.golang b/Makefile.golang new file mode 100644 index 0000000..ab0a0f7 --- /dev/null +++ b/Makefile.golang @@ -0,0 +1,57 @@ +# Variables for Go commands. + +GOBASE := $(shell pwd) +GOBINDIR := "$(GOBASE)/build" + +# Allow users to define GOFLAGS, but override it with flags mandatory for +# compilation. +GOFLAGS ?= +ifndef .GOFLAGS_GUARD +.GOFLAGS_GUARD := 1 +override GOFLAGS := -mod=vendor $(GOFLAGS) +endif +export GOFLAGS +ifdef DEBUG +$(info GOFLAGS = $(GOFLAGS)) +endif + +# Allow users to set custom build tags. +GOBUILDTAGS ?= + +# Allow users to set custom test timeout. +GOTESTTIMEOUT ?= + +# Allow users to run specific tests +GOTESTRUN ?= + +# Allow users to set all known build tags by passing ALLTAGS. +ifndef .ALLTAGS_GUARD +.ALLTAGS_GUARD := 1 +ifdef ALLTAGS +override GOBUILDTAGS := integration $(GOBUILDTAGS) +endif +endif + +GO ?= go +GOBUILD ?= $(GO) build +GOCLEAN ?= $(GO) clean +GOGENERATE ?= $(GO) generate +GOINSTALL ?= $(GO) install +GOMOD ?= $(GO) mod +GORUN ?= $(GO) run +GOTEST ?= $(GO) test +GOTOOL ?= $(GO) tool + +ifndef .GOSETUP_GUARD +.GOSETUP_GUARD := 1 +ifneq (,$(GOBUILDTAGS)) +GOBUILD := $(GOBUILD) -tags='$(GOBUILDTAGS)' +GOTEST := $(GOTEST) -tags='$(GOBUILDTAGS)' +endif +ifneq (,$(GOTESTTIMEOUT)) +GOTEST := $(GOTEST) -timeout='$(GOTESTTIMEOUT)' +endif +ifneq (,$(GOTESTRUN)) +GOTEST := $(GOTEST) -run='$(GOTESTRUN)' +endif +endif diff --git a/Makefile.silent b/Makefile.silent new file mode 100644 index 0000000..de6ff20 --- /dev/null +++ b/Makefile.silent @@ -0,0 +1,13 @@ +# Variables related to silent mode / `make -s`. + +# SILENT contains an 's' if make is in silent mode (`make -s`), otherwise it's +# empty. +SILENT ?= $(findstring s,$(MAKEFLAGS)) + +# SILENT_CMD_SUFFIX can be added to most noisy commands commands to make them +# respect silent mode. +ifeq (s,$(SILENT)) +SILENT_CMD_SUFFIX ?= 2>/dev/null 1>&2 +else +SILENT_CMD_SUFFIX ?= +endif diff --git a/README.md b/README.md index 9f1e51e..5a25027 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,84 @@ # codeowners-verifier -Small binary to verify is a path has a CODEOWNER. +Small binary to validate the CODEOWNERS file and check if a path matches a CODEOWNER entry. +Useful for using on CI to ensure CODEOWNERS coverage. + + +## Docker +Available at: [Docker Hub](https://hub.docker.com/r/tfgco/codeowners-verifier) and [Quay.io](https://quay.io/repository/tfgco/codeowners-verifier). + +## Overview + +codeowners-verifier verifies the entries inside a CODEOWNERS file. At the time being, It only supports Gitlab Code Owners. Although Code Owners works the same way for Gitlab and Github (the same validation checks are done by both), Wildlife's implementation also checks for valid Users and Groups inside a CODEOWNERS file. + +## Environment Variables + ++ `CODEOWNER_PROVIDER_URL`: The URL to the chosen provider. Defaults to *"https://gitlab.com/api/v4"*. ++ `CODEOWNER_PROVIDER_TOKEN`: Token to authenticate toward the chosen provider. There isn't default. ++ `CODEOWNER_PATH`: Path to the CODEOWNERS file. There isn't a default. + +Those environment variables may also be defined by the respective flags: `--base-url`, `--codeowners` and `--token`. + +A combination of using both flags and environment variables is possible, but keep in mind that flag values override environment variables values. + +## Usage + +:warning: Following how [.gitignore files works](https://git-scm.com/docs/gitignore), we didn't implement the "negate pattern". Github doesn't support it too. :warning: + +**There are three verbs available: `help`, `verify` and `validate`.** + +### Help + +Help displays basic help message on the available verbs and global flags. Can also be used to get help on the available verbs: + +``` +$ ./codeowners-verifier help verify +``` + +### Verify + +Verify must receive a path as argument. It then checks if the given path is covered by any of the existing entries. + +Example: + +```bash +$ codeowners-verifier verify dir1/ +INFO[0000] Found matching rule on line 7: /**/ [@group1] +``` + +Verify supports the `-i (--ignore)` flag to ignore users/groups. It can be used multiples times and/or by a comma separated list of groups/users. + +```bash +$ codeowners-verifier verify dir1/ -i @user1 --ignore @user2 +INFO[0000] Found matching rule on line 7: /**/ [@group1] + +$ codeowners-verifier verify dir1/ -i @user1 -i @user2,@group1 +FATA[0000] Missing CODEOWNER entry, matched rule from line 7 don't have valid owners: /**/ [@group1]. Check your ignore rules. +``` + +### Validate + +Validate validates the entire CODEOWNERS file, checking if the users and/or groups are valid. It does that by checking if the user or group is validy on the provider API. + +It must receive the name of the provider. YOu can check for the available providers by executing the help: + +```bash +$ codeowners-verifier validate -h +``` + +Then, execute with the provider name: + +```bash +$ codeowners-verifier validate gitlab +INFO[0007] Valid CODEOWNERS file +``` + +In case something is wrong: + +```bash +$ codeowners-verifier/codeowners-verifier validate gitlab +ERRO[0007] Error parsing line 7: user/group @user1 is invalid +ERRO[0007] Error parsing line 8, path test-dir/ does not exist +ERRO[0008] Error parsing line 8: user/group @group1 is invalid +ERRO[0008] Error parsing line 8: user/group @group2 is invalid +FATA[0008] Invalid CODEOWNERS file +``` \ No newline at end of file diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..d60ae32 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,69 @@ +package cmd + +import ( + "os" + + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var ( + token = "token" + baseurl = "base-url" + codeowners = "codeowners" +) + +// rootCmd represents the base command when called without any subcommands +var rootCmd = &cobra.Command{ + Use: "codeowners-verifier [flags] action path", + Short: "Verify the existence of a CODEONWERS to a file based on validation rules", + Long: `Codeowners-verifier is a tool made for running on CI pipelines. + It verifies the integrity of your CODEOWNERS file based on a predefined provider (currently only GITLAB), + You can check if every user and group declared actually exists. You can also check if a file has an CODEOWNER + defined, using the --ignore flag to ignore OWNERS.`, +} + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute() { + if err := rootCmd.Execute(); err != nil { + log.Fatal(err) + } +} + +func init() { + // Logging setup + // Output to stdout instead of the default stderr + // Can be any io.Writer, see below for File example + log.SetOutput(os.Stdout) + // Only log the warning severity or above. + log.SetLevel(log.InfoLevel) + cobra.OnInitialize(initConfig) + if err := viper.BindEnv(token, "CODEOWNER_PROVIDER_TOKEN"); err != nil { + log.Fatal("error initializing viper for env CODEOWNER_PROVIDER_TOKEN") + } + rootCmd.PersistentFlags().String(token, viper.GetString(token), "Token to be used to authenticate with the provider.(Defaults to CODEOWNER_PROVIDER_TOKEN env var)") + if err := viper.BindPFlag(token, rootCmd.PersistentFlags().Lookup(token)); err != nil { + log.Fatal("error binding viper for flag CODEOWNER_PROVIDER_TOKEN") + } + if err := viper.BindEnv(baseurl, "CODEOWNER_PROVIDER_URL"); err != nil { + log.Fatal("error initializing viper for env CODEOWNER_PROVIDER_URL") + } + rootCmd.PersistentFlags().String(baseurl, viper.GetString(baseurl), "BaseURL to connect to the provider (Defaults to CODEOWNER_PROVIDER_URL env var)") + if err := viper.BindPFlag(baseurl, rootCmd.PersistentFlags().Lookup(baseurl)); err != nil { + log.Fatal("error binding viper for flag CODEOWNER_PROVIDER_URL") + } + if err := viper.BindEnv(codeowners, "CODEOWNER_PATH"); err != nil { + log.Fatal("error initializing viper for env CODEOWNER_PATH") + } + rootCmd.PersistentFlags().String(codeowners, viper.GetString(codeowners), "Path to the CODEOWNERS file (Defaults to CODEOWNER_PATH env var)") + if err := viper.BindPFlag(codeowners, rootCmd.PersistentFlags().Lookup(codeowners)); err != nil { + log.Fatal("error binding viper for flag CODEOWNER_PATH") + } +} + +// initConfig reads in config file and ENV variables if set. +func initConfig() { + viper.AutomaticEnv() // read in environment variables that match +} diff --git a/cmd/validate.go b/cmd/validate.go new file mode 100644 index 0000000..ca91be4 --- /dev/null +++ b/cmd/validate.go @@ -0,0 +1,40 @@ +package cmd + +import ( + "fmt" + "os" + + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "github.com/topfreegames/codeowners-verifier/pkg/providers" + "github.com/topfreegames/codeowners-verifier/pkg/verifier" +) + +// validateCmd represents the validate command +var validateCmd = &cobra.Command{ + Use: "validate provider", + Short: "Validate the integrity of a CODEOWNERS file", + Long: fmt.Sprintf(`Check if every entry on the CODEOWNERS file exists on the provider. +Valid providers: %v`, providers.ListProviders()), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + client, err := providers.InitProvider(args[0], cmd.Flag(token).Value.String(), cmd.Flag(baseurl).Value.String()) + if err != nil { + log.Fatalf("Could not initialize provider: %s", err) + } + valid, err := verifier.ValidateCodeownerFile(client, cmd.Flag(codeowners).Value.String()) + if err != nil { + log.Fatalf("Error reading CODEOWNERS file contents: %s", err) + } + if valid { + log.Info("Valid CODEOWNERS file") + os.Exit(0) + } else { + log.Fatal("Invalid CODEOWNERS file") + } + }, +} + +func init() { + rootCmd.AddCommand(validateCmd) +} diff --git a/cmd/verify.go b/cmd/verify.go new file mode 100644 index 0000000..561a9fc --- /dev/null +++ b/cmd/verify.go @@ -0,0 +1,39 @@ +package cmd + +import ( + "os" + + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "github.com/topfreegames/codeowners-verifier/pkg/verifier" +) + +// checkCmd represents the check command +var ( + verifyCmd = &cobra.Command{ + Use: "verify path", + Short: "For a path, check if a CODEOWNER entry rule apples, excluding member from the ignore flag", + Long: `For a given path, goes through the CODEONWERS file trying to find a rule that matches the path, +Also, you can specify a list of members to ignore with the flag -i or --ignore. Example: +codeowners-verifier verify folder1 --ignore @user1 --ignore @group1`, + Run: func(cmd *cobra.Command, args []string) { + co, err := verifier.ReadCodeownersFile(cmd.Flag(codeowners).Value.String()) + if err != nil { + log.Fatalf("Couldn't read CODEOWNERS file: %s", err) + } + rule, valid := verifier.VerifyCodeowner(co, args[0], ignore) + if valid { + log.Infof("Found matching rule on line %d: %s %s", rule.Line, rule.Path, rule.Owners) + os.Exit(0) + } else { + log.Fatalf("Missing CODEOWNER entry, matched rule from line %d don't have valid owners: %s %s. Check your ignore rules.", rule.Line, rule.Path, rule.Owners) + } + }, + } + ignore []string +) + +func init() { + rootCmd.AddCommand(verifyCmd) + verifyCmd.Flags().StringSliceVarP(&ignore, "ignore", "i", []string{}, "Comma separated list of entries to ignore when validating a path E.g: @user1,@group1,@user2") +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ae8f8fc --- /dev/null +++ b/go.mod @@ -0,0 +1,33 @@ +module github.com/topfreegames/codeowners-verifier + +go 1.14 + +require ( + github.com/Flaque/filet v0.0.0-20190209224823-fc4d33cfcf93 + github.com/MichaelTJones/walk v0.0.0-20161122175330-4748e29d5718 // indirect + github.com/fsnotify/fsnotify v1.4.9 // indirect + github.com/golang/mock v1.4.3 + github.com/golang/protobuf v1.4.2 // indirect + github.com/hashicorp/go-retryablehttp v0.6.6 // indirect + github.com/mgutz/str v1.2.0 // indirect + github.com/mitchellh/mapstructure v1.3.2 // indirect + github.com/pelletier/go-toml v1.8.0 // indirect + github.com/sirupsen/logrus v1.6.0 + github.com/spf13/afero v1.3.2 // indirect + github.com/spf13/cast v1.3.1 // indirect + github.com/spf13/cobra v1.0.0 + github.com/spf13/jwalterweatherman v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/spf13/viper v1.7.0 + github.com/stretchr/testify v1.5.1 + github.com/xanzy/go-gitlab v0.33.0 + golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect + golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect + golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect + golang.org/x/text v0.3.3 // indirect + golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect + google.golang.org/appengine v1.6.6 // indirect + google.golang.org/protobuf v1.25.0 // indirect + gopkg.in/godo.v2 v2.0.9 + gopkg.in/ini.v1 v1.57.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..68fc543 --- /dev/null +++ b/go.sum @@ -0,0 +1,428 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Flaque/filet v0.0.0-20190209224823-fc4d33cfcf93 h1:NnAUCP75PRm8yWE7+MZBIAR6PA9iwsBYEc6ZNYOy+AQ= +github.com/Flaque/filet v0.0.0-20190209224823-fc4d33cfcf93/go.mod h1:TK+jB3mBs+8ZMWhU5BqZKnZWJ1MrLo8etNVg51ueTBo= +github.com/MichaelTJones/walk v0.0.0-20161122175330-4748e29d5718 h1:FSsoaa1q4jAaeiAUxf9H0PgFP7eA/UL6c3PdJH+nMN4= +github.com/MichaelTJones/walk v0.0.0-20161122175330-4748e29d5718/go.mod h1:VVwKsx9Dc8rNG55BWqogoJzGubjKnRoXdUvpGbWqeCc= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +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/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1 h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.3 h1:GV+pQPG/EUUbkh47niozDcADz6go/dUwhVzdUQHIVRw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= +github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= +github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= +github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-retryablehttp v0.6.4/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= +github.com/hashicorp/go-retryablehttp v0.6.6 h1:HJunrbHTDDbBb/ay4kxa1n+dLmttUlnP3V9oNE4hmsM= +github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= +github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= +github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= +github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= +github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +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/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mgutz/str v1.2.0 h1:4IzWSdIz9qPQWLfKZ0rJcV0jcUDpxvP4JVZ4GXQyvSw= +github.com/mgutz/str v1.2.0/go.mod h1:w1v0ofgLaJdoD0HpQ3fycxKD1WtxpjSo151pK/31q6w= +github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= +github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= +github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= +github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.3.2 h1:mRS76wmkOn3KkKAyXDu42V+6ebnXWIztFSYGN7GeoRg= +github.com/mitchellh/mapstructure v1.3.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pelletier/go-toml v1.8.0 h1:Keo9qb7iRJs2voHvunFtuuYFsbWeOBh8/P9v/kVMFtw= +github.com/pelletier/go-toml v1.8.0/go.mod h1:D6yutnOGMveHEPV7VQOuvI/gXY61bv+9bAOTRnLElKs= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= +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/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= +github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/afero v1.3.2 h1:GDarE4TJQI52kYSbSAmLiId1Elfj+xgSDqrUZxFhxlU= +github.com/spf13/afero v1.3.2/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4= +github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= +github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= +github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= +github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +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/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU= +github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= +github.com/spf13/viper v1.7.0 h1:xVKxvI7ouOI5I+U9s2eeiUfMaWBVoXA3AWskkrqK0VM= +github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +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= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/xanzy/go-gitlab v0.33.0 h1:MUJZknbLhVXSFzBA5eqGGhQ2yHSu8tPbGBPeB3sN4B0= +github.com/xanzy/go-gitlab v0.33.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +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/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181108082009-03003ca0c849/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= +golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s= +golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.6 h1:lMO5rYAqUxkmaj76jAkRUvt5JZgFymx/+Q5Mzfivuhc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +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/godo.v2 v2.0.9 h1:jnbznTzXVk0JDKOxN3/LJLDPYJzIl0734y+Z0cEJb4A= +gopkg.in/godo.v2 v2.0.9/go.mod h1:wgvPPKLsWN0hPIJ4JyxvFGGbIW3fJMSrXhdvSuZ1z/8= +gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.57.0 h1:9unxIsFcTt4I55uWluz+UmL95q4kdJ0buvQ1ZIqVQww= +gopkg.in/ini.v1 v1.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/main.go b/main.go new file mode 100644 index 0000000..62ea844 --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/topfreegames/codeowners-verifier/cmd" + +func main() { + cmd.Execute() +} diff --git a/pkg/providers/gitlab_client.go b/pkg/providers/gitlab_client.go new file mode 100644 index 0000000..14e4275 --- /dev/null +++ b/pkg/providers/gitlab_client.go @@ -0,0 +1,93 @@ +package providers + +import ( + "fmt" + + "github.com/xanzy/go-gitlab" +) + +// GitlabClient interface implements the Gitlab Client +//go:generate mockgen -destination=gitlab_client_mock.go -package=providers github.com/topfreegames/codeowners-verifier/pkg/providers ClientInterface +type ClientInterface interface { + NewClient(Token string, BaseURL string) + ListUsers(name string) ([]*gitlab.User, error) + ListGroups(name string) ([]*gitlab.Group, error) +} + +// Gitlab represents a Gitlab Client configuration +type Gitlab struct { + Token string + BaseURL string + Api ClientInterface +} + +// GitlabClient implements a wrapper for calling the gitlab library +type GitlabClient struct { + client *gitlab.Client +} + +// NewClient returns a new Gitlab client +func (c *GitlabClient) NewClient(Token string, BaseURL string) { + c.client, _ = gitlab.NewClient(Token, gitlab.WithBaseURL(BaseURL)) +} + +// ListUsers returns a list of Gitlab users matching the name +func (c *GitlabClient) ListUsers(name string) ([]*gitlab.User, error) { + users, _, err := c.client.Users.ListUsers(&gitlab.ListUsersOptions{Search: gitlab.String(name)}) + if err != nil { + return nil, fmt.Errorf("Error searching for user %s: %s", name, err) + } + return users, nil +} + +// ListGroups returns a list of Gitlab users matching the name +func (c *GitlabClient) ListGroups(name string) ([]*gitlab.Group, error) { + groups, _, err := c.client.Groups.ListGroups(&gitlab.ListGroupsOptions{Search: gitlab.String(name)}) + if err != nil { + return nil, fmt.Errorf("Error searching for group %s: %s", name, err) + } + return groups, nil +} + +// Init initializes the Gitlab Client +func (g *Gitlab) Init() error { + if g.Token == "" { + return fmt.Errorf("Token can't be empty") + } + if g.BaseURL == "" { + g.BaseURL = "https://gitlab.com/api/v4" + } + if g.Api == nil { + g.Api = &GitlabClient{} + } + g.Api.NewClient(g.Token, g.BaseURL) + return nil +} + +// SearchUser searches a user by name +func (g *Gitlab) UserExists(name string) (bool, error) { + users, err := g.Api.ListUsers(name) + if err != nil { + return false, err + } + for _, user := range users { + if user.Username == name { + return true, nil + } + } + return false, fmt.Errorf("User not found") +} + +// SearchGroup searches a group by name +func (g *Gitlab) GroupExists(name string) (bool, error) { + groups, err := g.Api.ListGroups(name) + if err != nil { + return false, err + } + for _, group := range groups { + if group.Name == name { + return true, nil + } + } + return false, fmt.Errorf("Group not found") +} diff --git a/pkg/providers/gitlab_client_mock.go b/pkg/providers/gitlab_client_mock.go new file mode 100644 index 0000000..aedb3c1 --- /dev/null +++ b/pkg/providers/gitlab_client_mock.go @@ -0,0 +1,76 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: pkg/providers/gitlab_client.go + +// Package providers is a generated GoMock package. +package providers + +import ( + gomock "github.com/golang/mock/gomock" + gitlab "github.com/xanzy/go-gitlab" + reflect "reflect" +) + +// MockClientInterface is a mock of ClientInterface interface +type MockClientInterface struct { + ctrl *gomock.Controller + recorder *MockClientInterfaceMockRecorder +} + +// MockClientInterfaceMockRecorder is the mock recorder for MockClientInterface +type MockClientInterfaceMockRecorder struct { + mock *MockClientInterface +} + +// NewMockClientInterface creates a new mock instance +func NewMockClientInterface(ctrl *gomock.Controller) *MockClientInterface { + mock := &MockClientInterface{ctrl: ctrl} + mock.recorder = &MockClientInterfaceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockClientInterface) EXPECT() *MockClientInterfaceMockRecorder { + return m.recorder +} + +// NewClient mocks base method +func (m *MockClientInterface) NewClient(Token, BaseURL string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "NewClient", Token, BaseURL) +} + +// NewClient indicates an expected call of NewClient +func (mr *MockClientInterfaceMockRecorder) NewClient(Token, BaseURL interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewClient", reflect.TypeOf((*MockClientInterface)(nil).NewClient), Token, BaseURL) +} + +// ListUsers mocks base method +func (m *MockClientInterface) ListUsers(name string) ([]*gitlab.User, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListUsers", name) + ret0, _ := ret[0].([]*gitlab.User) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListUsers indicates an expected call of ListUsers +func (mr *MockClientInterfaceMockRecorder) ListUsers(name interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListUsers", reflect.TypeOf((*MockClientInterface)(nil).ListUsers), name) +} + +// ListGroups mocks base method +func (m *MockClientInterface) ListGroups(name string) ([]*gitlab.Group, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListGroups", name) + ret0, _ := ret[0].([]*gitlab.Group) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListGroups indicates an expected call of ListGroups +func (mr *MockClientInterfaceMockRecorder) ListGroups(name interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListGroups", reflect.TypeOf((*MockClientInterface)(nil).ListGroups), name) +} diff --git a/pkg/providers/gitlab_client_test.go b/pkg/providers/gitlab_client_test.go new file mode 100644 index 0000000..bbefd6b --- /dev/null +++ b/pkg/providers/gitlab_client_test.go @@ -0,0 +1,232 @@ +package providers + +import ( + "fmt" + "testing" + + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" + "github.com/xanzy/go-gitlab" +) + +func TestNewClientSucessful(t *testing.T) { + mockCtrl := gomock.NewController(t) + defer mockCtrl.Finish() + MockGitlabClient := NewMockClientInterface(mockCtrl) + client := &Gitlab{ + Token: "example_token", + BaseURL: "example_url", + Api: MockGitlabClient, + } + MockGitlabClient.EXPECT().NewClient(client.Token, client.BaseURL).Times(1) + client.Api.NewClient(client.Token, client.BaseURL) +} + +func TestInitSucessful(t *testing.T) { + mockCtrl := gomock.NewController(t) + defer mockCtrl.Finish() + MockGitlabClient := NewMockClientInterface(mockCtrl) + client := &Gitlab{ + Token: "Token", + BaseURL: "BaseURL", + Api: MockGitlabClient, + } + MockGitlabClient.EXPECT().NewClient(client.Token, client.BaseURL).Times(1) + assert.Equal(t, nil, client.Init()) +} +func TestInitMissingToken(t *testing.T) { + client := &Gitlab{ + BaseURL: "BaseURL", + } + assert.Error(t, client.Init(), "Token can't be empty") +} +func TestEmptyBaseURL(t *testing.T) { + client := &Gitlab{ + Token: "token", + } + assert.Equal(t, nil, client.Init()) + assert.Equal(t, "https://gitlab.com/api/v4", client.BaseURL) +} + +func TestListUsersSuccess(t *testing.T) { + mockCtrl := gomock.NewController(t) + username := "mock_user" + gitlabUsers := []*gitlab.User{ + { + Username: username, + }, + } + defer mockCtrl.Finish() + MockGitlabClient := NewMockClientInterface(mockCtrl) + client := &Gitlab{ + Token: "example_token", + BaseURL: "example_url", + Api: MockGitlabClient, + } + MockGitlabClient.EXPECT().ListUsers(username).Return(gitlabUsers, nil).Times(1) + user, err := client.Api.ListUsers(username) + assert.Equal(t, err, nil) + assert.Equal(t, username, user[0].Username) +} +func TestListUsersFailure(t *testing.T) { + mockCtrl := gomock.NewController(t) + username := "mock_user" + defer mockCtrl.Finish() + MockGitlabClient := NewMockClientInterface(mockCtrl) + client := &Gitlab{ + Token: "example_token", + BaseURL: "example_url", + Api: MockGitlabClient, + } + MockGitlabClient.EXPECT().ListUsers(username).Return([]*gitlab.User{}, fmt.Errorf("Error searching for user %s:", username)).Times(1) + user, err := client.Api.ListUsers(username) + assert.Error(t, err, fmt.Errorf("Error searching for user %s:", username)) + assert.Equal(t, []*gitlab.User{}, user) +} + +func TestSearchUserSuccess(t *testing.T) { + mockCtrl := gomock.NewController(t) + username := "mock_user" + gitlabUsers := []*gitlab.User{ + { + Username: username, + }, + } + defer mockCtrl.Finish() + MockGitlabClient := NewMockClientInterface(mockCtrl) + client := &Gitlab{ + Token: "example_token", + BaseURL: "example_url", + Api: MockGitlabClient, + } + MockGitlabClient.EXPECT().ListUsers(username).Return(gitlabUsers, nil).Times(1) + valid, err := client.UserExists(username) + assert.Equal(t, nil, err) + assert.Equal(t, true, valid) +} +func TestSearchUserFailure(t *testing.T) { + mockCtrl := gomock.NewController(t) + username := "mock_user" + defer mockCtrl.Finish() + MockGitlabClient := NewMockClientInterface(mockCtrl) + client := &Gitlab{ + Token: "example_token", + BaseURL: "example_url", + Api: MockGitlabClient, + } + MockGitlabClient.EXPECT().ListUsers(username).Return([]*gitlab.User{}, fmt.Errorf("Error searching for user %s:", username)).Times(1) + valid, err := client.UserExists(username) + assert.Equal(t, fmt.Errorf("Error searching for user %s:", username), err) + assert.Equal(t, false, valid) +} +func TestSearchUserNotFound(t *testing.T) { + mockCtrl := gomock.NewController(t) + username := "mock_user" + defer mockCtrl.Finish() + MockGitlabClient := NewMockClientInterface(mockCtrl) + client := &Gitlab{ + Token: "example_token", + BaseURL: "example_url", + Api: MockGitlabClient, + } + MockGitlabClient.EXPECT().ListUsers(username).Return([]*gitlab.User{}, nil).Times(1) + valid, err := client.UserExists(username) + assert.Equal(t, fmt.Errorf("User not found"), err) + assert.Equal(t, false, valid) +} +func TestSearchUserMultipleUsers(t *testing.T) { + mockCtrl := gomock.NewController(t) + username := "mock_user" + gitlabUsers := []*gitlab.User{ + { + Username: username, + }, + { + Username: username + "_2", + }, + } + defer mockCtrl.Finish() + MockGitlabClient := NewMockClientInterface(mockCtrl) + client := &Gitlab{ + Token: "example_token", + BaseURL: "example_url", + Api: MockGitlabClient, + } + MockGitlabClient.EXPECT().ListUsers(username).Return(gitlabUsers, nil).Times(1) + valid, err := client.UserExists(username) + assert.Equal(t, nil, err) + assert.Equal(t, true, valid) +} +func TestSearchGroupSuccess(t *testing.T) { + mockCtrl := gomock.NewController(t) + groupName := "mock_group" + gitlabGroups := []*gitlab.Group{ + { + Name: groupName, + }, + } + defer mockCtrl.Finish() + MockGitlabClient := NewMockClientInterface(mockCtrl) + client := &Gitlab{ + Token: "example_token", + BaseURL: "example_url", + Api: MockGitlabClient, + } + MockGitlabClient.EXPECT().ListGroups(groupName).Return(gitlabGroups, nil).Times(1) + valid, err := client.GroupExists(groupName) + assert.Equal(t, err, nil) + assert.Equal(t, true, valid) +} +func TestSearchGroupFailure(t *testing.T) { + mockCtrl := gomock.NewController(t) + groupName := "mock_group" + defer mockCtrl.Finish() + MockGitlabClient := NewMockClientInterface(mockCtrl) + client := &Gitlab{ + Token: "example_token", + BaseURL: "example_url", + Api: MockGitlabClient, + } + MockGitlabClient.EXPECT().ListGroups(groupName).Return([]*gitlab.Group{}, fmt.Errorf("Error searching for group %s", groupName)).Times(1) + valid, err := client.GroupExists(groupName) + assert.Equal(t, fmt.Errorf("Error searching for group %s", groupName), err) + assert.Equal(t, false, valid) +} +func TestSearchGroupNotFound(t *testing.T) { + mockCtrl := gomock.NewController(t) + groupName := "mock_group" + defer mockCtrl.Finish() + MockGitlabClient := NewMockClientInterface(mockCtrl) + client := &Gitlab{ + Token: "example_token", + BaseURL: "example_url", + Api: MockGitlabClient, + } + MockGitlabClient.EXPECT().ListGroups(groupName).Return([]*gitlab.Group{}, nil).Times(1) + valid, err := client.GroupExists(groupName) + assert.Equal(t, fmt.Errorf("Group not found"), err) + assert.Equal(t, false, valid) +} +func TestSearchGroupMultipleGroups(t *testing.T) { + mockCtrl := gomock.NewController(t) + groupName := "mock_group" + gitlabGroups := []*gitlab.Group{ + { + Name: groupName, + }, + { + Name: groupName + "_2", + }, + } + defer mockCtrl.Finish() + MockGitlabClient := NewMockClientInterface(mockCtrl) + client := &Gitlab{ + Token: "example_token", + BaseURL: "example_url", + Api: MockGitlabClient, + } + MockGitlabClient.EXPECT().ListGroups(groupName).Return(gitlabGroups, nil).Times(1) + valid, err := client.GroupExists(groupName) + assert.Equal(t, nil, err) + assert.Equal(t, true, valid) +} diff --git a/pkg/providers/provider.go b/pkg/providers/provider.go new file mode 100644 index 0000000..054b9e3 --- /dev/null +++ b/pkg/providers/provider.go @@ -0,0 +1,30 @@ +package providers + +import "fmt" + +type Provider interface { + Init() error + UserExists(username string) (bool, error) + GroupExists(username string) (bool, error) +} + +func ListProviders() []string { + return []string{"gitlab"} +} + +func InitProvider(provider string, token string, baseURL string) (Provider, error) { + var client Provider + switch provider { + case "gitlab": + client = &Gitlab{ + Token: token, + BaseURL: baseURL, + } + if err := client.Init(); err != nil { + return nil, err + } + default: + return nil, fmt.Errorf("Invalid provider") + } + return client, nil +} diff --git a/pkg/providers/provider_test.go b/pkg/providers/provider_test.go new file mode 100644 index 0000000..b206379 --- /dev/null +++ b/pkg/providers/provider_test.go @@ -0,0 +1,31 @@ +package providers + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestInitProviderSuccess(t *testing.T) { + token := "xyz" + baseURL := "" + for _, p := range ListProviders() { + t.Logf("Validating provider %s", p) + provider, err := InitProvider(p, token, baseURL) + assert.Equal(t, nil, err) + _, ok := interface{}(provider).(Provider) + assert.Equal(t, true, ok) + } +} +func TestInitProviderError(t *testing.T) { + token := "" + baseURL := "" + for _, p := range ListProviders() { + t.Logf("Validating provider %s", p) + provider, err := InitProvider(p, token, baseURL) + assert.Equal(t, fmt.Errorf("Token can't be empty"), err) + _, ok := interface{}(provider).(Provider) + assert.Equal(t, false, ok) + } +} diff --git a/pkg/verifier/codeowner.go b/pkg/verifier/codeowner.go new file mode 100644 index 0000000..6d5f897 --- /dev/null +++ b/pkg/verifier/codeowner.go @@ -0,0 +1,213 @@ +package verifier + +import ( + "bufio" + "fmt" + "os" + "regexp" + "strings" + "unicode" + + glob "gopkg.in/godo.v2/glob" + + log "github.com/sirupsen/logrus" + "github.com/topfreegames/codeowners-verifier/pkg/providers" +) + +// CodeOwner represents a line in a CODEOWNERS file +type CodeOwner struct { + Path string + Regex *regexp.Regexp + Line int + Owners []string + Negate bool +} + +// reverseCodeOwners returns an inverted slice +func reverseCodeOwners(a []*CodeOwner) []*CodeOwner { + for left, right := 0, len(a)-1; left < right; left, right = left+1, right-1 { + a[left], a[right] = a[right], a[left] + } + return a +} + +// Used to remove comment lines +const commentChars = "[#]" + +// stripComment uses the commentChars to remove comments from lines +func stripComment(source string) string { + if cut := strings.IndexAny(source, commentChars); cut >= 0 { + return strings.TrimRightFunc(source[:cut], unicode.IsSpace) + } + return source +} + +// difference returns the difference between two slices +func difference(slice1 []string, slice2 []string) []string { + diffStr := []string{} + + for _, s1Val := range slice1 { + found := false + for _, s2Val := range slice2 { + if s1Val == s2Val { + found = true + break + } + } + if !found { + diffStr = append(diffStr, s1Val) + } + } + return diffStr +} + +// ReadCodeownersFile reads the file specified by filename +// and returns a list of CodeOwners strucs, as well as an error +func ReadCodeownersFile(filename string) ([]*CodeOwner, error) { + var codeowners []*CodeOwner + file, err := os.Open(filename) + if err != nil { + return nil, fmt.Errorf("Couldn't open file: %s", err) + } + defer file.Close() + scanner := bufio.NewScanner(file) + lineNumber := 1 + for scanner.Scan() { + line := stripComment(scanner.Text()) + line = strings.Join(strings.Fields(line), " ") + if line != "" { + elements := strings.Split(line, " ") + if len(elements) < 2 { + return nil, fmt.Errorf("Invalid CODEOWNERS entry: %d", lineNumber) + } + regex, negateRegex := getPatternFromLine(elements[0]) + if regex != nil { + c := &CodeOwner{ + Path: elements[0], + Regex: regex, + Line: lineNumber, + Owners: elements[1:], + Negate: negateRegex, + } + codeowners = append(codeowners, c) + } + } + lineNumber++ + } + return codeowners, nil +} + +// ValidateCodeownerFile check if every entry: +// 1. Has a valid file/path +// 2. Check if every owner is an user or a group. +func ValidateCodeownerFile(p providers.Provider, filename string) (bool, error) { + codeowners, err := ReadCodeownersFile(filename) + if err != nil { + return false, err + } + valid := true + for _, c := range codeowners { + // This doesn't works for ! patterns + if files, _, err := glob.Glob([]string{c.Path}); err != nil || len(files) < 1 { + log.Errorf("Error parsing line %d, path %s does not exist", c.Line, c.Path) + valid = false + } + for _, element := range c.Owners { + owner := strings.Replace(element, "@", "", 1) + exists, err := p.UserExists(owner) + if err != nil || !exists { + exists, err = p.GroupExists(owner) + if err != nil || !exists { + valid = false + log.Errorf("Error parsing line %d: user/group %s is invalid", c.Line, element) + } + } + } + } + return valid, nil +} + +// getPatternFromLine converts a line to a CODEOWNERS entry +// This is roughly addapted from https://github.com/sabhiram/go-gitignore +func getPatternFromLine(lineNumber string) (*regexp.Regexp, bool) { + // Trim OS-specific carriage returns. + lineNumber = strings.TrimRight(lineNumber, "\r") + + // TODO: Handle [Rule 4] which negates the match for patterns leading with "!" + negatePattern := false + if lineNumber[0] == '!' { + negatePattern = true + lineNumber = lineNumber[1:] + } + + // If we encounter a foo/*.blah in a folder, prepend the / char + if regexp.MustCompile(`([^\/+])/.*\*\.`).MatchString(lineNumber) && lineNumber[0] != '/' { + lineNumber = "/" + lineNumber + } + + // Handle escaping the "." char + lineNumber = regexp.MustCompile(`\.`).ReplaceAllString(lineNumber, `\.`) + + magicStar := "#$~" + + // Handle "/**/" usage + if strings.HasPrefix(lineNumber, "/**/") { + lineNumber = lineNumber[1:] + } + lineNumber = regexp.MustCompile(`/\*\*/`).ReplaceAllString(lineNumber, `(/|/.+/)`) + lineNumber = regexp.MustCompile(`\*\*/`).ReplaceAllString(lineNumber, `(|.`+magicStar+`/)`) + lineNumber = regexp.MustCompile(`/\*\*`).ReplaceAllString(lineNumber, `(|/.`+magicStar+`)`) + + // Handle escaping the "*" char + lineNumber = regexp.MustCompile(`\\\*`).ReplaceAllString(lineNumber, `\`+magicStar) + lineNumber = regexp.MustCompile(`\*`).ReplaceAllString(lineNumber, `([^/]*)`) + + // Handle escaping the "?" char + lineNumber = strings.Replace(lineNumber, "?", `\?`, -1) + + lineNumber = strings.Replace(lineNumber, magicStar, "*", -1) + + // Temporary regex + var expr = "" + if strings.HasSuffix(lineNumber, "/") { + expr = lineNumber + "(|.*)$" + } else { + expr = lineNumber + "(|/.*)$" + } + if strings.HasPrefix(expr, "/") { + expr = "^(|/)" + expr[1:] + } else { + expr = "^(|.*/)" + expr + } + pattern, _ := regexp.Compile(expr) + + return pattern, negatePattern +} + +// MatchesPath returns true if the given GitIgnore structure would target +// a given path string `f`. +func (co *CodeOwner) MatchesPath(f string) bool { + // Replace OS-specific path separator. + f = strings.Replace(f, string(os.PathSeparator), "/", -1) + + matchesPath := false + if co.Regex.MatchString(f) { + // If this is a regular target (not negated with a gitignore exclude "!" etc) + if !co.Negate { + matchesPath = true + } + } + return matchesPath +} + +// VerifyCodeowner check if a line matches any entry on the reversed list of CodeOwners +func VerifyCodeowner(codeowners []*CodeOwner, filename string, ignore []string) (*CodeOwner, bool) { + for _, c := range reverseCodeOwners(codeowners) { + match := c.MatchesPath(filename) + if match { + owners := difference(c.Owners, ignore) + return c, len(owners) > 0 + } + } + return &CodeOwner{}, false +} diff --git a/pkg/verifier/codeowner_test.go b/pkg/verifier/codeowner_test.go new file mode 100644 index 0000000..227dd5b --- /dev/null +++ b/pkg/verifier/codeowner_test.go @@ -0,0 +1,580 @@ +package verifier + +import ( + "regexp" + "sort" + "testing" + + filet "github.com/Flaque/filet" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" + "github.com/topfreegames/codeowners-verifier/pkg/providers" + "github.com/xanzy/go-gitlab" +) + +type TestCase struct { + Expected interface{} + Sample interface{} + Name string +} + +type ReturnWithError struct { + Value interface{} + Error bool +} + +func TestReverseCodeOwners(t *testing.T) { + codeOwnerEntries := []*CodeOwner{ + { + Path: "*", + Regex: nil, + Line: 1, + Owners: []string{"@defaultGroup"}, + Negate: false, + }, + { + Path: "path/to/file", + Regex: nil, + Line: 2, + Owners: []string{"@group1 @group2"}, + Negate: false, + }, + } + reversedCodeOwnerEntries := []*CodeOwner{ + { + Path: "path/to/file", + Regex: nil, + Line: 2, + Owners: []string{"@group1 @group2"}, + Negate: false, + }, + { + Path: "*", + Regex: nil, + Line: 1, + Owners: []string{"@defaultGroup"}, + Negate: false, + }, + } + emptyCodeOwner := []*CodeOwner{} + tests := []TestCase{ + { + Name: "Reversing CODEOWNERS file", + Sample: codeOwnerEntries, + Expected: reversedCodeOwnerEntries, + }, + { + Name: "Checking empty CODEOWNERS file", + Sample: emptyCodeOwner, + Expected: emptyCodeOwner, + }, + } + + for i, test := range tests { + t.Logf("Test case %d: %s", i, test.Name) + result := reverseCodeOwners(test.Sample.([]*CodeOwner)) + assert.Equal(t, test.Expected.([]*CodeOwner), result) + } +} + +func TestStripComment(t *testing.T) { + tests := []TestCase{ + { + Name: "Checking line with #", + Sample: "#testing", + Expected: "", + }, + { + Name: "Checking line section []", + Sample: "[SectionThatShouldBeSanitized]", + Expected: "", + }, + { + Name: "Checking valid line", + Sample: "* @test", + Expected: "* @test", + }, + } + + for i, test := range tests { + t.Logf("Test case %d: %s", i, test.Name) + result := stripComment(test.Sample.(string)) + assert.Equal(t, test.Expected.(string), result) + } +} + +func TestDifference(t *testing.T) { + tests := []TestCase{ + { + Name: "Checking Difference with 2 identical slices", + Sample: map[string]interface{}{ + "array1": []string{"a", "b", "c", "d"}, + "array2": []string{"a", "b", "c", "d"}, + }, + Expected: []string{}, + }, + { + Name: "Checking Difference with 2 slightly different slices", + Sample: map[string]interface{}{ + "array1": []string{"a", "b", "c", "d"}, + "array2": []string{"c", "d", "e", "f"}, + }, + Expected: []string{"a", "b"}, + }, + { + Name: "Checking Difference with 2 completely different slices", + Sample: map[string]interface{}{ + "array1": []string{"a", "b", "c", "d"}, + "array2": []string{"e", "f", "g", "h"}, + }, + Expected: []string{"a", "b", "c", "d"}, + }, + } + for i, test := range tests { + t.Logf("Test case %d: %s", i, test.Name) + result := difference(test.Sample.(map[string]interface{})["array1"].([]string), test.Sample.(map[string]interface{})["array2"].([]string)) + sort.Strings(result) + assert.Equal(t, test.Expected.([]string), result) + } +} + +func TestCodeOwnerReadFile(t *testing.T) { + tests := []TestCase{ + { + Name: "invalid file", + Sample: map[string]interface{}{ + "Filename": "non-existent-file", + "Contents": "", + }, + Expected: ReturnWithError{ + Value: nil, + Error: true, + }, + }, + { + Name: "valid codeowners", + Sample: map[string]interface{}{ + "Filename": "valid-codeowners", + "Contents": `* @user1 @user2 +folder1 @group1 +folder2/ @group1 +folder2/* @group2 +!file1 @user3 +folder1/*.tf @user4 +/**/ @group1`, + }, + Expected: ReturnWithError{ + Value: []*CodeOwner{ + { + Path: "*", + Regex: regexp.MustCompile("^(|.*/)([^/]*)(|/.*)$"), + Negate: false, + Owners: []string{ + "@user1", + "@user2", + }, + Line: 1, + }, + { + Path: "folder1", + Regex: regexp.MustCompile("^(|.*/)folder1(|/.*)$"), + Negate: false, + Owners: []string{ + "@group1", + }, + Line: 2, + }, + { + Path: "folder2/", + Regex: regexp.MustCompile("^(|.*/)folder2/(|.*)$"), + Negate: false, + Owners: []string{ + "@group1", + }, + Line: 3, + }, + { + Path: "folder2/*", + Regex: regexp.MustCompile("^(|.*/)folder2/([^/]*)(|/.*)$"), + Negate: false, + Owners: []string{ + "@group2", + }, + Line: 4, + }, + { + Path: "!file1", + Regex: regexp.MustCompile("^(|.*/)file1(|/.*)$"), + Negate: true, + Owners: []string{ + "@user3", + }, + Line: 5, + }, + { + Path: "folder1/*.tf", + Regex: regexp.MustCompile(`^(|/)folder1/([^/]*)\.tf(|/.*)$`), + Negate: false, + Owners: []string{ + "@user4", + }, + Line: 6, + }, + { + Path: "/**/", + Regex: regexp.MustCompile("^(|.*/)(|.*/)(|/.*)$"), + Negate: false, + Owners: []string{ + "@group1", + }, + Line: 7, + }, + }, + Error: false, + }, + }, + { + Name: "invalid codeowners entry", + Sample: map[string]interface{}{ + "Filename": "valid-codeowners", + "Contents": `* +folder1 +folder2/ +folder2/ @user2 +!file1 @user3`, + }, + Expected: ReturnWithError{ + Value: nil, + Error: true, + }, + }, + } + + for i, test := range tests { + t.Logf("Test case %d: %s", i, test.Name) + defer filet.CleanUp(t) + expected := test.Expected.(ReturnWithError) + sample := test.Sample.(map[string]interface{}) + + if sample["Contents"].(string) != "" { + filet.File(t, sample["Filename"].(string), sample["Contents"].(string)) + } + val, err := ReadCodeownersFile(sample["Filename"].(string)) + if expected.Error { + assert.Error(t, err, "should return an error") + assert.Nil(t, val, "return should be nil on error") + } else { + assert.Nil(t, err, "should not return error") + assert.Equal(t, expected.Value.([]*CodeOwner), val, "decoded value should match expected") + } + } +} + +func TestMatchesPath(t *testing.T) { + codeowners := []*CodeOwner{ + { + Path: "*", + Regex: regexp.MustCompile("^(|.*/)([^/]*)(|/.*)$"), + Negate: false, + Owners: []string{ + "@user1", + "@user2", + }, + Line: 1, + }, + { + Path: "folder1", + Regex: regexp.MustCompile("^(|.*/)folder1(|/.*)$"), + Negate: false, + Owners: []string{ + "@group1", + }, + Line: 2, + }, + { + Path: "!file1", + Regex: regexp.MustCompile("^(|.*/)file1(|/.*)$"), + Negate: true, + Owners: []string{ + "@user3", + }, + Line: 3, + }, + } + tests := []TestCase{ + { + Name: "Check covered path for given file", + Sample: map[string]interface{}{ + "CodeOwnerEntry": codeowners[0], + "File": "file2", + }, + Expected: true, + }, + { + Name: "Check non-covered path for given file", + Sample: map[string]interface{}{ + "CodeOwnerEntry": codeowners[1], + "File": "file2", + }, + Expected: false, + }, + { + Name: "Check negated path for given file", + Sample: map[string]interface{}{ + "CodeOwnerEntry": codeowners[2], + "File": "file1", + }, + Expected: false, + }, + } + + for i, test := range tests { + t.Logf("Test case %d: %s", i, test.Name) + sample := test.Sample.(map[string]interface{}) + result := sample["CodeOwnerEntry"].(*CodeOwner).MatchesPath(sample["File"].(string)) + assert.Equal(t, test.Expected, result) + } +} + +func TestVerifyCodeowner(t *testing.T) { + codeowners := []*CodeOwner{ + { + Path: "*", + Regex: regexp.MustCompile("^(|.*/)([^/]*)(|/.*)$"), + Negate: false, + Owners: []string{ + "@user1", + "@user2", + }, + Line: 1, + }, + { + Path: "folder1", + Regex: regexp.MustCompile("^(|.*/)folder1(|/.*)$"), + Negate: false, + Owners: []string{ + "@group1", + }, + Line: 2, + }, + { + Path: "folder2/", + Regex: regexp.MustCompile("^(|.*/)folder2/(|.*)$"), + Negate: false, + Owners: []string{ + "@group1", + }, + Line: 3, + }, + { + Path: "folder2/*", + Regex: regexp.MustCompile("^(|.*/)folder2/([^/]*)(|/.*)$"), + Negate: false, + Owners: []string{ + "@group2", + }, + Line: 4, + }, + { + Path: "!file1", + Regex: regexp.MustCompile("^(|.*/)file1(|/.*)$"), + Negate: true, + Owners: []string{ + "@user3", + }, + Line: 5, + }, + { + Path: "folder1/*.tf", + Regex: regexp.MustCompile(`^(|/)folder1/([^/]*)\.tf(|/.*)$`), + Negate: false, + Owners: []string{ + "@user4", + }, + Line: 6, + }, + { + Path: "/**/", + Regex: regexp.MustCompile("^(|.*/)(|.*/)(|/.*)$"), + Negate: false, + Owners: []string{ + "@group1", + }, + Line: 7, + }, + } + tests := []TestCase{ + { + Name: "Checking file on empty CODEOWNERS", + Sample: map[string]interface{}{ + "CodeOwners": []*CodeOwner{}, + "File": "", + "Ignore": []string{}, + }, + Expected: map[string]interface{}{ + "Codeowners": &CodeOwner{}, + "Valid": false, + }, + }, + { + Name: "Checking covered file on CODEOWNERS - no ignores", + Sample: map[string]interface{}{ + "CodeOwners": codeowners, + "File": "file2", + "Ignore": []string{}, + }, + Expected: map[string]interface{}{ + "Codeowners": codeowners[0], + "Valid": true, + }, + }, + { + Name: "Checking covered file on CODEOWNERS - with ignores", + Sample: map[string]interface{}{ + "CodeOwners": codeowners, + "File": "file2", + "Ignore": []string{ + "@user1", + "@user2", + }, + }, + Expected: map[string]interface{}{ + "Codeowners": codeowners[0], + "Valid": false, + }, + }, + } + for i, test := range tests { + t.Logf("Test case %d: %s", i, test.Name) + sample := test.Sample.(map[string]interface{}) + expected := test.Expected.(map[string]interface{}) + entry, valid := VerifyCodeowner(sample["CodeOwners"].([]*CodeOwner), sample["File"].(string), sample["Ignore"].([]string)) + + assert.Equal(t, expected["Codeowners"].(*CodeOwner), entry) + assert.Equal(t, expected["Valid"].(bool), valid) + } +} + +func TestValidateCodeownerFileGitlab(t *testing.T) { + defer filet.CleanUp(t) + /* + Directory Tree created for tests + ./ + ./folder1 + ./folder1/file1 + ./folder2 + ./folder2/file2 + ./folder2/folder3/ + ./folder2/folder3/file3 + ./file4 + */ + folder1 := filet.TmpDir(t, "") + folder2 := filet.TmpDir(t, "") + folder3 := filet.TmpDir(t, folder2) + filet.TmpFile(t, folder1, "") + filet.TmpFile(t, folder2, "") + file1 := filet.TmpFile(t, folder3, "").Name() + filet.TmpFile(t, "", "") + mockCtrl := gomock.NewController(t) + defer mockCtrl.Finish() + MockGitlabClient := providers.NewMockClientInterface(mockCtrl) + tests := []TestCase{ + { + Name: "invalid file", + Sample: map[string]interface{}{ + "CodeOwners": "non-existent-file", + "Provider": &providers.Gitlab{ + Token: "xxx", + Api: MockGitlabClient, + }, + }, + Expected: ReturnWithError{ + Value: false, + Error: true, + }, + }, + { + Name: "Correct CodeOwners File", + Sample: map[string]interface{}{ + "CodeOwners": filet.TmpFile(t, "", `* @user1 +`+folder1+` @user2 @group1 +`+folder1+`/* @user3 +`+folder2+`/** @group1 +`+folder3+` @user1 +`+file1+` @user1`).Name(), + "Provider": &providers.Gitlab{ + Token: "xxx", + Api: MockGitlabClient, + }, + }, + Expected: ReturnWithError{ + Value: true, + Error: false, + }, + }, + { + Name: "invalid codeowner entry", + Sample: map[string]interface{}{ + "CodeOwners": filet.TmpFile(t, "", `missing-owner`).Name(), + "Provider": &providers.Gitlab{ + Token: "xxx", + Api: MockGitlabClient, + }, + }, + Expected: ReturnWithError{ + Value: false, + Error: true, + }, + }, + { + Name: "non-existent path", + Sample: map[string]interface{}{ + "CodeOwners": filet.TmpFile(t, "", `invalid-path @user1`).Name(), + "Provider": &providers.Gitlab{ + Token: "xxx", + Api: MockGitlabClient, + }, + }, + Expected: ReturnWithError{ + Value: false, + Error: false, + }, + }, + { + Name: "non-existent owner", + Sample: map[string]interface{}{ + "CodeOwners": filet.TmpFile(t, "", folder1+` @user100`).Name(), + "Provider": &providers.Gitlab{ + Token: "xxx", + Api: MockGitlabClient, + }, + }, + Expected: ReturnWithError{ + Value: false, + Error: false, + }, + }, + } + for i, test := range tests { + t.Logf("Test case %d: %s", i, test.Name) + defer filet.CleanUp(t) + expected := test.Expected.(ReturnWithError) + sample := test.Sample.(map[string]interface{}) + // We could improve this logic + MockGitlabClient.EXPECT().ListUsers("user1").Return([]*gitlab.User{{Username: "user1"}}, nil).AnyTimes() + MockGitlabClient.EXPECT().ListUsers("user2").Return([]*gitlab.User{{Username: "user2"}}, nil).AnyTimes() + MockGitlabClient.EXPECT().ListUsers("user3").Return([]*gitlab.User{{Username: "user3"}}, nil).AnyTimes() + MockGitlabClient.EXPECT().ListUsers("user100").Return([]*gitlab.User{}, nil).AnyTimes() + MockGitlabClient.EXPECT().ListUsers("group1").Return([]*gitlab.User{}, nil).AnyTimes() + MockGitlabClient.EXPECT().ListGroups("group1").Return([]*gitlab.Group{{Name: "group1"}}, nil).AnyTimes() + MockGitlabClient.EXPECT().ListGroups("user100").Return([]*gitlab.Group{}, nil).AnyTimes() + val, err := ValidateCodeownerFile(sample["Provider"].(providers.Provider), sample["CodeOwners"].(string)) + if expected.Error { + assert.Error(t, err, "should return an error") + assert.Equal(t, false, val, "return should be false on error") + } else { + assert.Nil(t, err, "should not return error") + assert.Equal(t, expected.Value.(bool), val, "decoded value should match expected") + } + } +}