Use enumer to generate String() methods for most enums (#25705)

We have many hand-written String() methods (and similar) for enums.
These require more maintenance and are more error-prone than using
automatically generated methods. In addition, the auto-generated
versions can be more efficient.

Here, we switch to using https://github.com/loggerhead/enumer, itself
a fork of https://github.com/diegostamigni/enumer, no longer maintained,
and a fork of the mostly standard tool
https://pkg.go.dev/golang.org/x/tools/cmd/stringer.
We use this fork of enumer for Go 1.20+ compatibility and because
we require the `-transform` flag to be able to generate
constants that match our current code base.

Some enums were not targeted for this change:
This commit is contained in:
Christopher Swenson
2024-04-17 11:14:14 -07:00
committed by GitHub
parent 55241c2b09
commit 961bf20bdb
55 changed files with 1345 additions and 146 deletions

View File

@@ -86,6 +86,7 @@ runs:
- uses: ./.github/actions/set-up-go
with:
github-token: ${{ inputs.github-token }}
- uses: ./.github/actions/install-external-tools
- if: inputs.vault-edition != 'ce'
name: Configure Git
shell: bash

View File

@@ -31,3 +31,5 @@ runs:
shell: bash
- run: go install github.com/golangci/revgrep/cmd/revgrep@latest
shell: bash
- run: go install github.com/loggerhead/enumer@latest
shell: bash

View File

@@ -31,6 +31,7 @@ var (
DefaultRenewerRenewBuffer = 5
)
//go:generate enumer -type=RenewBehavior -trimprefix=RenewBehavior
type RenewBehavior uint
const (

View File

@@ -9,11 +9,9 @@ package api
import "fmt"
var PluginRuntimeTypes = []PluginRuntimeType{
PluginRuntimeTypeUnsupported,
PluginRuntimeTypeContainer,
}
var PluginRuntimeTypes = _PluginRuntimeTypeValues
//go:generate enumer -type=PluginRuntimeType -trimprefix=PluginRuntimeType -transform=snake
type PluginRuntimeType uint32
// This is a list of PluginRuntimeTypes used by Vault.
@@ -22,20 +20,11 @@ const (
PluginRuntimeTypeContainer
)
func (r PluginRuntimeType) String() string {
switch r {
case PluginRuntimeTypeContainer:
return "container"
default:
return "unsupported"
}
}
// ParsePluginRuntimeType is a wrapper around PluginRuntimeTypeString kept for backwards compatibility.
func ParsePluginRuntimeType(PluginRuntimeType string) (PluginRuntimeType, error) {
switch PluginRuntimeType {
case "container":
return PluginRuntimeTypeContainer, nil
default:
t, err := PluginRuntimeTypeString(PluginRuntimeType)
if err != nil {
return PluginRuntimeTypeUnsupported, fmt.Errorf("%q is not a supported plugin runtime type", PluginRuntimeType)
}
return t, nil
}

View File

@@ -0,0 +1,49 @@
// Code generated by "enumer -type=PluginRuntimeType -trimprefix=PluginRuntimeType -transform=snake"; DO NOT EDIT.
package api
import (
"fmt"
)
const _PluginRuntimeTypeName = "unsupportedcontainer"
var _PluginRuntimeTypeIndex = [...]uint8{0, 11, 20}
func (i PluginRuntimeType) String() string {
if i >= PluginRuntimeType(len(_PluginRuntimeTypeIndex)-1) {
return fmt.Sprintf("PluginRuntimeType(%d)", i)
}
return _PluginRuntimeTypeName[_PluginRuntimeTypeIndex[i]:_PluginRuntimeTypeIndex[i+1]]
}
var _PluginRuntimeTypeValues = []PluginRuntimeType{0, 1}
var _PluginRuntimeTypeNameToValueMap = map[string]PluginRuntimeType{
_PluginRuntimeTypeName[0:11]: 0,
_PluginRuntimeTypeName[11:20]: 1,
}
// PluginRuntimeTypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func PluginRuntimeTypeString(s string) (PluginRuntimeType, error) {
if val, ok := _PluginRuntimeTypeNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to PluginRuntimeType values", s)
}
// PluginRuntimeTypeValues returns all values of the enum
func PluginRuntimeTypeValues() []PluginRuntimeType {
return _PluginRuntimeTypeValues
}
// IsAPluginRuntimeType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i PluginRuntimeType) IsAPluginRuntimeType() bool {
for _, v := range _PluginRuntimeTypeValues {
if i == v {
return true
}
}
return false
}

View File

@@ -0,0 +1,50 @@
// Code generated by "enumer -type=RenewBehavior -trimprefix=RenewBehavior"; DO NOT EDIT.
package api
import (
"fmt"
)
const _RenewBehaviorName = "IgnoreErrorsRenewDisabledErrorOnErrors"
var _RenewBehaviorIndex = [...]uint8{0, 12, 25, 38}
func (i RenewBehavior) String() string {
if i >= RenewBehavior(len(_RenewBehaviorIndex)-1) {
return fmt.Sprintf("RenewBehavior(%d)", i)
}
return _RenewBehaviorName[_RenewBehaviorIndex[i]:_RenewBehaviorIndex[i+1]]
}
var _RenewBehaviorValues = []RenewBehavior{0, 1, 2}
var _RenewBehaviorNameToValueMap = map[string]RenewBehavior{
_RenewBehaviorName[0:12]: 0,
_RenewBehaviorName[12:25]: 1,
_RenewBehaviorName[25:38]: 2,
}
// RenewBehaviorString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func RenewBehaviorString(s string) (RenewBehavior, error) {
if val, ok := _RenewBehaviorNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to RenewBehavior values", s)
}
// RenewBehaviorValues returns all values of the enum
func RenewBehaviorValues() []RenewBehavior {
return _RenewBehaviorValues
}
// IsARenewBehavior returns "true" if the value is listed in the enum definition. "false" otherwise
func (i RenewBehavior) IsARenewBehavior() bool {
for _, v := range _RenewBehaviorValues {
if i == v {
return true
}
}
return false
}

View File

@@ -0,0 +1,51 @@
// Code generated by "enumer -type=DefaultDirectoryPolicyType"; DO NOT EDIT.
package pki
import (
"fmt"
)
const _DefaultDirectoryPolicyTypeName = "ForbidSignVerbatimRoleExternalPolicy"
var _DefaultDirectoryPolicyTypeIndex = [...]uint8{0, 6, 18, 22, 36}
func (i DefaultDirectoryPolicyType) String() string {
if i < 0 || i >= DefaultDirectoryPolicyType(len(_DefaultDirectoryPolicyTypeIndex)-1) {
return fmt.Sprintf("DefaultDirectoryPolicyType(%d)", i)
}
return _DefaultDirectoryPolicyTypeName[_DefaultDirectoryPolicyTypeIndex[i]:_DefaultDirectoryPolicyTypeIndex[i+1]]
}
var _DefaultDirectoryPolicyTypeValues = []DefaultDirectoryPolicyType{0, 1, 2, 3}
var _DefaultDirectoryPolicyTypeNameToValueMap = map[string]DefaultDirectoryPolicyType{
_DefaultDirectoryPolicyTypeName[0:6]: 0,
_DefaultDirectoryPolicyTypeName[6:18]: 1,
_DefaultDirectoryPolicyTypeName[18:22]: 2,
_DefaultDirectoryPolicyTypeName[22:36]: 3,
}
// DefaultDirectoryPolicyTypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func DefaultDirectoryPolicyTypeString(s string) (DefaultDirectoryPolicyType, error) {
if val, ok := _DefaultDirectoryPolicyTypeNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to DefaultDirectoryPolicyType values", s)
}
// DefaultDirectoryPolicyTypeValues returns all values of the enum
func DefaultDirectoryPolicyTypeValues() []DefaultDirectoryPolicyType {
return _DefaultDirectoryPolicyTypeValues
}
// IsADefaultDirectoryPolicyType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i DefaultDirectoryPolicyType) IsADefaultDirectoryPolicyType() bool {
for _, v := range _DefaultDirectoryPolicyTypeValues {
if i == v {
return true
}
}
return false
}

View File

@@ -0,0 +1,53 @@
// Code generated by "enumer -type=ifModifiedReqType -trimprefix=ifModified"; DO NOT EDIT.
package pki
import (
"fmt"
)
const _ifModifiedReqTypeName = "UnknownCACRLDeltaCRLUnifiedCRLUnifiedDeltaCRL"
var _ifModifiedReqTypeIndex = [...]uint8{0, 7, 9, 12, 20, 30, 45}
func (i ifModifiedReqType) String() string {
if i < 0 || i >= ifModifiedReqType(len(_ifModifiedReqTypeIndex)-1) {
return fmt.Sprintf("ifModifiedReqType(%d)", i)
}
return _ifModifiedReqTypeName[_ifModifiedReqTypeIndex[i]:_ifModifiedReqTypeIndex[i+1]]
}
var _ifModifiedReqTypeValues = []ifModifiedReqType{0, 1, 2, 3, 4, 5}
var _ifModifiedReqTypeNameToValueMap = map[string]ifModifiedReqType{
_ifModifiedReqTypeName[0:7]: 0,
_ifModifiedReqTypeName[7:9]: 1,
_ifModifiedReqTypeName[9:12]: 2,
_ifModifiedReqTypeName[12:20]: 3,
_ifModifiedReqTypeName[20:30]: 4,
_ifModifiedReqTypeName[30:45]: 5,
}
// ifModifiedReqTypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func ifModifiedReqTypeString(s string) (ifModifiedReqType, error) {
if val, ok := _ifModifiedReqTypeNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to ifModifiedReqType values", s)
}
// ifModifiedReqTypeValues returns all values of the enum
func ifModifiedReqTypeValues() []ifModifiedReqType {
return _ifModifiedReqTypeValues
}
// IsAifModifiedReqType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i ifModifiedReqType) IsAifModifiedReqType() bool {
for _, v := range _ifModifiedReqTypeValues {
if i == v {
return true
}
}
return false
}

View File

@@ -394,6 +394,7 @@ func getDefaultDirectoryPolicyType(defaultDirectoryPolicy string) (DefaultDirect
}
}
//go:generate enumer -type=DefaultDirectoryPolicyType
type DefaultDirectoryPolicyType int
const (

View File

@@ -23,15 +23,16 @@ import (
var tidyCancelledError = errors.New("tidy operation cancelled")
//go:generate enumer -type=tidyStatusState -trimprefix=tidyStatus
type tidyStatusState int
const (
tidyStatusInactive tidyStatusState = iota
tidyStatusStarted = iota
tidyStatusFinished = iota
tidyStatusError = iota
tidyStatusCancelling = iota
tidyStatusCancelled = iota
tidyStatusInactive tidyStatusState = iota
tidyStatusStarted
tidyStatusFinished
tidyStatusError
tidyStatusCancelling
tidyStatusCancelled
)
type tidyStatus struct {

View File

@@ -0,0 +1,53 @@
// Code generated by "enumer -type=tidyStatusState -trimprefix=tidyStatus"; DO NOT EDIT.
package pki
import (
"fmt"
)
const _tidyStatusStateName = "InactiveStartedFinishedErrorCancellingCancelled"
var _tidyStatusStateIndex = [...]uint8{0, 8, 15, 23, 28, 38, 47}
func (i tidyStatusState) String() string {
if i < 0 || i >= tidyStatusState(len(_tidyStatusStateIndex)-1) {
return fmt.Sprintf("tidyStatusState(%d)", i)
}
return _tidyStatusStateName[_tidyStatusStateIndex[i]:_tidyStatusStateIndex[i+1]]
}
var _tidyStatusStateValues = []tidyStatusState{0, 1, 2, 3, 4, 5}
var _tidyStatusStateNameToValueMap = map[string]tidyStatusState{
_tidyStatusStateName[0:8]: 0,
_tidyStatusStateName[8:15]: 1,
_tidyStatusStateName[15:23]: 2,
_tidyStatusStateName[23:28]: 3,
_tidyStatusStateName[28:38]: 4,
_tidyStatusStateName[38:47]: 5,
}
// tidyStatusStateString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func tidyStatusStateString(s string) (tidyStatusState, error) {
if val, ok := _tidyStatusStateNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to tidyStatusState values", s)
}
// tidyStatusStateValues returns all values of the enum
func tidyStatusStateValues() []tidyStatusState {
return _tidyStatusStateValues
}
// IsAtidyStatusState returns "true" if the value is listed in the enum definition. "false" otherwise
func (i tidyStatusState) IsAtidyStatusState() bool {
for _, v := range _tidyStatusStateValues {
if i == v {
return true
}
}
return false
}

View File

@@ -253,15 +253,16 @@ func parseIfNotModifiedSince(req *logical.Request) (time.Time, error) {
return headerTimeValue, nil
}
//go:generate enumer -type=ifModifiedReqType -trimprefix=ifModified
type ifModifiedReqType int
const (
ifModifiedUnknown ifModifiedReqType = iota
ifModifiedCA = iota
ifModifiedCRL = iota
ifModifiedDeltaCRL = iota
ifModifiedUnifiedCRL = iota
ifModifiedUnifiedDeltaCRL = iota
ifModifiedUnknown ifModifiedReqType = iota
ifModifiedCA
ifModifiedCRL
ifModifiedDeltaCRL
ifModifiedUnifiedCRL
ifModifiedUnifiedDeltaCRL
)
type IfModifiedSinceHelper struct {

View File

@@ -0,0 +1,51 @@
// Code generated by "enumer -type=childProcessState -trimprefix=childProcessState"; DO NOT EDIT.
package exec
import (
"fmt"
)
const _childProcessStateName = "NotStartedRunningRestartingStopped"
var _childProcessStateIndex = [...]uint8{0, 10, 17, 27, 34}
func (i childProcessState) String() string {
if i >= childProcessState(len(_childProcessStateIndex)-1) {
return fmt.Sprintf("childProcessState(%d)", i)
}
return _childProcessStateName[_childProcessStateIndex[i]:_childProcessStateIndex[i+1]]
}
var _childProcessStateValues = []childProcessState{0, 1, 2, 3}
var _childProcessStateNameToValueMap = map[string]childProcessState{
_childProcessStateName[0:10]: 0,
_childProcessStateName[10:17]: 1,
_childProcessStateName[17:27]: 2,
_childProcessStateName[27:34]: 3,
}
// childProcessStateString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func childProcessStateString(s string) (childProcessState, error) {
if val, ok := _childProcessStateNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to childProcessState values", s)
}
// childProcessStateValues returns all values of the enum
func childProcessStateValues() []childProcessState {
return _childProcessStateValues
}
// IsAchildProcessState returns "true" if the value is listed in the enum definition. "false" otherwise
func (i childProcessState) IsAchildProcessState() bool {
for _, v := range _childProcessStateValues {
if i == v {
return true
}
}
return false
}

View File

@@ -26,6 +26,7 @@ import (
"golang.org/x/exp/slices"
)
//go:generate enumer -type=childProcessState -trimprefix=childProcessState
type childProcessState uint8
const (

View File

@@ -16,6 +16,7 @@ import (
"github.com/hashicorp/vault/http"
)
//go:generate enumer -type=EnforceConsistency -trimprefix=EnforceConsistency
type EnforceConsistency int
const (
@@ -23,6 +24,7 @@ const (
EnforceConsistencyAlways
)
//go:generate enumer -type=WhenInconsistentAction -trimprefix=WhenInconsistent
type WhenInconsistentAction int
const (

View File

@@ -0,0 +1,49 @@
// Code generated by "enumer -type=EnforceConsistency -trimprefix=EnforceConsistency"; DO NOT EDIT.
package cache
import (
"fmt"
)
const _EnforceConsistencyName = "NeverAlways"
var _EnforceConsistencyIndex = [...]uint8{0, 5, 11}
func (i EnforceConsistency) String() string {
if i < 0 || i >= EnforceConsistency(len(_EnforceConsistencyIndex)-1) {
return fmt.Sprintf("EnforceConsistency(%d)", i)
}
return _EnforceConsistencyName[_EnforceConsistencyIndex[i]:_EnforceConsistencyIndex[i+1]]
}
var _EnforceConsistencyValues = []EnforceConsistency{0, 1}
var _EnforceConsistencyNameToValueMap = map[string]EnforceConsistency{
_EnforceConsistencyName[0:5]: 0,
_EnforceConsistencyName[5:11]: 1,
}
// EnforceConsistencyString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func EnforceConsistencyString(s string) (EnforceConsistency, error) {
if val, ok := _EnforceConsistencyNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to EnforceConsistency values", s)
}
// EnforceConsistencyValues returns all values of the enum
func EnforceConsistencyValues() []EnforceConsistency {
return _EnforceConsistencyValues
}
// IsAEnforceConsistency returns "true" if the value is listed in the enum definition. "false" otherwise
func (i EnforceConsistency) IsAEnforceConsistency() bool {
for _, v := range _EnforceConsistencyValues {
if i == v {
return true
}
}
return false
}

View File

@@ -0,0 +1,50 @@
// Code generated by "enumer -type=WhenInconsistentAction -trimprefix=WhenInconsistent"; DO NOT EDIT.
package cache
import (
"fmt"
)
const _WhenInconsistentActionName = "FailRetryForward"
var _WhenInconsistentActionIndex = [...]uint8{0, 4, 9, 16}
func (i WhenInconsistentAction) String() string {
if i < 0 || i >= WhenInconsistentAction(len(_WhenInconsistentActionIndex)-1) {
return fmt.Sprintf("WhenInconsistentAction(%d)", i)
}
return _WhenInconsistentActionName[_WhenInconsistentActionIndex[i]:_WhenInconsistentActionIndex[i+1]]
}
var _WhenInconsistentActionValues = []WhenInconsistentAction{0, 1, 2}
var _WhenInconsistentActionNameToValueMap = map[string]WhenInconsistentAction{
_WhenInconsistentActionName[0:4]: 0,
_WhenInconsistentActionName[4:9]: 1,
_WhenInconsistentActionName[9:16]: 2,
}
// WhenInconsistentActionString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func WhenInconsistentActionString(s string) (WhenInconsistentAction, error) {
if val, ok := _WhenInconsistentActionNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to WhenInconsistentAction values", s)
}
// WhenInconsistentActionValues returns all values of the enum
func WhenInconsistentActionValues() []WhenInconsistentAction {
return _WhenInconsistentActionValues
}
// IsAWhenInconsistentAction returns "true" if the value is listed in the enum definition. "false" otherwise
func (i WhenInconsistentAction) IsAWhenInconsistentAction() bool {
for _, v := range _WhenInconsistentActionValues {
if i == v {
return true
}
}
return false
}

View File

@@ -0,0 +1,50 @@
// Code generated by "enumer -type=generateRootKind -trimprefix=generateRoot"; DO NOT EDIT.
package command
import (
"fmt"
)
const _generateRootKindName = "RegularDRRecovery"
var _generateRootKindIndex = [...]uint8{0, 7, 9, 17}
func (i generateRootKind) String() string {
if i < 0 || i >= generateRootKind(len(_generateRootKindIndex)-1) {
return fmt.Sprintf("generateRootKind(%d)", i)
}
return _generateRootKindName[_generateRootKindIndex[i]:_generateRootKindIndex[i+1]]
}
var _generateRootKindValues = []generateRootKind{0, 1, 2}
var _generateRootKindNameToValueMap = map[string]generateRootKind{
_generateRootKindName[0:7]: 0,
_generateRootKindName[7:9]: 1,
_generateRootKindName[9:17]: 2,
}
// generateRootKindString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func generateRootKindString(s string) (generateRootKind, error) {
if val, ok := _generateRootKindNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to generateRootKind values", s)
}
// generateRootKindValues returns all values of the enum
func generateRootKindValues() []generateRootKind {
return _generateRootKindValues
}
// IsAgenerateRootKind returns "true" if the value is listed in the enum definition. "false" otherwise
func (i generateRootKind) IsAgenerateRootKind() bool {
for _, v := range _generateRootKindValues {
if i == v {
return true
}
}
return false
}

View File

@@ -128,7 +128,7 @@ func (e *Executor) Execute() (map[string][]*Result, error) {
for _, result := range results {
result.Endpoint = e.templatePath(result.Endpoint)
result.StatusDisplay = ResultStatusNameMap[result.Status]
result.StatusDisplay = result.Status.String()
}
ret[checker.Name()] = results
@@ -252,6 +252,7 @@ type Check interface {
Evaluate(e *Executor) ([]*Result, error)
}
//go:generate enumer -type=ResultStatus -trimprefix=Result -transform=snake
type ResultStatus int
const (
@@ -264,16 +265,6 @@ const (
ResultInsufficientPermissions
)
var ResultStatusNameMap = map[ResultStatus]string{
ResultNotApplicable: "not_applicable",
ResultOK: "ok",
ResultInformational: "informational",
ResultWarning: "warning",
ResultCritical: "critical",
ResultInvalidVersion: "invalid_version",
ResultInsufficientPermissions: "insufficient_permissions",
}
var NameResultStatusMap = map[string]ResultStatus{
"not_applicable": ResultNotApplicable,
"ok": ResultOK,

View File

@@ -65,9 +65,8 @@ func (h *CAValidityPeriod) LoadConfig(config map[string]interface{}) error {
if len(name_split) != 3 || name_split[1] != "expiry" {
return fmt.Errorf("bad parameter: %v / %v / %v", parameter, len(name_split), name_split[1])
}
status, present := NameResultStatusMap[name_split[2]]
if !present {
status, err := ResultStatusString(name_split[2])
if err != nil {
return fmt.Errorf("bad parameter: %v's type %v isn't in name map", parameter, name_split[2])
}

View File

@@ -0,0 +1,54 @@
// Code generated by "enumer -type=ResultStatus -trimprefix=Result -transform=snake"; DO NOT EDIT.
package healthcheck
import (
"fmt"
)
const _ResultStatusName = "not_applicableokinformationalwarningcriticalinvalid_versioninsufficient_permissions"
var _ResultStatusIndex = [...]uint8{0, 14, 16, 29, 36, 44, 59, 83}
func (i ResultStatus) String() string {
if i < 0 || i >= ResultStatus(len(_ResultStatusIndex)-1) {
return fmt.Sprintf("ResultStatus(%d)", i)
}
return _ResultStatusName[_ResultStatusIndex[i]:_ResultStatusIndex[i+1]]
}
var _ResultStatusValues = []ResultStatus{0, 1, 2, 3, 4, 5, 6}
var _ResultStatusNameToValueMap = map[string]ResultStatus{
_ResultStatusName[0:14]: 0,
_ResultStatusName[14:16]: 1,
_ResultStatusName[16:29]: 2,
_ResultStatusName[29:36]: 3,
_ResultStatusName[36:44]: 4,
_ResultStatusName[44:59]: 5,
_ResultStatusName[59:83]: 6,
}
// ResultStatusString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func ResultStatusString(s string) (ResultStatus, error) {
if val, ok := _ResultStatusNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to ResultStatus values", s)
}
// ResultStatusValues returns all values of the enum
func ResultStatusValues() []ResultStatus {
return _ResultStatusValues
}
// IsAResultStatus returns "true" if the value is listed in the enum definition. "false" otherwise
func (i ResultStatus) IsAResultStatus() bool {
for _, v := range _ResultStatusValues {
if i == v {
return true
}
}
return false
}

View File

@@ -23,6 +23,7 @@ var (
_ cli.CommandAutocomplete = (*OperatorGenerateRootCommand)(nil)
)
//go:generate enumer -type=generateRootKind -trimprefix=generateRoot
type generateRootKind int
const (

View File

@@ -0,0 +1,50 @@
// Code generated by "enumer -type=GenerateRootKind -trimprefix=GenerateRoot"; DO NOT EDIT.
package testhelpers
import (
"fmt"
)
const _GenerateRootKindName = "RegularDRGenerateRecovery"
var _GenerateRootKindIndex = [...]uint8{0, 7, 9, 25}
func (i GenerateRootKind) String() string {
if i < 0 || i >= GenerateRootKind(len(_GenerateRootKindIndex)-1) {
return fmt.Sprintf("GenerateRootKind(%d)", i)
}
return _GenerateRootKindName[_GenerateRootKindIndex[i]:_GenerateRootKindIndex[i+1]]
}
var _GenerateRootKindValues = []GenerateRootKind{0, 1, 2}
var _GenerateRootKindNameToValueMap = map[string]GenerateRootKind{
_GenerateRootKindName[0:7]: 0,
_GenerateRootKindName[7:9]: 1,
_GenerateRootKindName[9:25]: 2,
}
// GenerateRootKindString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func GenerateRootKindString(s string) (GenerateRootKind, error) {
if val, ok := _GenerateRootKindNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to GenerateRootKind values", s)
}
// GenerateRootKindValues returns all values of the enum
func GenerateRootKindValues() []GenerateRootKind {
return _GenerateRootKindValues
}
// IsAGenerateRootKind returns "true" if the value is listed in the enum definition. "false" otherwise
func (i GenerateRootKind) IsAGenerateRootKind() bool {
for _, v := range _GenerateRootKindValues {
if i == v {
return true
}
}
return false
}

View File

@@ -26,6 +26,7 @@ import (
"github.com/mitchellh/go-testing-interface"
)
//go:generate enumer -type=GenerateRootKind -trimprefix=GenerateRoot
type GenerateRootKind int
const (

View File

@@ -0,0 +1,49 @@
// Code generated by "enumer -type=EntropyMode -trimprefix=Entropy"; DO NOT EDIT.
package configutil
import (
"fmt"
)
const _EntropyModeName = "UnknownAugmentation"
var _EntropyModeIndex = [...]uint8{0, 7, 19}
func (i EntropyMode) String() string {
if i < 0 || i >= EntropyMode(len(_EntropyModeIndex)-1) {
return fmt.Sprintf("EntropyMode(%d)", i)
}
return _EntropyModeName[_EntropyModeIndex[i]:_EntropyModeIndex[i+1]]
}
var _EntropyModeValues = []EntropyMode{0, 1}
var _EntropyModeNameToValueMap = map[string]EntropyMode{
_EntropyModeName[0:7]: 0,
_EntropyModeName[7:19]: 1,
}
// EntropyModeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func EntropyModeString(s string) (EntropyMode, error) {
if val, ok := _EntropyModeNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to EntropyMode values", s)
}
// EntropyModeValues returns all values of the enum
func EntropyModeValues() []EntropyMode {
return _EntropyModeValues
}
// IsAEntropyMode returns "true" if the value is listed in the enum definition. "false" otherwise
func (i EntropyMode) IsAEntropyMode() bool {
for _, v := range _EntropyModeValues {
if i == v {
return true
}
}
return false
}

View File

@@ -38,7 +38,9 @@ var (
GetEnvConfigFunc = getEnvConfig
)
// Entropy contains Entropy configuration for the server
//go:generate enumer -type=EntropyMode -trimprefix=Entropy
// EntropyMode contains Entropy configuration for the server
type EntropyMode int
const (

View File

@@ -0,0 +1,50 @@
// Code generated by "enumer -type=CredentialType -trimprefix=CredentialType -transform=snake"; DO NOT EDIT.
package dbplugin
import (
"fmt"
)
const _CredentialTypeName = "passwordrsa_private_keyclient_certificate"
var _CredentialTypeIndex = [...]uint8{0, 8, 23, 41}
func (i CredentialType) String() string {
if i < 0 || i >= CredentialType(len(_CredentialTypeIndex)-1) {
return fmt.Sprintf("CredentialType(%d)", i)
}
return _CredentialTypeName[_CredentialTypeIndex[i]:_CredentialTypeIndex[i+1]]
}
var _CredentialTypeValues = []CredentialType{0, 1, 2}
var _CredentialTypeNameToValueMap = map[string]CredentialType{
_CredentialTypeName[0:8]: 0,
_CredentialTypeName[8:23]: 1,
_CredentialTypeName[23:41]: 2,
}
// CredentialTypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func CredentialTypeString(s string) (CredentialType, error) {
if val, ok := _CredentialTypeNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to CredentialType values", s)
}
// CredentialTypeValues returns all values of the enum
func CredentialTypeValues() []CredentialType {
return _CredentialTypeValues
}
// IsACredentialType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i CredentialType) IsACredentialType() bool {
for _, v := range _CredentialTypeValues {
if i == v {
return true
}
}
return false
}

View File

@@ -144,6 +144,8 @@ type NewUserResponse struct {
Username string
}
//go:generate enumer -type=CredentialType -trimprefix=CredentialType -transform=snake
// CredentialType is a type of database credential.
type CredentialType int
@@ -153,19 +155,6 @@ const (
CredentialTypeClientCertificate
)
func (k CredentialType) String() string {
switch k {
case CredentialTypePassword:
return "password"
case CredentialTypeRSAPrivateKey:
return "rsa_private_key"
case CredentialTypeClientCertificate:
return "client_certificate"
default:
return "unknown"
}
}
// ///////////////////////////////////////////////////////
// UpdateUser()
// ///////////////////////////////////////////////////////

View File

@@ -0,0 +1,50 @@
// Code generated by "enumer -type=CaseOp -transform=snake"; DO NOT EDIT.
package credsutil
import (
"fmt"
)
const _CaseOpName = "keep_caseuppercaselowercase"
var _CaseOpIndex = [...]uint8{0, 9, 18, 27}
func (i CaseOp) String() string {
if i < 0 || i >= CaseOp(len(_CaseOpIndex)-1) {
return fmt.Sprintf("CaseOp(%d)", i)
}
return _CaseOpName[_CaseOpIndex[i]:_CaseOpIndex[i+1]]
}
var _CaseOpValues = []CaseOp{0, 1, 2}
var _CaseOpNameToValueMap = map[string]CaseOp{
_CaseOpName[0:9]: 0,
_CaseOpName[9:18]: 1,
_CaseOpName[18:27]: 2,
}
// CaseOpString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func CaseOpString(s string) (CaseOp, error) {
if val, ok := _CaseOpNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to CaseOp values", s)
}
// CaseOpValues returns all values of the enum
func CaseOpValues() []CaseOp {
return _CaseOpValues
}
// IsACaseOp returns "true" if the value is listed in the enum definition. "false" otherwise
func (i CaseOp) IsACaseOp() bool {
for _, v := range _CaseOpValues {
if i == v {
return true
}
}
return false
}

View File

@@ -9,6 +9,7 @@ import (
"time"
)
//go:generate enumer -type=CaseOp -transform=snake
type CaseOp int
const (

View File

@@ -9,11 +9,9 @@ package consts
import "fmt"
var PluginRuntimeTypes = []PluginRuntimeType{
PluginRuntimeTypeUnsupported,
PluginRuntimeTypeContainer,
}
var PluginRuntimeTypes = _PluginRuntimeTypeValues
//go:generate enumer -type=PluginRuntimeType -trimprefix=PluginRuntimeType -transform=snake
type PluginRuntimeType uint32
// This is a list of PluginRuntimeTypes used by Vault.
@@ -24,20 +22,11 @@ const (
PluginRuntimeTypeContainer
)
func (r PluginRuntimeType) String() string {
switch r {
case PluginRuntimeTypeContainer:
return "container"
default:
return "unsupported"
}
}
// ParsePluginRuntimeType is a wrapper around PluginRuntimeTypeString kept for backwards compatibility.
func ParsePluginRuntimeType(PluginRuntimeType string) (PluginRuntimeType, error) {
switch PluginRuntimeType {
case "container":
return PluginRuntimeTypeContainer, nil
default:
t, err := PluginRuntimeTypeString(PluginRuntimeType)
if err != nil {
return PluginRuntimeTypeUnsupported, fmt.Errorf("%q is not a supported plugin runtime type", PluginRuntimeType)
}
return t, nil
}

View File

@@ -0,0 +1,50 @@
// Code generated by "enumer -type=PluginRuntimeType -trimprefix=PluginRuntimeType -transform=snake"; DO NOT EDIT.
package consts
import (
"fmt"
)
const _PluginRuntimeTypeName = "unsupportedcontainer"
var _PluginRuntimeTypeIndex = [...]uint8{0, 11, 20}
func (i PluginRuntimeType) String() string {
i -= 1
if i >= PluginRuntimeType(len(_PluginRuntimeTypeIndex)-1) {
return fmt.Sprintf("PluginRuntimeType(%d)", i+1)
}
return _PluginRuntimeTypeName[_PluginRuntimeTypeIndex[i]:_PluginRuntimeTypeIndex[i+1]]
}
var _PluginRuntimeTypeValues = []PluginRuntimeType{1, 2}
var _PluginRuntimeTypeNameToValueMap = map[string]PluginRuntimeType{
_PluginRuntimeTypeName[0:11]: 1,
_PluginRuntimeTypeName[11:20]: 2,
}
// PluginRuntimeTypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func PluginRuntimeTypeString(s string) (PluginRuntimeType, error) {
if val, ok := _PluginRuntimeTypeNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to PluginRuntimeType values", s)
}
// PluginRuntimeTypeValues returns all values of the enum
func PluginRuntimeTypeValues() []PluginRuntimeType {
return _PluginRuntimeTypeValues
}
// IsAPluginRuntimeType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i PluginRuntimeType) IsAPluginRuntimeType() bool {
for _, v := range _PluginRuntimeTypeValues {
if i == v {
return true
}
}
return false
}

View File

@@ -28,11 +28,12 @@ const (
HashTypeSHA3512
)
//go:generate enumer -type=MarshalingType -trimprefix=MarshalingType -transform=snake
type MarshalingType uint32
const (
_ = iota
MarshalingTypeASN1 MarshalingType = iota
_ MarshalingType = iota
MarshalingTypeASN1
MarshalingTypeJWS
)
@@ -76,8 +77,5 @@ var (
HashTypeSHA3512: crypto.SHA3_512,
}
MarshalingTypeMap = map[string]MarshalingType{
"asn1": MarshalingTypeASN1,
"jws": MarshalingTypeJWS,
}
MarshalingTypeMap = _MarshalingTypeNameToValueMap
)

View File

@@ -0,0 +1,50 @@
// Code generated by "enumer -type=MarshalingType -trimprefix=MarshalingType -transform=snake"; DO NOT EDIT.
package keysutil
import (
"fmt"
)
const _MarshalingTypeName = "asn1jws"
var _MarshalingTypeIndex = [...]uint8{0, 4, 7}
func (i MarshalingType) String() string {
i -= 1
if i >= MarshalingType(len(_MarshalingTypeIndex)-1) {
return fmt.Sprintf("MarshalingType(%d)", i+1)
}
return _MarshalingTypeName[_MarshalingTypeIndex[i]:_MarshalingTypeIndex[i+1]]
}
var _MarshalingTypeValues = []MarshalingType{1, 2}
var _MarshalingTypeNameToValueMap = map[string]MarshalingType{
_MarshalingTypeName[0:4]: 1,
_MarshalingTypeName[4:7]: 2,
}
// MarshalingTypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func MarshalingTypeString(s string) (MarshalingType, error) {
if val, ok := _MarshalingTypeNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to MarshalingType values", s)
}
// MarshalingTypeValues returns all values of the enum
func MarshalingTypeValues() []MarshalingType {
return _MarshalingTypeValues
}
// IsAMarshalingType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i MarshalingType) IsAMarshalingType() bool {
for _, v := range _MarshalingTypeValues {
if i == v {
return true
}
}
return false
}

View File

@@ -31,6 +31,8 @@ import (
"golang.org/x/crypto/ocsp"
)
//go:generate enumer -type=FailOpenMode -trimprefix=FailOpen
// FailOpenMode is OCSP fail open mode. FailOpenTrue by default and may
// set to ocspModeFailClosed for fail closed mode
type FailOpenMode uint32

View File

@@ -0,0 +1,50 @@
// Code generated by "enumer -type=FailOpenMode -trimprefix=FailOpen"; DO NOT EDIT.
package ocsp
import (
"fmt"
)
const _FailOpenModeName = "ocspFailOpenNotSetTrueFalse"
var _FailOpenModeIndex = [...]uint8{0, 18, 22, 27}
func (i FailOpenMode) String() string {
if i >= FailOpenMode(len(_FailOpenModeIndex)-1) {
return fmt.Sprintf("FailOpenMode(%d)", i)
}
return _FailOpenModeName[_FailOpenModeIndex[i]:_FailOpenModeIndex[i+1]]
}
var _FailOpenModeValues = []FailOpenMode{0, 1, 2}
var _FailOpenModeNameToValueMap = map[string]FailOpenMode{
_FailOpenModeName[0:18]: 0,
_FailOpenModeName[18:22]: 1,
_FailOpenModeName[22:27]: 2,
}
// FailOpenModeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func FailOpenModeString(s string) (FailOpenMode, error) {
if val, ok := _FailOpenModeNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to FailOpenMode values", s)
}
// FailOpenModeValues returns all values of the enum
func FailOpenModeValues() []FailOpenMode {
return _FailOpenModeValues
}
// IsAFailOpenMode returns "true" if the value is listed in the enum definition. "false" otherwise
func (i FailOpenMode) IsAFailOpenMode() bool {
for _, v := range _FailOpenModeValues {
if i == v {
return true
}
}
return false
}

View File

@@ -0,0 +1,50 @@
// Code generated by "enumer -type=GenerateRootKind -trimprefix=GenerateRoot"; DO NOT EDIT.
package testcluster
import (
"fmt"
)
const _GenerateRootKindName = "RegularDRGenerateRecovery"
var _GenerateRootKindIndex = [...]uint8{0, 7, 9, 25}
func (i GenerateRootKind) String() string {
if i < 0 || i >= GenerateRootKind(len(_GenerateRootKindIndex)-1) {
return fmt.Sprintf("GenerateRootKind(%d)", i)
}
return _GenerateRootKindName[_GenerateRootKindIndex[i]:_GenerateRootKindIndex[i+1]]
}
var _GenerateRootKindValues = []GenerateRootKind{0, 1, 2}
var _GenerateRootKindNameToValueMap = map[string]GenerateRootKind{
_GenerateRootKindName[0:7]: 0,
_GenerateRootKindName[7:9]: 1,
_GenerateRootKindName[9:25]: 2,
}
// GenerateRootKindString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func GenerateRootKindString(s string) (GenerateRootKind, error) {
if val, ok := _GenerateRootKindNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to GenerateRootKind values", s)
}
// GenerateRootKindValues returns all values of the enum
func GenerateRootKindValues() []GenerateRootKind {
return _GenerateRootKindValues
}
// IsAGenerateRootKind returns "true" if the value is listed in the enum definition. "false" otherwise
func (i GenerateRootKind) IsAGenerateRootKind() bool {
for _, v := range _GenerateRootKindValues {
if i == v {
return true
}
}
return false
}

View File

@@ -394,6 +394,7 @@ func Clients(vc VaultCluster) []*api.Client {
return ret
}
//go:generate enumer -type=GenerateRootKind -trimprefix=GenerateRoot
type GenerateRootKind int
const (

View File

@@ -0,0 +1,51 @@
// Code generated by "enumer -type=ClientTokenSource -trimprefix=ClientTokenFrom -transform=snake"; DO NOT EDIT.
package logical
import (
"fmt"
)
const _ClientTokenSourceName = "no_client_tokenvault_headerauthz_headerinternal_auth"
var _ClientTokenSourceIndex = [...]uint8{0, 15, 27, 39, 52}
func (i ClientTokenSource) String() string {
if i >= ClientTokenSource(len(_ClientTokenSourceIndex)-1) {
return fmt.Sprintf("ClientTokenSource(%d)", i)
}
return _ClientTokenSourceName[_ClientTokenSourceIndex[i]:_ClientTokenSourceIndex[i+1]]
}
var _ClientTokenSourceValues = []ClientTokenSource{0, 1, 2, 3}
var _ClientTokenSourceNameToValueMap = map[string]ClientTokenSource{
_ClientTokenSourceName[0:15]: 0,
_ClientTokenSourceName[15:27]: 1,
_ClientTokenSourceName[27:39]: 2,
_ClientTokenSourceName[39:52]: 3,
}
// ClientTokenSourceString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func ClientTokenSourceString(s string) (ClientTokenSource, error) {
if val, ok := _ClientTokenSourceNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to ClientTokenSource values", s)
}
// ClientTokenSourceValues returns all values of the enum
func ClientTokenSourceValues() []ClientTokenSource {
return _ClientTokenSourceValues
}
// IsAClientTokenSource returns "true" if the value is listed in the enum definition. "false" otherwise
func (i ClientTokenSource) IsAClientTokenSource() bool {
for _, v := range _ClientTokenSourceValues {
if i == v {
return true
}
}
return false
}

View File

@@ -0,0 +1,55 @@
// Code generated by "enumer -type=KeyUsage -trimprefix=KeyUsage -transform=snake"; DO NOT EDIT.
package logical
import (
"fmt"
)
const _KeyUsageName = "encryptdecryptsignverifywrapunwrapgenerate_random"
var _KeyUsageIndex = [...]uint8{0, 7, 14, 18, 24, 28, 34, 49}
func (i KeyUsage) String() string {
i -= 1
if i < 0 || i >= KeyUsage(len(_KeyUsageIndex)-1) {
return fmt.Sprintf("KeyUsage(%d)", i+1)
}
return _KeyUsageName[_KeyUsageIndex[i]:_KeyUsageIndex[i+1]]
}
var _KeyUsageValues = []KeyUsage{1, 2, 3, 4, 5, 6, 7}
var _KeyUsageNameToValueMap = map[string]KeyUsage{
_KeyUsageName[0:7]: 1,
_KeyUsageName[7:14]: 2,
_KeyUsageName[14:18]: 3,
_KeyUsageName[18:24]: 4,
_KeyUsageName[24:28]: 5,
_KeyUsageName[28:34]: 6,
_KeyUsageName[34:49]: 7,
}
// KeyUsageString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func KeyUsageString(s string) (KeyUsage, error) {
if val, ok := _KeyUsageNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to KeyUsage values", s)
}
// KeyUsageValues returns all values of the enum
func KeyUsageValues() []KeyUsage {
return _KeyUsageValues
}
// IsAKeyUsage returns "true" if the value is listed in the enum definition. "false" otherwise
func (i KeyUsage) IsAKeyUsage() bool {
for _, v := range _KeyUsageValues {
if i == v {
return true
}
}
return false
}

View File

@@ -11,6 +11,7 @@ import (
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
)
//go:generate enumer -type=KeyUsage -trimprefix=KeyUsage -transform=snake
type KeyUsage int
const (

View File

@@ -51,6 +51,7 @@ func (r *RequestWrapInfo) SentinelKeys() []string {
}
}
//go:generate enumer -type=ClientTokenSource -trimprefix=ClientTokenFrom -transform=snake
type ClientTokenSource uint32
const (

View File

@@ -11,9 +11,10 @@ import (
"strings"
"time"
sockaddr "github.com/hashicorp/go-sockaddr"
"github.com/hashicorp/go-sockaddr"
)
//go:generate enumer -type=TokenType -trimprefix=TokenType -transform=kebab
type TokenType uint8
const (
@@ -72,23 +73,6 @@ func (t *TokenType) UnmarshalJSON(b []byte) error {
return nil
}
func (t TokenType) String() string {
switch t {
case TokenTypeDefault:
return "default"
case TokenTypeService:
return "service"
case TokenTypeBatch:
return "batch"
case TokenTypeDefaultService:
return "default-service"
case TokenTypeDefaultBatch:
return "default-batch"
default:
panic("unreachable")
}
}
// TokenEntry is used to represent a given token
type TokenEntry struct {
Type TokenType `json:"type" mapstructure:"type" structs:"type" sentinel:""`

View File

@@ -0,0 +1,52 @@
// Code generated by "enumer -type=TokenType -trimprefix=TokenType -transform=kebab"; DO NOT EDIT.
package logical
import (
"fmt"
)
const _TokenTypeName = "defaultservicebatchdefault-servicedefault-batch"
var _TokenTypeIndex = [...]uint8{0, 7, 14, 19, 34, 47}
func (i TokenType) String() string {
if i >= TokenType(len(_TokenTypeIndex)-1) {
return fmt.Sprintf("TokenType(%d)", i)
}
return _TokenTypeName[_TokenTypeIndex[i]:_TokenTypeIndex[i+1]]
}
var _TokenTypeValues = []TokenType{0, 1, 2, 3, 4}
var _TokenTypeNameToValueMap = map[string]TokenType{
_TokenTypeName[0:7]: 0,
_TokenTypeName[7:14]: 1,
_TokenTypeName[14:19]: 2,
_TokenTypeName[19:34]: 3,
_TokenTypeName[34:47]: 4,
}
// TokenTypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func TokenTypeString(s string) (TokenType, error) {
if val, ok := _TokenTypeNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to TokenType values", s)
}
// TokenTypeValues returns all values of the enum
func TokenTypeValues() []TokenType {
return _TokenTypeValues
}
// IsATokenType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i TokenType) IsATokenType() bool {
for _, v := range _TokenTypeValues {
if i == v {
return true
}
}
return false
}

View File

@@ -47,6 +47,7 @@ install_external() {
gotest.tools/gotestsum@latest
honnef.co/go/tools/cmd/staticcheck@latest
mvdan.cc/gofumpt@latest
github.com/loggerhead/enumer@latest
)
echo "==> Installing external tools..."
@@ -64,6 +65,7 @@ check_external() {
local tools
tools=(
buf
enumer
gofumpt
goimports
gosimports

View File

@@ -0,0 +1,49 @@
// Code generated by "enumer -type=clientType -trimprefix=clientType -transform=snake"; DO NOT EDIT.
package vault
import (
"fmt"
)
const _clientTypeName = "confidentialpublic"
var _clientTypeIndex = [...]uint8{0, 12, 18}
func (i clientType) String() string {
if i < 0 || i >= clientType(len(_clientTypeIndex)-1) {
return fmt.Sprintf("clientType(%d)", i)
}
return _clientTypeName[_clientTypeIndex[i]:_clientTypeIndex[i+1]]
}
var _clientTypeValues = []clientType{0, 1}
var _clientTypeNameToValueMap = map[string]clientType{
_clientTypeName[0:12]: 0,
_clientTypeName[12:18]: 1,
}
// clientTypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func clientTypeString(s string) (clientType, error) {
if val, ok := _clientTypeNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to clientType values", s)
}
// clientTypeValues returns all values of the enum
func clientTypeValues() []clientType {
return _clientTypeValues
}
// IsAclientType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i clientType) IsAclientType() bool {
for _, v := range _clientTypeValues {
if i == v {
return true
}
}
return false
}

View File

@@ -3026,6 +3026,8 @@ func setPhysicalSealConfig(ctx context.Context, c *Core, label, configPath strin
return nil
}
//go:generate enumer -type=sealMigrationCheckResult -trimprefix=sealMigrationCheck -transform=snake
type sealMigrationCheckResult int
const (

View File

@@ -110,6 +110,7 @@ type client struct {
ClientSecret string `json:"client_secret"`
}
//go:generate enumer -type=clientType -trimprefix=clientType -transform=snake
type clientType int
const (
@@ -117,17 +118,6 @@ const (
public
)
func (k clientType) String() string {
switch k {
case confidential:
return "confidential"
case public:
return "public"
default:
return "unknown"
}
}
type provider struct {
Issuer string `json:"issuer"`
AllowedClientIDs []string `json:"allowed_client_ids"`

View File

@@ -1949,8 +1949,8 @@ func (b *SystemBackend) handleRemount(ctx context.Context, req *logical.Request,
err := b.moveMount(ns, logger, migrationID, entry, fromPathDetails, toPathDetails)
if err != nil {
logger.Error("remount failed", "error", err)
if err := b.Core.setMigrationStatus(migrationID, MigrationFailureStatus); err != nil {
logger.Error("Setting migration status failed", "error", err, "target_status", MigrationFailureStatus)
if err := b.Core.setMigrationStatus(migrationID, MigrationStatusFailure); err != nil {
logger.Error("Setting migration status failed", "error", err, "target_status", MigrationStatusFailure)
}
}
}(migrationID)
@@ -2006,7 +2006,7 @@ func (b *SystemBackend) moveMount(ns *namespace.Namespace, logger log.Logger, mi
return err
}
if err := b.Core.setMigrationStatus(migrationID, MigrationSuccessStatus); err != nil {
if err := b.Core.setMigrationStatus(migrationID, MigrationStatusSuccess); err != nil {
return err
}
logger.Info("Completed mount move operations")

View File

@@ -1074,7 +1074,7 @@ func TestSystemBackend_remount_auth(t *testing.T) {
)
migrationInfo := resp.Data["migration_info"].(*MountMigrationInfo)
if migrationInfo.MigrationStatus != MigrationSuccessStatus.String() {
if migrationInfo.MigrationStatus != MigrationStatusSuccess.String() {
return fmt.Errorf("Expected migration status to be successful, got %q", migrationInfo.MigrationStatus)
}
return nil
@@ -1226,7 +1226,7 @@ func TestSystemBackend_remount(t *testing.T) {
t.Fatalf("err: %v", err)
}
migrationInfo := resp.Data["migration_info"].(*MountMigrationInfo)
if migrationInfo.MigrationStatus != MigrationSuccessStatus.String() {
if migrationInfo.MigrationStatus != MigrationStatusSuccess.String() {
return fmt.Errorf("Expected migration status to be successful, got %q", migrationInfo.MigrationStatus)
}
return nil

View File

@@ -149,26 +149,16 @@ type MountTable struct {
Entries []*MountEntry `json:"entries"`
}
//go:generate enumer -type=MountMigrationStatus -trimprefix=MigrationStatus -transform=kebab
type MountMigrationStatus int
const (
MigrationInProgressStatus MountMigrationStatus = iota
MigrationSuccessStatus
MigrationFailureStatus
MigrationStatusInProgress MountMigrationStatus = iota
MigrationStatusSuccess
MigrationStatusFailure
)
func (m MountMigrationStatus) String() string {
switch m {
case MigrationInProgressStatus:
return "in-progress"
case MigrationSuccessStatus:
return "success"
case MigrationFailureStatus:
return "failure"
}
return "unknown"
}
type MountMigrationInfo struct {
SourceMount string `json:"source_mount"`
TargetMount string `json:"target_mount"`
@@ -1978,7 +1968,7 @@ func (c *Core) createMigrationStatus(from, to namespace.MountPathDetails) (strin
migrationInfo := MountMigrationInfo{
SourceMount: from.Namespace.Path + from.MountPath,
TargetMount: to.Namespace.Path + to.MountPath,
MigrationStatus: MigrationInProgressStatus.String(),
MigrationStatus: MigrationStatusInProgress.String(),
}
c.mountMigrationTracker.Store(migrationID, migrationInfo)
return migrationID, nil

View File

@@ -0,0 +1,50 @@
// Code generated by "enumer -type=MountMigrationStatus -trimprefix=MigrationStatus -transform=kebab"; DO NOT EDIT.
package vault
import (
"fmt"
)
const _MountMigrationStatusName = "in-progresssuccessfailure"
var _MountMigrationStatusIndex = [...]uint8{0, 11, 18, 25}
func (i MountMigrationStatus) String() string {
if i < 0 || i >= MountMigrationStatus(len(_MountMigrationStatusIndex)-1) {
return fmt.Sprintf("MountMigrationStatus(%d)", i)
}
return _MountMigrationStatusName[_MountMigrationStatusIndex[i]:_MountMigrationStatusIndex[i+1]]
}
var _MountMigrationStatusValues = []MountMigrationStatus{0, 1, 2}
var _MountMigrationStatusNameToValueMap = map[string]MountMigrationStatus{
_MountMigrationStatusName[0:11]: 0,
_MountMigrationStatusName[11:18]: 1,
_MountMigrationStatusName[18:25]: 2,
}
// MountMigrationStatusString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func MountMigrationStatusString(s string) (MountMigrationStatus, error) {
if val, ok := _MountMigrationStatusNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to MountMigrationStatus values", s)
}
// MountMigrationStatusValues returns all values of the enum
func MountMigrationStatusValues() []MountMigrationStatus {
return _MountMigrationStatusValues
}
// IsAMountMigrationStatus returns "true" if the value is listed in the enum definition. "false" otherwise
func (i MountMigrationStatus) IsAMountMigrationStatus() bool {
for _, v := range _MountMigrationStatusValues {
if i == v {
return true
}
}
return false
}

View File

@@ -0,0 +1,52 @@
// Code generated by "enumer -type=LeaseAction -trimprefix=LeaseAction -transform=snake"; DO NOT EDIT.
package quotas
import (
"fmt"
)
const _LeaseActionName = "unknownloadedcreateddeletedallow"
var _LeaseActionIndex = [...]uint8{0, 7, 13, 20, 27, 32}
func (i LeaseAction) String() string {
if i >= LeaseAction(len(_LeaseActionIndex)-1) {
return fmt.Sprintf("LeaseAction(%d)", i)
}
return _LeaseActionName[_LeaseActionIndex[i]:_LeaseActionIndex[i+1]]
}
var _LeaseActionValues = []LeaseAction{0, 1, 2, 3, 4}
var _LeaseActionNameToValueMap = map[string]LeaseAction{
_LeaseActionName[0:7]: 0,
_LeaseActionName[7:13]: 1,
_LeaseActionName[13:20]: 2,
_LeaseActionName[20:27]: 3,
_LeaseActionName[27:32]: 4,
}
// LeaseActionString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func LeaseActionString(s string) (LeaseAction, error) {
if val, ok := _LeaseActionNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to LeaseAction values", s)
}
// LeaseActionValues returns all values of the enum
func LeaseActionValues() []LeaseAction {
return _LeaseActionValues
}
// IsALeaseAction returns "true" if the value is listed in the enum definition. "false" otherwise
func (i LeaseAction) IsALeaseAction() bool {
for _, v := range _LeaseActionValues {
if i == v {
return true
}
}
return false
}

View File

@@ -30,28 +30,15 @@ const (
TypeLeaseCount Type = "lease-count"
)
//go:generate enumer -type=LeaseAction -trimprefix=LeaseAction -transform=snake
// LeaseAction is the action taken by the expiration manager on the lease. The
// quota manager will use this information to update the lease path cache and
// updating counters for relevant quota rules.
type LeaseAction uint32
// String converts each lease action into its string equivalent value
func (la LeaseAction) String() string {
switch la {
case LeaseActionLoaded:
return "loaded"
case LeaseActionCreated:
return "created"
case LeaseActionDeleted:
return "deleted"
case LeaseActionAllow:
return "allow"
}
return "unknown"
}
const (
_ LeaseAction = iota
LeaseActionUnknown LeaseAction = iota
// LeaseActionLoaded indicates loading of lease in the expiration manager after
// unseal.

View File

@@ -0,0 +1,51 @@
// Code generated by "enumer -type=sealMigrationCheckResult -trimprefix=sealMigrationCheck -transform=snake"; DO NOT EDIT.
package vault
import (
"fmt"
)
const _sealMigrationCheckResultName = "errorskipadjustdo_not_ajust"
var _sealMigrationCheckResultIndex = [...]uint8{0, 5, 9, 15, 27}
func (i sealMigrationCheckResult) String() string {
if i < 0 || i >= sealMigrationCheckResult(len(_sealMigrationCheckResultIndex)-1) {
return fmt.Sprintf("sealMigrationCheckResult(%d)", i)
}
return _sealMigrationCheckResultName[_sealMigrationCheckResultIndex[i]:_sealMigrationCheckResultIndex[i+1]]
}
var _sealMigrationCheckResultValues = []sealMigrationCheckResult{0, 1, 2, 3}
var _sealMigrationCheckResultNameToValueMap = map[string]sealMigrationCheckResult{
_sealMigrationCheckResultName[0:5]: 0,
_sealMigrationCheckResultName[5:9]: 1,
_sealMigrationCheckResultName[9:15]: 2,
_sealMigrationCheckResultName[15:27]: 3,
}
// sealMigrationCheckResultString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func sealMigrationCheckResultString(s string) (sealMigrationCheckResult, error) {
if val, ok := _sealMigrationCheckResultNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to sealMigrationCheckResult values", s)
}
// sealMigrationCheckResultValues returns all values of the enum
func sealMigrationCheckResultValues() []sealMigrationCheckResult {
return _sealMigrationCheckResultValues
}
// IsAsealMigrationCheckResult returns "true" if the value is listed in the enum definition. "false" otherwise
func (i sealMigrationCheckResult) IsAsealMigrationCheckResult() bool {
for _, v := range _sealMigrationCheckResultValues {
if i == v {
return true
}
}
return false
}