From 869310d7da92e90249f220fa0ff75ec71bf7c328 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Tue, 9 May 2023 11:12:03 -0400 Subject: [PATCH] Only create WithAutomaticVersioning if versioning is used (#3210) This option did not respect whether or not versioning was enabled when writing it out during generation. This does mean that there is a breaking change for auth tokens, but as it was a no-op anyways it's easy to fix and not something I want to /v2 about. --- CHANGELOG.md | 4 ++++ api/authtokens/option.gen.go | 10 ---------- internal/api/genapi/input.go | 19 ++++++++++--------- internal/api/genapi/templates.go | 6 ++++++ 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a19630f19a..fdee3417d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,10 @@ Canonical reference for changes, improvements, and bugfixes for Boundary. never result in permissions being granted, causing confusion. As a result, attempting to write such grants into roles may now result in an error; the error message gives hints for resolution. +* `WithAutomaticVersioning` for auth tokens in Go SDK: this option was + incorrectly being generated for auth token resources, which do not support + versioning. This is technically a breaking change, but it was a no-op option + anyways that there was no reason to be using. It has now been removed. ### New and Improved diff --git a/api/authtokens/option.gen.go b/api/authtokens/option.gen.go index 5fbac42995..6d99380d03 100644 --- a/api/authtokens/option.gen.go +++ b/api/authtokens/option.gen.go @@ -55,16 +55,6 @@ func getOpts(opt ...Option) (options, []api.Option) { return opts, apiOpts } -// If set, and if the version is zero during an update, the API will perform a -// fetch to get the current version of the resource and populate it during the -// update call. This is convenient but opens up the possibility for subtle -// order-of-modification issues, so use carefully. -func WithAutomaticVersioning(enable bool) Option { - return func(o *options) { - o.withAutomaticVersioning = enable - } -} - // WithSkipCurlOutput tells the API to not use the current call for cURL output. // Useful for when we need to look up versions. func WithSkipCurlOutput(skip bool) Option { diff --git a/internal/api/genapi/input.go b/internal/api/genapi/input.go index cb3f3c24c1..a9a4a20c9c 100644 --- a/internal/api/genapi/input.go +++ b/internal/api/genapi/input.go @@ -756,6 +756,15 @@ var inputStructs = []*structInfo{ createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType}, recursiveListing: true, }, + { + inProto: &hosts.StaticHostAttributes{}, + outFile: "hosts/static_host_attributes.gen.go", + subtypeName: "StaticHost", + parentTypeName: "Host", + templates: []*template.Template{ + mapstructureConversionTemplate, + }, + }, { inProto: &hosts.Host{}, outFile: "hosts/host.gen.go", @@ -772,15 +781,6 @@ var inputStructs = []*structInfo{ versionEnabled: true, createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType}, }, - { - inProto: &hosts.StaticHostAttributes{}, - outFile: "hosts/static_host_attributes.gen.go", - subtypeName: "StaticHost", - parentTypeName: "Host", - templates: []*template.Template{ - mapstructureConversionTemplate, - }, - }, { inProto: &hostsets.HostSet{}, outFile: "hostsets/host_set.gen.go", @@ -964,6 +964,7 @@ var inputStructs = []*structInfo{ pluralResourceName: "sessions", createResponseTypes: []string{CreateResponseType, ReadResponseType, UpdateResponseType, DeleteResponseType, ListResponseType}, fieldFilter: []string{"private_key"}, + versionEnabled: true, recursiveListing: true, }, { diff --git a/internal/api/genapi/templates.go b/internal/api/genapi/templates.go index 30816bcaa5..dd88d08bf1 100644 --- a/internal/api/genapi/templates.go +++ b/internal/api/genapi/templates.go @@ -194,6 +194,7 @@ func fillTemplates() { Package: pkg, Fields: fields, RecursiveListing: inputMap[pkg].recursiveListing, + VersionEnabled: inputMap[pkg].versionEnabled, } if err := optionTemplate.Execute(outBuf, input); err != nil { @@ -683,6 +684,9 @@ var optionTemplate = template.Must(template.New("").Funcs( "removeDups": removeDups, }, ).Parse(` +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + package {{ .Package }} import ( @@ -736,6 +740,7 @@ func getOpts(opt ...Option) (options, []api.Option) { return opts, apiOpts } +{{ if .VersionEnabled }} // If set, and if the version is zero during an update, the API will perform a // fetch to get the current version of the resource and populate it during the // update call. This is convenient but opens up the possibility for subtle @@ -745,6 +750,7 @@ func WithAutomaticVersioning(enable bool) Option { o.withAutomaticVersioning = enable } } +{{ end }} // WithSkipCurlOutput tells the API to not use the current call for cURL output. // Useful for when we need to look up versions.