mirror of
https://github.com/danderson/netboot.git
synced 2025-08-07 23:27:16 +02:00
pixiecore: refactor APIBooter commandline construction.
This allows API servers to return URL(x) in the cmdline template, which pixiecore translates to an appropriate ID(x) template call to get the file proxied via Pixiecore.
This commit is contained in:
parent
f904f42035
commit
81a8cca451
@ -165,7 +165,6 @@ func (b *apibooter) BootSpec(m Machine) (*Spec, error) {
|
|||||||
Cmdline interface{} `json:"cmdline"`
|
Cmdline interface{} `json:"cmdline"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
if err = json.NewDecoder(body).Decode(&r); err != nil {
|
if err = json.NewDecoder(body).Decode(&r); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -198,7 +197,6 @@ func (b *apibooter) BootSpec(m Machine) (*Spec, error) {
|
|||||||
if r.Cmdline != nil {
|
if r.Cmdline != nil {
|
||||||
switch c := r.Cmdline.(type) {
|
switch c := r.Cmdline.(type) {
|
||||||
case string:
|
case string:
|
||||||
ret.Cmdline = c
|
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
ret.Cmdline, err = b.constructCmdline(c)
|
ret.Cmdline, err = b.constructCmdline(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -209,6 +207,15 @@ func (b *apibooter) BootSpec(m Machine) (*Spec, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f := func(u string) (string, error) {
|
||||||
|
id, err := signURL(u, &b.key)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("{{ ID %q }}", id), nil
|
||||||
|
}
|
||||||
|
ret.Cmdline, err = expandCmdline(ret.Cmdline, template.FuncMap{"URL": f})
|
||||||
|
|
||||||
return &ret, nil
|
return &ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +297,7 @@ func (b *apibooter) constructCmdline(m map[string]interface{}) (string, error) {
|
|||||||
case bool:
|
case bool:
|
||||||
ret = append(ret, k)
|
ret = append(ret, k)
|
||||||
case string:
|
case string:
|
||||||
ret = append(ret, fmt.Sprintf("%s=%s", k, v))
|
ret = append(ret, fmt.Sprintf("%s=%q", k, v))
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
urlStr, ok := v["url"].(string)
|
urlStr, ok := v["url"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -300,11 +307,7 @@ func (b *apibooter) constructCmdline(m map[string]interface{}) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("invalid url for cmdline key %q: %s", k, err)
|
return "", fmt.Errorf("invalid url for cmdline key %q: %s", k, err)
|
||||||
}
|
}
|
||||||
encoded, err := signURL(urlStr, &b.key)
|
ret = append(ret, fmt.Sprintf("%s={{ URL %q }}", k, urlStr))
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
ret = append(ret, fmt.Sprintf("%s=%s", k, encoded))
|
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("unsupported value kind %T for cmdline key %q", m[k], k)
|
return "", fmt.Errorf("unsupported value kind %T for cmdline key %q", m[k], k)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user