Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyProjectConfig(ctx context.Context, stackName string, project *Project, stackEnv esc.Value, ...) error
- func CopyTemplateFiles(sourceDir, destDir string, force bool, projectName string, ...) error
- func CopyTemplateFilesDryRun(sourceDir, destDir, projectName string) error
- func DeleteAccount(key string) error
- func DeleteAllAccounts() error
- func DetectPolicyPackPathAt(path string) (string, error)
- func DetectPolicyPackPathFrom(path string) (string, error)
- func DetectProjectPath() (string, error)
- func DetectProjectPathFrom(dir string) (string, error)
- func DetectProjectStackDeploymentPath(stackName tokens.QName) (string, error)
- func DownloadToFile(ctx context.Context, pkgPlugin PluginSpec, ...) (*os.File, error)
- func GetCachedVersionFilePath() (string, error)
- func GetCodeinfraHomeDir() (string, error)
- func GetCodeinfraPath(elem ...string) (string, error)
- func GetPluginDir() (string, error)
- func GetPluginPath(d diag.Sink, kind apitype.PluginKind, name string, version *semver.Version, ...) (string, error)
- func GetPolicyDir(orgName string) (string, error)
- func GetPolicyPath(orgName, name, version string) (string, bool, error)
- func GetTemplateDir(templateKind TemplateKind) (string, error)
- func HasPlugin(spec PluginSpec) bool
- func HasPluginGTE(spec PluginSpec) (bool, error)
- func InferFullTypeName(typeName string, itemsType *ProjectConfigItemsType) string
- func IsPluginBundled(kind apitype.PluginKind, name string) bool
- func IsPluginKind(k string) booldeprecated
- func IsTemplateURL(templateNamePathOrURL string) bool
- func NewMissingError(kind apitype.PluginKind, name string, version *semver.Version, ...) error
- func NewRetryableClient() *http.Client
- func ReadCloserProgressBar(closer io.ReadCloser, size int64, message string, ...) io.ReadCloser
- func RetrieveGitFolder(ctx context.Context, rawurl string, path string) (string, error)
- func RetrieveZIPTemplateFolder(templateURL *url.URL, tempDir string, opts ...RequestOption) (string, error)
- func RewriteConfigPathIntoStackConfigDir(project map[string]interface{}) (map[string]interface{}, error)
- func RewriteShorthandConfigValues(project map[string]interface{}) map[string]interface{}
- func SaveProject(proj *Project) error
- func SaveProjectStack(stackName tokens.QName, stack *ProjectStack) error
- func SaveProjectStackDeployment(stackName tokens.QName, deployment *ProjectStackDeployment) error
- func SetBackendConfigDefaultOrg(backendURL, defaultOrg string) error
- func SimplifyMarshalledProject(raw interface{}) (map[string]interface{}, error)
- func SimplifyMarshalledValue(raw interface{}) (interface{}, error)
- func StoreAccount(key string, account Account, current bool) error
- func StoreCodeinfraConfig(config CodeinfraConfig) error
- func StoreCredentials(creds Credentials) error
- func ValidateConfigValue(typeName string, itemsType *ProjectConfigItemsType, value interface{}) bool
- func ValidateProject(raw interface{}) error
- func ValidateStackConfigAndApplyProjectConfig(ctx context.Context, stackName string, project *Project, stackEnv esc.Value, ...) error
- type Account
- type Analyzers
- type BackendConfig
- type CodeinfraConfig
- type Credentials
- type Environment
- func (e *Environment) Append(envs ...string) *Environment
- func (e *Environment) Definition() []byte
- func (e *Environment) Imports() []string
- func (e Environment) MarshalJSON() ([]byte, error)
- func (e Environment) MarshalYAML() (any, error)
- func (e *Environment) Remove(env string) *Environment
- func (e *Environment) UnmarshalJSON(b []byte) error
- func (e *Environment) UnmarshalYAML(n *yaml.Node) error
- type MissingError
- type PackageDescriptor
- type Parameterization
- type PluginContent
- type PluginInfo
- func GetPluginInfo(d diag.Sink, kind apitype.PluginKind, name string, version *semver.Version, ...) (*PluginInfo, error)
- func GetPlugins() ([]PluginInfo, error)
- func GetPluginsWithMetadata() ([]PluginInfo, error)
- func LegacySelectCompatiblePlugin(plugins []PluginInfo, kind apitype.PluginKind, name string, ...) *PluginInfo
- func SelectCompatiblePlugin(plugins []PluginInfo, kind apitype.PluginKind, name string, ...) *PluginInfo
- type PluginKinddeprecated
- type PluginOptions
- type PluginProject
- type PluginSource
- type PluginSpec
- func (spec PluginSpec) Dir() string
- func (spec PluginSpec) DirPath() (string, error)
- func (spec PluginSpec) Download(ctx context.Context) (io.ReadCloser, int64, error)
- func (spec PluginSpec) File() string
- func (spec PluginSpec) GetLatestVersion(ctx context.Context) (*semver.Version, error)
- func (spec PluginSpec) GetSource() (PluginSource, error)
- func (spec PluginSpec) Install(tgz io.ReadCloser, reinstall bool) error
- func (spec PluginSpec) InstallWithContext(ctx context.Context, content PluginContent, reinstall bool) error
- func (spec PluginSpec) LockFilePath() (string, error)
- func (spec PluginSpec) PartialFilePath() (string, error)
- func (spec PluginSpec) String() string
- type Plugins
- type PolicyPackProject
- type PolicyPackTemplate
- type Project
- func DetectProject() (*Project, error)
- func DetectProjectAndPath() (*Project, string, error)
- func DetectProjectStackPath(stackName tokens.QName) (*Project, string, error)
- func LoadProject(path string) (*Project, error)
- func LoadProjectBytes(b []byte, path string, marshaller encoding.Marshaler) (*Project, error)
- type ProjectBackend
- type ProjectConfigItemsType
- type ProjectConfigKey
- type ProjectConfigType
- type ProjectOptions
- type ProjectPlugin
- type ProjectRuntimeInfo
- func (info ProjectRuntimeInfo) MarshalJSON() ([]byte, error)
- func (info ProjectRuntimeInfo) MarshalYAML() (interface{}, error)
- func (info *ProjectRuntimeInfo) Name() string
- func (info *ProjectRuntimeInfo) Options() map[string]interface{}
- func (info *ProjectRuntimeInfo) SetOption(key string, value interface{})
- func (info *ProjectRuntimeInfo) UnmarshalJSON(data []byte) error
- func (info *ProjectRuntimeInfo) UnmarshalYAML(unmarshal func(interface{}) error) error
- type ProjectStack
- type ProjectStackDeployment
- type ProjectTemplate
- type ProjectTemplateConfigValue
- type RequestOption
- type Settings
- type SortedPluginInfo
- type SortedPluginSpec
- type StackName
- type Template
- type TemplateKind
- type TemplateRepository
- type TokenInformation
- type W
Constants ¶
const ( // BackupDir is the name of the folder where backup stack information is stored. BackupDir = "backups" // BookkeepingDir is the name of our bookkeeping folder, we store state here (like .git for git). BookkeepingDir = ".codeinfra" // ConfigDir is the name of the folder that holds local configuration information. ConfigDir = "config" // GitDir is the name of the folder git uses to store information. GitDir = ".git" // HistoryDir is the name of the directory that holds historical information for projects. HistoryDir = "history" // PluginDir is the name of the directory containing plugins. PluginDir = "plugins" // PolicyDir is the name of the directory that holds policy packs. PolicyDir = "policies" // StackDir is the name of the directory that holds stack information for projects. StackDir = "stacks" // LockDir is the name of the directory that holds locking information for projects. LockDir = "locks" // TemplateDir is the name of the directory containing templates. TemplateDir = "templates" // TemplatePolicyDir is the name of the directory containing templates for Policy Packs. TemplatePolicyDir = "templates-policy" // WorkspaceDir is the name of the directory that holds workspace information for projects. WorkspaceDir = "workspaces" // IgnoreFile is the name of the file that we use to control what to upload to the service. IgnoreFile = ".codeinfraignore" // ProjectFile is the base name of a project file. ProjectFile = "Codeinfra" // DeploymentSuffix is the base suffix for deployment settings files (e.g. "Codeinfra.<stack>.deploy.yaml"). DeploymentSuffix = "deploy" // RepoFile is the name of the file that holds information specific to the entire repository. RepoFile = "settings.json" // WorkspaceFile is the name of the file that holds workspace information. WorkspaceFile = "workspace.json" // CachedVersionFile is the name of the file we use to store when we last checked if the CLI was out of date CachedVersionFile = ".cachedVersionInfo" // CodeinfraHomeEnvVar is a path to the '.codeinfra' folder with plugins, access token, etc. // The folder can have any name, not necessarily '.codeinfra'. // It defaults to the '<user's home>/.codeinfra' if not specified. CodeinfraHomeEnvVar = "CODEINFRA_HOME" // PolicyPackFile is the base name of a Codeinfra policy pack file. PolicyPackFile = "CodeinfraPolicy" )
const ( AnalyzerPlugin = apitype.AnalyzerPlugin LanguagePlugin = apitype.LanguagePlugin ResourcePlugin = apitype.ResourcePlugin ConverterPlugin = apitype.ConverterPlugin ToolPlugin = apitype.ToolPlugin )
ProductKind types definition
Deprecated: PluginKind type was moved to "github.com/khulnasoft/codeinfra/sdk/v3/go/common/apitype"
const CodeinfraCredentialsPathEnvVar = "CODEINFRA_CREDENTIALS_PATH"
CodeinfraCredentialsPathEnvVar is a path to the folder where credentials are stored. We use this in testing so that tests which log in and out do not impact the local developer's credentials or tests interacting with one another
const CodeinfraTagsConfigKey = "codeinfra:tags"
To mitigate an import cycle, we define this here.
const RetryCount = 6
Variables ¶
var ErrProjectNotFound = errors.New("no project file found")
var ProjectSchema *jsonschema.Schema
Functions ¶
func ApplyProjectConfig ¶
func ApplyProjectConfig( ctx context.Context, stackName string, project *Project, stackEnv esc.Value, stackConfig config.Map, encrypter config.Encrypter, ) error
ApplyConfigDefaults applies the default values for the project configuration onto the stack configuration without validating the contents of stack config values. This is because sometimes during codeinfra config ls and codeinfra config get, if users are using PassphraseDecrypter, we don't want to always prompt for the values when not necessary
func CopyTemplateFiles ¶
func CopyTemplateFiles( sourceDir, destDir string, force bool, projectName string, projectDescription string, ) error
CopyTemplateFiles does the actual copy operation to a destination directory.
func CopyTemplateFilesDryRun ¶
CopyTemplateFilesDryRun does a dry run of copying a template to a destination directory, to ensure it won't overwrite any files.
func DeleteAccount ¶
DeleteAccount deletes an account underneath the given key.
func DeleteAllAccounts ¶
func DeleteAllAccounts() error
func DetectPolicyPackPathAt ¶
DetectPolicyPackPathAt locates the CodeinfraPolicy file at the given path. If no project is found, an empty path is returned. Unlike DetectPolicyPackPathFrom, this function does not search upwards in the directory hierarchy.
func DetectPolicyPackPathFrom ¶
DetectPolicyPackPathFrom locates the closest Codeinfra policy project from the given path, searching "upwards" in the directory hierarchy. If no project is found, an empty path is returned.
func DetectProjectPath ¶
DetectProjectPath locates the closest project from the current working directory, or an error if not found.
func DetectProjectPathFrom ¶
DetectProjectPathFrom locates the closest project from the given path, searching "upwards" in the directory hierarchy. If no project is found, an empty path is returned.
func DownloadToFile ¶
func DownloadToFile( ctx context.Context, pkgPlugin PluginSpec, wrapper func(stream io.ReadCloser, size int64) io.ReadCloser, retry func(err error, attempt int, limit int, delay time.Duration), ) (*os.File, error)
DownloadToFile downloads the given PluginInfo to a temporary file and returns that temporary file. This has some retry logic to re-attempt the download if it errors for any reason. The context supplied may be used for cancellable I/O.
func GetCachedVersionFilePath ¶
GetCachedVersionFilePath returns the location where the CLI caches information from codeinfra.com on the newest available version of the CLI
func GetCodeinfraHomeDir ¶
GetCodeinfraHomeDir returns the path of the '.codeinfra' folder where Codeinfra puts its artifacts.
func GetCodeinfraPath ¶
GetCodeinfraPath returns the path to a file or directory under the '.codeinfra' folder. It joins the path of the '.codeinfra' folder with elements passed as arguments.
func GetPluginDir ¶
GetPluginDir returns the directory in which plugins on the current machine are managed.
func GetPluginPath ¶
func GetPluginPath(d diag.Sink, kind apitype.PluginKind, name string, version *semver.Version, projectPlugins []ProjectPlugin, ) (string, error)
GetPluginPath finds a plugin's path by its kind, name, and optional version. It will match the latest version that is >= the version specified. If no version is supplied, the latest plugin for that given kind/name pair is loaded, using standard semver sorting rules. A plugin may be overridden entirely by placing it on your $PATH, though it is possible to opt out of this behavior by setting CODEINFRA_IGNORE_AMBIENT_PLUGINS to any non-empty value.
func GetPolicyDir ¶
GetPolicyDir returns the directory in which an organization's Policy Packs on the current machine are managed.
func GetPolicyPath ¶
GetPolicyPath finds a PolicyPack by its name version, as well as a bool marked true if the path already exists and is a directory.
func GetTemplateDir ¶
func GetTemplateDir(templateKind TemplateKind) (string, error)
GetTemplateDir returns the directory in which templates on the current machine are stored.
func HasPlugin ¶
func HasPlugin(spec PluginSpec) bool
HasPlugin returns true if the given plugin exists.
func HasPluginGTE ¶
func HasPluginGTE(spec PluginSpec) (bool, error)
HasPluginGTE returns true if the given plugin exists at the given version number or greater.
func InferFullTypeName ¶
func InferFullTypeName(typeName string, itemsType *ProjectConfigItemsType) string
func IsPluginBundled ¶
func IsPluginBundled(kind apitype.PluginKind, name string) bool
We currently bundle some plugins with "codeinfra" and thus expect them to be next to the codeinfra binary. Eventually we want to fix this so new plugins are true plugins in the plugin cache.
func IsPluginKind
deprecated
func IsTemplateURL ¶
IsTemplateURL returns true if templateNamePathOrURL starts with "https://" (SSL) or "git@" (SSH).
func NewMissingError ¶
func NewMissingError(kind apitype.PluginKind, name string, version *semver.Version, includeAmbient bool) error
NewMissingError allocates a new error indicating the given plugin info was not found.
func NewRetryableClient ¶
func ReadCloserProgressBar ¶
func ReadCloserProgressBar( closer io.ReadCloser, size int64, message string, colorization colors.Colorization, ) io.ReadCloser
ReadCloserProgressBar displays a progress bar for the given closer and returns a wrapper closer to manipulate it.
func RetrieveGitFolder ¶
RetrieveGitFolder downloads the repo to path and returns the full path on disk.
func RewriteConfigPathIntoStackConfigDir ¶
func RewriteConfigPathIntoStackConfigDir(project map[string]interface{}) (map[string]interface{}, error)
RewriteConfigPathIntoStackConfigDir checks if the project is using the old "config" property to declare a path to the stack configuration directory. If that is the case, we rewrite it such that the value in config: {value} is moved to stackConfigDir: {value}. if the user defines both values as strings, we error out.
func RewriteShorthandConfigValues ¶
RewriteShorthandConfigValues rewrites short-hand version of configuration into a configuration type for example the following config block definition:
config: instanceSize: t3.mirco aws:region: us-west-2
will be rewritten into a typed value:
config: instanceSize: default: t3.micro aws:region: value: us-west-2
Note that short-hand values without namespaces (project config) are turned into a type where as short-hand values with namespaces (such as aws:region) are turned into a value.
func SaveProject ¶
SaveProject saves the project file on top of the existing one, using the standard location.
func SaveProjectStack ¶
func SaveProjectStack(stackName tokens.QName, stack *ProjectStack) error
func SaveProjectStackDeployment ¶
func SaveProjectStackDeployment(stackName tokens.QName, deployment *ProjectStackDeployment) error
func SimplifyMarshalledValue ¶
func SimplifyMarshalledValue(raw interface{}) (interface{}, error)
Cast any map[interface{}] from the yaml decoder to map[string]
func StoreAccount ¶
StoreAccount saves the given account underneath the given key.
func StoreCodeinfraConfig ¶
func StoreCodeinfraConfig(config CodeinfraConfig) error
func StoreCredentials ¶
func StoreCredentials(creds Credentials) error
StoreCredentials updates the stored credentials on the machine, replacing the existing set. If the credentials are empty, the auth file will be deleted rather than just serializing an empty map.
func ValidateConfigValue ¶
func ValidateConfigValue(typeName string, itemsType *ProjectConfigItemsType, value interface{}) bool
ValidateConfig validates the config value against its config type definition. We use this to validate the default config values alongside their type definition but also to validate config values coming from individual stacks.
func ValidateProject ¶
func ValidateProject(raw interface{}) error
Types ¶
type Account ¶
type Account struct { // The access token for this account. AccessToken string `json:"accessToken,omitempty"` // The username for this account. Username string `json:"username,omitempty"` // The organizations for this account. Organizations []string `json:"organizations,omitempty"` // The last time this token was validated. LastValidatedAt time.Time `json:"lastValidatedAt,omitempty"` // Allow insecure server connections when using SSL. Insecure bool `json:"insecure,omitempty"` // Information about the token used to authenticate. TokenInformation *TokenInformation `json:"tokenInformation,omitempty"` }
Account holds the information associated with a Codeinfra account.
func GetAccount ¶
GetAccount returns an account underneath a given key.
Note that the account may not be fully populated: it may only have a valid AccessToken. In that case, it is up to the caller to fill in the username and last validation time.
type BackendConfig ¶
type BackendConfig struct {
DefaultOrg string `json:"defaultOrg,omitempty"` // The default org for this backend config.
}
type CodeinfraConfig ¶
type CodeinfraConfig struct {
BackendConfig map[string]BackendConfig `json:"backends,omitempty"` // a map of arbitrary backends configs.
}
func GetCodeinfraConfig ¶
func GetCodeinfraConfig() (CodeinfraConfig, error)
type Credentials ¶
type Credentials struct { Current string `json:"current,omitempty"` // the currently selected key. AccessTokens map[string]string `json:"accessTokens,omitempty"` // a map of arbitrary key strings to tokens. Accounts map[string]Account `json:"accounts,omitempty"` // a map of arbitrary keys to account info. }
Credentials hold the information necessary for authenticating Codeinfra Cloud API requests. It contains a map from the cloud API URL to the associated access token.
func GetStoredCredentials ¶
func GetStoredCredentials() (Credentials, error)
GetStoredCredentials returns any credentials stored on the local machine.
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
func NewEnvironment ¶
func NewEnvironment(envs []string) *Environment
func (*Environment) Append ¶
func (e *Environment) Append(envs ...string) *Environment
func (*Environment) Definition ¶
func (e *Environment) Definition() []byte
func (*Environment) Imports ¶
func (e *Environment) Imports() []string
func (Environment) MarshalJSON ¶
func (e Environment) MarshalJSON() ([]byte, error)
func (Environment) MarshalYAML ¶
func (e Environment) MarshalYAML() (any, error)
func (*Environment) Remove ¶
func (e *Environment) Remove(env string) *Environment
func (*Environment) UnmarshalJSON ¶
func (e *Environment) UnmarshalJSON(b []byte) error
func (*Environment) UnmarshalYAML ¶
func (e *Environment) UnmarshalYAML(n *yaml.Node) error
type MissingError ¶
type MissingError struct {
// contains filtered or unexported fields
}
MissingError is returned by functions that attempt to load plugins if a plugin can't be located.
func (*MissingError) Error ¶
func (err *MissingError) Error() string
type PackageDescriptor ¶
type PackageDescriptor struct { // A specification for the plugin that provides the package. PluginSpec // An optional parameterization to apply to the providing plugin to produce // the package. Parameterization *Parameterization }
A PackageDescriptor specifies a package: the source PluginSpec that provides it, and any parameterization that must be applied to that plugin in order to produce the package.
func (PackageDescriptor) PackageName ¶
func (pd PackageDescriptor) PackageName() string
PackageName returns the name of the package.
func (PackageDescriptor) PackageVersion ¶
func (pd PackageDescriptor) PackageVersion() *semver.Version
PackageVersion returns the version of the package.
func (PackageDescriptor) String ¶
func (pd PackageDescriptor) String() string
type Parameterization ¶
type Parameterization struct { // The name of the package that will be produced by the parameterization. Name string // The version of the package that will be produced by the parameterization. Version semver.Version // A plugin-dependent bytestring representing the value of the parameter to be // passed to the plugin. Value []byte }
A Parameterization may be applied to a supporting plugin to yield a package.
type PluginContent ¶
func DirPlugin ¶
func DirPlugin(rootPath string) PluginContent
func SingleFilePlugin ¶
func SingleFilePlugin(f *os.File, spec PluginSpec) PluginContent
func TarPlugin ¶
func TarPlugin(tgz io.ReadCloser) PluginContent
type PluginInfo ¶
type PluginInfo struct { Name string // the simple name of the plugin. Path string // the path that a plugin was loaded from (this will always be a directory) Kind apitype.PluginKind // the kind of the plugin (language, resource, etc). Version *semver.Version // the plugin's semantic version, if present. Size uint64 // the size of the plugin, in bytes. InstallTime time.Time // the time the plugin was installed. LastUsedTime time.Time // the last time the plugin was used. SchemaPath string // if set, used as the path for loading and caching the schema SchemaTime time.Time // if set and newer than the file at SchemaPath, used to invalidate a cached schema }
PluginInfo provides basic information about a plugin. Each plugin gets installed into a system-wide location, by default `~/.codeinfra/plugins/<kind>-<name>-<version>/`. A plugin may contain multiple files, however the primary loadable executable must be named `codeinfra-<kind>-<name>`.
func GetPluginInfo ¶
func GetPluginInfo(d diag.Sink, kind apitype.PluginKind, name string, version *semver.Version, projectPlugins []ProjectPlugin, ) (*PluginInfo, error)
func GetPlugins ¶
func GetPlugins() ([]PluginInfo, error)
GetPlugins returns a list of installed plugins without size info and last accessed metadata. Plugin size requires recursively traversing the plugin directory, which can be extremely expensive with the introduction of nodejs multilang components that have deeply nested node_modules folders.
func GetPluginsWithMetadata ¶
func GetPluginsWithMetadata() ([]PluginInfo, error)
GetPluginsWithMetadata returns a list of installed plugins with metadata about size, and last access (POOR RUNTIME PERF). Plugin size requires recursively traversing the plugin directory, which can be extremely expensive with the introduction of nodejs multilang components that have deeply nested node_modules folders.
func LegacySelectCompatiblePlugin ¶
func LegacySelectCompatiblePlugin( plugins []PluginInfo, kind apitype.PluginKind, name string, version *semver.Version, ) *PluginInfo
LegacySelectCompatiblePlugin selects a plugin from the list of plugins with the given kind and name that satisfies the requested version. It returns the highest version plugin greater than the requested version, or an error if no such plugin could be found.
If there exist plugins in the plugin list that don't have a version, LegacySelectCompatiblePlugin will select them if there are no other compatible plugins available.
func SelectCompatiblePlugin ¶
func SelectCompatiblePlugin( plugins []PluginInfo, kind apitype.PluginKind, name string, requested semver.Range, ) *PluginInfo
SelectCompatiblePlugin selects a plugin from the list of plugins with the given kind and name that sastisfies the requested semver range. It returns the highest version plugin that satisfies the requested constraints, or an error if no such plugin could be found.
If there exist plugins in the plugin list that don't have a version, SelectCompatiblePlugin will select them if there are no other compatible plugins available.
func (*PluginInfo) Delete ¶
func (info *PluginInfo) Delete() error
Delete removes the plugin from the cache. It also deletes any supporting files in the cache, which includes any files that contain the same prefix as the plugin itself.
func (*PluginInfo) SetFileMetadata ¶
func (info *PluginInfo) SetFileMetadata(path string) error
SetFileMetadata adds extra metadata from the given file, representing this plugin's directory.
func (*PluginInfo) Spec ¶
func (info *PluginInfo) Spec() PluginSpec
Spec returns the PluginSpec for this PluginInfo
func (PluginInfo) String ¶
func (info PluginInfo) String() string
type PluginKind
deprecated
type PluginKind = apitype.PluginKind
Re exporting PluginKind to keep backward compatibility, this should be kept in sync with the definitions in sdk/go/common/apitype/plugins.go
Deprecated: PluginKind type was moved to "github.com/khulnasoft/codeinfra/sdk/v3/go/common/apitype"
type PluginOptions ¶
type PluginProject ¶
type PluginProject struct { // Runtime is a required runtime that executes code. Runtime ProjectRuntimeInfo `json:"runtime" yaml:"runtime"` }
func LoadPluginProject ¶
func LoadPluginProject(path string) (*PluginProject, error)
LoadPluginProject reads a plugin project definition from a file.
func (*PluginProject) Validate ¶
func (proj *PluginProject) Validate() error
type PluginSource ¶
type PluginSource interface { // Download fetches an io.ReadCloser for this plugin and also returns the size of the response (if known). // The context supplied enables I/O to be canceled as needed. Download(ctx context.Context, version semver.Version, opSy string, arch string, getHTTPResponse func(*http.Request) (io.ReadCloser, int64, error)) (io.ReadCloser, int64, error) // GetLatestVersion tries to find the latest version for this plugin. This is currently only supported for // plugins we can get from GitHub releases. The context supplied enables I/O to be canceled as needed. GetLatestVersion(ctx context.Context, getHTTPResponse func(*http.Request) (io.ReadCloser, int64, error)) (*semver.Version, error) // A base URL that can uniquely identify the source. Has the same structure as the PluginDownloadURL // schema option. Example: "github://api.github.com/khulnasoft/codeinfra-aws". URL() string }
PluginSource deals with downloading a specific version of a plugin, or looking up the latest version of it.
type PluginSpec ¶
type PluginSpec struct { Name string // the simple name of the plugin. Kind apitype.PluginKind // the kind of the plugin (language, resource, etc). Version *semver.Version // the plugin's semantic version, if present. PluginDownloadURL string // an optional server to use when downloading this plugin. PluginDir string // if set, will be used as the root plugin dir instead of ~/.codeinfra/plugins. // if set will be used to validate the plugin downloaded matches. This is keyed by "$os-$arch", e.g. "linux-x64". Checksums map[string][]byte }
PluginSpec provides basic specification for a plugin.
func NewPluginSpec ¶
func NewPluginSpec( source string, kind apitype.PluginKind, version *semver.Version, pluginDownloadURL string, checksums map[string][]byte, ) (PluginSpec, error)
func (PluginSpec) Dir ¶
func (spec PluginSpec) Dir() string
Dir gets the expected plugin directory for this plugin.
func (PluginSpec) DirPath ¶
func (spec PluginSpec) DirPath() (string, error)
DirPath returns the directory where this plugin should be installed.
func (PluginSpec) Download ¶
func (spec PluginSpec) Download(ctx context.Context) (io.ReadCloser, int64, error)
Download fetches an io.ReadCloser for this plugin and also returns the size of the response (if known). The context allows for I/O cancellation.
func (PluginSpec) File ¶
func (spec PluginSpec) File() string
File gets the expected filename for this plugin, excluding any platform specific suffixes (e.g. ".exe" on windows).
func (PluginSpec) GetLatestVersion ¶
GetLatestVersion tries to find the latest version for this plugin. This is currently only supported for plugins we can get from github releases. The context allows for I/O cancellation.
func (PluginSpec) GetSource ¶
func (spec PluginSpec) GetSource() (PluginSource, error)
func (PluginSpec) Install ¶
func (spec PluginSpec) Install(tgz io.ReadCloser, reinstall bool) error
Install installs a plugin's tarball into the cache. See InstallWithContext for details.
func (PluginSpec) InstallWithContext ¶
func (spec PluginSpec) InstallWithContext(ctx context.Context, content PluginContent, reinstall bool) error
InstallWithContext installs a plugin's tarball into the cache. It validates that plugin names are in the expected format. Previous versions of Codeinfra extracted the tarball to a temp directory first, and then renamed the temp directory to the final directory. The rename operation fails often enough on Windows due to aggressive virus scanners opening files in the temp directory. To address this, we now extract the tarball directly into the final directory, and use file locks to prevent concurrent installs.
Each plugin has its own file lock, with the same name as the plugin directory, with a `.lock` suffix. During installation an empty file with a `.partial` suffix is created, indicating that installation is in-progress. The `.partial` file is deleted when installation is complete, indicating that the plugin has finished installing. If a failure occurs during installation, the `.partial` file will remain, indicating the plugin wasn't fully installed. The next time the plugin is installed, the old installation directory will be removed and replaced with a fresh installation.
func (PluginSpec) LockFilePath ¶
func (spec PluginSpec) LockFilePath() (string, error)
LockFilePath returns the full path to the plugin's lock file used during installation to prevent concurrent installs.
func (PluginSpec) PartialFilePath ¶
func (spec PluginSpec) PartialFilePath() (string, error)
PartialFilePath returns the full path to the plugin's partial file used during installation to indicate installation of the plugin hasn't completed yet.
func (PluginSpec) String ¶
func (spec PluginSpec) String() string
type Plugins ¶
type Plugins struct { Providers []PluginOptions `json:"providers,omitempty" yaml:"providers,omitempty"` Languages []PluginOptions `json:"languages,omitempty" yaml:"languages,omitempty"` Analyzers []PluginOptions `json:"analyzers,omitempty" yaml:"analyzers,omitempty"` }
type PolicyPackProject ¶
type PolicyPackProject struct { // Runtime is a required runtime that executes code. Runtime ProjectRuntimeInfo `json:"runtime" yaml:"runtime"` // Version specifies the version of the policy pack. If set, it will override the // version specified in `package.json` for Node.js policy packs. Version string `json:"version,omitempty" yaml:"version,omitempty"` // Main is an optional override for the program's main entry-point location. Main string `json:"main,omitempty" yaml:"main,omitempty"` // Description is an optional informational description. Description *string `json:"description,omitempty" yaml:"description,omitempty"` // Author is an optional author that created this project. Author *string `json:"author,omitempty" yaml:"author,omitempty"` // Website is an optional website for additional info about this project. Website *string `json:"website,omitempty" yaml:"website,omitempty"` // License is the optional license governing this project's usage. License *string `json:"license,omitempty" yaml:"license,omitempty"` // contains filtered or unexported fields }
func LoadPolicyPack ¶
func LoadPolicyPack(path string) (*PolicyPackProject, error)
LoadPolicyPack reads a policy pack definition from a file.
func (PolicyPackProject) RawValue ¶
func (proj PolicyPackProject) RawValue() []byte
func (*PolicyPackProject) Save ¶
func (proj *PolicyPackProject) Save(path string) error
Save writes a project definition to a file.
func (*PolicyPackProject) Validate ¶
func (proj *PolicyPackProject) Validate() error
type PolicyPackTemplate ¶
type PolicyPackTemplate struct { Dir string // The directory containing CodeinfraPolicy.yaml. Name string // The name of the template. Description string // Description of the template. Error error // Non-nil if the template is broken. }
PolicyPackTemplate represents a Policy Pack template.
func LoadPolicyPackTemplate ¶
func LoadPolicyPackTemplate(path string) (PolicyPackTemplate, error)
LoadPolicyPackTemplate returns a Policy Pack template from a path.
func (PolicyPackTemplate) Errored ¶
func (t PolicyPackTemplate) Errored() bool
Errored returns if the template has an error
type Project ¶
type Project struct { // Name is a required fully qualified name. Name tokens.PackageName `json:"name" yaml:"name"` // Runtime is a required runtime that executes code. Runtime ProjectRuntimeInfo `json:"runtime" yaml:"runtime"` // Main is an optional override for the program's main entry-point location. Main string `json:"main,omitempty" yaml:"main,omitempty"` // Description is an optional informational description. Description *string `json:"description,omitempty" yaml:"description,omitempty"` // Author is an optional author that created this project. Author *string `json:"author,omitempty" yaml:"author,omitempty"` // Website is an optional website for additional info about this project. Website *string `json:"website,omitempty" yaml:"website,omitempty"` // License is the optional license governing this project's usage. License *string `json:"license,omitempty" yaml:"license,omitempty"` // Config has been renamed to StackConfigDir. Config map[string]ProjectConfigType `json:"config,omitempty" yaml:"config,omitempty"` // StackConfigDir indicates where to store the Codeinfra.<stack-name>.yaml files, combined with the folder // Codeinfra.yaml is in. StackConfigDir string `json:"stackConfigDir,omitempty" yaml:"stackConfigDir,omitempty"` // Template is an optional template manifest, if this project is a template. Template *ProjectTemplate `json:"template,omitempty" yaml:"template,omitempty"` // Backend is an optional backend configuration Backend *ProjectBackend `json:"backend,omitempty" yaml:"backend,omitempty"` // Options is an optional set of project options Options *ProjectOptions `json:"options,omitempty" yaml:"options,omitempty"` Plugins *Plugins `json:"plugins,omitempty" yaml:"plugins,omitempty"` // Handle additional keys, albeit in a way that will remove comments and trivia. AdditionalKeys map[string]interface{} `yaml:",inline"` // contains filtered or unexported fields }
Project is a Codeinfra project manifest.
We explicitly add yaml tags (instead of using the default behavior from https://github.com/ghodss/yaml which works in terms of the JSON tags) so we can directly marshall and unmarshall this struct using go-yaml an have the fields in the serialized object match the order they are defined in this struct.
TODO[codeinfra/codeinfra#423]: use DOM based marshalling so we can roundtrip the seralized structure perfectly.
func DetectProject ¶
DetectProject loads the closest project from the current working directory, or an error if not found.
func DetectProjectAndPath ¶
DetectProjectAndPath loads the closest package from the current working directory, or an error if not found. It also returns the path where the package was found.
func DetectProjectStackPath ¶
DetectProjectStackPath returns the name of the file to store stack specific project settings in. We place stack specific settings next to the Codeinfra.yaml file, named like: Codeinfra.<stack-name>.yaml
func LoadProject ¶
LoadProject reads a project definition from a file.
func LoadProjectBytes ¶
LoadProjectBytes reads a project definition from a byte slice.
func (*Project) AddConfigStackTags ¶
AddConfigStackTags sets the project tags config to the given map of tags.
type ProjectBackend ¶
type ProjectBackend struct { // URL is optional field to explicitly set backend url URL string `json:"url,omitempty" yaml:"url,omitempty"` }
ProjectBackend is the configuration for where the backend state is stored. If unset, will use the system's currently logged-in backend.
Use the same URL format that is passed to "codeinfra login", see https://www.codeinfra.com/docs/cli/commands/codeinfra_login/
To explicitly use the Codeinfra Cloud backend, use URL "https://api.codeinfra.com"
type ProjectConfigItemsType ¶
type ProjectConfigItemsType struct { Type string `json:"type,omitempty" yaml:"type,omitempty"` Items *ProjectConfigItemsType `json:"items,omitempty" yaml:"items,omitempty"` }
type ProjectConfigKey ¶
type ProjectConfigKey = string
type ProjectConfigType ¶
type ProjectConfigType struct { Type *string `json:"type,omitempty" yaml:"type,omitempty"` Description string `json:"description,omitempty" yaml:"description,omitempty"` Items *ProjectConfigItemsType `json:"items,omitempty" yaml:"items,omitempty"` Default interface{} `json:"default,omitempty" yaml:"default,omitempty"` Value interface{} `json:"value,omitempty" yaml:"value,omitempty"` Secret bool `json:"secret,omitempty" yaml:"secret,omitempty"` }
func (*ProjectConfigType) IsExplicitlyTyped ¶
func (configType *ProjectConfigType) IsExplicitlyTyped() bool
IsExplicitlyTyped returns whether the project config type is explicitly typed. When that is the case, we validate stack config values against this type, given that the stack config value is namespaced by the project.
func (*ProjectConfigType) TypeName ¶
func (configType *ProjectConfigType) TypeName() string
type ProjectOptions ¶
type ProjectOptions struct { // Refresh is the ability to always run a refresh as part of a codeinfra update / preview / destroy Refresh string `json:"refresh,omitempty" yaml:"refresh,omitempty"` }
type ProjectPlugin ¶
type ProjectPlugin struct { Name string // the simple name of the plugin. Kind apitype.PluginKind // the kind of the plugin (language, resource, etc). Version *semver.Version // the plugin's semantic version, if present. Path string // the path that a plugin is to be loaded from (this will always be a directory) }
ProjectPlugin Information about a locally installed plugin specified by the project.
func (ProjectPlugin) Spec ¶
func (pp ProjectPlugin) Spec() PluginSpec
Spec Return a PluginSpec object for this project plugin.
type ProjectRuntimeInfo ¶
type ProjectRuntimeInfo struct {
// contains filtered or unexported fields
}
func NewProjectRuntimeInfo ¶
func NewProjectRuntimeInfo(name string, options map[string]interface{}) ProjectRuntimeInfo
func (ProjectRuntimeInfo) MarshalJSON ¶
func (info ProjectRuntimeInfo) MarshalJSON() ([]byte, error)
func (ProjectRuntimeInfo) MarshalYAML ¶
func (info ProjectRuntimeInfo) MarshalYAML() (interface{}, error)
func (*ProjectRuntimeInfo) Name ¶
func (info *ProjectRuntimeInfo) Name() string
func (*ProjectRuntimeInfo) Options ¶
func (info *ProjectRuntimeInfo) Options() map[string]interface{}
func (*ProjectRuntimeInfo) SetOption ¶
func (info *ProjectRuntimeInfo) SetOption(key string, value interface{})
func (*ProjectRuntimeInfo) UnmarshalJSON ¶
func (info *ProjectRuntimeInfo) UnmarshalJSON(data []byte) error
func (*ProjectRuntimeInfo) UnmarshalYAML ¶
func (info *ProjectRuntimeInfo) UnmarshalYAML(unmarshal func(interface{}) error) error
type ProjectStack ¶
type ProjectStack struct { // SecretsProvider is this stack's secrets provider. SecretsProvider string `json:"secretsprovider,omitempty" yaml:"secretsprovider,omitempty"` // EncryptedKey is the KMS-encrypted ciphertext for the data key used for secrets encryption. // Only used for cloud-based secrets providers. EncryptedKey string `json:"encryptedkey,omitempty" yaml:"encryptedkey,omitempty"` // EncryptionSalt is this stack's base64 encoded encryption salt. Only used for // passphrase-based secrets providers. EncryptionSalt string `json:"encryptionsalt,omitempty" yaml:"encryptionsalt,omitempty"` // Config is an optional config bag. Config config.Map `json:"config,omitempty" yaml:"config,omitempty"` // Environment is an optional environment definition or list of environments. Environment *Environment `json:"environment,omitempty" yaml:"environment,omitempty"` // contains filtered or unexported fields }
ProjectStack holds stack specific information about a project.
func DetectProjectStack ¶
func DetectProjectStack(stackName tokens.QName) (*ProjectStack, error)
func LoadProjectStack ¶
func LoadProjectStack(project *Project, path string) (*ProjectStack, error)
LoadProjectStack reads a stack definition from a file.
func LoadProjectStackBytes ¶
func LoadProjectStackBytes( project *Project, b []byte, path string, marshaller encoding.Marshaler, ) (*ProjectStack, error)
LoadProjectStack reads a stack definition from a byte slice.
func (ProjectStack) EnvironmentBytes ¶
func (ps ProjectStack) EnvironmentBytes() []byte
func (ProjectStack) RawValue ¶
func (ps ProjectStack) RawValue() []byte
func (*ProjectStack) Save ¶
func (ps *ProjectStack) Save(path string) error
Save writes a project definition to a file.
type ProjectStackDeployment ¶
type ProjectStackDeployment struct {
DeploymentSettings apitype.DeploymentSettings `json:"settings" yaml:"settings"`
}
func DetectProjectStackDeployment ¶
func DetectProjectStackDeployment(stackName tokens.QName) (*ProjectStackDeployment, error)
func LoadProjectStackDeployment ¶
func LoadProjectStackDeployment(path string) (*ProjectStackDeployment, error)
func (*ProjectStackDeployment) Save ¶
func (psd *ProjectStackDeployment) Save(path string) error
type ProjectTemplate ¶
type ProjectTemplate struct { // DisplayName is an optional user friendly name of the template. DisplayName string `json:"displayName,omitempty" yaml:"displayName,omitempty"` // Description is an optional description of the template. Description string `json:"description,omitempty" yaml:"description,omitempty"` // Quickstart contains optional text to be displayed after template creation. Quickstart string `json:"quickstart,omitempty" yaml:"quickstart,omitempty"` // Config is an optional template config. Config map[string]ProjectTemplateConfigValue `json:"config,omitempty" yaml:"config,omitempty"` // Important indicates the template is important. Important bool `json:"important,omitempty" yaml:"important,omitempty"` // Metadata are key/value pairs used to attach additional metadata to a template. Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty"` }
ProjectTemplate is a Codeinfra project template manifest.
type ProjectTemplateConfigValue ¶
type ProjectTemplateConfigValue struct { // Description is an optional description for the config value. Description string `json:"description,omitempty" yaml:"description,omitempty"` // Default is an optional default value for the config value. Default string `json:"default,omitempty" yaml:"default,omitempty"` // Secret may be set to true to indicate that the config value should be encrypted. Secret bool `json:"secret,omitempty" yaml:"secret,omitempty"` }
ProjectTemplateConfigValue is a config value included in the project template manifest.
type RequestOption ¶
RequestOption is a function that modifies an http.Request.
type Settings ¶
type Settings struct { // Stack is an optional default stack to use. Stack string `json:"stack,omitempty" yaml:"env,omitempty"` }
Settings defines workspace settings shared amongst many related projects.
type SortedPluginInfo ¶
type SortedPluginInfo []PluginInfo
SortedPluginInfo is a wrapper around PluginInfo that allows for sorting by version.
func (SortedPluginInfo) Len ¶
func (sp SortedPluginInfo) Len() int
func (SortedPluginInfo) Less ¶
func (sp SortedPluginInfo) Less(i, j int) bool
func (SortedPluginInfo) Swap ¶
func (sp SortedPluginInfo) Swap(i, j int)
type SortedPluginSpec ¶
type SortedPluginSpec []PluginSpec
SortedPluginSpec is a wrapper around PluginSpec that allows for sorting by version.
func (SortedPluginSpec) Len ¶
func (sp SortedPluginSpec) Len() int
func (SortedPluginSpec) Less ¶
func (sp SortedPluginSpec) Less(i, j int) bool
func (SortedPluginSpec) Swap ¶
func (sp SortedPluginSpec) Swap(i, j int)
type Template ¶
type Template struct { Dir string // The directory containing Codeinfra.yaml. Name string // The name of the template. Description string // Description of the template. Quickstart string // Optional text to be displayed after template creation. Config map[string]ProjectTemplateConfigValue // Optional template config. Important bool // Indicates whether the template should be listed by default. Error error // Non-nil if the template is broken. ProjectName string // Name of the project. ProjectDescription string // Optional description of the project. }
Template represents a project template.
func LoadTemplate ¶
LoadTemplate returns a template from a path.
type TemplateKind ¶
type TemplateKind int
TemplateKind describes the form of a template.
const ( // TemplateKindCodeinfraProject is a template for a Codeinfra stack. TemplateKindCodeinfraProject TemplateKind = 0 // TemplateKindPolicyPack is a template for a Policy Pack. TemplateKindPolicyPack TemplateKind = 1 )
type TemplateRepository ¶
type TemplateRepository struct { Root string // The full path to the root directory of the repository. SubDirectory string // The full path to the sub directory within the repository. ShouldDelete bool // Whether the root directory should be deleted. }
TemplateRepository represents a repository of templates.
func RetrieveTemplates ¶
func RetrieveTemplates(ctx context.Context, templateNamePathOrURL string, offline bool, templateKind TemplateKind, ) (TemplateRepository, error)
RetrieveTemplates retrieves a "template repository" based on the specified name, path, or URL.
func RetrieveZIPTemplates ¶
func RetrieveZIPTemplates(templateURL string, opts ...RequestOption) (TemplateRepository, error)
func (TemplateRepository) Delete ¶
func (repo TemplateRepository) Delete() error
Delete deletes the template repository.
func (TemplateRepository) PolicyTemplates ¶
func (repo TemplateRepository) PolicyTemplates() ([]PolicyPackTemplate, error)
PolicyTemplates lists the policy templates in the repository.
func (TemplateRepository) Templates ¶
func (repo TemplateRepository) Templates() ([]Template, error)
Templates lists the templates in the repository.
type TokenInformation ¶
type TokenInformation struct { Name string `json:"name"` // The name of the token. Organization string `json:"organization,omitempty"` // If this was an organization token, the organization it was for. Team string `json:"team,omitempty"` // If this was a team token, the team it was for. }
Information about the token that was used to authenticate the current user. One (or none) of Team or Organization will be set, but not both.