Documentation ¶
Overview ¶
A development kit for the cloud based of modular components.
A Lacework component package to help facilitate the loading and execution of components
Index ¶
- Constants
- Variables
- func CatalogCacheDir() (string, error)
- func CatalogV1Enabled(client *api.Client) bool
- func Dir() (string, error)
- func DownloadFile(path string, url string) error
- func IsNotFound(err error) bool
- func LoadLocalComponents() (components map[string]CDKComponent, err error)
- type ApiInfo
- type Artifact
- type Breadcrumbs
- type CDKComponent
- type Catalog
- func (c *Catalog) ComponentCount() int
- func (c *Catalog) Delete(component *CDKComponent) error
- func (c *Catalog) GetComponent(name string) (*CDKComponent, error)
- func (c *Catalog) Install(component *CDKComponent) error
- func (c *Catalog) ListComponentVersions(component *CDKComponent) ([]*semver.Version, error)
- func (c *Catalog) PrintComponents() [][]string
- func (c *Catalog) Stage(component *CDKComponent, version string, ...) (stageClose func(), err error)
- func (c *Catalog) Verify(component *CDKComponent) error
- type Component
- func (c Component) ArtifactForRunningHost(version string) (*Artifact, bool)
- func (c Component) CurrentVersion() (*semver.Version, error)
- func (c Component) EnterDevelopmentMode() error
- func (c Component) IsCommandType() bool
- func (c Component) IsExecutable() bool
- func (c Component) IsInstalled() bool
- func (c Component) ListVersions(installed *semver.Version) string
- func (c Component) MakeUpdateMessage(from, to semver.Version) string
- func (c Component) MarshalJSON() ([]byte, error)
- func (c Component) Path() (string, error)
- func (c Component) RootPath() (string, error)
- func (c Component) RunAndOutput(args []string, envs ...string) error
- func (c Component) RunAndReturn(args []string, stdin io.Reader, envs ...string) (stdout string, stderr string, err error)
- func (c Component) SignatureFromDisk() ([]byte, error)
- func (c Component) Status() Status
- func (c Component) UnderDevelopment() bool
- func (c *Component) UnmarshalJSON(data []byte) error
- func (c Component) UpdateAvailable() (bool, error)
- func (c Component) WriteSignature(signature []byte) error
- func (c Component) WriteVersion(installed string) error
- type DevInfo
- type Executer
- type HostInfo
- type Library
- type RunError
- type StageConstructor
- type Stager
- type State
- type Status
- type Type
Constants ¶
const ( EmptyType Type = "" // the component is a binary BinaryType = "BINARY" // will this component be accessible via the CLI CommandType = "CLI_COMMAND" // the component is a library, only provides content for the CLI or other components LibraryType = "LIBRARY" // the component is standalone, should be available in $PATH StandaloneType = "STANDALONE" )
const (
DefaultMaxRetry = 3
)
const (
DevelopmentEnv = "LW_CDK_DEV_COMPONENT"
)
Variables ¶
var ( ErrNonExecutable error = errors.New("component not executable") ErrRun string = "unable to run component" )
var ( VersionFile = ".version" SignatureFile = ".signature" InfoFile = ".info" DevelopmentFile = ".dev" )
var (
ErrComponentNotFound = errors.New("component not found on disk")
)
Functions ¶
func CatalogCacheDir ¶
Returns the local directory that Components will be stored in.
func CatalogV1Enabled ¶
func DownloadFile ¶
Retry 3 times (4 requests total) Resty default RetryWaitTime is 100ms Exponential backoff to a maximum of RetryWaitTime of 2s
func IsNotFound ¶
IsNotFound returns a boolean indicating whether the error is known to have determined the component is not found. It is satisfied by ErrNotApplyComment
func LoadLocalComponents ¶
func LoadLocalComponents() (components map[string]CDKComponent, err error)
Types ¶
type ApiInfo ¶
type Breadcrumbs ¶
type Breadcrumbs struct { InstallationMessage string `json:"installationMessage,omitempty"` UpdateMessage string `json:"updateMessage,omitempty"` }
Components should leave a trail/crumb after installation or update, these messages will be shown by the Lacework CLI
type CDKComponent ¶
type CDKComponent struct { Name string `json:"name"` Description string `json:"description"` Type Type `json:"type"` Status Status `json:"-"` InstallMessage string `json:"-"` UpdateMessage string `json:"-"` Exec Executer `json:"-"` ApiInfo *ApiInfo `json:"apiInfo,omitempty"` HostInfo *HostInfo `json:"-"` // contains filtered or unexported fields }
func NewCDKComponent ¶
func NewCDKComponent(apiInfo *ApiInfo, hostInfo *HostInfo) CDKComponent
func (*CDKComponent) Dir ¶
func (c *CDKComponent) Dir() (string, error)
func (*CDKComponent) EnterDevMode ¶
func (c *CDKComponent) EnterDevMode() error
func (*CDKComponent) InstalledVersion ¶
func (c *CDKComponent) InstalledVersion() *semver.Version
func (*CDKComponent) LatestVersion ¶
func (c *CDKComponent) LatestVersion() *semver.Version
func (*CDKComponent) PrintSummary ¶
func (c *CDKComponent) PrintSummary() []string
type Catalog ¶
type Catalog struct { Components map[string]CDKComponent // contains filtered or unexported fields }
func NewCachedCatalog ¶
func NewCatalog ¶
func NewCatalog( client *api.Client, stageConstructor StageConstructor, ) (*Catalog, error)
func (*Catalog) ComponentCount ¶
func (*Catalog) Delete ¶
func (c *Catalog) Delete(component *CDKComponent) error
Delete a CDKComponent
Remove the Component install directory and all sub-directory. This function will not return an error if the Component is not installed.
func (*Catalog) GetComponent ¶
func (c *Catalog) GetComponent(name string) (*CDKComponent, error)
Return a CDKComponent that is present on the host.
func (*Catalog) Install ¶
func (c *Catalog) Install(component *CDKComponent) error
func (*Catalog) ListComponentVersions ¶
func (c *Catalog) ListComponentVersions(component *CDKComponent) ([]*semver.Version, error)
func (*Catalog) PrintComponents ¶
func (*Catalog) Verify ¶
func (c *Catalog) Verify(component *CDKComponent) error
type Component ¶
type Component struct { Name string `json:"name"` Description string `json:"description"` Type Type `json:"type"` LatestVersion semver.Version `json:"-"` Artifacts []Artifact `json:"artifacts"` Breadcrumbs Breadcrumbs `json:"breadcrumbs,omitempty"` // @dhazekamp command_name required when CLICommand is true? CommandName string `json:"command_name,omitempty"` }
Component can be a command-line tool, a new command that extends the Lacework CLI, or a library that contains files used by another Lacework component.
func (Component) ArtifactForRunningHost ¶
ArtifactForRunningHost returns the right component artifact for the running host,
func (Component) CurrentVersion ¶
CurrentVersion returns the current installed version of the component
func (Component) EnterDevelopmentMode ¶
func (Component) IsCommandType ¶
func (Component) IsExecutable ¶
func (Component) IsInstalled ¶
IsInstalled returns true if the component is installed on disk
TODO: @jon-stewart: remove - is in wrong place
func (Component) MakeUpdateMessage ¶
func (Component) MarshalJSON ¶
func (Component) RunAndOutput ¶
RunAndOutput runs the command and outputs to os.Stdout and os.Stderr, the provided environment variables will be accessible by the component
func (Component) RunAndReturn ¶
func (c Component) RunAndReturn(args []string, stdin io.Reader, envs ...string) ( stdout string, stderr string, err error, )
RunAndReturn runs the command and returns its standard output and standard error, the provided environment variables will be accessible by the component
func (Component) SignatureFromDisk ¶
SignatureFromDisk returns the component signature stored on disk ("RootPath()/.signature")
func (Component) UnderDevelopment ¶
UnderDevelopment returns true if the component is under development that is, if the component root path has the '.dev' specs file or, if the environment variable 'LW_CDK_DEV_COMPONENT' matches the component name
func (*Component) UnmarshalJSON ¶
func (Component) UpdateAvailable ¶
UpdateAvailable returns true if there is a newer version of the component
func (Component) WriteSignature ¶
WriteSignature stores the component signature on disk
func (Component) WriteVersion ¶
WriteVersion stores the component version on disk
type Executer ¶
type Executer interface { Executable() bool Execute(args []string, envs ...string) (stdout string, stderr string, err error) ExecuteInline(args []string, envs ...string) (err error) Path() string }
func NewExecuable ¶
type HostInfo ¶
type HostInfo struct { Name string `json:"name"` ComponentType Type `json:"type"` Desc string `json:"description"` Dir string `json:"-"` }
func LoadHostInfo ¶
func (*HostInfo) Development ¶
type Library ¶
type Library interface { // Install downloads the library and deploys the files and index Install() error // Index returns the index of files that the library contains Index() []string // GetFile returns the content of one file from the library GetFile(string) ([]byte, error) }
A library component provides one or more files that other components use
type RunError ¶
RunError is a struct used to pass an error when a component tries to run and it fails, a few functions will return this error so that callers (upstream packages) can unwrap and identify that the error comes from this package
type StageConstructor ¶
type Stager ¶
type State ¶
State holds the components specification
You can load the state from the Lacework API server by passing an `api.Client`.
client, err := api.NewClient(account, opts...) cState, err := lwcomponent.LoadState(client)
Or, you can load the state from the local storage.
cState, err := lwcomponent.LocalState()
func LocalState ¶
LocalState loads the state from the local storage ("Dir()/state")
func (State) GetComponent ¶
GetComponent returns the pointer of a component, if the component is not found, this function will return a `nil` pointer and `false`
Usage:
component, found := state.GetComponent(name) if !found { fmt.Println("Component %s not found", name) }
func (State) WriteState ¶
WriteState stores the components state to disk