pkg

package
v0.1.29 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 30 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ContentTypeMultiPart string = "multipart/form-data; boundary=\"========\""
	Boundary             string = "========"
)
View Source
const DefaultParseOptions = UseEnvironmentVars
View Source
const DefaultPrefix = "ITZ_"
View Source
const RawGitHubUrlHost = "raw.githubusercontent.com"

Variables

This section is empty.

Functions

func AppendToFile

func AppendToFile(source string, to string) error

func AppendToFilename added in v0.1.26

func AppendToFilename(fn string, suffix string) (string, error)

AppendToFilename appends the suffix to the name of the file. The file is expected to be a URL

func BuildDestination added in v0.1.26

func BuildDestination(base string, gitURL string) (string, error)

BuildDestination builds the destination path using the git path to the pipeline.

func BuildPipelinePrompt added in v0.1.26

func BuildPipelinePrompt(name string, reader ParamReader, resolver ParamResolver) (*prompt.Prompt, error)

func ConfigOptions added in v0.1.26

func ConfigOptions(config *mapstructure.DecoderConfig)

func CreateCliRunner

func CreateCliRunner(cmd *cobra.Command, cfg *ServiceConfig) (*atkmod.CliModuleRunner, error)

CreateCliRunner creates an instance of a atkmod.CliModuleRunner for the given cobra.Command and ServiceConfig. The cobra.Command is used for variable substitution in the ServiceConfig. For example, you can use {{solution}} in the environment variables and it will substitute the value used for `--solution` on the command line.

func DoContainerizedStep

func DoContainerizedStep(cmd *cobra.Command, step string, inHandler InputHandlerFunc,
	outHandler OutputHandlerFunc) error

DoContainerizedStep is a function that acts as a Facade and does several operations. First, it loads the configuration for the cmd and the step from the CLI configuration file. It configures the CLI further using the ServiceConfig structure loaded from the CLI configuration file, then it sets up handler functions for handling STDIN and STDOUT in the container, then calls the Run method on the CliModuleRunner to run the container.

func ExecPipelineRun added in v0.1.26

func ExecPipelineRun(pipeline *v1beta1.Pipeline, run *v1beta1.PipelineRun, runScript string, useContainer bool, cluster ClusterInfo, cred CredInfo, in io.Reader, out io.Writer) error

ExecPipelineRun

func FindClusterByName

func FindClusterByName(in *Project, name string) (*string, error)

func FindParam added in v0.1.26

func FindParam(in v1beta1.Params, name string) (*v1beta1.Param, bool)

func FlattenCommandName

func FlattenCommandName(cmd *cobra.Command, suffix string) string

FlattenCommandName returns a string, such as "command.subcommand.step"

func GetITZHomeDir added in v0.1.26

func GetITZHomeDir() (string, error)

GetITZHomeDir returns the home directory or the ITZ command

func HomeTempFile added in v0.1.26

func HomeTempFile(base string, name string) string

HomeTempFile returns the path name of a file based on the metadata

func ImageFound

func ImageFound(out *bytes.Buffer, name string) bool

ImageFound returns true if the name of the image was found in the output. TODO: create a different function for finding the exact image, or add a flag here...

func IsPipeline added in v0.1.26

func IsPipeline(p v1beta1.Pipeline) bool

func IsPipelineRun added in v0.1.26

func IsPipelineRun(p v1beta1.PipelineRun) bool

func Keyify

func Keyify(name string) string

Keyify returns a string value that is suitable for use as a YAML configuration key.

func Lookup

func Lookup(parm JobParam, vars map[string]string) (string, bool)

func MergePipelineRun added in v0.1.26

func MergePipelineRun(run *v1beta1.PipelineRun, pl *v1beta1.Pipeline, reader ParamReader, resolver ParamResolver) (*v1beta1.PipelineRun, error)

func MustITZHomeDir added in v0.1.26

func MustITZHomeDir() string

func NewRunContext

func NewRunContext(svc *ServiceConfig, cmd *cobra.Command) *atkmod.RunContext

NewRunContext propertly creates the atkmod.RunContext for the given ServiceConfig and cobra.Command

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile reads the given file into the byte array

func ReadHttpGetB

func ReadHttpGetB(url string, user string, password string, handler ReturnCodeHandlerFunc) ([]byte, error)

func ReadHttpGetBWithFunc

func ReadHttpGetBWithFunc(url string, user string, password string, handler ReturnCodeHandlerFunc) ([]byte, error)

func ReadHttpGetT

func ReadHttpGetT(url string, token string) ([]byte, error)

func ReadHttpGetTWithFunc

func ReadHttpGetTWithFunc(url string, token string, handler ReturnCodeHandlerFunc) ([]byte, error)

func ResolveInterpolation

func ResolveInterpolation(cmd *cobra.Command, s string) (string, error)

ResolveInterpolation resolves the tokens in the string using the arguments configured in the cmd.

func ResolveVars

func ResolveVars(ref interface{}, cfg *ResolveVarConfig) (map[string]string, error)

ResolveVars looks through the given structure and returns a map of the values If cfg is nil, a default set of configuration options (see NewDefaultResolveVarConfig) are used.

func Sluggify added in v0.1.26

func Sluggify(s string) string

func StringSliceContains

func StringSliceContains(s []string, e string) bool

func ToEnvVar added in v0.1.26

func ToEnvVar(prefix, k string) string

func UnmarshalPipeline added in v0.1.26

func UnmarshalPipeline(yamlFile []byte) (interface{}, error)

func UnmarshalPipelineRun added in v0.1.26

func UnmarshalPipelineRun(content []byte) (interface{}, error)

func Unzip

func Unzip(src, dest string) error

Unzip extracts the zip archive to the specified directory

func WriteFile

func WriteFile(path string, data []byte) error

func WriteMessage

func WriteMessage(msg string, w io.Writer)

WriteMessage writes the given message to the output writer.

func WriteToFile added in v0.1.26

func WriteToFile(fn string, create bool, obj runtime.Object) error

Types

type ArgsParamParser added in v0.1.26

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

func (*ArgsParamParser) EnabledFor added in v0.1.26

func (p *ArgsParamParser) EnabledFor(opt ResolverOption) bool

func (*ArgsParamParser) Lookup added in v0.1.26

func (p *ArgsParamParser) Lookup(k string) (string, bool)

func (*ArgsParamParser) Supports added in v0.1.26

func (p *ArgsParamParser) Supports() ResolverOption

type AuthHandlerFunc

type AuthHandlerFunc func(req *http.Request) error

type BuildParamResolver

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

BuildParamResolver is used to resolve missing parameters

func NewBuildParamResolver

func NewBuildParamResolver(project *Project, cluster string, params []JobParam) (*BuildParamResolver, error)

func (*BuildParamResolver) BuildPrompter

func (r *BuildParamResolver) BuildPrompter(solution string) (*prompt.Prompt, error)

func (*BuildParamResolver) ResolvedParams

func (r *BuildParamResolver) ResolvedParams() map[string]string

type ChainedResolver added in v0.1.26

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

ChainedResolver is a Resolver itself that resolves the variables from different locations, such as a Pipeline defaults, the command line, or environment variables.

func NewChainedResolver added in v0.1.26

func NewChainedResolver(opt ResolverOption, enabled ...ParamResolver) *ChainedResolver

func (*ChainedResolver) EnabledFor added in v0.1.26

func (p *ChainedResolver) EnabledFor(opt ResolverOption) bool

EnabledFor returns true if the `ParamResolver` is enabled for the given option.

func (*ChainedResolver) Lookup added in v0.1.26

func (p *ChainedResolver) Lookup(k string) (string, bool)

func (*ChainedResolver) Supports added in v0.1.26

func (p *ChainedResolver) Supports() ResolverOption

type ClusterInfo

type ClusterInfo struct {
	State             string `yaml:"state"`
	URL               string `yaml:"api_url" tfvar:"server_url"`
	Name              string `yaml:"name"`
	CName             string `yaml:"cluster_name"`
	CredId            string `yaml:"credentialId"`
	Id                string `yaml:"cluster_id"`
	PubSvcEndpointURL string `yaml:"public_service_endpoint_url"`
	Infra             string `yaml:"infra_host"`
	Region            string `yaml:"region" tfvar:"region"`
}

type CredInfo

type CredInfo struct {
	Name   string `yaml:"name"`
	Infra  string `yaml:"infra"`
	State  string `yaml:"state"`
	ApiKey string `yaml:"api_key" tfvar:"ibmcloud_api_key"`
}

type EnvParamResolver added in v0.1.26

type EnvParamResolver struct {
	Prefix string
}

func (*EnvParamResolver) EnabledFor added in v0.1.26

func (p *EnvParamResolver) EnabledFor(opt ResolverOption) bool

func (*EnvParamResolver) Lookup added in v0.1.26

func (p *EnvParamResolver) Lookup(k string) (string, bool)

func (*EnvParamResolver) Supports added in v0.1.26

func (p *EnvParamResolver) Supports() ResolverOption

type GitServiceClient added in v0.1.26

type GitServiceClient struct {
	BaseDest string
}

GitServiceClient can download (get) the objects from a Git repository location

func (*GitServiceClient) Get added in v0.1.26

func (g *GitServiceClient) Get(gitURL string, marshaller MarshallerFunc) (interface{}, error)

Get the Pipeline from the Git repository

type InputHandlerFunc

type InputHandlerFunc func(in *bytes.Buffer) error

InputHandlerFunc is a handler for working with the input of a command.

type JobParam

type JobParam struct {
	Name    string `json:"name"`
	Value   string `json:"value,omitempty"`
	Default string `json:"default,omitempty"`
}

type MarshallerFunc added in v0.1.26

type MarshallerFunc func(b []byte) (interface{}, error)

type MetaInfo

type MetaInfo struct {
	Name string `yaml:"project_name"`
}

type OutputHandlerFunc

type OutputHandlerFunc func(out *bytes.Buffer) error

OutputHandlerFunc is a handler for working with the output of a command.

type ParamBuilderFunc

type ParamBuilderFunc func() map[string]string

type ParamReader added in v0.1.26

type ParamReader interface {
	// Params gets all `ParamSpec` objects
	Params() ([]v1beta1.ParamSpec, error)
}

ParamReader reads the `ParamSpec` objects from a source.

type ParamResolver added in v0.1.26

type ParamResolver interface {
	Supports() ResolverOption
	// EnabledFor returns true if the `ParamResolver` is enabled for the given
	// option.
	EnabledFor(opt ResolverOption) bool
	// Lookup returns the value of the parameter, if found, as well as
	// a bool that indicates if it was found.
	Lookup(p string) (string, bool)
}

ParamResolver resolves the parameter values from a source.

func NewArgsParamParser added in v0.1.26

func NewArgsParamParser(args []string) ParamResolver

func NewEnvParamResolver added in v0.1.26

func NewEnvParamResolver() ParamResolver

func NewPromptResolver added in v0.1.26

func NewPromptResolver(p *prompt.Prompt) ParamResolver

type PipelineParamOption added in v0.1.26

type PipelineParamOption struct {
	Text    string
	Value   string
	Default string
}

func (*PipelineParamOption) IsDefault added in v0.1.26

func (o *PipelineParamOption) IsDefault() bool

type PipelineParamOptions added in v0.1.26

type PipelineParamOptions struct {
	Options []PipelineParamOption
}

type PipelineParamParts added in v0.1.26

type PipelineParamParts struct {
	Description  string
	ParamOptions PipelineParamOptions
}

func ParseParamDescription added in v0.1.26

func ParseParamDescription(from string) (*PipelineParamParts, error)

func (*PipelineParamParts) HasOptions added in v0.1.26

func (p *PipelineParamParts) HasOptions() bool

type PipelineResolver added in v0.1.26

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

func NewPipelineResolver added in v0.1.26

func NewPipelineResolver(p *v1beta1.Pipeline) *PipelineResolver

NewPipelineResolver creates a new pipeline resolver that will resolve the parameters so long as they have default values. This is useful when accepting the defaults and not prompting the user unnecessarily.

func (*PipelineResolver) EnabledFor added in v0.1.26

func (p *PipelineResolver) EnabledFor(opt ResolverOption) bool

EnabledFor returns true if the `ParamResolver` is enabled for the given option.

func (*PipelineResolver) Lookup added in v0.1.26

func (p *PipelineResolver) Lookup(k string) (string, bool)

Lookup returns the value of the parameter, if found, as well as a bool that indicates if it was found. In the case of the `PipelineResolver`, this returns true if the `Pipeline` parameter has a default value.

func (*PipelineResolver) Params added in v0.1.26

func (p *PipelineResolver) Params() ([]v1beta1.ParamSpec, error)

func (*PipelineResolver) Supports added in v0.1.26

func (p *PipelineResolver) Supports() ResolverOption

type Project

type Project struct {
	Clusters    map[string]ClusterInfo `yaml:"clusters"`
	Meta        MetaInfo               `yaml:"general"`
	Credentials map[string]CredInfo    `yaml:"credentials"`
}

func LoadProject

func LoadProject(path string) (*Project, error)

LoadProject loads the given project from the yaml file.

func (*Project) Write

func (p *Project) Write(out io.Writer) error

type PromptResolver added in v0.1.26

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

func (*PromptResolver) EnabledFor added in v0.1.26

func (p *PromptResolver) EnabledFor(opt ResolverOption) bool

func (*PromptResolver) Lookup added in v0.1.26

func (p *PromptResolver) Lookup(k string) (string, bool)

func (*PromptResolver) Supports added in v0.1.26

func (p *PromptResolver) Supports() ResolverOption

type ResolveVarConfig

type ResolveVarConfig struct {
	Prefix string
	Tag    string
}

ResolveVarConfig are the configuration options for the ResolveVars func.

func NewDefaultResolveVarConfig

func NewDefaultResolveVarConfig() *ResolveVarConfig

type ResolverOption added in v0.1.26

type ResolverOption uint32
const (
	UsePipelineDefaults ResolverOption = 1 << iota
	UseEnvironmentVars
	UseCommandLineArgs
	UsePromptAnswers
)

func (ResolverOption) Includes added in v0.1.26

func (o ResolverOption) Includes(opt ResolverOption) bool

type ResponseHandlerFunc

type ResponseHandlerFunc func(reader io.ReadCloser) error

type ReturnCodeHandlerFunc

type ReturnCodeHandlerFunc func(code int) error

type ServiceClient

type ServiceClient struct {
	Method             string
	BaseURL            string
	QParams            ParamBuilderFunc
	FParams            ParamBuilderFunc
	ResponseHandler    ResponseHandlerFunc
	AuthHandler        AuthHandlerFunc
	Body               io.Reader
	ExpectedStatusCode int
	ContentType        string
}

ServiceClient is a client operation that provides more structure-driven interaction with the backend APIs so there don't have to be so many variations of HTTP methods.

type ServiceClientAuthType

type ServiceClientAuthType string
const (
	Bearer ServiceClientAuthType = "Bearer"
	Basic  ServiceClientAuthType = "Basic"
)

type ServiceConfig

type ServiceConfig struct {
	Env       []string    `yaml:"env,omitempty"`
	Image     string      `yaml:"image"`
	Local     bool        `yaml:"local"`
	MountOpts string      `yaml:"mountopts,omitempty"`
	Name      string      `yaml:"name,omitempty"`
	Type      ServiceType `yaml:"type,omitempty"`
	URL       *url.URL    `yaml:"url,omitempty"`
	Volumes   []string    `yaml:"volumes,omitempty"`
}

ServiceConfig represents a configuration record for a service in the CLI's configuration file. The reason this struct is repeated compared to just using the atkmod.CliParts struct is because the layer of abstraction allows us to tweak the YAML structure.

func LoadServiceConfig

func LoadServiceConfig(cmd *cobra.Command, path string) (*ServiceConfig, error)

LoadServiceConfig loads the service configuration for the given command and path.

type ServiceType

type ServiceType string
const (
	Background  ServiceType = "background"
	Interactive ServiceType = "interactive"
	InOut       ServiceType = "inout"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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