project

package
v0.0.0-...-41e44c1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: BSD-3-Clause Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const NamespaceRegex = `^([\w-_]+)\/([\w-_\.]+)(?:#([-a-fA-F0-9]*))?$`

NamespaceRegex matches the org and project name in a namespace, eg. org/project

View Source
const ProjectCategory = "project"

ProjectCategory is the string used when referencing project secrets (eg. $secrets.project.foo)

View Source
const ProjectRegex = `^([\w-_\.]+)(?:#([-a-fA-F0-9]*))?$`

ProjectRegex matches the project name for a namespace with omitted org.

View Source
const TopLevelExpanderName = "toplevel"
View Source
const UserCategory = "user"

UserCategory is the string used when referencing user secrets (eg. $secrets.user.foo)

Variables

View Source
var (
	ErrExpandBadName = errs.New("Bad expander name")
	ErrExpandNoFunc  = errs.New("Expander has no handler")
)
View Source
var ErrSecretNotFound = errors.New("secret not found")

Functions

func ConstantExpander

func ConstantExpander(_ string, name string, meta string, isFunction bool, ctx *Expansion) (string, error)

ConstantExpander expands constants defined in the project-file.

func DefaultScriptLanguage

func DefaultScriptLanguage() []language.Language

DefaultScriptLanguage returns the default script language for the current platform. (ie. batch or bash)

func EventExpander

func EventExpander(_ string, name string, meta string, isFunction bool, ctx *Expansion) (string, error)

EventExpander expands events defined in the project-file.

func ExpandFromProject

func ExpandFromProject(s string, p *Project) (string, error)

ExpandFromProject searches for $category.name-style variables in the given string and substitutes them with their contents, derived from the given project, and subject to the given constraints (if any).

func ExpandFromProjectBashifyPaths

func ExpandFromProjectBashifyPaths(s string, p *Project) (string, error)

ExpandFromProjectBashifyPaths is like ExpandFromProject, but bashifies all instances of $script.name.path().

func ExpandFromScript

func ExpandFromScript(s string, script *Script) (string, error)

func IsRegistered

func IsRegistered(handle string) bool

IsRegistered returns true if an Expander Func is registered for a given handle/name.

func ProjectExpander

func ProjectExpander(_ string, name string, _ string, isFunction bool, ctx *Expansion) (string, error)

ProjectExpander expands constants defined in the project-file.

func RegisterConditional

func RegisterConditional(conditional *constraints.Conditional)

RegisterConditional is a a temporary method for registering our conditional as a global yes this is bad, but at the time of implementation refactoring the project package to not be global is out of scope

func RegisterExpander

func RegisterExpander(handle string, expanderFn ExpanderFunc) error

RegisterExpander registers an Expander Func for some given handler value. The handler value must not effectively be a blank string and the Func must be defined. It is definitely possible to replace an existing handler using this function.

func ScriptExpander

func ScriptExpander(_ string, name string, meta string, isFunction bool, ctx *Expansion) (string, error)

ScriptExpander expands scripts defined in the project-file.

func TopLevelExpander

func TopLevelExpander(variable string, name string, _ string, _ bool, ctx *Expansion) (string, error)

Types

type Build

type Build map[string]string

Build covers the build structure

type ConfigAble

type ConfigAble interface {
	projectfile.ConfigGetter
}

type Constant

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

Constant covers the constant structure

func (*Constant) Name

func (c *Constant) Name() string

Name returns constant name

func (*Constant) Value

func (c *Constant) Value() (string, error)

Value returns constant value

type Event

type Event struct {
	BashifyPaths bool // for script path() calls, which varies by subshell
	// contains filtered or unexported fields
}

Event covers the hook structure

func (*Event) Name

func (e *Event) Name() string

Name returns Event name

func (*Event) Scope

func (e *Event) Scope() ([]string, error)

Scope returns the scope property of the event

func (*Event) Source

func (e *Event) Source() *projectfile.Project

Source returns the source projectfile

func (*Event) Value

func (e *Event) Value() (string, error)

Value returned with all secrets evaluated

type EventType

type EventType string
const (
	BeforeCmd     EventType = "before-command"
	AfterCmd      EventType = "after-command"
	Activate      EventType = "activate"
	FirstActivate EventType = "first-activate"
)

func ActivateEvents

func ActivateEvents() []EventType

func (EventType) String

func (e EventType) String() string

type ExpanderFunc

type ExpanderFunc func(variable, name, meta string, isFunction bool, ctx *Expansion) (string, error)

ExpanderFunc defines an Expander function which can expand the name for a category. An Expander expects the name to be expanded along with the project-file definition. It will return the expanded value of the name or a Failure if expansion was unsuccessful.

func NewSecretPromptingExpander

func NewSecretPromptingExpander(secretsClient *secretsapi.Client, prompt prompt.Prompter, cfg keypairs.Configurable, auth *authentication.Auth) ExpanderFunc

NewSecretPromptingExpander creates an Expander which can retrieve and decrypt stored user secrets. Additionally, it will prompt the user to provide a value for a secret -- in the event none is found -- and save the new value with the secrets service.

func NewSecretQuietExpander

func NewSecretQuietExpander(secretsClient *secretsapi.Client, cfg keypairs.Configurable, auth *authentication.Auth) ExpanderFunc

NewSecretQuietExpander creates an Expander which can retrieve and decrypt stored user secrets.

func RegisteredExpander

func RegisteredExpander(handle string) ExpanderFunc

RegisteredExpander returns the expander registered for the given handle

type Expansion

type Expansion struct {
	Project      *Project
	Script       *Script
	BashifyPaths bool
}

func NewExpansion

func NewExpansion(p *Project) *Expansion

func (*Expansion) ApplyWithMaxDepth

func (ctx *Expansion) ApplyWithMaxDepth(s string, depth int) (string, error)

ApplyWithMaxDepth limits the depth of an expansion to avoid infinite expansion of a value.

type Job

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

Job covers the command structure

func (*Job) Constants

func (j *Job) Constants() []*Constant

func (*Job) Name

func (j *Job) Name() string

func (*Job) Scripts

func (j *Job) Scripts() ([]*Script, error)

type Mixin

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

Mixin provides expansions that are not sourced from a project file

func NewMixin

func NewMixin(auth *authentication.Auth) *Mixin

NewMixin creates a Mixin object providing extra expansions

func (*Mixin) Expander

func (m *Mixin) Expander(_ string, name string, meta string, _ bool, _ *Expansion) (string, error)

Expander expands mixin variables

type Namespaced

type Namespaced struct {
	Owner          string
	Project        string
	CommitID       *strfmt.UUID
	AllowOmitOwner bool
}

Namespaced represents a project namespace of the form <org/project>

func NameSpaceForConfig

func NameSpaceForConfig(configFile string) *Namespaced

NameSpaceForConfig returns a valid project namespace. This version prefers to create a namespace from a configFile if it exists

func NewNamespace

func NewNamespace(owner, project, commitID string) *Namespaced

func ParseNamespace

func ParseNamespace(raw string) (*Namespaced, error)

ParseNamespace returns a valid project namespace

func ParseProjectNoOwner

func ParseProjectNoOwner(raw string) (*Namespaced, error)

func (*Namespaced) IsValid

func (ns *Namespaced) IsValid() bool

IsValid returns whether or not the namespace is set sufficiently.

func (*Namespaced) Set

func (ns *Namespaced) Set(v string) error

Set implements the captain argmarshaler interface.

func (*Namespaced) String

func (ns *Namespaced) String() string

String implements the fmt.Stringer interface.

func (*Namespaced) Type

func (ns *Namespaced) Type() string

Type returns the human readable type name of Namespaced.

func (*Namespaced) Validate

func (ns *Namespaced) Validate() error

Validate returns a failure if the namespace is not valid.

type Project

type Project struct {
	output.Outputer
	// contains filtered or unexported fields
}

Project covers the platform structure

func FromEnv

func FromEnv() (*Project, error)

FromEnv will return the project as per the environment configuration (eg. env var, working dir, global default, ..)

func FromExactPath

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

FromExactPath will return the project that's located at the given path without walking up the directory tree

func FromPath

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

FromPath will return the project that's located at the given path (this will walk up the directory tree until it finds the project)

func FromWD

func FromWD() (*Project, error)

FromWD will return the project that's located at the current working directory

func New

New creates a new Project struct

func NewLegacy

func NewLegacy(p *projectfile.Project) (*Project, error)

NewLegacy is for legacy use-cases only, DO NOT USE

func Parse

func Parse(fpath string) (*Project, error)

Parse will parse the given projectfile and instantiate a Project struct with it

func (*Project) BranchName

func (p *Project) BranchName() string

BranchName returns the project branch name

func (*Project) Cache

func (p *Project) Cache() string

Cache returns the cache information for this project

func (*Project) Channel

func (p *Project) Channel() string

Channel returns channel that we're pinned to (useless unless version is also set)

func (*Project) ConstantByName

func (p *Project) ConstantByName(name string) *Constant

ConstantByName returns a constant matching the given name (if any)

func (*Project) Constants

func (p *Project) Constants() []*Constant

Constants returns a reference to projectfile.Constants

func (*Project) Dir

func (p *Project) Dir() string

Dir returns the project dir

func (*Project) Environments

func (p *Project) Environments() string

Environments returns project environment

func (*Project) EventByName

func (p *Project) EventByName(name string, bashifyPaths bool) *Event

EventByName returns a reference to a projectfile.Script with a given name.

func (*Project) Events

func (p *Project) Events() []*Event

Events returns a reference to projectfile.Events

func (*Project) InitSecret

func (p *Project) InitSecret(name string, scope SecretScope, cfg keypairs.Configurable, auth *authentication.Auth) *Secret

InitSecret creates a new secret with the given name and all default settings

func (*Project) IsHeadless

func (p *Project) IsHeadless() bool

func (*Project) IsLocked

func (p *Project) IsLocked() bool

IsLocked returns whether the current project is locked

func (*Project) IsPortable

func (p *Project) IsPortable() bool

func (*Project) Jobs

func (p *Project) Jobs() []*Job

Jobs returns a reference to projectfile.Jobs

func (*Project) LegacyCommitID

func (p *Project) LegacyCommitID() string

LegacyCommitID is for use by legacy mechanics ONLY

func (*Project) Lock

func (p *Project) Lock() string

Lock returns the lock information for this project

func (*Project) Name

func (p *Project) Name() string

Name returns project name

func (*Project) Namespace

func (p *Project) Namespace() *Namespaced

Namespace returns project namespace

func (*Project) NamespaceString

func (p *Project) NamespaceString() string

NamespaceString is a convenience function to make interfaces simpler

func (*Project) NewSecret

func (p *Project) NewSecret(s *projectfile.Secret, scope SecretScope, cfg keypairs.Configurable, auth *authentication.Auth) *Secret

NewSecret creates a new secret struct

func (*Project) NormalizedName

func (p *Project) NormalizedName() string

NormalizedName returns the project name in a normalized format (alphanumeric, lowercase)

func (*Project) Owner

func (p *Project) Owner() string

Owner returns project owner

func (*Project) Path

func (p *Project) Path() string

Path returns the project path

func (*Project) Private

func (p *Project) Private() bool

func (*Project) ProjectDir

func (p *Project) ProjectDir() string

ProjectDir is an alias for Dir() to satisfy interfaces that may also target the setup.Targeter interface.

func (*Project) ScriptByName

func (p *Project) ScriptByName(name string) (*Script, error)

ScriptByName returns a reference to a projectfile.Script with a given name.

func (*Project) Scripts

func (p *Project) Scripts() ([]*Script, error)

Scripts returns a reference to projectfile.Scripts

func (*Project) SecretByName

func (p *Project) SecretByName(name string, scope SecretScope, cfg keypairs.Configurable, auth *authentication.Auth) *Secret

SecretByName returns a secret matching the given name (if any)

func (*Project) Secrets

func (p *Project) Secrets(cfg keypairs.Configurable, auth *authentication.Auth) []*Secret

Secrets returns a reference to projectfile.Secrets

func (*Project) SetLegacyCommit

func (p *Project) SetLegacyCommit(commitID string) error

func (*Project) Source

func (p *Project) Source() *projectfile.Project

Source returns the source projectfile

func (*Project) URL

func (p *Project) URL() string

URL returns the Project field of the project file

func (*Project) Version

func (p *Project) Version() string

Version returns the locked state tool version

type Script

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

Script covers the command structure

func (*Script) Description

func (script *Script) Description() string

Description returns script description

func (*Script) LanguageSafe

func (script *Script) LanguageSafe() []language.Language

LanguageSafe returns the first languages of this script. The returned languages are guaranteed to be of a known scripting language

func (*Script) Languages

func (script *Script) Languages() []language.Language

Languages returns the languages of this script

func (*Script) Name

func (script *Script) Name() string

Name returns script name

func (*Script) Raw

func (script *Script) Raw() string

Raw returns the script value with no secrets or constants expanded

func (*Script) Source

func (script *Script) Source() *projectfile.Project

Source returns the source projectfile

func (*Script) SourceScript

func (script *Script) SourceScript() *projectfile.Script

SourceScript returns the source script

func (*Script) Standalone

func (script *Script) Standalone() bool

Standalone returns if the script is standalone or not

func (*Script) Value

func (script *Script) Value() (string, error)

Value returned with all secrets evaluated

type Secret

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

Secret covers the secret structure

func (*Secret) Description

func (s *Secret) Description() string

Description returns secret description

func (*Secret) IsProject

func (s *Secret) IsProject() bool

IsProject returns whether this secret is project scoped

func (*Secret) IsUser

func (s *Secret) IsUser() bool

IsUser returns whether this secret is user scoped

func (*Secret) Name

func (s *Secret) Name() string

Name returns secret name

func (*Secret) Scope

func (s *Secret) Scope() string

Scope returns the scope as a string

func (*Secret) Source

func (s *Secret) Source() *projectfile.Project

Source returns the source projectfile

func (*Secret) Value

func (s *Secret) Value() (string, error)

Value returned with all secrets evaluated

func (*Secret) ValueOrNil

func (s *Secret) ValueOrNil() (*string, error)

ValueOrNil acts as Value() except it can return a nil

type SecretAccess

type SecretAccess struct {
	IsUser bool
	Name   string
}

SecretAccess is used to track secrets that were requested

type SecretExpander

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

SecretExpander takes care of expanding secrets

func NewSecretExpander

func NewSecretExpander(secretsClient *secretsapi.Client, prj *Project, prompt prompt.Prompter, cfg keypairs.Configurable, auth *authentication.Auth) *SecretExpander

NewSecretExpander returns a new instance of SecretExpander

func (*SecretExpander) Expand

func (e *SecretExpander) Expand(_ string, category string, name string, isFunction bool, ctx *Expansion) (string, error)

Expand will expand a variable to a secret value, if no secret exists it will return an empty string

func (*SecretExpander) ExpandWithPrompt

func (e *SecretExpander) ExpandWithPrompt(_ string, category string, name string, isFunction bool, ctx *Expansion) (string, error)

ExpandWithPrompt will expand a variable to a secret value, if no secret exists the user will be prompted

func (*SecretExpander) FetchDefinition

func (e *SecretExpander) FetchDefinition(name string, isUser bool) (*secretsModels.SecretDefinition, error)

FetchDefinition retrieves the definition associated with a secret

func (*SecretExpander) FetchSecret

func (e *SecretExpander) FetchSecret(name string, isUser bool) (string, error)

FetchSecret retrieves the given secret

func (*SecretExpander) FindSecret

func (e *SecretExpander) FindSecret(name string, isUser bool) (*secretsModels.UserSecret, error)

FindSecret will find the secret appropriate for the current project

func (*SecretExpander) KeyPair

func (e *SecretExpander) KeyPair() (keypairs.Keypair, error)

KeyPair acts as a caching layer for secrets.LoadKeypairFromConfigDir, and ensures that we have a projectfile

func (*SecretExpander) Organization

func (e *SecretExpander) Organization() (*mono_models.Organization, error)

Organization acts as a caching layer, and ensures that we have a projectfile

func (*SecretExpander) Project

func (e *SecretExpander) Project() (*mono_models.Project, error)

Project acts as a caching layer, and ensures that we have a projectfile

func (*SecretExpander) Secrets

func (e *SecretExpander) Secrets() ([]*secretsModels.UserSecret, error)

Secrets acts as a caching layer, and ensures that we have a projectfile

func (*SecretExpander) SecretsAccessed

func (e *SecretExpander) SecretsAccessed() []*SecretAccess

SecretsAccessed returns all secrets that were accessed since initialization

type SecretFunc

type SecretFunc func(name string, project *Project) (string, error)

SecretFunc defines what our expander functions will be returning

type SecretScope

type SecretScope string

SecretScope defines the scope of a secret

const (
	// SecretScopeUser defines a secret as being a user secret
	SecretScopeUser SecretScope = "user"
	// SecretScopeProject defines a secret as being a Project secret
	SecretScopeProject SecretScope = "project"
)

func NewSecretScope

func NewSecretScope(name string) (SecretScope, error)

NewSecretScope creates a new SecretScope from the given string name and will fail if the given string name does not match one of the available scopes

Jump to

Keyboard shortcuts

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