client/lxd_containers.go
func (r *ProtocolLXD) GetContainerFile(containerName string, path string) (io.ReadCloser, *ContainerFileResponse, error) {
	// Prepare the HTTP request
	requestURL, err := shared.URLEncode(
		fmt.Sprintf("%s/1.0/containers/%s/files", r.httpHost, url.QueryEscape(containerName)),
		map[string]string{"path": path})
	if err != nil {
		return nil, nil, err
	}

	requestURL, err = r.setQueryAttributes(requestURL)
	if err != nil {
		return nil, nil, err
	}

	req, err := http.NewRequest("GET", requestURL, nil)
	if err != nil {
		return nil, nil, err
	}

	// Set the user agent
	if r.httpUserAgent != "" {
		req.Header.Set("User-Agent", r.httpUserAgent)
	}

	// Send the request
	resp, err := r.do(req)
	if err != nil {
		return nil, nil, err
	}

	// Check the return value for a cleaner error
	if resp.StatusCode != http.StatusOK {
		_, _, err := lxdParseResponse(resp)
		if err != nil {
			return nil, nil, err
		}
	}

	// Parse the headers
	uid, gid, mode, fileType, _ := shared.ParseLXDFileHeaders(resp.Header)
	fileResp := ContainerFileResponse{
		UID:  uid,
		GID:  gid,
		Mode: mode,
		Type: fileType,
	}

	if fileResp.Type == "directory" {
		// Decode the response
		response := api.Response{}
		decoder := json.NewDecoder(resp.Body)

		err = decoder.Decode(&response)
		if err != nil {
			return nil, nil, err
		}

		// Get the file list
		entries := []string{}
		err = response.MetadataAsStruct(&entries)
		if err != nil {
			return nil, nil, err
		}

		fileResp.Entries = entries

		return nil, &fileResp, err
	}

	return resp.Body, &fileResp, err
}
func (r *ProtocolLXD) GetContainerFile(containerName string, path string) (io.ReadCloser, *ContainerFileResponse, error) {
	// Prepare the HTTP request
	requestURL, err := shared.URLEncode(
		fmt.Sprintf("%s/1.0/containers/%s/files", r.httpHost, url.QueryEscape(containerName)),
		map[string]string{"path": path})
	if err != nil {
		return nil, nil, err
	}

	requestURL, err = r.setQueryAttributes(requestURL)
	if err != nil {
		return nil, nil, err
	}

	req, err := http.NewRequest("GET", requestURL, nil)
	if err != nil {
		return nil, nil, err
	}

	// Set the user agent
	if r.httpUserAgent != "" {
		req.Header.Set("User-Agent", r.httpUserAgent)
	}

	// Send the request
	resp, err := r.do(req)
	if err != nil {
		return nil, nil, err
	}

	// Check the return value for a cleaner error
	if resp.StatusCode != http.StatusOK {
		_, _, err := lxdParseResponse(resp)
		if err != nil {
			return nil, nil, err
		}
	}

	// Parse the headers
	uid, gid, mode, fileType, _ := shared.ParseLXDFileHeaders(resp.Header)
	fileResp := ContainerFileResponse{
		UID:  uid,
		GID:  gid,
		Mode: mode,
		Type: fileType,
	}

	if fileResp.Type == "directory" {
		// Decode the response
		response := api.Response{}
		decoder := json.NewDecoder(resp.Body)

		err = decoder.Decode(&response)
		if err != nil {
			return nil, nil, err
		}

		// Get the file list
		entries := []string{}
		err = response.MetadataAsStruct(&entries)
		if err != nil {
			return nil, nil, err
		}

		fileResp.Entries = entries

		return nil, &fileResp, err
	}

	return resp.Body, &fileResp, err
}
func ( r * ProtocolLXD ) GetContainerFile ( containerName string , path string ) ( io . ReadCloser , * ContainerFileResponse , error ) { // Prepare the HTTP request requestURL , err := shared . URLEncode ( fmt . Sprintf ( " " , r . httpHost , url . QueryEscape ( containerName ) ) , map [ string ] string { " " : path } ) if err != nil { return nil , nil , err } requestURL , err = r . setQueryAttributes ( requestURL ) if err != nil { return nil , nil , err } req , err := http . NewRequest ( " " , requestURL , nil ) if err != nil { return nil , nil , err } // Set the user agent if r . httpUserAgent != " " { req . Header . Set ( " " , r . httpUserAgent ) } // Send the request resp , err := r . do ( req ) if err != nil { return nil , nil , err } // Check the return value for a cleaner error if resp . StatusCode != http . StatusOK { _ , _ , err := lxdParseResponse ( resp ) if err != nil { return nil , nil , err } } // Parse the headers uid , gid , mode , fileType , _ := shared . ParseLXDFileHeaders ( resp . Header ) fileResp := ContainerFileResponse { UID : uid , GID : gid , Mode : mode , Type : fileType , } if fileResp . Type == " " { // Decode the response response := api . Response { } decoder := json . NewDecoder ( resp . Body ) err = decoder . Decode ( & response ) if err != nil { return nil , nil , err } // Get the file list entries := [ ] string { } err = response . MetadataAsStruct ( & entries ) if err != nil { return nil , nil , err } fileResp . Entries = entries return nil , & fileResp , err } return resp . Body , & fileResp , err }
// GetContainerFile retrieves the provided path from the container
GetContainerFile retrieves the provided path from the container