@@ -26,34 +26,39 @@ func (tmpl *Template) useAbsLocators() error {
26
26
return err
27
27
}
28
28
for i , baseLocator := range tmpl .Config .Base {
29
- locator , err := absPath (baseLocator .URL , basePath )
29
+ absLocator , err := absPath (baseLocator .URL , basePath )
30
30
if err != nil {
31
31
return err
32
32
}
33
33
if i == 0 {
34
- // base can either be a single string, or a list of strings
35
- tmpl .expr .WriteString (fmt .Sprintf ("| ($a.base | select(type == \" !!str\" )) |= %q\n " , locator ))
36
- tmpl .expr .WriteString (fmt .Sprintf ("| ($a.base | select(type == \" !!seq\" ) | .[0]) |= %q\n " , locator ))
34
+ // base can be either a single string (URL), or a single locator object, or a list whose first element can be either a string or an object
35
+ tmpl .expr .WriteString (fmt .Sprintf ("| ($a.base | select(type == \" !!str\" )) |= %q\n " , absLocator ))
36
+ tmpl .expr .WriteString (fmt .Sprintf ("| ($a.base | select(type == \" !!map\" ) | .url) |= %q\n " , absLocator ))
37
+ tmpl .expr .WriteString (fmt .Sprintf ("| ($a.base | select(type == \" !!seq\" and (.[0] | type) == \" !!str\" ) | .[0]) |= %q\n " , absLocator ))
38
+ tmpl .expr .WriteString (fmt .Sprintf ("| ($a.base | select(type == \" !!seq\" and (.[0] | type) == \" !!map\" ) | .[0].url) |= %q\n " , absLocator ))
37
39
} else {
38
- tmpl .expr .WriteString (fmt .Sprintf ("| $a.base[%d] = %q\n " , i , locator ))
40
+ tmpl .expr .WriteString (fmt .Sprintf ("| ($a.base[%d] | select(type == \" !!str\" )) |= %q\n " , i , absLocator ))
41
+ tmpl .expr .WriteString (fmt .Sprintf ("| ($a.base[%d] | select(type == \" !!map\" ) | .url) |= %q\n " , i , absLocator ))
39
42
}
40
43
}
41
44
for i , p := range tmpl .Config .Probes {
42
45
if p .File != nil {
43
- locator , err := absPath (p .File .URL , basePath )
46
+ absLocator , err := absPath (p .File .URL , basePath )
44
47
if err != nil {
45
48
return err
46
49
}
47
- tmpl .expr .WriteString (fmt .Sprintf ("| $a.probes[%d].file = %q\n " , i , locator ))
50
+ tmpl .expr .WriteString (fmt .Sprintf ("| ($a.probes[%d].file | select(type == \" !!str\" )) = %q\n " , i , absLocator ))
51
+ tmpl .expr .WriteString (fmt .Sprintf ("| ($a.probes[%d].file | select(type == \" !!map\" ) | .url) = %q\n " , i , absLocator ))
48
52
}
49
53
}
50
54
for i , p := range tmpl .Config .Provision {
51
55
if p .File != nil {
52
- locator , err := absPath (p .File .URL , basePath )
56
+ absLocator , err := absPath (p .File .URL , basePath )
53
57
if err != nil {
54
58
return err
55
59
}
56
- tmpl .expr .WriteString (fmt .Sprintf ("| $a.provision[%d].file = %q\n " , i , locator ))
60
+ tmpl .expr .WriteString (fmt .Sprintf ("| ($a.provision[%d].file | select(type == \" !!str\" )) = %q\n " , i , absLocator ))
61
+ tmpl .expr .WriteString (fmt .Sprintf ("| ($a.provision[%d].file | select(type == \" !!map\" ) | .url) = %q\n " , i , absLocator ))
57
62
}
58
63
}
59
64
return tmpl .evalExpr ()
@@ -90,6 +95,9 @@ func basePath(locator string) (string, error) {
90
95
91
96
// absPath either returns the locator directly, or combines it with the basePath if the locator is a relative path.
92
97
func absPath (locator , basePath string ) (string , error ) {
98
+ if locator == "" {
99
+ return "" , errors .New ("locator is empty" )
100
+ }
93
101
u , err := url .Parse (locator )
94
102
if err == nil && len (u .Scheme ) > 1 {
95
103
return locator , nil
0 commit comments