GetInstanceFile retrieves the provided path from the instance.
(instanceName string, filePath string)
| 1432 | |
| 1433 | // GetInstanceFile retrieves the provided path from the instance. |
| 1434 | func (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 | } |
nothing calls this directly
no test coverage detected