Skip to content

Commit

Permalink
Use urn.Type instead of QualifiedType
Browse files Browse the repository at this point in the history
  • Loading branch information
rquitales committed Dec 14, 2023
1 parent 9f7d864 commit 12d709a
Showing 1 changed file with 4 additions and 30 deletions.
34 changes: 4 additions & 30 deletions provider/pkg/kinds/util.go
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)
}

0 comments on commit 12d709a

Please sign in to comment.