Documentation
¶
Index ¶
- Constants
- Variables
- func Contains(arr []string, str string) bool
- func PrintObject(object interface{})
- func Uniq(arr []string) []string
- type Change
- type ChangeType
- type Changes
- type ChangesByEnvironment
- type Context
- func (ctx *Context) AddFile(file keystonefile.FileKey, envContentMap map[string][]byte) *Context
- func (c *Context) AddHook(command string)
- func (ctx *Context) AddSecret(secretName string, secretValue map[string]string, flag SecretStrictFlag) *Context
- func (c *Context) CachedDotEnvPath() string
- func (c *Context) CachedEnvironmentDotEnvPath(environmentName string) string
- func (c *Context) CachedEnvironmentFilesPath(environmentName string) string
- func (c *Context) CachedEnvironmentPath(environmentName string) string
- func (context *Context) CleanUp()
- func (ctx *Context) CompareNewFileWhithChanges(filePath string, changesByEnvironment ChangesByEnvironment) *Context
- func (ctx *Context) CompareNewSecretWithChanges(secretName string, newSecret map[string]string, ...) *Context
- func (ctx *Context) CompareRemovedSecretWithChanges(secretName string, changesByEnvironment ChangesByEnvironment) *Context
- func (ctx *Context) CurrentEnvironment() string
- func (ctx *Context) Destroy() error
- func (c *Context) DotKeystonePath() string
- func (ctx *Context) EnvironmentID() string
- func (ctx *Context) EnvironmentVersion() string
- func (ctx *Context) EnvironmentVersionByName(name string) string
- func (ctx *Context) EnvironmentVersionHasChanged(name string, environmentVersion string) bool
- func (ctx *Context) EnvironmentsFromConfig() []environmentsfile.Env
- func (context *Context) Err() *kserrors.Error
- func (ctx *Context) FilesUseEnvironment(currentEnvironment string, targetEnvironment string, forceCopy bool) *Context
- func (ctx *Context) GetAllSecrets(envName string) map[string]string
- func (ctx *Context) GetFileContents(fileName string, environmentName string) (contents []byte, err error)
- func (c *Context) GetHook() (hook *Hook, ok bool)
- func (ctx *Context) GetLocalFileContents(fileName string) (contents []byte, err error)
- func (ctx *Context) GetProjectID() string
- func (ctx *Context) GetProjectName() string
- func (ctx *Context) GetSecret(secretName string) *Secret
- func (ctx *Context) GetSecrets() map[string]string
- func (ctx *Context) HasEnvironment(name string) bool
- func (ctx *Context) HasFile(fileName string) bool
- func (ctx *Context) HasSecret(secretName string) bool
- func (ctx *Context) Init(project models.Project) *Context
- func (ctx *Context) IsFileModified(filePath, environment string) (isModified bool)
- func (ctx *Context) ListAllFiles(environmentName string) []FileDescriptor
- func (ctx *Context) ListCachedFilesForEnvironment(envname string) []keystonefile.FileKey
- func (ctx *Context) ListEnvironments() []string
- func (ctx *Context) ListFiles() []keystonefile.FileKey
- func (ctx *Context) ListFilesFromCache() []keystonefile.FileKey
- func (ctx *Context) ListSecrets() []Secret
- func (ctx *Context) ListSecretsFromCache() []Secret
- func (ctx *Context) LoadEnvironmentsFile() *environmentsfile.EnvironmentsFile
- func (ctx *Context) LocallyModifiedFiles(envname string) []keystonefile.FileKey
- func (ctx *Context) MarkFileRequired(filePath string, required bool) *Context
- func (ctx *Context) MarkSecretRequired(secretName string, required bool) *Context
- func (ctx *Context) MissingFilesForEnvironment(environmentName string) ([]string, bool)
- func (ctx *Context) MissingSecretsForEnvironment(environmentName string) ([]string, bool)
- func (ctx *Context) MustHaveAccessToEnvironment(environmentName string) *Context
- func (ctx *Context) MustHaveEnvironment(name string)
- func (ctx *Context) MustHaveProject()
- func (ctx *Context) PrepareMessagePayload(environment models.Environment) (models.MessagePayload, error)
- func (ctx *Context) PurgeSecrets() *Context
- func (ctx *Context) RemoveEnvironment(name string) *Context
- func (ctx *Context) RemoveFile(filePath string, force bool, purge bool, ...) *Context
- func (ctx *Context) RemoveForbiddenEnvironments(accessibleEnvironments []models.Environment)
- func (ctx *Context) RemoveSecret(secretName string, purge bool) *Context
- func (c *Context) RunHook() error
- func (ctx *Context) SaveMessages(MessageByEnvironments models.GetMessageByEnvironmentResponse) ChangesByEnvironment
- func (ctx *Context) SecretIsRequired(secretName string) bool
- func (ctx *Context) SetAllSecrets(name string, secrets map[string]string) *Context
- func (ctx *Context) SetCurrent(name string) *Context
- func (ctx *Context) SetError(err *kserrors.Error) *Context
- func (ctx *Context) SetFile(filePath string, content []byte) *Context
- func (ctx *Context) SetSecret(envName string, secretName string, secretValue string) *Context
- func (ctx *Context) UnsetSecret(envName string, secretName string) *Context
- func (ctx *Context) UpdateEnvironment(environment models.Environment) *Context
- type EnvironmentName
- type FileDescriptor
- type FileStrictFlag
- type Hook
- type Secret
- type SecretStrictFlag
- type SecretValue
Constants ¶
const ( CTX_INIT = "init" CTX_RESOLVE = "resolve" )
const ( CTX_OVERWRITE_LOCAL_FILES = true CTX_KEEP_LOCAL_FILES = !CTX_OVERWRITE_LOCAL_FILES )
Variables ¶
var ErrorHookFailed = errors.New("hook failed")
Functions ¶
func PrintObject ¶
func PrintObject(object interface{})
PrintObject function prints an object. For debugging.
Types ¶
type Change ¶
type Change struct {
Name string // Secret name or file path
From string // Value before, empty if creation
To string // New value, empty if deletion
Type ChangeType // Type of change (file, secret, version only)
}
Change struct describers sercret/file changes
func GetSecretsChanges ¶
func GetSecretsChanges( localSecrets []models.SecretVal, newSecrets []models.SecretVal, ) (changes []Change)
GetSecretsChanges function Returns a list of changes for secrets
func (Change) IsSecretAdd ¶
IsSecretAdd method tells if the change is adding a secret
func (Change) IsSecretChange ¶
IsSecretChange method tells if the change is changing a secret
func (Change) IsSecretDelete ¶
IsSecretDelete method tells if the change is removing a secret
type ChangeType ¶
type ChangeType string
const ( ChangeTypeSecretAdd ChangeType = "secret" ChangeTypeSecretChange ChangeType = "change" ChangeTypeSecretDelete ChangeType = "delete" ChangeTypeFile ChangeType = "file" // This one happens when environment version changed // but there is no messages along with it ChangeTypeVersion ChangeType = "version" )
type Changes ¶
type Changes []Change
func (Changes) IsSingleVersionChange ¶
IsSingleVersionChange method return true if the list of changes has single version change, which means the environment changed, but we don't have a message for it
type ChangesByEnvironment ¶
ChangesByEnvironment struct is a list of changes grouped by environment
func (ChangesByEnvironment) ChangedEnvironmentsWithoutPayload ¶
func (ce ChangesByEnvironment) ChangedEnvironmentsWithoutPayload() []string
/ Returns a list of all environments that have a different / VersionID but no payload for the user.
type Context ¶
type Context struct {
Wd string
TmpDir string
ConfigDir string
AccessibleEnvironments []models.Environment
// contains filtered or unexported fields
}
func New ¶
Creates a new execution context
When flag equals CTX_INIT, the current working directory is used as the project's root. When flag equals CTX_RESOLVE, the program tries to find the project's root in a parent directory. En error is returned if none is found.
An error will be returned if flag is neither of those values
func (*Context) AddSecret ¶
func (ctx *Context) AddSecret( secretName string, secretValue map[string]string, flag SecretStrictFlag, ) *Context
Sets an env variable to keep track of across environments [secretName] is the name of the variable to set [secretValue] maps environment to the varable value (key is environment name, and value, the value of the variable in that environment)
func (*Context) CachedDotEnvPath ¶
CachedDotEnvPath method returns the path of the .env in .keystone
func (*Context) CachedEnvironmentDotEnvPath ¶
CachedEnvironmentDotEnvPath method returns the path to the .env for the given environment in cache
func (*Context) CachedEnvironmentFilesPath ¶
CachedEnvironmentFilesPath method returns the path to the files dir for the given environment in cache
func (*Context) CachedEnvironmentPath ¶
CachedEnvironmentPath method returns the path to the environment in cache e.g. `$PWD/.keystone/cache/dev`
func (*Context) CompareNewFileWhithChanges ¶
func (ctx *Context) CompareNewFileWhithChanges( filePath string, changesByEnvironment ChangesByEnvironment, ) *Context
CompareNewFileWhithChanges method compares the latest set of changes with a new file
func (*Context) CompareNewSecretWithChanges ¶
func (ctx *Context) CompareNewSecretWithChanges( secretName string, newSecret map[string]string, changesByEnvironment ChangesByEnvironment, ) *Context
CompareNewSecretWithChanges method compares recent changes with new secret name and values
func (*Context) CompareRemovedSecretWithChanges ¶
func (ctx *Context) CompareRemovedSecretWithChanges( secretName string, changesByEnvironment ChangesByEnvironment, ) *Context
CompareRemovedSecretWithChanges method compares the removed secrete with the latest set of changes
func (*Context) CurrentEnvironment ¶
CurrentEnvironment method returns the current environment name
func (*Context) DotKeystonePath ¶
DotKeystonePath method returns the path to the .keystone dir
func (*Context) EnvironmentID ¶
EnvironmentID method returns the environmentID of the current environment
func (*Context) EnvironmentVersion ¶
EnvironmentVersion method returns the local version of the current environment
func (*Context) EnvironmentVersionByName ¶
EnvironmentVersionByName method returns the local version of the environment named `name`
func (*Context) EnvironmentVersionHasChanged ¶
EnvironmentVersionHasChanged method indiciates whether the versions differ
func (*Context) EnvironmentsFromConfig ¶
func (ctx *Context) EnvironmentsFromConfig() []environmentsfile.Env
EnvironmentsFromConfig method reads the environmentfile
func (*Context) FilesUseEnvironment ¶
func (ctx *Context) FilesUseEnvironment( currentEnvironment string, targetEnvironment string, forceCopy bool, ) *Context
FilesUseEnvironment creates copies of files found in the project’s keystone.yaml file, from the environment `targetEnvironment` in cache.
func (*Context) GetAllSecrets ¶
GetAllSecrets method returns all the secrets and thei value for the given environment
func (*Context) GetFileContents ¶
func (ctx *Context) GetFileContents( fileName string, environmentName string, ) (contents []byte, err error)
GetFileContents returns the file contents for the given envsrionment as a slice of bytes. It returns an error if reading the file fails (Pemission denied, no exists…) or if the file is empty (content length equals 0)
func (*Context) GetLocalFileContents ¶
GetLocalFileContents returns the file contents as a slice of bytes. It returns an error if reading the file fails (Pemission denied, no exists…)
func (*Context) GetProjectID ¶
GetProjectID method returns the project ID from the keystonefile
func (*Context) GetProjectName ¶
GetProjectName method returns the project name from the keysotnefile
func (*Context) GetSecrets ¶
Returns all environments variable for the current environment, a map
func (*Context) HasEnvironment ¶
HasEnvironment method returns true environment exists
func (*Context) HasFile ¶
Returns a boolean indicating wether the file `fileName` exists in the local files
func (*Context) HasSecret ¶
Returns a boolean indicating wether the secret `secretName` exists in the local files
func (*Context) Init ¶
Initialize the projects directory structure.
In the execution context's working directory, it creates: - keystone.yaml - .keystone/ - .keystone/environment - .keystone/cache/ - .keystone/cache/.env - .keystone/cache/dev/ - .keystone/cache/ci/ - .keystone/cache/staging/ - .keystone/cache/prod/
It adds .keystone to .gitignore, creating it if does not exist
func (*Context) IsFileModified ¶
IsFileModified method indicates whether the local version, and the in-cache version for the current environment of a file differ
func (*Context) ListAllFiles ¶
func (ctx *Context) ListAllFiles(environmentName string) []FileDescriptor
/ Returns a list of display friendly FileDescriptors, / for every file that exist in the project, both in the `keystone.yaml` file / and the `.keystone` cache folder.
func (*Context) ListCachedFilesForEnvironment ¶
func (ctx *Context) ListCachedFilesForEnvironment( envname string, ) []keystonefile.FileKey
ListCachedFilesForEnvironment method returns a list of all the files present in the cache for the given environment
func (*Context) ListEnvironments ¶
ListEnvironments method returns a list of environments that can be found in the cache
func (*Context) ListFiles ¶
func (ctx *Context) ListFiles() []keystonefile.FileKey
ListFiles method returns a list of all files in the keystone file
func (*Context) ListFilesFromCache ¶
func (ctx *Context) ListFilesFromCache() []keystonefile.FileKey
ListFilesFromCache method returns a list of the files present in the cache
func (*Context) ListSecrets ¶
Returns secrets from keystone.yaml, and their value in each environment.
func (*Context) ListSecretsFromCache ¶
List secret from .keystone/cache, and their value in each environment.
func (*Context) LoadEnvironmentsFile ¶
func (ctx *Context) LoadEnvironmentsFile() *environmentsfile.EnvironmentsFile
LoadEnvironmentsFile method
func (*Context) LocallyModifiedFiles ¶
func (ctx *Context) LocallyModifiedFiles( envname string, ) []keystonefile.FileKey
LocallyModifiedFiles returns the list of file whose local content are different than the version in cache for the given environment (e.g. modified by the user)
func (*Context) MarkFileRequired ¶
MarkFileRequired method changes the required status of a file
func (*Context) MarkSecretRequired ¶
MarkSecretRequired method changes the required status of a secret
func (*Context) MissingFilesForEnvironment ¶
MissingFilesForEnvironment return a list of missing files for the given environment. The second returned value indicates whether the list contains something or not.
func (*Context) MissingSecretsForEnvironment ¶
MissingSecretsForEnvironment method returns a list of all the secrets that are listed in keystone.yaml and are not in the cache. The second value is true if there are missing things.
func (*Context) MustHaveAccessToEnvironment ¶
MustHaveAccessToEnvironment method exits with an error if the user does not have read access to the environment
func (*Context) MustHaveEnvironment ¶
MustHaveEnvironment method exits with an error if the environment does not exist
func (*Context) MustHaveProject ¶
func (ctx *Context) MustHaveProject()
MustHaveProject method sets a context error if the keystonefile does not have a project id
func (*Context) PrepareMessagePayload ¶
func (ctx *Context) PrepareMessagePayload( environment models.Environment, ) (models.MessagePayload, error)
Return PayloadContent, with secrets and files of current environment.
func (*Context) PurgeSecrets ¶
PurgeSecets Removes from the cache of all environments all secrets that are not found in the project’s keystone.yaml This implies that sending the environment to other users will remove those values for them too
func (*Context) RemoveEnvironment ¶
RemoveEnvironment method Deprecated
func (*Context) RemoveFile ¶
func (ctx *Context) RemoveFile( filePath string, force bool, purge bool, accessibleEnvironments []models.Environment, ) *Context
RemoveFile method removes a file from the keystonefile. `purge` also removes the file from the cache
func (*Context) RemoveForbiddenEnvironments ¶
func (ctx *Context) RemoveForbiddenEnvironments( accessibleEnvironments []models.Environment, )
RemoveForbiddenEnvironments method removes the environments information the current user may not access.
func (*Context) RemoveSecret ¶
Unsets a previously set environment variable
[varname] The variable to unset It will be removed in all existing environment.
func (*Context) SaveMessages ¶
func (ctx *Context) SaveMessages( MessageByEnvironments models.GetMessageByEnvironmentResponse, ) ChangesByEnvironment
/ Writes the contents of messages in the project's cache / It will replace secrets value with the new ones, / add new secrets and their values / remove secrets that have been removed by other user
func (*Context) SecretIsRequired ¶
SecretIsRequired method tells if `secretName` is required.
func (*Context) SetAllSecrets ¶
SetAllSecrets method sets all the secrets at once in the cache
func (*Context) SetCurrent ¶
SetCurrent method changes the current environment
func (*Context) SetSecret ¶
Sets an existing an secret for a given envitronment [envName] name of the target environment [secretName] [secretValue]
func (*Context) UnsetSecret ¶
UnsetSecret method clears the secret value
func (*Context) UpdateEnvironment ¶
func (ctx *Context) UpdateEnvironment(environment models.Environment) *Context
UpdateEnvironment method updates environment info (e.g. versionID)
type EnvironmentName ¶
type EnvironmentName string
type FileDescriptor ¶
type Secret ¶
type Secret struct {
Name string
Required bool
Values map[EnvironmentName]SecretValue
FromCache bool
}
func FilterSecretsFromCache ¶
Returns an array of secrets that are in the first list, an not in the second
type SecretStrictFlag ¶
type SecretStrictFlag int
const ( S_REQUIRED SecretStrictFlag = iota S_OPTIONAL )
type SecretValue ¶
type SecretValue string