Skip to content

Commit

Permalink
✨ add method to build asset url chain from path
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus committed Mar 8, 2024
1 parent 673f417 commit 01b8db2
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion providers-sdk/v1/inventory/asset_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"regexp"
"sort"
"strconv"
"strings"
)

Expand Down Expand Up @@ -365,4 +366,22 @@ func buildParentQuery(leaf *AssetUrlBranch, value string) AssetUrlChain {
return res
}

func (a *AssetUrlSchema) PathToAssetUrlChain(path []string)
func (a *AssetUrlSchema) PathToAssetUrlChain(path []string) (AssetUrlChain, error) {
cur := a.root
res := make([]KV, len(path))
for idx, term := range path {
if cur == nil {
return nil, errors.New("invalid asset url, no more definitions at depth " + strconv.Itoa(idx) + " (value: " + term + ")")
}

next, ok := cur.Values[term]
if !ok {
return nil, errors.New("invalid asset url, value not found: " + cur.Key + "=" + term)
}

res[idx] = KV{cur.Key, term}
cur = next
}

return res, nil
}

0 comments on commit 01b8db2

Please sign in to comment.