diff --git a/Makefile b/Makefile index d287b292fc925..faa79da3611e3 100644 --- a/Makefile +++ b/Makefile @@ -702,13 +702,16 @@ lint-go: golangci-lint run -c .golangci.yml --build-tags='$(LIBFIDO2_TEST_TAG) $(TOUCHID_TAG) $(PIV_TEST_TAG)' $(GO_LINT_FLAGS) .PHONY: fix-imports -fix-imports: GOLANG_LINT_ARGS = --build-tags='$(LIBFIDO2_TEST_TAG) $(TOUCHID_TAG) $(PIV_TEST_TAG)' --fix fix-imports: - golangci-lint run -c .golangci.yml $(GOLANG_LINT_ARGS) - cd api/ && golangci-lint run -c ../.golangci.yml $(GOLANG_LINT_ARGS) - cd build.assets/tooling && golangci-lint run -c ../../.golangci.yml $(GOLANG_LINT_ARGS) - cd .cloudbuild/scripts && golangci-lint run -c ../../.golangci.yml $(GOLANG_LINT_ARGS) - cd assets/backport && golangci-lint run -c ../../.golangci.yml $(GOLANG_LINT_ARGS) + make -C build.assets/ fix-imports + +.PHONY: fix-imports/host +fix-imports/host: + @if ! type gci >/dev/null 2>&1; then\ + echo 'gci is not installed or is missing from PATH, consider installing it ("go install github.com/daixiang0/gci@latest") or use "make -C build.assets/ fix-imports"';\ + exit 1;\ + fi + gci write -s 'standard,default,prefix(github.com/gravitational/teleport)' --skip-generated . .PHONY: lint-build-tooling lint-build-tooling: GO_LINT_FLAGS ?= diff --git a/build.assets/Dockerfile b/build.assets/Dockerfile index 5df41ffd9ee57..a445d7be03951 100644 --- a/build.assets/Dockerfile +++ b/build.assets/Dockerfile @@ -166,6 +166,9 @@ RUN go install github.com/google/addlicense@v1.0.0 # Install golangci-lint. RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1 +# Install GCI +RUN go install github.com/daixiang0/gci@v0.8.2 + # Install helm. RUN (mkdir -p helm-tarball && curl -L https://get.helm.sh/helm-v3.5.2-$(go env GOOS)-$(go env GOARCH).tar.gz | tar -C helm-tarball -xz && \ cp helm-tarball/$(go env GOOS)-$(go env GOARCH)/helm /bin/ && \ diff --git a/build.assets/Makefile b/build.assets/Makefile index 9596d2cd5a106..22ae17eee223a 100644 --- a/build.assets/Makefile +++ b/build.assets/Makefile @@ -261,6 +261,13 @@ grpc-teleterm: buildbox-teleterm $(DOCKERFLAGS) -e CLANG_FORMAT=/usr/bin/clang-format-10 -t $(BUILDBOX_TELETERM) \ make -C /go/src/github.com/gravitational/teleport grpc-teleterm/host +# fix-imports runs GCI to sort and re-order Go imports in a deterministic way. +.PHONY: fix-imports +fix-imports: buildbox + docker run \ + $(DOCKERFLAGS) -t $(BUILDBOX) \ + make -C /go/src/github.com/gravitational/teleport fix-imports/host + # # Removes the docker image # diff --git a/examples/go-client/main.go b/examples/go-client/main.go index a50e713a23fda..d739810313062 100644 --- a/examples/go-client/main.go +++ b/examples/go-client/main.go @@ -21,10 +21,10 @@ import ( "fmt" "log" + "github.com/google/uuid" + "github.com/gravitational/teleport/api/client" "github.com/gravitational/teleport/api/types" - - "github.com/google/uuid" ) func main() { diff --git a/examples/workflows/main.go b/examples/workflows/main.go index 2b5cb4ebefb93..bb7871320f608 100644 --- a/examples/workflows/main.go +++ b/examples/workflows/main.go @@ -26,12 +26,12 @@ import ( "fmt" "log" + "github.com/gravitational/trace" + "github.com/pelletier/go-toml" + "github.com/gravitational/teleport/api/client" "github.com/gravitational/teleport/api/types" "github.com/gravitational/teleport/api/utils" - - "github.com/gravitational/trace" - "github.com/pelletier/go-toml" ) type config struct { diff --git a/lib/auth/state_windows.go b/lib/auth/state_windows.go index 8b4adde4bd2a3..16b501560a9ef 100644 --- a/lib/auth/state_windows.go +++ b/lib/auth/state_windows.go @@ -22,9 +22,9 @@ package auth import ( "context" - "github.com/gravitational/teleport/lib/backend/memory" - "github.com/gravitational/trace" + + "github.com/gravitational/teleport/lib/backend/memory" ) // NewProcessStorage returns a new instance of the process storage. diff --git a/lib/auth/touchid/api_darwin.go b/lib/auth/touchid/api_darwin.go index 10e897d79970b..c92e48c291f7a 100644 --- a/lib/auth/touchid/api_darwin.go +++ b/lib/auth/touchid/api_darwin.go @@ -38,7 +38,6 @@ import ( "github.com/google/uuid" "github.com/gravitational/trace" - log "github.com/sirupsen/logrus" ) diff --git a/lib/auth/webauthnwin/webauthn_windows.go b/lib/auth/webauthnwin/webauthn_windows.go index 61911f116c4f1..55dc621813916 100644 --- a/lib/auth/webauthnwin/webauthn_windows.go +++ b/lib/auth/webauthnwin/webauthn_windows.go @@ -22,10 +22,11 @@ import ( "unsafe" "github.com/duo-labs/webauthn/protocol" - wanlib "github.com/gravitational/teleport/lib/auth/webauthn" "github.com/gravitational/trace" log "github.com/sirupsen/logrus" "golang.org/x/sys/windows" + + wanlib "github.com/gravitational/teleport/lib/auth/webauthn" ) var ( diff --git a/lib/backend/dynamo/configure_test.go b/lib/backend/dynamo/configure_test.go index f7bc689bbf7ce..57fab587e574f 100644 --- a/lib/backend/dynamo/configure_test.go +++ b/lib/backend/dynamo/configure_test.go @@ -24,12 +24,11 @@ import ( "fmt" "testing" - "github.com/gravitational/trace" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/applicationautoscaling" "github.com/aws/aws-sdk-go/service/dynamodb" "github.com/google/uuid" + "github.com/gravitational/trace" "github.com/stretchr/testify/require" ) diff --git a/lib/bpf/bpf.go b/lib/bpf/bpf.go index be3390876b435..d7875978bf1ea 100644 --- a/lib/bpf/bpf.go +++ b/lib/bpf/bpf.go @@ -32,13 +32,13 @@ import ( "time" "unsafe" + "github.com/gravitational/trace" + "github.com/gravitational/ttlmap" + "github.com/gravitational/teleport/api/constants" apievents "github.com/gravitational/teleport/api/types/events" controlgroup "github.com/gravitational/teleport/lib/cgroup" "github.com/gravitational/teleport/lib/events" - - "github.com/gravitational/trace" - "github.com/gravitational/ttlmap" ) //go:embed bytecode diff --git a/lib/bpf/bpf_test.go b/lib/bpf/bpf_test.go index c20557f8f6cd1..83d622adc486a 100644 --- a/lib/bpf/bpf_test.go +++ b/lib/bpf/bpf_test.go @@ -33,16 +33,16 @@ import ( "time" "unsafe" - "github.com/gravitational/teleport/api/constants" - apidefaults "github.com/gravitational/teleport/api/defaults" - apievents "github.com/gravitational/teleport/api/types/events" - "github.com/gravitational/teleport/lib/events/eventstest" - "github.com/aquasecurity/libbpfgo" "github.com/google/uuid" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/testutil" "github.com/stretchr/testify/require" + + "github.com/gravitational/teleport/api/constants" + apidefaults "github.com/gravitational/teleport/api/defaults" + apievents "github.com/gravitational/teleport/api/types/events" + "github.com/gravitational/teleport/lib/events/eventstest" ) func TestRootWatch(t *testing.T) { diff --git a/lib/bpf/command.go b/lib/bpf/command.go index 48c30afba436c..bfa2682b9bf1c 100644 --- a/lib/bpf/command.go +++ b/lib/bpf/command.go @@ -20,15 +20,14 @@ limitations under the License. package bpf import ( - "github.com/gravitational/trace" - - "github.com/gravitational/teleport" - "github.com/gravitational/teleport/lib/observability/metrics" + _ "embed" "github.com/aquasecurity/libbpfgo" + "github.com/gravitational/trace" "github.com/prometheus/client_golang/prometheus" - _ "embed" + "github.com/gravitational/teleport" + "github.com/gravitational/teleport/lib/observability/metrics" ) var ( diff --git a/lib/bpf/disk.go b/lib/bpf/disk.go index 5cc2922efdb0a..4779eb67d8379 100644 --- a/lib/bpf/disk.go +++ b/lib/bpf/disk.go @@ -20,15 +20,14 @@ limitations under the License. package bpf import ( - "github.com/gravitational/trace" - - "github.com/gravitational/teleport" - "github.com/gravitational/teleport/lib/observability/metrics" + _ "embed" "github.com/aquasecurity/libbpfgo" + "github.com/gravitational/trace" "github.com/prometheus/client_golang/prometheus" - _ "embed" + "github.com/gravitational/teleport" + "github.com/gravitational/teleport/lib/observability/metrics" ) var ( diff --git a/lib/bpf/helper.go b/lib/bpf/helper.go index 61dabe0498856..2b02985cfb2b6 100644 --- a/lib/bpf/helper.go +++ b/lib/bpf/helper.go @@ -20,17 +20,17 @@ limitations under the License. package bpf import ( + "encoding/binary" + "os" + "sync" + "unsafe" + "github.com/aquasecurity/libbpfgo" "github.com/gravitational/trace" "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" "github.com/gravitational/teleport" - - "encoding/binary" - "os" - "sync" - "unsafe" ) var log = logrus.WithFields(logrus.Fields{ diff --git a/lib/bpf/network.go b/lib/bpf/network.go index 3df4541031797..5238703661bff 100644 --- a/lib/bpf/network.go +++ b/lib/bpf/network.go @@ -20,15 +20,14 @@ limitations under the License. package bpf import ( + _ "embed" + "github.com/aquasecurity/libbpfgo" "github.com/gravitational/trace" "github.com/prometheus/client_golang/prometheus" - "github.com/gravitational/teleport/lib/observability/metrics" - "github.com/gravitational/teleport" - - _ "embed" + "github.com/gravitational/teleport/lib/observability/metrics" ) var ( diff --git a/lib/client/terminal/terminal_windows.go b/lib/client/terminal/terminal_windows.go index 7391adbae1d49..46d3ec3a7a387 100644 --- a/lib/client/terminal/terminal_windows.go +++ b/lib/client/terminal/terminal_windows.go @@ -23,10 +23,11 @@ import ( "syscall" "github.com/Azure/go-ansiterm/winterm" - "github.com/gravitational/teleport/lib/client/tncon" - "github.com/gravitational/teleport/lib/utils" "github.com/gravitational/trace" "github.com/moby/term" + + "github.com/gravitational/teleport/lib/client/tncon" + "github.com/gravitational/teleport/lib/utils" ) // initTerminal configures the terminal for raw, VT compatible output and diff --git a/lib/events/s3sessions/s3handler_test.go b/lib/events/s3sessions/s3handler_test.go index c9009d05ccac6..5a10570e16f10 100644 --- a/lib/events/s3sessions/s3handler_test.go +++ b/lib/events/s3sessions/s3handler_test.go @@ -25,10 +25,10 @@ import ( "os" "testing" + "github.com/stretchr/testify/require" + "github.com/gravitational/teleport/lib/events/test" "github.com/gravitational/teleport/lib/utils" - - "github.com/stretchr/testify/require" ) func TestMain(m *testing.M) { diff --git a/lib/pam/pam.go b/lib/pam/pam.go index 51abd39ff11e3..1d8f1a4e5e4c2 100644 --- a/lib/pam/pam.go +++ b/lib/pam/pam.go @@ -54,10 +54,10 @@ import ( "syscall" "unsafe" - "github.com/gravitational/teleport" "github.com/gravitational/trace" - "github.com/sirupsen/logrus" + + "github.com/gravitational/teleport" ) func init() { diff --git a/lib/restrictedsession/audit.go b/lib/restrictedsession/audit.go index 5ad1e7756a3da..4caf71144f674 100644 --- a/lib/restrictedsession/audit.go +++ b/lib/restrictedsession/audit.go @@ -26,10 +26,11 @@ import ( "net" "unsafe" + "github.com/gravitational/trace" + "github.com/gravitational/teleport/api/types/events" "github.com/gravitational/teleport/lib/bpf" api "github.com/gravitational/teleport/lib/events" - "github.com/gravitational/trace" ) const ( diff --git a/lib/restrictedsession/restricted.go b/lib/restrictedsession/restricted.go index c406ca024a016..33f20f0b793d4 100644 --- a/lib/restrictedsession/restricted.go +++ b/lib/restrictedsession/restricted.go @@ -27,13 +27,13 @@ import ( "sync" "unsafe" - "github.com/gravitational/teleport" - "github.com/gravitational/teleport/lib/bpf" + "github.com/aquasecurity/libbpfgo" "github.com/gravitational/trace" "github.com/prometheus/client_golang/prometheus" - - "github.com/aquasecurity/libbpfgo" "github.com/sirupsen/logrus" + + "github.com/gravitational/teleport" + "github.com/gravitational/teleport/lib/bpf" ) var log = logrus.WithFields(logrus.Fields{ diff --git a/lib/restrictedsession/restricted_test.go b/lib/restrictedsession/restricted_test.go index a77afdb7e2030..fbe3512829a4b 100644 --- a/lib/restrictedsession/restricted_test.go +++ b/lib/restrictedsession/restricted_test.go @@ -30,6 +30,10 @@ import ( "testing" "time" + go_cmp "github.com/google/go-cmp/cmp" + "github.com/google/uuid" + "github.com/stretchr/testify/require" + apidefaults "github.com/gravitational/teleport/api/defaults" api "github.com/gravitational/teleport/api/types" apievents "github.com/gravitational/teleport/api/types/events" @@ -38,10 +42,6 @@ import ( "github.com/gravitational/teleport/lib/events/eventstest" "github.com/gravitational/teleport/lib/services" "github.com/gravitational/teleport/lib/utils" - - go_cmp "github.com/google/go-cmp/cmp" - "github.com/google/uuid" - "github.com/stretchr/testify/require" ) type blockAction int diff --git a/lib/restrictedsession/watcher.go b/lib/restrictedsession/watcher.go index 15dbf0b98cfc5..11d1070089aad 100644 --- a/lib/restrictedsession/watcher.go +++ b/lib/restrictedsession/watcher.go @@ -25,13 +25,13 @@ import ( "sync" "time" + "github.com/gravitational/trace" + "github.com/gravitational/teleport" "github.com/gravitational/teleport/api/types" "github.com/gravitational/teleport/api/utils/retryutils" "github.com/gravitational/teleport/lib/defaults" "github.com/gravitational/teleport/lib/utils" - - "github.com/gravitational/trace" ) // NewRestrictionsWatcher returns a new instance of changeset diff --git a/lib/srv/desktop/rdp/rdpclient/client.go b/lib/srv/desktop/rdp/rdpclient/client.go index 753ffcda179ba..344b7675c8da3 100644 --- a/lib/srv/desktop/rdp/rdpclient/client.go +++ b/lib/srv/desktop/rdp/rdpclient/client.go @@ -75,10 +75,10 @@ import ( "time" "unsafe" - "github.com/gravitational/teleport/lib/srv/desktop/tdp" "github.com/gravitational/trace" - "github.com/sirupsen/logrus" + + "github.com/gravitational/teleport/lib/srv/desktop/tdp" ) func init() { diff --git a/lib/utils/agentconn/agent_windows.go b/lib/utils/agentconn/agent_windows.go index 04ac71cfddbeb..772e92213ca8a 100644 --- a/lib/utils/agentconn/agent_windows.go +++ b/lib/utils/agentconn/agent_windows.go @@ -22,9 +22,8 @@ package agentconn import ( "net" - "github.com/gravitational/trace" - "github.com/Microsoft/go-winio" + "github.com/gravitational/trace" ) const namedPipe = `\\.\pipe\openssh-ssh-agent`