projectfile

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: 35 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigVersion = 1
View Source
const LocalProjectsConfigKey = "projects"

Variables

View Source
var (

	// ProjectURLRe Regex used to validate project fields /orgname/projectname[?commitID=someUUID]
	ProjectURLRe = regexp.MustCompile(urlProjectRegexStr)
	// CommitURLRe Regex used to validate commit info /commit/someUUID
	CommitURLRe = regexp.MustCompile(urlCommitRegexStr)
)

Functions

func AddLockInfo

func AddLockInfo(projectFilePath, branch, version string) error

AddLockInfo adds the lock field to activestate.yaml

func CleanProjectMapping

func CleanProjectMapping(cfg ConfigGetter)

CleanProjectMapping removes projects that no longer exist on a user's filesystem from the projects config entry

func GetCachedProjectNameForPath

func GetCachedProjectNameForPath(config ConfigGetter, projectPath string) string

func GetProjectFileMapping

func GetProjectFileMapping(config ConfigGetter) map[string][]*Project

func GetProjectFilePath

func GetProjectFilePath() (string, error)

GetProjectFilePath returns the path to the project activestate.yaml It considers projects in the following order: 1. Environment variable (e.g. `state shell` sets one) 2. Working directory (i.e. walk up directory tree looking for activestate.yaml) 3. Fall back on default project

func GetProjectMapping

func GetProjectMapping(config ConfigGetter) map[string][]string

func GetProjectPaths

func GetProjectPaths(cfg ConfigGetter, namespace string) []string

GetProjectPaths returns the paths of all projects associated with the namespace

func GetStaleProjectMapping

func GetStaleProjectMapping(config ConfigGetter) map[string][]string

GetStaleProjectMapping returns a project mapping from the last time the state tool was run. This mapping could include projects that are no longer on the system.

func NewProjectField

func NewProjectField() *projectField

func NewYamlField

func NewYamlField(field string, value interface{}) *yamlField

func RegisterMigrator

func RegisterMigrator(m MigratorFunc)

func RemoveLockInfo

func RemoveLockInfo(projectFilePath string) error

func SetRecentlyUsedNamespace

func SetRecentlyUsedNamespace(cfg ConfigGetter, namespace string)

func StoreProjectMapping

func StoreProjectMapping(cfg ConfigGetter, namespace, projectPath string)

StoreProjectMapping associates the namespace with the project path in the config

func ValidateProjectURL

func ValidateProjectURL(url string) error

ValidateProjectURL validates the configured project URL

Types

type Build

type Build map[string]string

Build covers the build map, which can go under languages or packages Build can hold variable keys, so we cannot predict what they are, hence why it is a map

type Conditional

type Conditional string

Conditional is an `if` conditional that when evalutes to true enables the entity its under it is meant to replace Constraints

type ConfigGetter

type ConfigGetter interface {
	GetStringMapStringSlice(key string) map[string][]string
	AllKeys() []string
	GetStringSlice(string) []string
	GetString(string) string
	Set(string, interface{}) error
	GetThenSet(string, func(interface{}) (interface{}, error)) error
	Close() error
}

type Constant

type Constant struct {
	NameVal        `yaml:",inline"`
	ConstantFields `yaml:",inline"`
}

Constant covers the constant structure, which goes under Project

func MakeConstantsFromConstrainedEntities

func MakeConstantsFromConstrainedEntities(items []ConstrainedEntity) (constants []*Constant)

MakeConstantsFromConstrainedEntities unboxes ConstraintedEntities as Constants

func (*Constant) ConditionalFilter

func (c *Constant) ConditionalFilter() Conditional

func (*Constant) ID

func (c *Constant) ID() string

ID returns the constant name

func (*Constant) UnmarshalYAML

func (c *Constant) UnmarshalYAML(unmarshal func(interface{}) error) error

type ConstantFields

type ConstantFields struct {
	Conditional Conditional `yaml:"if,omitempty"`
}

ConstantFields are the common fields for the Constant type. This is required for type composition related to its yaml.Unmarshaler implementation.

type Constants

type Constants []*Constant

Constants is a slice of constant values

func (Constants) AsConstrainedEntities

func (constants Constants) AsConstrainedEntities() (items []ConstrainedEntity)

AsConstrainedEntities boxes constants as a slice ConstrainedEntities

type ConstrainedEntity

type ConstrainedEntity interface {
	// ID returns the name of the entity
	ID() string

	ConditionalFilter() Conditional
}

ConstrainedEntity is an entity in a project file that can be filtered with constraints

type CreateParams

type CreateParams struct {
	Owner      string
	Project    string
	BranchName string
	Directory  string
	Content    string
	Language   string
	Private    bool

	ProjectURL string
	Cache      string
	Portable   bool
	// contains filtered or unexported fields
}

CreateParams are parameters that we create a custom activestate.yaml file from

type ErrorNoDefaultProject

type ErrorNoDefaultProject struct{ *locale.LocalizedError }

type ErrorNoProject

type ErrorNoProject struct{ *locale.LocalizedError }

type ErrorNoProjectFromEnv

type ErrorNoProjectFromEnv struct{ *locale.LocalizedError }

type ErrorParseProject

type ErrorParseProject struct{ *locale.LocalizedError }

type Event

type Event struct {
	NameVal     `yaml:",inline"`
	EventFields `yaml:",inline"`
}

Event covers the event structure, which goes under Project

func MakeEventsFromConstrainedEntities

func MakeEventsFromConstrainedEntities(items []ConstrainedEntity) (events []*Event)

MakeEventsFromConstrainedEntities unboxes ConstraintedEntities as Events

func (Event) ConditionalFilter

func (e Event) ConditionalFilter() Conditional

func (Event) ID

func (e Event) ID() string

ID returns the event name

func (*Event) UnmarshalYAML

func (e *Event) UnmarshalYAML(unmarshal func(interface{}) error) error

type EventFields

type EventFields struct {
	Scope       []string    `yaml:"scope"`
	Conditional Conditional `yaml:"if,omitempty"`
	// contains filtered or unexported fields
}

EventFields are the common fields for the Event type. This is required for type composition related to its yaml.Unmarshaler implementation.

type Events

type Events []Event

Events is a slice of Event definitions

func (Events) AsConstrainedEntities

func (events Events) AsConstrainedEntities() (items []ConstrainedEntity)

AsConstrainedEntities boxes events as a slice of ConstrainedEntities

type Job

type Job struct {
	Name      string   `yaml:"name"`
	Constants []string `yaml:"constants"`
	Scripts   []string `yaml:"scripts"`
}

Job covers the job structure, which goes under Project

type Jobs

type Jobs []Job

Jobs is a slice of jobs

type MigratorFunc

type MigratorFunc func(project *Project, configVersion int) (int, error)

type NameVal

type NameVal struct {
	Name  string `yaml:"name"`
	Value string `yaml:"value"`
}

func (*NameVal) UnmarshalYAML

func (nv *NameVal) UnmarshalYAML(unmarshal func(interface{}) error) error

type Package

type Package struct {
	Name        string      `yaml:"name"`
	Version     string      `yaml:"version"`
	Conditional Conditional `yaml:"if,omitempty"`
	Build       Build       `yaml:"build,omitempty"`
}

Package covers the package structure, which goes under the language struct

func MakePackagesFromConstrainedEntities

func MakePackagesFromConstrainedEntities(items []ConstrainedEntity) (packages []*Package)

MakePackagesFromConstrainedEntities unboxes ConstraintedEntities as Packages

func (Package) ConditionalFilter

func (p Package) ConditionalFilter() Conditional

func (Package) ID

func (p Package) ID() string

ID returns the package name

type Packages

type Packages []Package

Packages is a slice of Package configurations

func (Packages) AsConstrainedEntities

func (packages Packages) AsConstrainedEntities() (items []ConstrainedEntity)

AsConstrainedEntities boxes Packages as a slice of ConstrainedEntities

type Project

type Project struct {
	Project       string        `yaml:"project"`
	ConfigVersion int           `yaml:"config_version"`
	Lock          string        `yaml:"lock,omitempty"`
	Environments  string        `yaml:"environments,omitempty"`
	Constants     Constants     `yaml:"constants,omitempty"`
	Secrets       *SecretScopes `yaml:"secrets,omitempty"`
	Events        Events        `yaml:"events,omitempty"`
	Scripts       Scripts       `yaml:"scripts,omitempty"`
	Jobs          Jobs          `yaml:"jobs,omitempty"`
	Private       bool          `yaml:"private,omitempty"`
	Cache         string        `yaml:"cache,omitempty"`
	Portable      bool          `yaml:"portable,omitempty"`
	// contains filtered or unexported fields
}

Project covers the top level project structure of our yaml

func Create

func Create(params *CreateParams) (*Project, error)

Create will create a new activestate.yaml with a projectURL for the given details

func FromEnv

func FromEnv() (*Project, error)

FromEnv returns the project configuration based on environment information (env vars, cwd, etc)

func FromExactPath

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

FromExactPath will return the projectfile 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 projectfile that's located at the given path (this will walk up the directory tree until it finds the project)

func Parse

func Parse(configFilepath string) (_ *Project, rerr error)

Parse the given filepath, which should be the full path to an activestate.yaml file

func (*Project) BranchName

func (p *Project) BranchName() string

BranchName returns the branch name specified in the project

func (*Project) Channel

func (p *Project) Channel() string

Channel returns the channel as it was interpreted from the lock

func (*Project) Dir

func (p *Project) Dir() string

func (*Project) Init

func (p *Project) Init() error

Init initializes the parsedURL field from the project url string

func (*Project) LegacyCommitID

func (p *Project) LegacyCommitID() string

LegacyCommitID is for use by legacy mechanics ONLY It returns a pre-migrated project's commit ID from activestate.yaml.

func (*Project) Name

func (p *Project) Name() string

Name returns the project namespace's name

func (*Project) Owner

func (p *Project) Owner() string

Owner returns the project namespace's organization

func (*Project) Path

func (p *Project) Path() string

Path returns the project's activestate.yaml file path.

func (*Project) Reload

func (p *Project) Reload() error

Reload the project file from disk

func (*Project) Save

func (p *Project) Save(cfg ConfigGetter) error

Save the project to its activestate.yaml file

func (*Project) SetBranch

func (p *Project) SetBranch(branch string) error

SetBranch sets the branch within the current project file. This is done in-place so that line order is preserved.

func (*Project) SetLegacyCommit

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

SetLegacyCommit sets the commit id within the current project file. This is done in-place so that line order is preserved.

func (*Project) SetNamespace

func (p *Project) SetNamespace(owner, project string) error

SetNamespace updates the namespace in the project file

func (*Project) SetPath

func (p *Project) SetPath(path string)

SetPath sets the path of the project file and should generally only be used by tests

func (*Project) URL

func (p *Project) URL() string

URL returns the project namespace's string URL from activestate.yaml.

func (*Project) Version

func (p *Project) Version() string

Version returns the version as it was interpreted from the lock

type ProjectSimple

type ProjectSimple struct {
	Project string `yaml:"project"`
}

ProjectSimple reflects a bare basic project structure

type Script

type Script struct {
	NameVal      `yaml:",inline"`
	ScriptFields `yaml:",inline"`
}

Script covers the script structure, which goes under Project

func MakeScriptsFromConstrainedEntities

func MakeScriptsFromConstrainedEntities(items []ConstrainedEntity) (scripts []*Script)

MakeScriptsFromConstrainedEntities unboxes ConstraintedEntities as Scripts

func (Script) ConditionalFilter

func (s Script) ConditionalFilter() Conditional

func (Script) ID

func (s Script) ID() string

ID returns the script name

func (*Script) UnmarshalYAML

func (s *Script) UnmarshalYAML(unmarshal func(interface{}) error) error

type ScriptFields

type ScriptFields struct {
	Description string      `yaml:"description,omitempty"`
	Filename    string      `yaml:"filename,omitempty"`
	Standalone  bool        `yaml:"standalone,omitempty"`
	Language    string      `yaml:"language,omitempty"`
	Conditional Conditional `yaml:"if,omitempty"`
}

ScriptFields are the common fields for the Script type. This is required for type composition related to its yaml.Unmarshaler implementation.

type Scripts

type Scripts []Script

Scripts is a slice of scripts

func (Scripts) AsConstrainedEntities

func (scripts Scripts) AsConstrainedEntities() (items []ConstrainedEntity)

AsConstrainedEntities boxes scripts as a slice of ConstrainedEntities

type Secret

type Secret struct {
	Name        string      `yaml:"name"`
	Description string      `yaml:"description"`
	Conditional Conditional `yaml:"if,omitempty"`
}

Secret covers the variable structure, which goes under Project

func MakeSecretsFromConstrainedEntities

func MakeSecretsFromConstrainedEntities(items []ConstrainedEntity) (secrets []*Secret)

MakeSecretsFromConstrainedEntities unboxes ConstraintedEntities as Secrets

func (*Secret) ConditionalFilter

func (s *Secret) ConditionalFilter() Conditional

func (*Secret) ID

func (s *Secret) ID() string

ID returns the secret name

type SecretScopes

type SecretScopes struct {
	User    Secrets `yaml:"user,omitempty"`
	Project Secrets `yaml:"project,omitempty"`
}

SecretScopes holds secret scopes, scopes define what the secrets belong to

type Secrets

type Secrets []*Secret

Secrets is a slice of Secret definitions

func (Secrets) AsConstrainedEntities

func (secrets Secrets) AsConstrainedEntities() (items []ConstrainedEntity)

AsConstrainedEntities box Secrets as a slice of ConstrainedEntities

type VersionInfo

type VersionInfo struct {
	Channel string `yaml:"branch"` // branch for backward compatibility
	Version string
	Lock    string `yaml:"lock"`
}

VersionInfo is used in cases where we only care about parsing the version and channel fields. In all other cases the version is parsed via the Project struct

func ParseLock

func ParseLock(lock string) (*VersionInfo, error)

func ParseVersionInfo

func ParseVersionInfo(projectFilePath string) (*VersionInfo, error)

ParseVersionInfo parses the lock field from the projectfile and updates the activestate.yaml if an older version representation is present

Jump to

Keyboard shortcuts

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