From 61fcd857ecd38e5b7486e26d399aed100cd3b818 Mon Sep 17 00:00:00 2001 From: Timothy Messier Date: Mon, 9 Oct 2023 19:42:02 +0000 Subject: [PATCH] feat(resource): Add function to get type from plural string --- internal/types/resource/resource.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/types/resource/resource.go b/internal/types/resource/resource.go index a21d1cdcce..14106c3bcb 100644 --- a/internal/types/resource/resource.go +++ b/internal/types/resource/resource.go @@ -3,7 +3,10 @@ package resource -import "encoding/json" +import ( + "encoding/json" + "strings" +) // Type defines the types of resources in the system type Type uint @@ -81,6 +84,16 @@ func (r Type) PluralString() string { } } +func FromPlural(s string) (Type, bool) { + switch s { + case "credential-libraries": + return CredentialLibrary, true + default: + t, ok := Map[strings.TrimSuffix(s, "s")] + return t, ok + } +} + var Map = map[string]Type{ Unknown.String(): Unknown, All.String(): All,