1package consts 2 3import "fmt" 4 5var PluginTypes = []PluginType{ 6 PluginTypeUnknown, 7 PluginTypeCredential, 8 PluginTypeDatabase, 9 PluginTypeSecrets, 10} 11 12type PluginType uint32 13 14// This is a list of PluginTypes used by Vault. 15// If we need to add any in the future, it would 16// be best to add them to the _end_ of the list below 17// because they resolve to incrementing numbers, 18// which may be saved in state somewhere. Thus if 19// the name for one of those numbers changed because 20// a value were added to the middle, that could cause 21// the wrong plugin types to be read from storage 22// for a given underlying number. Example of the problem 23// here: https://play.golang.org/p/YAaPw5ww3er 24const ( 25 PluginTypeUnknown PluginType = iota 26 PluginTypeCredential 27 PluginTypeDatabase 28 PluginTypeSecrets 29) 30 31func (p PluginType) String() string { 32 switch p { 33 case PluginTypeUnknown: 34 return "unknown" 35 case PluginTypeCredential: 36 return "auth" 37 case PluginTypeDatabase: 38 return "database" 39 case PluginTypeSecrets: 40 return "secret" 41 default: 42 return "unsupported" 43 } 44} 45 46func ParsePluginType(pluginType string) (PluginType, error) { 47 switch pluginType { 48 case "unknown": 49 return PluginTypeUnknown, nil 50 case "auth": 51 return PluginTypeCredential, nil 52 case "database": 53 return PluginTypeDatabase, nil 54 case "secret": 55 return PluginTypeSecrets, nil 56 default: 57 return PluginTypeUnknown, fmt.Errorf("%q is not a supported plugin type", pluginType) 58 } 59} 60