client

package
v0.0.0-...-8b5928e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Copyright 2023 Google LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// Value to pass as credentials to the Host Orchestrator service endpoints. Any non-empty value is enough.
	InjectedCredentials = "inject"
)

Variables

This section is empty.

Functions

func BuilHostIndexURL

func BuilHostIndexURL(rootEndpoint, host string) string

func BuildCVDLogsURL

func BuildCVDLogsURL(rootEndpoint, host, cvd string) string

func BuildRootEndpoint

func BuildRootEndpoint(serviceURL, version, zone string) string

Types

type ApiCallError

type ApiCallError struct {
	Code     int    `json:"code,omitempty"`
	ErrorMsg string `json:"error,omitempty"`
	Details  string `json:"details,omitempty"`
}

func (*ApiCallError) Error

func (e *ApiCallError) Error() string

func (*ApiCallError) Is

func (e *ApiCallError) Is(target error) bool

type AuthnOpts

type AuthnOpts struct {
	OIDCToken *OIDCToken
	HTTPBasic *HTTPBasic
}

type ConnectWebRTCOpts

type ConnectWebRTCOpts struct {
	LocalICEConfig *wclient.ICEConfig
}

type ExpBackOffOptions

type ExpBackOffOptions struct {
	InitialDuration     time.Duration
	RandomizationFactor float64
	Multiplier          float64
	MaxElapsedTime      time.Duration
}

type FilesUploader

type FilesUploader struct {
	HTTPHelper HTTPHelper
	UploadDir  string
	DumpOut    io.Writer
	UploadOptions
}

func (*FilesUploader) Upload

func (u *FilesUploader) Upload(files []string) error

type HTTPBasic

type HTTPBasic struct {
	Username string
}

type HTTPHelper

type HTTPHelper struct {
	Client            *http.Client
	RootEndpoint      string
	Dumpster          io.Writer
	AccessToken       string
	HTTPBasicUsername string
}

func (*HTTPHelper) NewDeleteRequest

func (h *HTTPHelper) NewDeleteRequest(path string) *HTTPRequestBuilder

func (*HTTPHelper) NewGetRequest

func (h *HTTPHelper) NewGetRequest(path string) *HTTPRequestBuilder

func (*HTTPHelper) NewPostRequest

func (h *HTTPHelper) NewPostRequest(path string, jsonBody any) *HTTPRequestBuilder

func (*HTTPHelper) NewUploadFileRequest

func (h *HTTPHelper) NewUploadFileRequest(ctx context.Context, path string, body io.Reader, contentType string) *HTTPRequestBuilder

type HTTPRequestBuilder

type HTTPRequestBuilder struct {
	// contains filtered or unexported fields
}

func (*HTTPRequestBuilder) AddHeader

func (rb *HTTPRequestBuilder) AddHeader(key, value string)

func (*HTTPRequestBuilder) Do

func (rb *HTTPRequestBuilder) Do() (*http.Response, error)

func (*HTTPRequestBuilder) JSONResDo

func (rb *HTTPRequestBuilder) JSONResDo(ret any) error

Expects a response with JSON body to be decoded into `ret`.

func (*HTTPRequestBuilder) JSONResDoWithRetries

func (rb *HTTPRequestBuilder) JSONResDoWithRetries(ret any, retryOpts RetryOptions) error

Expects a response with JSON body to be decoded into `ret`.

func (*HTTPRequestBuilder) SetBasicAuth

func (rb *HTTPRequestBuilder) SetBasicAuth()

func (*HTTPRequestBuilder) SetHeader

func (rb *HTTPRequestBuilder) SetHeader(key, value string)

type HostOrchestratorService

type HostOrchestratorService interface {
	// Lists currently running devices.
	ListCVDs() ([]*hoapi.CVD, error)

	// Creates a directory in the host where user artifacts can be uploaded to.
	CreateUploadDir() (string, error)

	// Uploads file into the given directory.
	UploadFile(uploadDir string, filename string) error
	UploadFileWithOptions(uploadDir string, filename string, options UploadOptions) error

	// Extracts a compressed file.
	ExtractFile(uploadDir string, filename string) (*hoapi.Operation, error)

	// Create a new device with artifacts from the build server or previously uploaded by the user.
	// If not empty, the provided credentials will be used to download necessary artifacts from the build api.
	CreateCVD(req *hoapi.CreateCVDRequest, buildAPICredentials string) (*hoapi.CreateCVDResponse, error)

	// Deletes an existing cvd instance.
	DeleteCVD(id string) error

	// Calls cvd fetch in the remote host, the downloaded artifacts can be used to create a CVD later.
	// If not empty, the provided credentials will be used by the host orchestrator to access the build api.
	FetchArtifacts(req *hoapi.FetchArtifactsRequest, buildAPICredentials string) (*hoapi.FetchArtifactsResponse, error)

	// Downloads runtime artifacts tar file into `dst`.
	DownloadRuntimeArtifacts(dst io.Writer) error

	// Creates a webRTC connection to a device running in this host.
	ConnectWebRTC(device string, observer wclient.Observer, logger io.Writer, opts ConnectWebRTCOpts) (*wclient.Connection, error)

	// Wait for an operation, `result` will be populated with the relevant operation's result object.
	WaitForOperation(name string, result any) error
}

A client to the host orchestrator service running in a remote host.

func NewHostOrchestratorService

func NewHostOrchestratorService(url string) HostOrchestratorService

type HostOrchestratorServiceImpl

type HostOrchestratorServiceImpl struct {
	HTTPHelper                HTTPHelper
	WaitRetries               uint
	WaitRetryDelay            time.Duration
	BuildAPICredentialsHeader string
}

func (*HostOrchestratorServiceImpl) ConnectWebRTC

func (c *HostOrchestratorServiceImpl) ConnectWebRTC(device string, observer wclient.Observer, logger io.Writer, opts ConnectWebRTCOpts) (*wclient.Connection, error)

func (*HostOrchestratorServiceImpl) CreateCVD

func (*HostOrchestratorServiceImpl) CreateUploadDir

func (c *HostOrchestratorServiceImpl) CreateUploadDir() (string, error)

func (*HostOrchestratorServiceImpl) DeleteCVD

func (c *HostOrchestratorServiceImpl) DeleteCVD(id string) error

func (*HostOrchestratorServiceImpl) DownloadRuntimeArtifacts

func (c *HostOrchestratorServiceImpl) DownloadRuntimeArtifacts(dst io.Writer) error

func (*HostOrchestratorServiceImpl) ExtractFile

func (c *HostOrchestratorServiceImpl) ExtractFile(uploadDir string, filename string) (*hoapi.Operation, error)

func (*HostOrchestratorServiceImpl) FetchArtifacts

func (*HostOrchestratorServiceImpl) ListCVDs

func (c *HostOrchestratorServiceImpl) ListCVDs() ([]*hoapi.CVD, error)

func (*HostOrchestratorServiceImpl) UploadFile

func (c *HostOrchestratorServiceImpl) UploadFile(uploadDir string, filename string) error

func (*HostOrchestratorServiceImpl) UploadFileWithOptions

func (c *HostOrchestratorServiceImpl) UploadFileWithOptions(uploadDir string, filename string, uploadOpts UploadOptions) error

func (*HostOrchestratorServiceImpl) WaitForOperation

func (c *HostOrchestratorServiceImpl) WaitForOperation(name string, res any) error

type OIDCToken

type OIDCToken struct {
	Value string
}

type RetryOptions

type RetryOptions struct {
	StatusCodes []int
	NumRetries  uint
	RetryDelay  time.Duration
}

type Service

type Service interface {
	CreateHost(req *apiv1.CreateHostRequest) (*apiv1.HostInstance, error)

	ListHosts() (*apiv1.ListHostsResponse, error)

	DeleteHosts(names []string) error

	HostService(host string) HostOrchestratorService

	RootURI() string
}

func NewService

func NewService(opts *ServiceOptions) (Service, error)

type ServiceBuilder

type ServiceBuilder func(opts *ServiceOptions) (Service, error)

type ServiceOptions

type ServiceOptions struct {
	RootEndpoint   string
	ProxyURL       string
	DumpOut        io.Writer
	ErrOut         io.Writer
	RetryAttempts  int
	RetryDelay     time.Duration
	ChunkSizeBytes int64
	Authn          *AuthnOpts
}

type UploadOptions

type UploadOptions struct {
	BackOffOpts    ExpBackOffOptions
	ChunkSizeBytes int64
	NumWorkers     int
}

func DefaultUploadOptions

func DefaultUploadOptions() UploadOptions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL