From c40ebca99fcae0c7544fa8a610723670d9e145d3 Mon Sep 17 00:00:00 2001 From: Dave Mihalcik Date: Thu, 3 Sep 2026 17:45:03 -0400 Subject: [PATCH] fix(examples): DSPX-4607 clear goconst and SA1019 lint findings Signed-off-by: Dave Mihalcik --- examples/cmd/attributes.go | 6 +++++- examples/cmd/benchmark.go | 4 ++-- examples/cmd/benchmark_bulk.go | 4 ++-- examples/cmd/benchmark_decision.go | 4 ++-- examples/cmd/benchmark_decision_v2.go | 3 +-- examples/cmd/benchmark_experimental.go | 3 +-- examples/cmd/encrypt.go | 2 +- examples/cmd/examples.go | 7 +++++++ 8 files changed, 21 insertions(+), 12 deletions(-) diff --git a/examples/cmd/attributes.go b/examples/cmd/attributes.go index 1648ed240e..cae8497481 100644 --- a/examples/cmd/attributes.go +++ b/examples/cmd/attributes.go @@ -173,7 +173,11 @@ func attruuid(ctx context.Context, s *sdk.SDK, nsu, fqn string) (string, error) } func avuuid(ctx context.Context, s *sdk.SDK, auuid, vs string) (string, error) { - resp, err := s.Attributes.GetAttribute(ctx, &attributes.GetAttributeRequest{Id: auuid}) + req := &attributes.GetAttributeRequest{ + //nolint:staticcheck // the deprecated Id field is kept here deliberately; migrating to the identifier oneof is tracked separately + Id: auuid, + } + resp, err := s.Attributes.GetAttribute(ctx, req) if err != nil { slog.Error("failed to GetAttribute", slog.Any("error", err)) return "", errors.Join(err, ErrInvalidArgument) diff --git a/examples/cmd/benchmark.go b/examples/cmd/benchmark.go index 8c4fbe80dd..6bcfd1d89d 100644 --- a/examples/cmd/benchmark.go +++ b/examples/cmd/benchmark.go @@ -34,7 +34,7 @@ var config BenchmarkConfig func init() { benchmarkCmd := &cobra.Command{ Use: "benchmark", - Short: "OpenTDF benchmark tool", + Short: benchmarkCmdShort, Long: `A OpenTDF benchmark tool to measure throughput and latency with configurable concurrency.`, RunE: runBenchmark, } @@ -68,7 +68,7 @@ func runBenchmark(cmd *cobra.Command, _ []string) error { } }() - dataAttributes := []string{"https://example.com/attr/attr1/value/value1"} + dataAttributes := []string{exampleAttrValueFQN} opts := []sdk.TDFOption{sdk.WithDataAttributes(dataAttributes...), sdk.WithAutoconfigure(false)} if insecurePlaintextConn || strings.HasPrefix(platformEndpoint, "http://") { opts = append(opts, sdk.WithKasInformation( diff --git a/examples/cmd/benchmark_bulk.go b/examples/cmd/benchmark_bulk.go index a6c8e7a0bb..afe0a11acb 100644 --- a/examples/cmd/benchmark_bulk.go +++ b/examples/cmd/benchmark_bulk.go @@ -18,7 +18,7 @@ import ( func init() { benchmarkCmd := &cobra.Command{ Use: "benchmark-bulk", - Short: "OpenTDF benchmark tool", + Short: benchmarkCmdShort, Long: `A OpenTDF benchmark tool to measure Bulk Rewrap.`, RunE: runBenchmarkBulk, } @@ -49,7 +49,7 @@ func runBenchmarkBulk(cmd *cobra.Command, _ []string) error { } }() - dataAttributes := []string{"https://example.com/attr/attr1/value/value1"} + dataAttributes := []string{exampleAttrValueFQN} opts := []sdk.TDFOption{sdk.WithDataAttributes(dataAttributes...), sdk.WithAutoconfigure(false)} if insecurePlaintextConn || strings.HasPrefix(platformEndpoint, "http://") { opts = append(opts, sdk.WithKasInformation( diff --git a/examples/cmd/benchmark_decision.go b/examples/cmd/benchmark_decision.go index 5cab508f6d..b30bed354d 100644 --- a/examples/cmd/benchmark_decision.go +++ b/examples/cmd/benchmark_decision.go @@ -14,7 +14,7 @@ import ( func init() { benchmarkCmd := &cobra.Command{ Use: "benchmark-decision", - Short: "OpenTDF benchmark tool", + Short: benchmarkCmdShort, Long: `A OpenTDF benchmark tool to measure throughput and latency with configurable concurrency.`, RunE: runDecisionBenchmark, } @@ -31,7 +31,7 @@ func runDecisionBenchmark(_ *cobra.Command, _ []string) error { ras := []*authorization.ResourceAttribute{} for i := 0; i < config.RequestCount; i++ { - ras = append(ras, &authorization.ResourceAttribute{AttributeValueFqns: []string{"https://example.com/attr/attr1/value/value1"}}) + ras = append(ras, &authorization.ResourceAttribute{AttributeValueFqns: []string{exampleAttrValueFQN}}) } start := time.Now() diff --git a/examples/cmd/benchmark_decision_v2.go b/examples/cmd/benchmark_decision_v2.go index 0b362c9ec3..7e245943b1 100644 --- a/examples/cmd/benchmark_decision_v2.go +++ b/examples/cmd/benchmark_decision_v2.go @@ -32,14 +32,13 @@ func runDecisionBenchmarkV2(_ *cobra.Command, _ []string) error { } var resources []*authzV2.Resource - attrValueFQN := "https://example.com/attr/attr1/value/value1" for i := range config.RequestCount { r := &authzV2.Resource{ EphemeralId: "resource-%d" + strconv.Itoa(i), Resource: &authzV2.Resource_AttributeValues_{ AttributeValues: &authzV2.Resource_AttributeValues{ - Fqns: []string{attrValueFQN}, + Fqns: []string{exampleAttrValueFQN}, }, }, } diff --git a/examples/cmd/benchmark_experimental.go b/examples/cmd/benchmark_experimental.go index f50c5cc348..e6a5c872b4 100644 --- a/examples/cmd/benchmark_experimental.go +++ b/examples/cmd/benchmark_experimental.go @@ -22,7 +22,6 @@ import ( var ( payloadSize int segmentChunk int - testAttr = "https://example.com/attr/attr1/value/value1" ) func init() { @@ -65,7 +64,7 @@ func runExperimentalWriterBenchmark(_ *cobra.Command, _ []string) error { }, } - attrs = append(attrs, &policy.Value{Fqn: testAttr, KasKeys: []*policy.SimpleKasKey{simpleyKey}, Attribute: &policy.Attribute{Namespace: &policy.Namespace{Name: "example.com"}, Fqn: testAttr}}) + attrs = append(attrs, &policy.Value{Fqn: exampleAttrValueFQN, KasKeys: []*policy.SimpleKasKey{simpleyKey}, Attribute: &policy.Attribute{Namespace: &policy.Namespace{Name: "example.com"}, Fqn: exampleAttrValueFQN}}) writer, err := tdf.NewWriter(context.Background(), tdf.WithDefaultKASForWriter(simpleyKey), tdf.WithInitialAttributes(attrs), tdf.WithSegmentIntegrityAlgorithm(tdf.HS256)) if err != nil { return fmt.Errorf("failed to create writer: %w", err) diff --git a/examples/cmd/encrypt.go b/examples/cmd/encrypt.go index d6574335e1..8128fb8764 100644 --- a/examples/cmd/encrypt.go +++ b/examples/cmd/encrypt.go @@ -25,7 +25,7 @@ func init() { RunE: encrypt, Args: cobra.MinimumNArgs(1), } - encryptCmd.Flags().StringSliceVarP(&dataAttributes, "data-attributes", "a", []string{"https://example.com/attr/attr1/value/value1"}, "space separated list of data attributes") + encryptCmd.Flags().StringSliceVarP(&dataAttributes, "data-attributes", "a", []string{exampleAttrValueFQN}, "space separated list of data attributes") encryptCmd.Flags().BoolVar(&autoconfigure, "autoconfigure", true, "Use attribute grants to select kases") encryptCmd.Flags().BoolVar(&noKIDInKAO, "no-kid-in-kao", false, "[deprecated] Disable storing key identifiers in TDF KAOs") encryptCmd.Flags().StringVarP(&outputName, "output", "o", "sensitive.txt.tdf", "name or path of output file; - for stdout") diff --git a/examples/cmd/examples.go b/examples/cmd/examples.go index e8f1c158d8..719370caf7 100644 --- a/examples/cmd/examples.go +++ b/examples/cmd/examples.go @@ -11,6 +11,13 @@ import ( "github.com/spf13/cobra" ) +const ( + // benchmarkCmdShort is the one-line description shared by the benchmark subcommands. + benchmarkCmdShort = "OpenTDF benchmark tool" + // exampleAttrValueFQN is the attribute value FQN the examples default to. + exampleAttrValueFQN = "https://example.com/attr/attr1/value/value1" +) + var ( platformEndpoint string clientCredentials string