diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index 4ea479c6ef..fcbc2276d8 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -547,23 +547,25 @@ jobs: cukes_platform_report.log retention-days: 1 - # test latest otdfctl CLI 'main' against platform PR branch + # test otdfctl CLI e2e against platform PR branch otdfctl-test: permissions: contents: read name: otdfctl e2e tests runs-on: ubuntu-latest steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + fetch-depth: 0 + persist-credentials: false - name: Install GNU parallel run: | sudo apt update sudo apt install -y parallel - - uses: opentdf/platform/test/start-up-with-containers@main + - uses: ./test/start-up-with-containers with: platform-ref: ${{ github.event.pull_request.head.sha || github.sha }} - - uses: opentdf/otdfctl/e2e@main - with: - otdfctl-ref: "main" + - uses: ./otdfctl/e2e env: TESTRAIL_USER: ${{ secrets.TESTRAIL_USER }} TESTRAIL_PASS: ${{ secrets.TESTRAIL_PASS }} diff --git a/.github/workflows/nightly-checks.yaml b/.github/workflows/nightly-checks.yaml index 03e9345712..07b0149304 100644 --- a/.github/workflows/nightly-checks.yaml +++ b/.github/workflows/nightly-checks.yaml @@ -27,6 +27,7 @@ jobs: check-latest: false cache-dependency-path: | platform/examples/go.sum + platform/otdfctl/go.sum platform/protocol/go/go.sum platform/sdk/go.sum platform/service/go.sum @@ -60,18 +61,11 @@ jobs: wait-for: 90s working-directory: platform - ######## CHECKOUT/BUILD 'otdfctl' ############# - - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - with: - repository: opentdf/otdfctl - ref: main - fetch-depth: 0 - path: otdfctl - persist-credentials: false - - run: go build -o otdfctl - working-directory: otdfctl - - run: cp otdfctl ../platform - working-directory: otdfctl + ######## BUILD 'otdfctl' (now part of platform monorepo) ############# + - run: go build -o otdfctl . + working-directory: platform/otdfctl + - run: cp otdfctl ../ + working-directory: platform/otdfctl ######## RUN TESTS ############# - run: ./.github/scripts/connectivity-test.sh diff --git a/.golangci.yaml b/.golangci.yaml index 19cdbd1217..9513d465d3 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -186,9 +186,31 @@ linters: - linters: - goimport text: http://www.apache.org/licenses/LICENSE-2.0 + # otdfctl: defer refactoring-level lint fixes to follow-up + - path: otdfctl/ + linters: + - contextcheck + text: should pass the context parameter + - path: otdfctl/ + linters: + - revive + text: unused-parameter + - path: otdfctl/ + linters: + - revive + text: unexported-return + - path: otdfctl/ + linters: + - revive + text: var-naming + - path: otdfctl/ + linters: + - nolintlint + text: "exhaustive" paths: - .*\.pb\.go - .*\.pb\.gw.go + - otdfctl/tui/ # excluded during migration, matching original otdfctl lint config - third_party$ - builtin$ - examples$ @@ -204,6 +226,7 @@ formatters: paths: - .*\.pb\.go - .*\.pb\.gw.go + - otdfctl/tui/ - third_party$ - builtin$ - examples$ diff --git a/otdfctl/cmd/common/common.go b/otdfctl/cmd/common/common.go index 431d06c0dc..f3532c1387 100644 --- a/otdfctl/cmd/common/common.go +++ b/otdfctl/cmd/common/common.go @@ -43,10 +43,12 @@ func InitProfile(c *cli.Cli) *profiles.OtdfctlProfileStore { hasKeyringStore, err := osprofiles.HasGlobalStore(config.AppName, osprofiles.WithKeyringStore()) if err != nil { - slog.Warn("Could not determine whether any profiles were stored on the keyring, defaulting to filesystem.", "error", err) + slog.Warn("could not determine whether any profiles were stored on the keyring, defaulting to filesystem", + slog.Any("error", err), + ) } if hasKeyringStore { - slog.Debug("Keyring store still active, migrating profiles to filesystem.") + slog.Debug("keyring store still active, migrating profiles to filesystem") err := profiles.Migrate(profiles.ProfileDriverFileSystem, profiles.ProfileDriverKeyring) if err != nil { cli.ExitWithError(fmt.Sprintf("Error during profile migration from %s, to %s. %s cannot continue with profiles being stored within %s, please use the `profile migrate` command to manually migrate profiles", profiles.ProfileDriverKeyring, profiles.ProfileDriverFileSystem, config.AppName, profiles.ProfileDriverKeyring), err) @@ -67,12 +69,12 @@ func InitProfile(c *cli.Cli) *profiles.OtdfctlProfileStore { profileName = defaultProfileName } - slog.Debug("Using profile", "profile", profileName) + slog.Debug("using profile", slog.String("profile", profileName)) // load profile store, err := profiles.LoadOtdfctlProfileStore(profiles.ProfileDriverFileSystem, profileName) if err != nil { - c.ExitWithError(fmt.Sprintf("Failed to load profile: %s", profileName), err) + c.ExitWithError("Failed to load profile: "+profileName, err) } applyOutputFormatPreference(c, store) diff --git a/otdfctl/cmd/execute.go b/otdfctl/cmd/execute.go index d76380c263..32dc8ec7c3 100644 --- a/otdfctl/cmd/execute.go +++ b/otdfctl/cmd/execute.go @@ -1,7 +1,7 @@ package cmd import ( - "fmt" + "errors" "os" "github.com/opentdf/platform/otdfctl/pkg/cli" @@ -52,7 +52,7 @@ func Execute(opts ...ExecuteOptFunc) { func MountRoot(newRoot *cobra.Command, cmd *cobra.Command) error { if newRoot == nil { - return fmt.Errorf("newRoot is nil") + return errors.New("newRoot is nil") } if cmd != nil { diff --git a/otdfctl/cmd/policy/actions.go b/otdfctl/cmd/policy/actions.go index 025e162856..ef4fadf8d1 100644 --- a/otdfctl/cmd/policy/actions.go +++ b/otdfctl/cmd/policy/actions.go @@ -26,9 +26,9 @@ func policyGetAction(cmd *cobra.Command, args []string) { action, err := h.GetAction(cmd.Context(), id, name, namespace) if err != nil { - identifier := fmt.Sprintf("id: %s", id) + identifier := "id: " + id if id == "" { - identifier = fmt.Sprintf("name: %s", name) + identifier = "name: " + name } errMsg := fmt.Sprintf("Failed to find action (%s)", identifier) cli.ExitWithError(errMsg, err) diff --git a/otdfctl/cmd/policy/attributeValues.go b/otdfctl/cmd/policy/attributeValues.go index f934c39acb..b4b626476f 100644 --- a/otdfctl/cmd/policy/attributeValues.go +++ b/otdfctl/cmd/policy/attributeValues.go @@ -78,7 +78,7 @@ func filterValuesByState(values []*policy.Value, state policycommon.ActiveStateE func paginateValues(values []*policy.Value, limit, offset int32) ([]*policy.Value, *policy.PageResponse) { total := len(values) pagination := &policy.PageResponse{ - Total: int32(min(total, math.MaxInt32)), //nolint:gosec // bounded by min + Total: int32(min(total, math.MaxInt32)), CurrentOffset: offset, } diff --git a/otdfctl/cmd/policy/kasKeys.go b/otdfctl/cmd/policy/kasKeys.go index 9e7dd7fc74..5c1c408b62 100644 --- a/otdfctl/cmd/policy/kasKeys.go +++ b/otdfctl/cmd/policy/kasKeys.go @@ -781,7 +781,7 @@ func policyUnsafeDeleteKasKey(cmd *cobra.Command, args []string) { kasURI := c.Flags.GetRequiredString("kas-uri") force := c.Flags.GetOptionalBool("force") - cli.ConfirmAction(cli.ActionDelete, fmt.Sprintf("key with kas uri: %s, and key identifier: %s", kasURI, kid), fmt.Sprintf("Id: %s", id), force) + cli.ConfirmAction(cli.ActionDelete, "key with kas uri: "+kasURI+", and key identifier: "+kid, "Id: "+id, force) key, err := h.UnsafeDeleteKasKey(ctx, id, kid, kasURI) if err != nil { diff --git a/otdfctl/cmd/policy/kasRegistry.go b/otdfctl/cmd/policy/kasRegistry.go index ca56298409..006c9fecab 100644 --- a/otdfctl/cmd/policy/kasRegistry.go +++ b/otdfctl/cmd/policy/kasRegistry.go @@ -12,9 +12,7 @@ import ( "github.com/spf13/cobra" ) -var ( - KasRegistryCmd = man.Docs.GetCommand("policy/kas-registry") -) +var KasRegistryCmd = man.Docs.GetCommand("policy/kas-registry") func getKeyAccessRegistry(cmd *cobra.Command, args []string) { c := cli.New(cmd, args) @@ -77,7 +75,7 @@ func listKeyAccessRegistries(cmd *cobra.Command, args []string) { ) rows := []table.Row{} for _, kas := range resp.GetKeyAccessServers() { - //TODO: Remove in next release + // TODO: Remove in next release key := policy.PublicKey{} key.PublicKey = &policy.PublicKey_Cached{Cached: kas.GetPublicKey().GetCached()} if kas.GetPublicKey().GetRemote() != "" { diff --git a/otdfctl/cmd/policy/keyManagementProvider.go b/otdfctl/cmd/policy/keyManagementProvider.go index 1c9d265c8f..55b31f8d94 100644 --- a/otdfctl/cmd/policy/keyManagementProvider.go +++ b/otdfctl/cmd/policy/keyManagementProvider.go @@ -1,8 +1,6 @@ package policy import ( - "fmt" - "github.com/evertras/bubble-table/table" "github.com/opentdf/platform/otdfctl/cmd/common" "github.com/opentdf/platform/otdfctl/pkg/cli" @@ -163,7 +161,7 @@ func deleteProviderConfig(cmd *cobra.Command, args []string) { cli.ExitWithError("Failed to get provider config", err) } - cli.ConfirmAction(cli.ActionDelete, fmt.Sprintf("key provider config with id: %s", id), fmt.Sprintf("Provider Name: %s", pc.GetName()), force) + cli.ConfirmAction(cli.ActionDelete, "key provider config with id: "+id, "Provider Name: "+pc.GetName(), force) err = h.DeleteProviderConfig(c.Context(), id) if err != nil { diff --git a/otdfctl/cmd/policy/obligations.go b/otdfctl/cmd/policy/obligations.go index bf67c469bc..3d4e0b1148 100644 --- a/otdfctl/cmd/policy/obligations.go +++ b/otdfctl/cmd/policy/obligations.go @@ -3,9 +3,8 @@ package policy import ( "encoding/json" "fmt" - "strings" - "strconv" + "strings" "github.com/evertras/bubble-table/table" "github.com/opentdf/platform/otdfctl/cmd/common" @@ -69,11 +68,11 @@ func policyGetObligation(cmd *cobra.Command, args []string) { obl, err := h.GetObligation(cmd.Context(), id, fqn) if err != nil { - identifier := fmt.Sprintf("id: %s", id) + identifier := "id: " + id if id == "" { - identifier = fmt.Sprintf("fqn: %s", fqn) + identifier = "fqn: " + fqn } - errMsg := fmt.Sprintf("Failed to find obligation (%s)", identifier) + errMsg := "Failed to find obligation (" + identifier + ")" cli.ExitWithError(errMsg, err) } @@ -248,11 +247,11 @@ func policyGetObligationValue(cmd *cobra.Command, args []string) { value, err := h.GetObligationValue(cmd.Context(), id, fqn) if err != nil { - identifier := fmt.Sprintf("id: %s", id) + identifier := "id: " + id if id == "" { - identifier = fmt.Sprintf("fqn: %s", fqn) + identifier = "fqn: " + fqn } - errMsg := fmt.Sprintf("Failed to find obligation value (%s)", identifier) + errMsg := "Failed to find obligation value (" + identifier + ")" cli.ExitWithError(errMsg, err) } diff --git a/otdfctl/cmd/policy/policy.go b/otdfctl/cmd/policy/policy.go index 3c426a5e9b..28d2ab5e31 100644 --- a/otdfctl/cmd/policy/policy.go +++ b/otdfctl/cmd/policy/policy.go @@ -12,7 +12,7 @@ import ( var ( metadataLabels []string defaultListFlagLimit int32 = 300 - defaultListFlagOffset int32 = 0 + defaultListFlagOffset int32 Cmd = &cobra.Command{ Use: man.Docs.GetDoc("policy").Use, diff --git a/otdfctl/cmd/policy/registeredResources.go b/otdfctl/cmd/policy/registeredResources.go index bec293b828..e33cf7cd04 100644 --- a/otdfctl/cmd/policy/registeredResources.go +++ b/otdfctl/cmd/policy/registeredResources.go @@ -71,11 +71,11 @@ func policyGetRegisteredResource(cmd *cobra.Command, args []string) { resource, err := h.GetRegisteredResource(cmd.Context(), id, name, namespace) if err != nil { - identifier := fmt.Sprintf("id: %s", id) + identifier := "id: " + id if id == "" { - identifier = fmt.Sprintf("name: %s", name) + identifier = "name: " + name } - errMsg := fmt.Sprintf("Failed to find registered resource (%s)", identifier) + errMsg := "Failed to find registered resource (" + identifier + ")" cli.ExitWithError(errMsg, err) } @@ -263,11 +263,11 @@ func policyGetRegisteredResourceValue(cmd *cobra.Command, args []string) { value, err := h.GetRegisteredResourceValue(cmd.Context(), id, fqn) if err != nil { - identifier := fmt.Sprintf("id: %s", id) + identifier := "id: " + id if id == "" { - identifier = fmt.Sprintf("fqn: %s", fqn) + identifier = "fqn: " + fqn } - errMsg := fmt.Sprintf("Failed to find registered resource value (%s)", identifier) + errMsg := "Failed to find registered resource value (" + identifier + ")" cli.ExitWithError(errMsg, err) } diff --git a/otdfctl/cmd/policy/resourceMappingGroups.go b/otdfctl/cmd/policy/resourceMappingGroups.go index 1adaec65bf..1df8815da2 100644 --- a/otdfctl/cmd/policy/resourceMappingGroups.go +++ b/otdfctl/cmd/policy/resourceMappingGroups.go @@ -10,9 +10,7 @@ import ( "github.com/spf13/cobra" ) -var ( - policyResourceMappingGroupsCmd *cobra.Command -) +var policyResourceMappingGroupsCmd *cobra.Command func policyCreateResourceMappingGroup(cmd *cobra.Command, args []string) { c := cli.New(cmd, args) diff --git a/otdfctl/cmd/policy/resourceMappings.go b/otdfctl/cmd/policy/resourceMappings.go index 0ea277b32a..57a0ba2fde 100644 --- a/otdfctl/cmd/policy/resourceMappings.go +++ b/otdfctl/cmd/policy/resourceMappings.go @@ -1,7 +1,7 @@ package policy import ( - _ "embed" + _ "embed" // required for go:embed directives "fmt" "strings" diff --git a/otdfctl/cmd/policy/subjectConditionSets.go b/otdfctl/cmd/policy/subjectConditionSets.go index 8fa25f1b4d..d117ce7e72 100644 --- a/otdfctl/cmd/policy/subjectConditionSets.go +++ b/otdfctl/cmd/policy/subjectConditionSets.go @@ -71,13 +71,13 @@ func createSubjectConditionSet(cmd *cobra.Command, args []string) { if ssFileJSON != "" { jsonFile, err := os.Open(ssFileJSON) if err != nil { - cli.ExitWithError(fmt.Sprintf("Failed to open file at path: %s", ssFileJSON), err) + cli.ExitWithError("Failed to open file at path: "+ssFileJSON, err) } defer jsonFile.Close() bytes, err := io.ReadAll(jsonFile) if err != nil { - cli.ExitWithError(fmt.Sprintf("Failed to read bytes from file at path: %s", ssFileJSON), err) + cli.ExitWithError("Failed to read bytes from file at path: "+ssFileJSON, err) } ssBytes = bytes } else { @@ -208,13 +208,13 @@ func updateSubjectConditionSet(cmd *cobra.Command, args []string) { if ssFileJSON != "" { jsonFile, err := os.Open(ssFileJSON) if err != nil { - cli.ExitWithError(fmt.Sprintf("Failed to open file at path: %s", ssFileJSON), err) + cli.ExitWithError("Failed to open file at path: "+ssFileJSON, err) } defer jsonFile.Close() bytes, err := io.ReadAll(jsonFile) if err != nil { - cli.ExitWithError(fmt.Sprintf("Failed to read bytes from file at path: %s", ssFileJSON), err) + cli.ExitWithError("Failed to read bytes from file at path: "+ssFileJSON, err) } ssBytes = bytes } else { diff --git a/otdfctl/cmd/profile.go b/otdfctl/cmd/profile.go index 901b14a87f..5ee92a3293 100644 --- a/otdfctl/cmd/profile.go +++ b/otdfctl/cmd/profile.go @@ -102,14 +102,14 @@ var profileListCmd = &cobra.Command{ defaultProfile := globalCfg.GetDefaultProfile() var sb strings.Builder - sb.WriteString(fmt.Sprintf("Listing profiles from %s\n", driverType)) + fmt.Fprintf(&sb, "Listing profiles from %s\n", driverType) for _, p := range osprofiles.ListProfiles(profiler) { if p == defaultProfile { - sb.WriteString(fmt.Sprintf("* %s\n", p)) + fmt.Fprintf(&sb, "* %s\n", p) continue } - sb.WriteString(fmt.Sprintf(" %s\n", p)) + fmt.Fprintf(&sb, " %s\n", p) } c.ExitWithMessage(sb.String(), cli.ExitCodeSuccess) @@ -127,7 +127,7 @@ var profileGetCmd = &cobra.Command{ driverType := getDriverTypeFromUser(c) profileStore, err := profiles.LoadOtdfctlProfileStore(driverType, profileName) if err != nil { - cli.ExitWithError(fmt.Sprintf("Error loading profile store for profile %s", profileName), err) + cli.ExitWithError("Error loading profile store for profile "+profileName, err) } isDefault := "false" diff --git a/otdfctl/cmd/root.go b/otdfctl/cmd/root.go index 9739473a4d..e4256759e5 100644 --- a/otdfctl/cmd/root.go +++ b/otdfctl/cmd/root.go @@ -48,7 +48,12 @@ func init() { } version := fmt.Sprintf("%s version %s (%s) %s", config.AppName, config.Version, config.BuildTime, config.CommitSha) - slog.Debug(version) + slog.Debug("otdfctl version", + slog.String("app", config.AppName), + slog.String("version", config.Version), + slog.String("build_time", config.BuildTime), + slog.String("commit_sha", config.CommitSha), + ) c.ExitWith(version, v, cli.ExitCodeSuccess, os.Stdout) return } diff --git a/otdfctl/cmd/tdf/encrypt.go b/otdfctl/cmd/tdf/encrypt.go index fa40c1d187..3935825f28 100644 --- a/otdfctl/cmd/tdf/encrypt.go +++ b/otdfctl/cmd/tdf/encrypt.go @@ -1,7 +1,6 @@ package tdf import ( - "fmt" "io" "log/slog" "os" @@ -89,7 +88,7 @@ func encryptRun(cmd *cobra.Command, args []string) { // auto-detect mime type if not provided if fileMimeType == "" { - slog.Debug("Detecting mime type of file") + slog.Debug("detecting mime type of file") // get the mime type of the file mimetype.SetLimit(Size1MB) // limit to 1MB m := mimetype.Detect(bytesSlice) @@ -102,9 +101,9 @@ func encryptRun(cmd *cobra.Command, args []string) { } } } - slog.Debug("Encrypting file", - slog.Int("file-len", len(bytesSlice)), - slog.String("mime-type", fileMimeType), + slog.Debug("encrypting file", + slog.Int("file_len", len(bytesSlice)), + slog.String("mime_type", fileMimeType), ) // Do the encryption @@ -131,7 +130,7 @@ func encryptRun(cmd *cobra.Command, args []string) { } tdfFile, err := os.Create(out) if err != nil { - cli.ExitWithError(fmt.Sprintf("Failed to write encrypted file %s", out), err) + cli.ExitWithError("Failed to write encrypted file "+out, err) } defer tdfFile.Close() dest = tdfFile diff --git a/otdfctl/e2e/action.yaml b/otdfctl/e2e/action.yaml index 7f6c0042c1..45b9450f16 100644 --- a/otdfctl/e2e/action.yaml +++ b/otdfctl/e2e/action.yaml @@ -1,10 +1,6 @@ name: 'end-to-end' description: 'Run end-to-end tests for the otdfctl CLI' inputs: - otdfctl-ref: - required: false - description: 'The ref to check out for the otdfctl CLI' - default: 'main' testrail-run-name-for-cli-test: required: false description: 'The name to use for the TestRail test run created for the CLI tests' @@ -13,17 +9,9 @@ inputs: runs: using: 'composite' steps: - - name: Check out otdfctl CLI - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - with: - repository: opentdf/otdfctl - ref: ${{ inputs.otdfctl-ref }} - path: otdfctl - # Build the CLI and run tests - - name: Set up go (CLI version, if needed) - if: steps.setup-go.outcome != 'success' - uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 + - name: Set up Go + uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0 with: go-version-file: otdfctl/go.mod - name: Build the CLI @@ -38,10 +26,9 @@ runs: shell: bash working-directory: otdfctl run: | - git fetch --tags origin v0.26.2 - git worktree add ../otdfctl_v0.26.2 v0.26.2 + git worktree add ../otdfctl_v0.26.2 otdfctl/v0.26.2 cd ../otdfctl_v0.26.2 - go build -o ../otdfctl/otdfctl_v0.26.2 . + GOWORK=off go build -o ../otdfctl/otdfctl_v0.26.2 . echo "LEGACY_OTDFCTL_BIN=./otdfctl_v0.26.2" >> $GITHUB_ENV - name: Install keyring dependencies shell: bash diff --git a/otdfctl/migrations/registered-resources.go b/otdfctl/migrations/registered-resources.go index 73c423e1da..413310dc8d 100644 --- a/otdfctl/migrations/registered-resources.go +++ b/otdfctl/migrations/registered-resources.go @@ -134,7 +134,7 @@ func (p *HuhPrompter) ConfirmResourceNamespace(resourceName, detectedNamespaceFQ huh.NewSelect[string](). Title(fmt.Sprintf("Resource '%s' belongs in namespace '%s' (detected from AAVs):", resourceName, detectedNamespaceFQN)). Options( - huh.NewOption(fmt.Sprintf("Confirm: %s", detectedNamespaceFQN), detectedNamespaceFQN), + huh.NewOption("Confirm: "+detectedNamespaceFQN, detectedNamespaceFQN), huh.NewOption("Skip this resource", optSkipResource), huh.NewOption("Abort entire migration", optAbortAll), ). @@ -557,7 +557,7 @@ func runBatchRegisteredResourceMigration(ctx context.Context, h MigrationHandler fmt.Println(styles.styleWarning.Render(errMsg)) failedResources[p.Resource.GetId()] = err.Error() } else { - fmt.Println(styles.styleAction.Render(fmt.Sprintf(" Successfully migrated resource %s", p.Resource.GetName()))) + fmt.Println(styles.styleAction.Render(" Successfully migrated resource " + p.Resource.GetName())) successCount++ } } @@ -734,7 +734,7 @@ func runInteractiveRegisteredResourceMigration(ctx context.Context, h MigrationH fmt.Println(styles.styleWarning.Render(errMsg)) failedResources[p.Resource.GetId()] = err.Error() } else { - fmt.Println(styles.styleAction.Render(fmt.Sprintf(" Successfully migrated resource %s", p.Resource.GetName()))) + fmt.Println(styles.styleAction.Render(" Successfully migrated resource " + p.Resource.GetName())) successCount++ } } diff --git a/otdfctl/migrations/registered-resources_test.go b/otdfctl/migrations/registered-resources_test.go index 4246e8ded4..bd6725938c 100644 --- a/otdfctl/migrations/registered-resources_test.go +++ b/otdfctl/migrations/registered-resources_test.go @@ -447,7 +447,7 @@ func TestRunBatchRegisteredResourceMigration(t *testing.T) { t.Run("reports partial failure", func(t *testing.T) { handler := &MockMigrationHandler{ - CreateResourceErr: fmt.Errorf("create failed"), + CreateResourceErr: errors.New("create failed"), } prompter := &MockMigrationPrompter{ BatchNamespaceResponse: "https://example.com", @@ -880,7 +880,7 @@ func TestCommitRegisteredResourceMigration(t *testing.T) { t.Run("returns error when create fails", func(t *testing.T) { mock := &MockMigrationHandler{ - CreateResourceErr: fmt.Errorf("create failed"), + CreateResourceErr: errors.New("create failed"), } plan := RegisteredResourceMigrationPlan{ @@ -902,7 +902,7 @@ func TestCommitRegisteredResourceMigration(t *testing.T) { t.Run("returns error when delete fails", func(t *testing.T) { mock := &MockMigrationHandler{ - DeleteResourceErr: fmt.Errorf("delete failed"), + DeleteResourceErr: errors.New("delete failed"), } plan := RegisteredResourceMigrationPlan{ diff --git a/otdfctl/pkg/auth/auth.go b/otdfctl/pkg/auth/auth.go index e8bdc63140..bd505d88ab 100644 --- a/otdfctl/pkg/auth/auth.go +++ b/otdfctl/pkg/auth/auth.go @@ -29,7 +29,7 @@ const authCallbackPath = "/callback" type ClientCredentials struct { ClientID string `json:"clientId"` - ClientSecret string `json:"clientSecret"` //nolint:gosec // not a hard-coded secret; populated at runtime + ClientSecret string `json:"clientSecret"` Scopes []string `json:"scopes,omitempty"` } @@ -250,7 +250,7 @@ func GetFreePort(ctx context.Context) (int, error) { // Get the address information from the listener addr, ok := listener.Addr().(*net.TCPAddr) if !ok { - return 0, fmt.Errorf("failed to get TCP address from listener") + return 0, errors.New("failed to get TCP address from listener") } // Return the port that was assigned diff --git a/otdfctl/pkg/cli/confirm.go b/otdfctl/pkg/cli/confirm.go index 0724bd70f0..36dc46048a 100644 --- a/otdfctl/pkg/cli/confirm.go +++ b/otdfctl/pkg/cli/confirm.go @@ -31,7 +31,7 @@ func ConfirmActionSubtext(action, resource, id, subtext string, force bool) { if subtext != "" { // since we don't return an error to stay consistent with the original function, // only append the subtext if populated - title += fmt.Sprintf("\n\n%s", subtext) + title += "\n\n" + subtext } err := huh.NewConfirm(). Title(title). diff --git a/otdfctl/pkg/cli/pipe.go b/otdfctl/pkg/cli/pipe.go index 922399afed..561c8ff19f 100644 --- a/otdfctl/pkg/cli/pipe.go +++ b/otdfctl/pkg/cli/pipe.go @@ -1,7 +1,6 @@ package cli import ( - "fmt" "io" "os" ) @@ -9,12 +8,11 @@ import ( func ReadFromArgsOrPipe(args []string, pipe *os.File) []byte { if len(args) > 0 { return ReadFromFile(args[0]) - } else { - if pipe == nil { - pipe = os.Stdin - } - return ReadFromPipe(pipe) } + if pipe == nil { + pipe = os.Stdin + } + return ReadFromPipe(pipe) } func ReadFromPipe(in *os.File) []byte { @@ -35,13 +33,13 @@ func ReadFromPipe(in *os.File) []byte { func ReadFromFile(filePath string) []byte { fileToEncrypt, err := os.Open(filePath) if err != nil { - ExitWithError(fmt.Sprintf("Failed to git open file at path: %s", filePath), err) + ExitWithError("Failed to git open file at path: "+filePath, err) } defer fileToEncrypt.Close() bytes, err := io.ReadAll(fileToEncrypt) if err != nil { - ExitWithError(fmt.Sprintf("Failed to read bytes from file at path: %s", filePath), err) + ExitWithError("Failed to read bytes from file at path: "+filePath, err) } return bytes } diff --git a/otdfctl/pkg/cli/printer.go b/otdfctl/pkg/cli/printer.go index b7b9900ef7..f630bcbf3e 100644 --- a/otdfctl/pkg/cli/printer.go +++ b/otdfctl/pkg/cli/printer.go @@ -2,11 +2,12 @@ package cli import ( "encoding/json" + "errors" "fmt" "io" ) -var ErrPrinterExpectsCommand = fmt.Errorf("printer expects a command") +var ErrPrinterExpectsCommand = errors.New("printer expects a command") type Printer struct { enabled bool diff --git a/otdfctl/pkg/cli/utils.go b/otdfctl/pkg/cli/utils.go index 11e8d02859..ff7317e2a9 100644 --- a/otdfctl/pkg/cli/utils.go +++ b/otdfctl/pkg/cli/utils.go @@ -36,13 +36,15 @@ func TermWidth() int { } func PrettyList(values []string) string { - var l string + var b strings.Builder for i, v := range values { if i == len(values)-1 { - l += "or " + v + b.WriteString("or ") + b.WriteString(v) } else { - l += v + ", " + b.WriteString(v) + b.WriteString(", ") } } - return l + return b.String() } diff --git a/otdfctl/pkg/handlers/kas-keys.go b/otdfctl/pkg/handlers/kas-keys.go index b2d51e23c7..d18fb66c99 100644 --- a/otdfctl/pkg/handlers/kas-keys.go +++ b/otdfctl/pkg/handlers/kas-keys.go @@ -90,7 +90,8 @@ func (h Handler) ListKasKeys( limit, offset int32, algorithm policy.Algorithm, identifier KasIdentifier, - legacy *bool) (*kasregistry.ListKeysResponse, error) { + legacy *bool, +) (*kasregistry.ListKeysResponse, error) { req := kasregistry.ListKeysRequest{ Pagination: &policy.PageRequest{ Limit: limit, diff --git a/otdfctl/pkg/handlers/provider-config.go b/otdfctl/pkg/handlers/provider-config.go index 0b8a735b85..be25e3d4ed 100644 --- a/otdfctl/pkg/handlers/provider-config.go +++ b/otdfctl/pkg/handlers/provider-config.go @@ -12,7 +12,8 @@ func (h Handler) CreateProviderConfig( ctx context.Context, name, manager string, config []byte, - metadata *common.MetadataMutable) (*policy.KeyProviderConfig, error) { + metadata *common.MetadataMutable, +) (*policy.KeyProviderConfig, error) { req := keymanagement.CreateProviderConfigRequest{ Name: name, Manager: manager, @@ -53,7 +54,8 @@ func (h Handler) UpdateProviderConfig( id, name, manager string, config []byte, metadata *common.MetadataMutable, - behavior common.MetadataUpdateEnum) (*policy.KeyProviderConfig, error) { + behavior common.MetadataUpdateEnum, +) (*policy.KeyProviderConfig, error) { req := keymanagement.UpdateProviderConfigRequest{ Id: id, Name: name, diff --git a/otdfctl/pkg/handlers/tdf.go b/otdfctl/pkg/handlers/tdf.go index 4075cf4d05..d8a5b0d69f 100644 --- a/otdfctl/pkg/handlers/tdf.go +++ b/otdfctl/pkg/handlers/tdf.go @@ -114,7 +114,6 @@ func (h Handler) DecryptBytes( out := &bytes.Buffer{} pt := io.Writer(out) ec := bytes.NewReader(toDecrypt) - //nolint:exhaustive // Only standard TDF is supported; other container types are treated as unknown. switch sdk.GetTdfType(ec) { case sdk.Standard: opts := []sdk.TDFReaderOption{ @@ -164,7 +163,6 @@ func (h Handler) DecryptBytes( func (h Handler) InspectTDF(toInspect []byte) (TDFInspect, []error) { b := bytes.NewReader(toInspect) - //nolint:exhaustive // Only standard TDF is supported; other container types are treated as not inspectable. switch sdk.GetTdfType(b) { case sdk.Standard: // grouping errors so we don't impact the piping of the data @@ -197,7 +195,7 @@ func (h Handler) InspectTDF(toInspect []byte) (TDFInspect, []error) { case sdk.Invalid: return TDFInspect{}, []error{ErrTDFInspectFailNotValidTDF} default: - return TDFInspect{}, []error{fmt.Errorf("tdf format unrecognized")} + return TDFInspect{}, []error{errors.New("tdf format unrecognized")} } } @@ -267,7 +265,9 @@ func formatDecryptError(ctx context.Context, getObligations func(ctx context.Con if errors.Is(err, sdk.ErrRewrapForbidden) { obligations, oblErr := getObligations(ctx) if oblErr != nil { - slog.DebugContext(ctx, "Failed to get obligations after decrypt, obligations must not be cached", "error", oblErr) + slog.DebugContext(ctx, "failed to get obligations after decrypt, obligations must not be cached", + slog.Any("error", oblErr), + ) } if len(obligations.FQNs) > 0 { diff --git a/otdfctl/pkg/man/man.go b/otdfctl/pkg/man/man.go index 7c093b9106..c6d36c53b3 100644 --- a/otdfctl/pkg/man/man.go +++ b/otdfctl/pkg/man/man.go @@ -2,6 +2,7 @@ package man import ( "embed" + "errors" "fmt" "io/fs" "log/slog" @@ -78,7 +79,7 @@ func (m *Manual) SetLang(l string) { case "en", "fr": m.lang = l default: - panic(fmt.Sprintf("Unknown language: %s", l)) + panic("Unknown language: " + l) } } @@ -91,12 +92,15 @@ func (m Manual) GetDoc(cmd string) *Doc { return m.Fr[cmd] } // if no doc found in french, fallback to english - slog.Debug(fmt.Sprintf("No doc found for cmd, %s in %s", cmd, m.lang)) + slog.Debug("no doc found for cmd, falling back to english", + slog.String("cmd", cmd), + slog.String("lang", m.lang), + ) } } if _, ok := m.En[cmd]; !ok { - panic(fmt.Sprintf("No doc found for cmd, %s", cmd)) + panic("No doc found for cmd, " + cmd) } return m.En[cmd] @@ -158,7 +162,10 @@ func ProcessEmbeddedDocs(manFiles embed.FS) { cmd = "" } - slog.Debug("Found doc", slog.String("cmd", cmd), slog.String("lang", lang)) + slog.Debug("found doc", + slog.String("cmd", cmd), + slog.String("lang", lang), + ) c, err := manFiles.ReadFile(path) if err != nil { return fmt.Errorf("could not read file, %s: %s ", path, err.Error()) @@ -169,7 +176,10 @@ func ProcessEmbeddedDocs(manFiles embed.FS) { return fmt.Errorf("could not process doc, %s: %s", path, err.Error()) } - slog.Debug("Adding doc: ", cmd, " ", lang, "\n") + slog.Debug("adding doc", + slog.String("cmd", cmd), + slog.String("lang", lang), + ) switch lang { case "fr": Docs.Fr[cmd] = doc @@ -187,7 +197,7 @@ func ProcessEmbeddedDocs(manFiles embed.FS) { } func init() { - slog.Debug("Loading docs from embed") + slog.Debug("loading docs from embed") Docs = Manual{ Docs: make(map[string]*Doc), En: make(map[string]*Doc), @@ -199,7 +209,7 @@ func init() { func ProcessDoc(doc string) (*Doc, error) { if len(doc) == 0 { - return nil, fmt.Errorf("empty document") + return nil, errors.New("empty document") } var matter struct { Title string `yaml:"title"` @@ -220,7 +230,7 @@ func ProcessDoc(doc string) (*Doc, error) { c := matter.Command if c.Name == "" { - return nil, fmt.Errorf("required 'command' property") + return nil, errors.New("required 'command' property") } long := "# " + matter.Title + "\n\n" + strings.TrimSpace(string(rest)) diff --git a/otdfctl/pkg/profiles/profile.go b/otdfctl/pkg/profiles/profile.go index b1352af813..8fa06cc0b9 100644 --- a/otdfctl/pkg/profiles/profile.go +++ b/otdfctl/pkg/profiles/profile.go @@ -2,7 +2,6 @@ package profiles import ( "errors" - "fmt" "log/slog" "runtime" "strings" @@ -92,7 +91,11 @@ func Migrate(to ProfileDriver, from ProfileDriver) error { defaultProfileBeingMigrated := osprofiles.GetGlobalConfig(fromProfiler).GetDefaultProfile() - slog.Debug("Migrating profiles", slog.Any("count", len(profilesToMigrate)), slog.Any("from", string(from)), slog.Any("to", string(to))) + slog.Debug("migrating profiles", + slog.Any("count", len(profilesToMigrate)), + slog.Any("from", string(from)), + slog.Any("to", string(to)), + ) for _, profileName := range profilesToMigrate { store, err := osprofiles.GetProfile[*ProfileConfig](fromProfiler, profileName) @@ -111,14 +114,20 @@ func Migrate(to ProfileDriver, from ProfileDriver) error { return err } - slog.Debug("Migrated profile", "profile", profileName, "setDefault", setDefault) + slog.Debug("migrated profile", + slog.String("profile", profileName), + slog.Bool("set_default", setDefault), + ) } - slog.Debug(fmt.Sprintf("Removing profiles from %s", string(from)), slog.Any("count", len(profilesToMigrate))) + slog.Debug("removing profiles", + slog.String("from", string(from)), + slog.Any("count", len(profilesToMigrate)), + ) if err = fromProfiler.Cleanup(false); err != nil { return errors.Join(ErrCleaningUpProfiles, err) } - slog.Debug("Migration complete.") + slog.Debug("migration complete") return nil }