Skip to content

Commit

Permalink
Comment and simplify flattenAssets
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas11 committed Jun 11, 2024
1 parent f50c880 commit 84deb60
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions infer/internal/ende/ende.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,34 +357,48 @@ const (
isEmptyArr = iota
)

// flattenAssets pulls out assets and archives from AssetOrArchive objects.
// From:
//
// types.AssetSignature:
// sig.Key: sig.AssetSig
// ...
//
// To:
//
// sig.Key: sig.AssetSig
// ...
func flattenAssets(a any) (resource.PropertyValue, bool) {
if aMap, ok := a.(map[string]any); ok {
rawAsset, hasAsset := aMap[types.AssetSignature]
rawArchive, hasArchive := aMap[types.ArchiveSignature]
aMap, ok := a.(map[string]any)
if !ok {
return resource.NewNullProperty(), false
}

rawAsset, hasAsset := aMap[types.AssetSignature]
rawArchive, hasArchive := aMap[types.ArchiveSignature]

if hasAsset && hasArchive {
panic(`Encountered both an asset and an archive in the same AssetOrArchive. This
if hasAsset && hasArchive {
panic(`Encountered both an asset and an archive in the same AssetOrArchive. This
should never happen. Please file an issue at https://github.com/pulumi/pulumi-go-provider/issues.`)
}
}

raw := rawAsset
if hasArchive {
raw = rawArchive
}
raw := rawAsset
if hasArchive {
raw = rawArchive
}

if asset, ok := raw.(map[string]any); ok {
if kind, ok := asset[sig.Key]; ok {
if kind, ok := kind.(string); ok {
if kind == sig.AssetSig || kind == sig.ArchiveSig {
// It's an asset/archive inside an AssetOrArchive. Pull it out.
return resource.NewObjectProperty(resource.NewPropertyMapFromMap(asset)), true
}
panic(`Encountered an unknown kind in an AssetOrArchive. This should never
happen. Please file an issue at https://github.com/pulumi/pulumi-go-provider/issues.`)
if asset, ok := raw.(map[string]any); ok {
if kind, ok := asset[sig.Key]; ok {
if kind, ok := kind.(string); ok {
if kind == sig.AssetSig || kind == sig.ArchiveSig {
return resource.NewObjectProperty(resource.NewPropertyMapFromMap(asset)), true
}
panic(`Encountered an unknown kind in an AssetOrArchive. This should never
happen. Please file an issue at https://github.com/pulumi/pulumi-go-provider/issues.`)
}
}
}

return resource.NewNullProperty(), false
}

Expand Down

0 comments on commit 84deb60

Please sign in to comment.