swagger:operation GET /1.0/instances/{name}/metadata/templates instances instance_metadata_templates_get Get the template file names or a specific If no path specified, returns a list of template file names. If a path is specified, returns the file content. --- produces: - application/jso
(d *Daemon, r *http.Request)
| 428 | // "500": |
| 429 | // $ref: "#/responses/InternalServerError" |
| 430 | func instanceMetadataTemplatesGet(d *Daemon, r *http.Request) response.Response { |
| 431 | s := d.State() |
| 432 | |
| 433 | projectName := request.ProjectParam(r) |
| 434 | name, err := pathVar(r, "name") |
| 435 | if err != nil { |
| 436 | return response.SmartError(err) |
| 437 | } |
| 438 | |
| 439 | if internalInstance.IsSnapshot(name) { |
| 440 | return response.BadRequest(errors.New("Invalid instance name")) |
| 441 | } |
| 442 | |
| 443 | // Handle requests targeted to a container on a different node |
| 444 | resp, err := forwardedResponseIfInstanceIsRemote(s, r, projectName, name) |
| 445 | if err != nil { |
| 446 | return response.SmartError(err) |
| 447 | } |
| 448 | |
| 449 | if resp != nil { |
| 450 | return resp |
| 451 | } |
| 452 | |
| 453 | // Load the container |
| 454 | c, err := instance.LoadByProjectAndName(s, projectName, name) |
| 455 | if err != nil { |
| 456 | return response.SmartError(err) |
| 457 | } |
| 458 | |
| 459 | // Start the storage if needed |
| 460 | pool, err := storagePools.LoadByInstance(s, c) |
| 461 | if err != nil { |
| 462 | return response.SmartError(err) |
| 463 | } |
| 464 | |
| 465 | _, err = storagePools.InstanceMount(pool, c, nil) |
| 466 | if err != nil { |
| 467 | return response.SmartError(err) |
| 468 | } |
| 469 | |
| 470 | defer logger.WarnOnError(func() error { return storagePools.InstanceUnmount(pool, c, nil) }, "Failed to unmount instance") |
| 471 | |
| 472 | // Confine all template access to the instance directory. |
| 473 | root, err := os.OpenRoot(c.Path()) |
| 474 | if err != nil { |
| 475 | return response.SmartError(err) |
| 476 | } |
| 477 | |
| 478 | defer logger.WarnOnError(root.Close, "Failed to close instance root") |
| 479 | |
| 480 | // Look at the request |
| 481 | templateName := r.FormValue("path") |
| 482 | if templateName == "" { |
| 483 | templates := []string{} |
| 484 | |
| 485 | // List templates |
| 486 | entries, err := fs.ReadDir(root.FS(), "templates") |
| 487 | if err != nil { |
nothing calls this directly
no test coverage detected
searching dependent graphs…