sdkcommon

package
v0.0.0-...-bbc9ce3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeviceNameKey  string = "device-name"
	BucketKey      string = "bucket"
	ImageKey       string = "image"
	DeviceIPKey    string = "device-ip"
	SSHPortKey     string = "ssh-port"
	PackageRepoKey string = "package-repo"
	PackagePortKey string = "package-port"
	DefaultKey     string = "default"

	FFXIsolatedEnvKey = "FFX_ISOLATED_CONFIG"
)

Property keys used to get and set device configuration

View Source
const (
	DefaultSSHPort string = "22"
)

Variables

View Source
var (
	// ExecCommand exports exec.Command as a variable so it can be mocked.
	ExecCommand = exec.Command
	// ExecLookPath exported to support mocking.
	ExecLookPath = exec.LookPath
)
View Source
var GetHostname = DefaultGetHostname

GetHostname to allow mocking.

View Source
var GetUserHomeDir = DefaultGetUserHomeDir

GetUserHomeDir to allow mocking.

View Source
var GetUsername = DefaultGetUsername

GetUsername to allow mocking.

Functions

func DefaultGetHostname

func DefaultGetHostname() (string, error)

DefaultGetHostname is the default implementation of GetHostname() to allow mocking of user.Current()

func DefaultGetUserHomeDir

func DefaultGetUserHomeDir() (string, error)

DefaultGetUserHomeDir is the default implementation of GetUserHomeDir() to allow mocking of user.Current()

func DefaultGetUsername

func DefaultGetUsername() (string, error)

DefaultGetUsername is the default implementation of GetUsername() to allow mocking of user.Current()

func DirectoryExists

func DirectoryExists(dirname string) bool

DirectoryExists returns true if dirname exists.

func FileExists

func FileExists(filename string) bool

FileExists returns true if filename exists.

func GCSCopy

func GCSCopy(gcsSource string, localDest string) (string, error)

func GCSFileExists

func GCSFileExists(gcsPath string) (string, error)

Types

type DeviceConfig

type DeviceConfig struct {
	DeviceName   string `json:"device-name"`
	Bucket       string `json:"bucket"`
	Image        string `json:"image"`
	DeviceIP     string `json:"device-ip"`
	SSHPort      string `json:"ssh-port"`
	PackageRepo  string `json:"package-repo"`
	PackagePort  string `json:"package-port"`
	IsDefault    bool   `json:"default"`
	Discoverable bool   `json:"discoverable"`
}

DeviceConfig holds all the properties that are configured for a given device.

type FuchsiaDevice

type FuchsiaDevice struct {
	// SSH address of the Fuchsia device.
	SSHAddr string
	// Nodename of the Fuchsia device.
	Name string
}

FuchsiaDevice represent a Fuchsia device.

func (*FuchsiaDevice) String

func (f *FuchsiaDevice) String() string

type GCSImage

type GCSImage struct {
	Bucket  string
	Name    string
	Version string
}

GCSImage is used to return the bucket, name and version of a prebuilt.

type SDKProperties

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

SDKProperties holds the common data for SDK tools. These values should be set or initialized by calling New().

func New

func New() (SDKProperties, error)

New creates an initialized SDKProperties using the default location for the data directory.

func NewWithDataPath

func NewWithDataPath(dataPath string) (SDKProperties, error)

func (SDKProperties) GetAvailableImages

func (sdk SDKProperties) GetAvailableImages(version string, bucket string) ([]GCSImage, error)

GetAvailableImages returns the images available for the given version and bucket. If bucket is not the default bucket, the images in the default bucket are also returned.

func (SDKProperties) GetDefaultDevice

func (sdk SDKProperties) GetDefaultDevice(deviceName string) (DeviceConfig, error)

GetDefaultDevice gets the default device to use by default.

func (SDKProperties) GetDeviceConfiguration

func (sdk SDKProperties) GetDeviceConfiguration(name string) (DeviceConfig, error)

GetDeviceConfiguration returns the configuration for the device with the given name.

func (SDKProperties) GetDeviceConfigurations

func (sdk SDKProperties) GetDeviceConfigurations() ([]DeviceConfig, error)

GetDeviceConfigurations returns a list of all device configurations.

func (SDKProperties) GetFuchsiaProperty

func (sdk SDKProperties) GetFuchsiaProperty(device string, property string) (string, error)

GetFuchsiaProperty returns the value for the given property for the given device. If the device name is empty, the default device is used via GetDefaultDevice(). It is an error if the property cannot be found.

func (SDKProperties) GetPackageSourcePath

func (sdk SDKProperties) GetPackageSourcePath(version string, bucket string, image string) string

GetPackageSourcePath returns the GCS path for the given values.

func (SDKProperties) GetSDKDataPath

func (sdk SDKProperties) GetSDKDataPath() string

GetSDKDataPath returns the path to the directory for storing SDK related data,

or empty if not set.

Use sdkcommon.New() to create an initialized SDKProperties struct.

func (SDKProperties) GetSDKVersion

func (sdk SDKProperties) GetSDKVersion() string

GetSDKVersion returns the version of the SDK or empty if not set. Use sdkcommon.New() to create an initialized SDKProperties struct.

func (SDKProperties) GetToolsDir

func (sdk SDKProperties) GetToolsDir() (string, error)

GetToolsDir returns the path to the SDK tools for the current CPU architecture. This is implemented by default of getting the directory of the currently exeecuting binary.

func (SDKProperties) GetValidPropertyNames

func (sdk SDKProperties) GetValidPropertyNames() []string

GetValidPropertyNames returns the list of valid properties for a device configuration.

func (SDKProperties) IsValidProperty

func (sdk SDKProperties) IsValidProperty(property string) bool

IsValidProperty returns true if the property is a valid property name.

func (SDKProperties) RemoveDeviceConfiguration

func (sdk SDKProperties) RemoveDeviceConfiguration(deviceName string) error

RemoveDeviceConfiguration removes the device settings for the given name.

func (SDKProperties) ResolveTargetAddress

func (sdk SDKProperties) ResolveTargetAddress(deviceIP string, deviceName string) (DeviceConfig, error)

ResolveTargetAddress evaluates the deviceIP and deviceName passed in to determine the target IP address. This include consulting the configuration information set via `fconfig`.

func (SDKProperties) RunFFX

func (sdk SDKProperties) RunFFX(args []string, interactive bool) (string, error)

RunFFX executes ffx with the given args, returning stdout. If there is an error, the error will usually be of type *ExitError.

func (SDKProperties) RunFFXDoctor

func (sdk SDKProperties) RunFFXDoctor() (string, error)

RunFFXDoctor runs common checks for the ffx tool and host environment and returns the stdout.

func (SDKProperties) RunSFTPCommand

func (sdk SDKProperties) RunSFTPCommand(targetAddress string, customSSHConfig string, privateKey string,
	sshPort string, toTarget bool, src string, dst string) error

RunSFTPCommand runs sftp (one of SSH's file copy tools). Setting toTarget to true will copy file SRC from host to DST on the target. Otherwise it will copy file from SRC from target to DST on the host. sshPort if non-empty will use this port to connect to the device. The return value is the error if any.

func (SDKProperties) RunSSHCommand

func (sdk SDKProperties) RunSSHCommand(targetAddress string, customSSHConfig string,
	privateKey string, sshPort string, verbose bool, args []string) (string, error)

RunSSHCommand runs the command provided in args on the given target device. The customSSHconfig is optional and overrides the SSH configuration defined by the SDK. privateKey is optional to specify a private key to use to access the device. verbose adds the -v flag to ssh. sshPort if non-empty is used as the custom ssh port on the commandline. The return value is the stdout.

func (SDKProperties) RunSSHShell

func (sdk SDKProperties) RunSSHShell(targetAddress string, customSSHConfig string,
	privateKey string, sshPort string, verbose bool, args []string) error

RunSSHShell runs the command provided in args on the given target device and uses the system stdin, stdout, stderr. Returns when the ssh process exits. The customSSHconfig is optional and overrides the SSH configuration defined by the SDK. privateKey is optional to specify a private key to use to access the device. sshPort if non-empty is used as the custom ssh port on the commandline. verbose adds the -v flag to ssh. The return value is the stdout.

func (SDKProperties) SaveDeviceConfiguration

func (sdk SDKProperties) SaveDeviceConfiguration(newConfig DeviceConfig) error

SaveDeviceConfiguration persists the given device configuration properties.

func (SDKProperties) SetDeviceIP

func (sdk SDKProperties) SetDeviceIP(deviceIP, sshPort string) error

SetDeviceIP manually adds a target via `ffx target add`.

Jump to

Keyboard shortcuts

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