2020-08-19 10:51:15 -07:00
|
|
|
package host
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/internal/host/static"
|
|
|
|
|
)
|
|
|
|
|
|
2021-05-17 15:36:45 -04:00
|
|
|
type Subtype int
|
2020-08-19 10:51:15 -07:00
|
|
|
|
|
|
|
|
const (
|
2021-05-17 15:36:45 -04:00
|
|
|
UnknownSubtype Subtype = iota
|
2020-08-19 10:51:15 -07:00
|
|
|
StaticSubtype
|
|
|
|
|
)
|
|
|
|
|
|
2021-05-17 15:36:45 -04:00
|
|
|
func (t Subtype) String() string {
|
2020-08-19 10:51:15 -07:00
|
|
|
switch t {
|
|
|
|
|
case StaticSubtype:
|
|
|
|
|
return "static"
|
|
|
|
|
}
|
|
|
|
|
return "unknown"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Subtype uses the provided subtype
|
2021-05-17 15:36:45 -04:00
|
|
|
func SubtypeFromType(t string) Subtype {
|
2020-08-19 10:51:15 -07:00
|
|
|
switch {
|
|
|
|
|
case strings.EqualFold(strings.TrimSpace(t), StaticSubtype.String()):
|
|
|
|
|
return StaticSubtype
|
|
|
|
|
}
|
|
|
|
|
return UnknownSubtype
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-17 15:36:45 -04:00
|
|
|
func SubtypeFromId(id string) Subtype {
|
2020-08-19 10:51:15 -07:00
|
|
|
switch {
|
2020-09-04 14:48:11 -07:00
|
|
|
case strings.HasPrefix(strings.TrimSpace(id), static.HostPrefix),
|
|
|
|
|
strings.HasPrefix(strings.TrimSpace(id), static.HostSetPrefix),
|
|
|
|
|
strings.HasPrefix(strings.TrimSpace(id), static.HostCatalogPrefix):
|
2020-08-19 10:51:15 -07:00
|
|
|
return StaticSubtype
|
|
|
|
|
}
|
|
|
|
|
return UnknownSubtype
|
|
|
|
|
}
|