From 1aef3f4c716b54bd3ba133e1a75ed329db887917 Mon Sep 17 00:00:00 2001 From: Olivia Haven Date: Wed, 21 Oct 2026 22:09:45 +0000 Subject: [PATCH 1/2] Upgrade Go to 1.27.3 and fix lint CI Bump go directive to 1.27.3, use go-version-file in workflows, and move golangci-lint to v2.15.0 (action v9) with a v2-format .golangci.yml, since the v1 binary the old action resolved was built with Go 1.24. Co-Authored-By: Claude Opus 5.5 Co-authored-by: c1-squire-dev[bot] --- .github/workflows/ci.yaml | 23 ++-- .github/workflows/main.yaml | 17 ++- .golangci.yml | 204 ++++++++++++++++++++---------------- go.mod | 4 +- 4 files changed, 132 insertions(+), 116 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b3e8f22a..f8e28862 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,31 +4,30 @@ jobs: go-lint: runs-on: ubuntu-latest steps: + - name: Checkout code + uses: actions/checkout@v4 - name: Install Go uses: actions/setup-go@v5 with: - go-version: 1.24.x - - name: Checkout code - uses: actions/checkout@v4 + go-version-file: go.mod - name: Run linters - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v9 with: - version: latest + version: v2.15.0 args: --timeout=3m go-test: strategy: matrix: - go-version: [1.22.x, 1.24.x] platform: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: + - name: Checkout code + uses: actions/checkout@v4 - name: Install Go if: success() uses: actions/setup-go@v5 with: - go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v4 + go-version-file: go.mod - name: go tests run: go test -v -covermode=count -json ./... > test.json - name: annotate go tests @@ -48,12 +47,12 @@ jobs: CONNECTOR_PRINCIPAL_TYPE: 'user' CONNECTOR_PRINCIPAL: '257' steps: + - name: Checkout code + uses: actions/checkout@v4 - name: Install Go uses: actions/setup-go@v5 with: - go-version: 1.24.x - - name: Checkout code - uses: actions/checkout@v4 + go-version-file: go.mod - name: Run Docker Compose as a Daemon (to start sql server) run: docker compose -f ./docker-compose.yml up --detach - name: Install baton diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index a248aa79..b74817e3 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -7,31 +7,30 @@ jobs: go-lint: runs-on: ubuntu-latest steps: + - name: Checkout code + uses: actions/checkout@v3 - name: Install Go uses: actions/setup-go@v5 with: - go-version: 1.24.x - - name: Checkout code - uses: actions/checkout@v3 + go-version-file: go.mod - name: Run linters - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v9 with: - version: latest + version: v2.15.0 args: --timeout=3m go-test: strategy: matrix: - go-version: [1.24.x] platform: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: + - name: Checkout code + uses: actions/checkout@v3 - name: Install Go if: success() uses: actions/setup-go@v5 with: - go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v3 + go-version-file: go.mod - name: go tests run: go test -v -covermode=count -json ./... > test.json - name: annotate go tests diff --git a/.golangci.yml b/.golangci.yml index f19f7f12..38018708 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,96 +1,116 @@ -#AUTO GENERATED CODE. UPDATE THE CONFIG IN BATON-TEMPLATE FIRST -linters-settings: - exhaustive: - default-signifies-exhaustive: true - gocritic: - enabled-checks: - - ruleguard - # The list of supported checkers can be find in https://go-critic.github.io/overview. - settings: - underef: - # Whether to skip (*x).method() calls where x is a pointer receiver. - skipRecvDeref: false - ruleguard: - rules: "${configDir}/tools/rules.go" - govet: - enable-all: true - disable: - - fieldalignment # too strict - - shadow # complains too much about shadowing errors. All research points to this being fine. - nakedret: - max-func-lines: 0 - nolintlint: - allow-no-explanation: [forbidigo, tracecheck, gomnd, gochecknoinits, makezero] - require-explanation: true - require-specific: true - revive: - ignore-generated-header: true - severity: error - rules: - - name: atomic - - name: line-length-limit - arguments: [200] - # These are functions that we use without checking the errors often. Most of these can't return an error even - # though they implement an interface that can. - - name: unhandled-error - arguments: - - fmt.Printf - - fmt.Println - - fmt.Fprint - - fmt.Fprintf - - fmt.Fprintln - - os.Stderr.Sync - - sb.WriteString - - buf.WriteString - - hasher.Write - - os.Setenv - - os.RemoveAll - - name: var-naming - arguments: [["ID", "URL", "HTTP", "API"], []] - tenv: - all: true +version: "2" linters: - disable-all: true + default: none enable: - - errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases - - gosimple # Linter for Go source code that specializes in simplifying a code - - govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string - - ineffassign # Detects when assignments to existing variables are not used - - staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks - - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code - - unused # Checks Go code for unused constants, variables, functions and types - - asasalint # Check for pass []any as any in variadic func(...any) - - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers - - bidichk # Checks for dangerous unicode character sequences - - bodyclose # checks whether HTTP response body is closed successfully - - durationcheck # check for two durations multiplied together - - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. - - exhaustive # check exhaustiveness of enum switch statements - - forbidigo # Forbids identifiers - - gochecknoinits # Checks that no init functions are present in Go code - - goconst # Finds repeated strings that could be replaced by a constant - - gocritic # Provides diagnostics that check for bugs, performance and style issues. - - godot # Check if comments end in a period - - goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. - - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. - - goprintffuncname # Checks that printf-like functions are named with f at the end - - gosec # Inspects source code for security problems - - nakedret # Finds naked returns in functions greater than a specified function length - - nilerr # Finds the code that returns nil even if it checks that the error is not nil. - - noctx # noctx finds sending http request without context.Context - - nolintlint # Reports ill-formed or insufficient nolint directives - - nonamedreturns # Reports all named returns - - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. - - predeclared # find code that shadows one of Go's predeclared identifiers - - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. - - tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 - - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes - - unconvert # Remove unnecessary type conversions - - usestdlibvars # detect the possibility to use variables/constants from the Go standard library - - whitespace # Tool for detection of leading and trailing whitespace + - asasalint + - asciicheck + - bidichk + - bodyclose + - durationcheck + - errcheck + - errorlint + - exhaustive + - forbidigo + - gochecknoinits + - goconst + - gocritic + - godot + - gomoddirectives + - goprintffuncname + - gosec + - govet + - ineffassign + - nakedret + - nilerr + - noctx + - nolintlint + - nonamedreturns + - nosprintfhostport + - predeclared + - revive + - staticcheck + - tparallel + - unconvert + - unused + - usestdlibvars + - whitespace + settings: + exhaustive: + default-signifies-exhaustive: true + gocritic: + enabled-checks: + - ruleguard + settings: + ruleguard: + rules: ${base-path}/tools/rules.go + underef: + skipRecvDeref: false + govet: + disable: + - fieldalignment + - shadow + enable-all: true + nakedret: + max-func-lines: 0 + nolintlint: + require-explanation: true + require-specific: true + allow-no-explanation: + - forbidigo + - tracecheck + - gomnd + - gochecknoinits + - makezero + revive: + severity: error + rules: + - name: atomic + - name: line-length-limit + arguments: + - 200 + - name: unhandled-error + arguments: + - fmt.Printf + - fmt.Println + - fmt.Fprint + - fmt.Fprintf + - fmt.Fprintln + - os.Stderr.Sync + - sb.WriteString + - buf.WriteString + - hasher.Write + - os.Setenv + - os.RemoveAll + - name: var-naming + arguments: + - - ID + - URL + - HTTP + - API + - [] + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - godot + source: (TODO) + paths: + - third_party$ + - builtin$ + - examples$ issues: max-same-issues: 50 - exclude-rules: - # Don't require TODO comments to end in a period - - source: "(TODO)" - linters: [godot] +formatters: + enable: + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/go.mod b/go.mod index addc56fa..8db13522 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/conductorone/baton-sql-server -go 1.26.0 - -toolchain go1.26.9 +go 1.27.3 require ( github.com/conductorone/baton-sdk v0.2.99 From 558ac646ee379c1c917f322547c1a0274a77f34d Mon Sep 17 00:00:00 2001 From: Olivia Haven Date: Wed, 21 Oct 2026 22:16:08 +0000 Subject: [PATCH 2/2] Fix lint findings surfaced by golangci-lint v2 Co-Authored-By: Claude Opus 5.5 Co-authored-by: c1-squire-dev[bot] --- .golangci.yml | 3 +++ pkg/connector/connector.go | 7 ++++++- pkg/connector/database_role.go | 9 ++++----- pkg/connector/server_role.go | 4 ++-- pkg/connector/server_user.go | 8 ++++---- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 38018708..5fd17d68 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -99,6 +99,9 @@ linters: - linters: - godot source: (TODO) + - linters: + - goconst + path: _test\.go paths: - third_party$ - builtin$ diff --git a/pkg/connector/connector.go b/pkg/connector/connector.go index 072f7f68..d28b72fd 100644 --- a/pkg/connector/connector.go +++ b/pkg/connector/connector.go @@ -11,6 +11,11 @@ import ( "github.com/conductorone/baton-sql-server/pkg/mssqldb" ) +const ( + profileKeyUsername = "username" + resourceTypeIDInit = "init" +) + type Mssqldb struct { client *mssqldb.Client } @@ -57,7 +62,7 @@ func (o *Mssqldb) Metadata(ctx context.Context) (*v2.ConnectorMetadata, error) { Placeholder: "DOMAIN", Order: 2, }, - "username": { + profileKeyUsername: { DisplayName: "Username", Required: true, Description: "The username for which to create a SQL Server login.", diff --git a/pkg/connector/database_role.go b/pkg/connector/database_role.go index b10089e7..53b7c51f 100644 --- a/pkg/connector/database_role.go +++ b/pkg/connector/database_role.go @@ -14,7 +14,6 @@ import ( "github.com/conductorone/baton-sdk/pkg/pagination" enTypes "github.com/conductorone/baton-sdk/pkg/types/entitlement" grTypes "github.com/conductorone/baton-sdk/pkg/types/grant" - "github.com/conductorone/baton-sdk/pkg/types/resource" sdkResources "github.com/conductorone/baton-sdk/pkg/types/resource" "github.com/conductorone/baton-sql-server/pkg/mssqldb" "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap" @@ -55,12 +54,12 @@ func (d *databaseRolePrincipalSyncer) List(ctx context.Context, parentResourceID var ret []*v2.Resource for _, principalModel := range principals { - r, err := resource.NewRoleResource( + r, err := sdkResources.NewRoleResource( fmt.Sprintf("%s (%s)", principalModel.Name, db.Name), d.ResourceType(ctx), fmt.Sprintf("%s:%d", db.Name, principalModel.ID), nil, - resource.WithParentResourceID(parentResourceID), + sdkResources.WithParentResourceID(parentResourceID), ) if err != nil { return nil, "", nil, err @@ -99,7 +98,7 @@ func (d *databaseRolePrincipalSyncer) loadGrantPaging(token *pagination.Token) ( if b.Current() == nil { b.Push(pagination.PageState{ - ResourceTypeID: "init", + ResourceTypeID: resourceTypeIDInit, }) } @@ -144,7 +143,7 @@ func (d *databaseRolePrincipalSyncer) Grants( } switch b.ResourceTypeID() { - case "init": + case resourceTypeIDInit: b.Pop() b.Push(pagination.PageState{ ResourceTypeID: resourceTypeDatabaseRole.Id, diff --git a/pkg/connector/server_role.go b/pkg/connector/server_role.go index bda2ecde..2580ed80 100644 --- a/pkg/connector/server_role.go +++ b/pkg/connector/server_role.go @@ -93,7 +93,7 @@ func (d *serverRolePrincipalSyncer) loadGrantPaging(token *pagination.Token) (*p if b.Current() == nil { b.Push(pagination.PageState{ - ResourceTypeID: "init", + ResourceTypeID: resourceTypeIDInit, }) } @@ -134,7 +134,7 @@ func (d *serverRolePrincipalSyncer) Grants(ctx context.Context, resource *v2.Res } switch b.ResourceTypeID() { - case "init": + case resourceTypeIDInit: b.Pop() b.Push(pagination.PageState{ ResourceTypeID: resourceTypeServerRole.Id, diff --git a/pkg/connector/server_user.go b/pkg/connector/server_user.go index a3cf59d5..57726c6d 100644 --- a/pkg/connector/server_user.go +++ b/pkg/connector/server_user.go @@ -111,7 +111,7 @@ func (d *userPrincipalSyncer) CreateAccount( loginType := mssqldb.LoginType(loginTypeStr) // Extract required username field from profile - usernameVal := accountInfo.Profile.GetFields()["username"] + usernameVal := accountInfo.Profile.GetFields()[profileKeyUsername] if usernameVal == nil || usernameVal.GetStringValue() == "" { return nil, nil, nil, fmt.Errorf("missing required username field") } @@ -141,9 +141,9 @@ func (d *userPrincipalSyncer) CreateAccount( // Create a resource for the newly created login profile := map[string]interface{}{ - "username": username, - "login_type": string(loginType), - "formatted_login": formattedUsername, + profileKeyUsername: username, + "login_type": string(loginType), + "formatted_login": formattedUsername, } // Add domain if it exists (for Windows auth)