sdkcommon

package
v0.0.0-...-8023e94 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: BSD-2-Clause Imports: 13 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"
)

Property keys used to get and set device configuration

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 implmentation of GetHostname() to allow mocking of user.Current()

func DefaultGetUserHomeDir

func DefaultGetUserHomeDir() (string, error)

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

func DefaultGetUsername

func DefaultGetUsername() (string, error)

DefaultGetUsername is the default implmentation 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"`
}

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

type FuchsiaDevice

type FuchsiaDevice struct {
	// IPv4 or IPv6 of the Fuchsia device.
	IpAddr 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 (sdk *SDKProperties) Init().

func New

func New() (SDKProperties, error)

New creates an initialized SDKProperties

func (SDKProperties) FindDeviceByIP

func (sdk SDKProperties) FindDeviceByIP(ipAddr string) (*FuchsiaDevice, error)

FindDeviceByIP returns a fuchsia device matching a specific ip address.

func (SDKProperties) FindDeviceByName

func (sdk SDKProperties) FindDeviceByName(deviceName string) (*FuchsiaDevice, error)

FindDeviceByName returns a fuchsia device matching a specific device name.

func (SDKProperties) GetAddressByName

func (sdk SDKProperties) GetAddressByName(deviceName string) (string, error)

GetAddressByName returns the IPv6 address of the device.

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) GetDefaultDeviceName

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

GetDefaultDeviceName returns the name of the target 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 GetDefaultDeviceName(). 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 initalized 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 initalized 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) ListDevices

func (sdk SDKProperties) ListDevices() ([]*FuchsiaDevice, error)

ListDevices returns all available fuchsia devices.

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) (string, error)

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

func (SDKProperties) RunSSHCommand

func (sdk SDKProperties) RunSSHCommand(targetAddress string, customSSHConfig string, privateKey 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. The return value is the stdout.

func (SDKProperties) RunSSHShell

func (sdk SDKProperties) RunSSHShell(targetAddress string, customSSHConfig string, privateKey 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. 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.

Jump to

Keyboard shortcuts

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