From ab02a2d71484e34e486bac26b6bbacbce5ddb52d Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Wed, 16 Mar 2022 12:12:26 +0100 Subject: [PATCH 1/3] feat: upgrade Go to 1.18 Signed-off-by: Mark Sagi-Kazar --- .github/workflows/ci.yaml | 2 +- .golangci.yml | 4 +++- Dockerfile | 2 +- flake.lock | 12 ++++++------ flake.nix | 2 +- go.mod | 2 +- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2cab1bd1ed..c0714ef15d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -64,7 +64,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.17 + go-version: 1.18 - name: Checkout code uses: actions/checkout@v3 diff --git a/.golangci.yml b/.golangci.yml index ceadcb230a..cfb64a75bf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -45,13 +45,15 @@ linters: - structcheck - stylecheck - tparallel - - typecheck - unconvert - unparam - unused - varcheck - whitespace + # Disable temporarily until everything works with Go 1.18 + # - typecheck + # TODO: fix linter errors before enabling # - exhaustivestruct # - gochecknoglobals diff --git a/Dockerfile b/Dockerfile index e528c9b893..87c93b40ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ ARG BASE_IMAGE=alpine -FROM golang:1.17.8-alpine3.14 AS builder +FROM golang:1.18.0-alpine3.15 AS builder WORKDIR /usr/local/src/dex diff --git a/flake.lock b/flake.lock index 715570a3a5..f1a446706c 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "flake-utils": { "locked": { - "lastModified": 1634851050, - "narHash": "sha256-N83GlSGPJJdcqhUxSCS/WwW5pksYf3VP1M13cDRTSVA=", + "lastModified": 1648297722, + "narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "c91f3de5adaf1de973b797ef7485e441a65b8935", + "rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade", "type": "github" }, "original": { @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1636800699, - "narHash": "sha256-SwbyVxXffu3G2ulJIbTf0iQfqhbGbdml4Dyv5j9BiAI=", + "lastModified": 1649225869, + "narHash": "sha256-u1zLtPmQzhT9mNXyM8Ey9pk7orDrIKdwooeGDEXm5xM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "2fa862644fc15ecb525eb8cd0a60276f1c340c7c", + "rev": "b6966d911da89e5a7301aaef8b4f0a44c77e103c", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 8f444d5e91..57aa2b0537 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; - buildDeps = with pkgs; [ git go_1_17 gnumake ]; + buildDeps = with pkgs; [ git go_1_18 gnumake ]; devDeps = with pkgs; buildDeps ++ [ golangci-lint diff --git a/go.mod b/go.mod index d5723e5217..ea7f3c13e5 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/dexidp/dex -go 1.17 +go 1.18 require ( entgo.io/ent v0.10.1 From 1736f95024a530c54f45e9a034c73007a552e4e2 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Wed, 25 May 2022 10:58:20 +0200 Subject: [PATCH 2/3] chore: upgrade linter Signed-off-by: Mark Sagi-Kazar --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 32cb9cc5e8..9c55ad2b11 100644 --- a/Makefile +++ b/Makefile @@ -117,7 +117,7 @@ proto-internal: @protoc --go_out=paths=source_relative:. server/internal/*.proto # Dependency versions -GOLANGCI_VERSION = 1.42.0 +GOLANGCI_VERSION = 1.46.0 GOTESTSUM_VERSION ?= 1.7.0 PROTOC_VERSION = 3.15.6 PROTOC_GEN_GO_VERSION = 1.26.0 From a02f2e8facfe8f1484aee0883b3229e670ffd30e Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Wed, 25 May 2022 11:17:34 +0200 Subject: [PATCH 3/3] chore: fix lint violations Signed-off-by: Mark Sagi-Kazar --- connector/keystone/keystone.go | 3 ++- connector/keystone/keystone_test.go | 9 ++++----- connector/ldap/ldap.go | 3 ++- connector/openshift/openshift.go | 12 ++++++++---- storage/conformance/jwks.go | 1 - storage/ent/mysql.go | 5 +---- storage/ent/postgres.go | 4 +--- storage/ent/sqlite.go | 4 +--- storage/kubernetes/storage_test.go | 2 +- storage/sql/crud_test.go | 1 + storage/sql/migrate_test.go | 1 + storage/sql/postgres_test.go | 1 + storage/sql/sqlite.go | 1 + storage/sql/sqlite_test.go | 1 + 14 files changed, 25 insertions(+), 23 deletions(-) diff --git a/connector/keystone/keystone.go b/connector/keystone/keystone.go index c4e98d0569..db97b5a71f 100644 --- a/connector/keystone/keystone.go +++ b/connector/keystone/keystone.go @@ -168,7 +168,8 @@ func (p *conn) Login(ctx context.Context, scopes connector.Scopes, username, pas func (p *conn) Prompt() string { return "username" } func (p *conn) Refresh( - ctx context.Context, scopes connector.Scopes, identity connector.Identity) (connector.Identity, error) { + ctx context.Context, scopes connector.Scopes, identity connector.Identity, +) (connector.Identity, error) { token, err := p.getAdminToken(ctx) if err != nil { return identity, fmt.Errorf("keystone: failed to obtain admin token: %v", err) diff --git a/connector/keystone/keystone_test.go b/connector/keystone/keystone_test.go index cf007f19c3..fc6c01e229 100644 --- a/connector/keystone/keystone_test.go +++ b/connector/keystone/keystone_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "encoding/json" - "fmt" "io" "net/http" "os" @@ -454,22 +453,22 @@ func setupVariables(t *testing.T) { keystoneAdminPassEnv := "DEX_KEYSTONE_ADMIN_PASS" keystoneURL = os.Getenv(keystoneURLEnv) if keystoneURL == "" { - t.Skip(fmt.Sprintf("variable %q not set, skipping keystone connector tests\n", keystoneURLEnv)) + t.Skipf("variable %q not set, skipping keystone connector tests\n", keystoneURLEnv) return } keystoneAdminURL = os.Getenv(keystoneAdminURLEnv) if keystoneAdminURL == "" { - t.Skip(fmt.Sprintf("variable %q not set, skipping keystone connector tests\n", keystoneAdminURLEnv)) + t.Skipf("variable %q not set, skipping keystone connector tests\n", keystoneAdminURLEnv) return } adminUser = os.Getenv(keystoneAdminUserEnv) if adminUser == "" { - t.Skip(fmt.Sprintf("variable %q not set, skipping keystone connector tests\n", keystoneAdminUserEnv)) + t.Skipf("variable %q not set, skipping keystone connector tests\n", keystoneAdminUserEnv) return } adminPass = os.Getenv(keystoneAdminPassEnv) if adminPass == "" { - t.Skip(fmt.Sprintf("variable %q not set, skipping keystone connector tests\n", keystoneAdminPassEnv)) + t.Skipf("variable %q not set, skipping keystone connector tests\n", keystoneAdminPassEnv) return } authTokenURL = keystoneURL + "/v3/auth/tokens/" diff --git a/connector/ldap/ldap.go b/connector/ldap/ldap.go index df69d60e3c..543402718c 100644 --- a/connector/ldap/ldap.go +++ b/connector/ldap/ldap.go @@ -220,7 +220,8 @@ func (c *Config) OpenConnector(logger log.Logger) (interface { connector.Connector connector.PasswordConnector connector.RefreshConnector -}, error) { +}, error, +) { return c.openConnector(logger) } diff --git a/connector/openshift/openshift.go b/connector/openshift/openshift.go index 05919973e3..81d2b35633 100644 --- a/connector/openshift/openshift.go +++ b/connector/openshift/openshift.go @@ -78,7 +78,8 @@ func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, e // OpenWithHTTPClient returns a connector which can be used to login users through an upstream // OpenShift OAuth2 provider. It provides the ability to inject a http.Client. func (c *Config) OpenWithHTTPClient(id string, logger log.Logger, - httpClient *http.Client) (conn connector.Connector, err error) { + httpClient *http.Client, +) (conn connector.Connector, err error) { ctx, cancel := context.WithCancel(context.Background()) wellKnownURL := strings.TrimSuffix(c.Issuer, "/") + wellKnownURLPath @@ -156,7 +157,8 @@ func (e *oauth2Error) Error() string { // HandleCallback parses the request and returns the user's identity func (c *openshiftConnector) HandleCallback(s connector.Scopes, - r *http.Request) (identity connector.Identity, err error) { + r *http.Request, +) (identity connector.Identity, err error) { q := r.URL.Query() if errType := q.Get("error"); errType != "" { return identity, &oauth2Error{errType, q.Get("error_description")} @@ -176,7 +178,8 @@ func (c *openshiftConnector) HandleCallback(s connector.Scopes, } func (c *openshiftConnector) Refresh(ctx context.Context, s connector.Scopes, - oldID connector.Identity) (connector.Identity, error) { + oldID connector.Identity, +) (connector.Identity, error) { var token oauth2.Token err := json.Unmarshal(oldID.ConnectorData, &token) if err != nil { @@ -189,7 +192,8 @@ func (c *openshiftConnector) Refresh(ctx context.Context, s connector.Scopes, } func (c *openshiftConnector) identity(ctx context.Context, s connector.Scopes, - token *oauth2.Token) (identity connector.Identity, err error) { + token *oauth2.Token, +) (identity connector.Identity, err error) { client := c.oauth2Config.Client(ctx, token) user, err := c.user(ctx, client) if err != nil { diff --git a/storage/conformance/jwks.go b/storage/conformance/jwks.go index f42d3d1802..0f05703e1b 100644 --- a/storage/conformance/jwks.go +++ b/storage/conformance/jwks.go @@ -11,7 +11,6 @@ type keyPair struct { // keys are generated beforehand so we don't have to generate RSA keys for every test. var jsonWebKeys = []keyPair{ - { Public: mustLoadJWK(`{ "use": "sig", diff --git a/storage/ent/mysql.go b/storage/ent/mysql.go index c922eb1626..2d3c833b5b 100644 --- a/storage/ent/mysql.go +++ b/storage/ent/mysql.go @@ -14,10 +14,7 @@ import ( entSQL "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/schema" - "github.com/go-sql-driver/mysql" - - // Register postgres driver. - _ "github.com/lib/pq" + "github.com/go-sql-driver/mysql" // Register mysql driver. "github.com/dexidp/dex/pkg/log" "github.com/dexidp/dex/storage" diff --git a/storage/ent/postgres.go b/storage/ent/postgres.go index 3e8df4413c..c52c29023d 100644 --- a/storage/ent/postgres.go +++ b/storage/ent/postgres.go @@ -13,9 +13,7 @@ import ( entSQL "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/schema" - - // Register postgres driver. - _ "github.com/lib/pq" + _ "github.com/lib/pq" // Register postgres driver. "github.com/dexidp/dex/pkg/log" "github.com/dexidp/dex/storage" diff --git a/storage/ent/sqlite.go b/storage/ent/sqlite.go index 3e54e1b721..bb98ac06f4 100644 --- a/storage/ent/sqlite.go +++ b/storage/ent/sqlite.go @@ -7,9 +7,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/schema" - - // Register sqlite driver. - _ "github.com/mattn/go-sqlite3" + _ "github.com/mattn/go-sqlite3" // Register sqlite driver. "github.com/dexidp/dex/pkg/log" "github.com/dexidp/dex/storage" diff --git a/storage/kubernetes/storage_test.go b/storage/kubernetes/storage_test.go index 4571327a15..828ff472cf 100644 --- a/storage/kubernetes/storage_test.go +++ b/storage/kubernetes/storage_test.go @@ -24,7 +24,7 @@ const kubeconfigPathVariableName = "DEX_KUBERNETES_CONFIG_PATH" func TestStorage(t *testing.T) { if os.Getenv(kubeconfigPathVariableName) == "" { - t.Skip(fmt.Sprintf("variable %q not set, skipping kubernetes storage tests\n", kubeconfigPathVariableName)) + t.Skipf("variable %q not set, skipping kubernetes storage tests\n", kubeconfigPathVariableName) } suite.Run(t, new(StorageTestSuite)) diff --git a/storage/sql/crud_test.go b/storage/sql/crud_test.go index 9e3282e58b..7cca1d6fcd 100644 --- a/storage/sql/crud_test.go +++ b/storage/sql/crud_test.go @@ -1,3 +1,4 @@ +//go:build cgo // +build cgo package sql diff --git a/storage/sql/migrate_test.go b/storage/sql/migrate_test.go index 7ec6d95706..4b77eb2fbe 100644 --- a/storage/sql/migrate_test.go +++ b/storage/sql/migrate_test.go @@ -1,3 +1,4 @@ +//go:build cgo // +build cgo package sql diff --git a/storage/sql/postgres_test.go b/storage/sql/postgres_test.go index d58abc70bf..3e5f8a8f65 100644 --- a/storage/sql/postgres_test.go +++ b/storage/sql/postgres_test.go @@ -1,3 +1,4 @@ +//go:build go1.11 // +build go1.11 package sql diff --git a/storage/sql/sqlite.go b/storage/sql/sqlite.go index 0994b19014..43df671a7c 100644 --- a/storage/sql/sqlite.go +++ b/storage/sql/sqlite.go @@ -1,3 +1,4 @@ +//go:build cgo // +build cgo package sql diff --git a/storage/sql/sqlite_test.go b/storage/sql/sqlite_test.go index 8be9939041..89d06aee29 100644 --- a/storage/sql/sqlite_test.go +++ b/storage/sql/sqlite_test.go @@ -1,3 +1,4 @@ +//go:build cgo // +build cgo package sql