MCPcopy
hub / github.com/lxc/incus / GetInstanceFile

Method GetInstanceFile

client/incus_instances.go:1434–1533  ·  view source on GitHub ↗

GetInstanceFile retrieves the provided path from the instance.

(instanceName string, filePath string)

Source from the content-addressed store, hash-verified

1432
1433// GetInstanceFile retrieves the provided path from the instance.
1434func (r *ProtocolIncus) GetInstanceFile(instanceName string, filePath string) (io.ReadCloser, *InstanceFileResponse, error) {
1435 var err error
1436 var requestURL string
1437
1438 urlEncode := func(path string, query map[string]string) (string, error) {
1439 u, err := url.Parse(path)
1440 if err != nil {
1441 return "", err
1442 }
1443
1444 params := url.Values{}
1445 for key, value := range query {
1446 params.Add(key, value)
1447 }
1448
1449 u.RawQuery = params.Encode()
1450 return u.String(), nil
1451 }
1452
1453 if r.IsAgent() {
1454 requestURL, err = urlEncode(
1455 fmt.Sprintf("%s/1.0/files", r.httpBaseURL.String()),
1456 map[string]string{"path": filePath},
1457 )
1458 } else {
1459 var path string
1460
1461 path, _, err = r.instanceTypeToPath(api.InstanceTypeAny)
1462 if err != nil {
1463 return nil, nil, err
1464 }
1465
1466 // Prepare the HTTP request
1467 requestURL, err = urlEncode(
1468 fmt.Sprintf("%s/1.0%s/%s/files", r.httpBaseURL.String(), path, url.PathEscape(instanceName)),
1469 map[string]string{"path": filePath},
1470 )
1471 }
1472
1473 if err != nil {
1474 return nil, nil, err
1475 }
1476
1477 requestURL, err = r.setQueryAttributes(requestURL)
1478 if err != nil {
1479 return nil, nil, err
1480 }
1481
1482 req, err := http.NewRequest("GET", requestURL, nil)
1483 if err != nil {
1484 return nil, nil, err
1485 }
1486
1487 // Send the request
1488 resp, err := r.DoHTTP(req)
1489 if err != nil {
1490 return nil, nil, err
1491 }

Callers

nothing calls this directly

Calls 10

IsAgentMethod · 0.95
instanceTypeToPathMethod · 0.95
setQueryAttributesMethod · 0.95
DoHTTPMethod · 0.95
MetadataAsStructMethod · 0.95
ParseFileHeadersFunction · 0.92
incusParseResponseFunction · 0.85
ParseMethod · 0.65
AddMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected