getModuleNameInline loads the string value from raw of moduleNameKey, where raw must be a JSON encoding of a map. It returns that value, along with the result of removing that key from raw.
(moduleNameKey string, raw json.RawMessage)
| 261 | // where raw must be a JSON encoding of a map. It returns that value, |
| 262 | // along with the result of removing that key from raw. |
| 263 | func getModuleNameInline(moduleNameKey string, raw json.RawMessage) (string, json.RawMessage, error) { |
| 264 | var tmp map[string]any |
| 265 | err := json.Unmarshal(raw, &tmp) |
| 266 | if err != nil { |
| 267 | return "", nil, err |
| 268 | } |
| 269 | |
| 270 | moduleName, ok := tmp[moduleNameKey].(string) |
| 271 | if !ok || moduleName == "" { |
| 272 | return "", nil, fmt.Errorf("module name not specified with key '%s' in %+v", moduleNameKey, tmp) |
| 273 | } |
| 274 | |
| 275 | // remove key from the object, otherwise decoding it later |
| 276 | // will yield an error because the struct won't recognize it |
| 277 | // (this is only needed because we strictly enforce that |
| 278 | // all keys are recognized when loading modules) |
| 279 | delete(tmp, moduleNameKey) |
| 280 | result, err := json.Marshal(tmp) |
| 281 | if err != nil { |
| 282 | return "", nil, fmt.Errorf("re-encoding module configuration: %v", err) |
| 283 | } |
| 284 | |
| 285 | return moduleName, result, nil |
| 286 | } |
| 287 | |
| 288 | // Provisioner is implemented by modules which may need to perform |
| 289 | // some additional "setup" steps immediately after being loaded. |