-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use urn.Type instead of QualifiedType
- Loading branch information
Showing
1 changed file
with
4 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,19 @@ | ||
package kinds | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/pulumi/pulumi/sdk/v3/go/common/resource" | ||
) | ||
|
||
func suffixSearch(s string, suffixes []string) bool { | ||
for _, suffix := range suffixes { | ||
if strings.HasSuffix(s, suffix) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// IsPatchURN returns true if the URN is for a Patch resource. | ||
func IsPatchURN(urn resource.URN) bool { | ||
urnS := urn.QualifiedType().String() | ||
urnS := urn.Type().String() | ||
|
||
// Do a simple O(1) lookup in a set of known patch types. | ||
if PatchQualifiedTypes.Has(urnS) { | ||
return true | ||
} | ||
|
||
// Do a suffix search in case the resource is a component resource containing | ||
// a patch resource. Eg. a component resource patch resource could have the following URN: | ||
// my:component:Resource$kubernetes:apps/v1:DaemonSetPatch. | ||
return suffixSearch(urnS, PatchQualifiedTypes.SortedValues()) | ||
return PatchQualifiedTypes.Has(urnS) | ||
} | ||
|
||
// IsListURN returns true if the URN is for a List resource. | ||
func IsListURN(urn resource.URN) bool { | ||
urnS := urn.QualifiedType().String() | ||
|
||
// Do a simple O(1) lookup in a set of known list types. | ||
if ListQualifiedTypes.Has(urnS) { | ||
return true | ||
} | ||
urnS := urn.Type().String() | ||
|
||
// Do a suffix search in case the resource is a component resource containing | ||
// a list resource. | ||
return suffixSearch(urnS, ListQualifiedTypes.SortedValues()) | ||
return ListQualifiedTypes.Has(urnS) | ||
} |