Documentation
¶
Index ¶
- Constants
- func CreateProjectConfigDir(ctx context.Context, fs afero.Fs, projectDirPath string) (configDirPath string, err error)
- func CreateProjectConfigDirDotGitIgnoreFile(fs afero.Fs, projectDirPath string) (path string, err error)
- func CreateProjectConfigJSONFile(fs afero.Fs, projectDirPath string) (path string, err error)
- func CreateProjectHooksJSONFile(fs afero.Fs, projectDirPath string, data []byte) (path string, err error)
- func GetContextEnterpriseID(ctx context.Context) string
- func GetContextTeamDomain(ctx context.Context) string
- func GetContextTeamID(ctx context.Context) string
- func GetContextToken(ctx context.Context) string
- func GetContextUserID(ctx context.Context) string
- func GetProjectConfigDirDotGitIgnoreFilePath(projectDirPath string) string
- func GetProjectConfigDirPath(projectDirPath string) string
- func GetProjectConfigJSONFilePath(projectDirPath string) string
- func GetProjectDirPath(fs afero.Fs, os types.Os) (string, error)
- func GetProjectHooksJSONFilePath(projectDirPath ...string) string
- func ProjectConfigJSONFileExists(fs afero.Fs, os types.Os, projectDirPath string) bool
- func SetContextEnterpriseID(ctx context.Context, enterpriseID string) context.Context
- func SetContextTeamDomain(ctx context.Context, teamDomain string) context.Context
- func SetContextTeamID(ctx context.Context, teamID string) context.Context
- func SetContextToken(ctx context.Context, token string) context.Context
- func SetContextUserID(ctx context.Context, userID string) context.Context
- func SetManifestSource(ctx context.Context, fs afero.Fs, os types.Os, source ManifestSource) error
- func WriteProjectConfigFile(ctx context.Context, fs afero.Fs, os types.Os, projectConfig ProjectConfig) (string, error)
- type Config
- func (c *Config) DeprecatedFlagSubstitutions(cmd *cobra.Command) error
- func (c *Config) GetDotEnvFileVariables() (map[string]string, error)
- func (c *Config) GetExperiments() []experiment.Experiment
- func (c *Config) GetSurveyConfig(ctx context.Context, name string) (SurveyConfig, error)
- func (c *Config) InitializeGlobalFlags(cmd *cobra.Command)
- func (c *Config) LoadEnvironmentVariables() error
- func (c *Config) LoadExperiments(ctx context.Context, ...)
- func (c *Config) SetFlags(cmd *cobra.Command)
- func (c *Config) SkipLocalFs() bool
- func (c *Config) WithExperimentOn(experimentToCheck experiment.Experiment) bool
- type ManifestConfig
- type ManifestSource
- type ProjectConfig
- func (c *ProjectConfig) Cache() cache.Cacher
- func (c *ProjectConfig) GetManifestSource(ctx context.Context) (ManifestSource, error)
- func (c *ProjectConfig) GetProjectID(ctx context.Context) (string, error)
- func (c *ProjectConfig) GetSurveyConfig(ctx context.Context, name string) (SurveyConfig, error)
- func (c *ProjectConfig) InitProjectID(ctx context.Context, overwriteExistingProjectID bool) (string, error)
- func (c *ProjectConfig) SetProjectID(ctx context.Context, projectID string) (string, error)
- func (c *ProjectConfig) SetSurveyConfig(ctx context.Context, name string, surveyConfig SurveyConfig) error
- type ProjectConfigManager
- type ProjectConfigMock
- func (m *ProjectConfigMock) AddDefaultMocks()
- func (m *ProjectConfigMock) Cache() cache.Cacher
- func (m *ProjectConfigMock) GetManifestSource(ctx context.Context) (ManifestSource, error)
- func (m *ProjectConfigMock) GetProjectID(ctx context.Context) (string, error)
- func (m *ProjectConfigMock) GetSurveyConfig(ctx context.Context, id string) (SurveyConfig, error)
- func (m *ProjectConfigMock) InitProjectID(ctx context.Context, overwriteExistingProjectID bool) (string, error)
- func (m *ProjectConfigMock) SetProjectID(ctx context.Context, projectID string) (string, error)
- func (m *ProjectConfigMock) SetSurveyConfig(ctx context.Context, id string, surveyConfig SurveyConfig) error
- type SurveyConfig
- type SystemConfig
- func (c *SystemConfig) GetLastUpdateCheckedAt(ctx context.Context) (time.Time, error)
- func (c *SystemConfig) GetSurveyConfig(ctx context.Context, name string) (SurveyConfig, error)
- func (c *SystemConfig) GetSystemID(ctx context.Context) (string, error)
- func (c *SystemConfig) GetTrustUnknownSources(ctx context.Context) (bool, error)
- func (c *SystemConfig) InitSystemID(ctx context.Context) (string, error)
- func (c *SystemConfig) LogsDir(ctx context.Context) (string, error)
- func (c *SystemConfig) SetCustomConfigDirPath(customConfigDirPath string)
- func (c *SystemConfig) SetLastUpdateCheckedAt(ctx context.Context, lastUpdateCheckedAt time.Time) (path string, err error)
- func (c *SystemConfig) SetSurveyConfig(ctx context.Context, name string, surveyConfig SurveyConfig) error
- func (c *SystemConfig) SetSystemID(ctx context.Context, systemID string) (string, error)
- func (c *SystemConfig) SetTrustUnknownSources(ctx context.Context, value bool) error
- func (c *SystemConfig) SlackConfigDir(ctx context.Context) (string, error)
- func (c *SystemConfig) UserConfig(ctx context.Context) (*SystemConfig, error)
- type SystemConfigManager
- type SystemConfigMock
- func (m *SystemConfigMock) GetLastUpdateCheckedAt(ctx context.Context) (time.Time, error)
- func (m *SystemConfigMock) GetSurveyConfig(ctx context.Context, id string) (SurveyConfig, error)
- func (m *SystemConfigMock) GetSystemID(ctx context.Context) (string, error)
- func (m *SystemConfigMock) GetTrustUnknownSources(ctx context.Context) (bool, error)
- func (m *SystemConfigMock) InitSystemID(ctx context.Context) (string, error)
- func (m *SystemConfigMock) LogsDir(ctx context.Context) (string, error)
- func (m *SystemConfigMock) SetCustomConfigDirPath(customConfigDirPath string)
- func (m *SystemConfigMock) SetLastUpdateCheckedAt(ctx context.Context, lastUpdateCheckedAt time.Time) (path string, err error)
- func (m *SystemConfigMock) SetSurveyConfig(ctx context.Context, id string, surveyConfig SurveyConfig) error
- func (m *SystemConfigMock) SetSystemID(ctx context.Context, systemID string) (string, error)
- func (m *SystemConfigMock) SetTrustUnknownSources(ctx context.Context, value bool) error
- func (m *SystemConfigMock) SlackConfigDir(ctx context.Context) (string, error)
- func (m *SystemConfigMock) UserConfig(ctx context.Context) (*SystemConfig, error)
Constants ¶
const ( // ProjectHooksJSONFilename is the project-level hooks.json filename ProjectHooksJSONFilename = "hooks.json" // ProjectConfigDirName is the name of the project-level configuration directory ProjectConfigDirName = ".slack" // ProjectConfigJSONFilename is the project-level config.json filename ProjectConfigJSONFilename = "config.json" )
const ContextToken contextKey = "token"
Variables ¶
This section is empty.
Functions ¶
func CreateProjectConfigDir ¶
func CreateProjectConfigDir(ctx context.Context, fs afero.Fs, projectDirPath string) (configDirPath string, err error)
CreateProjectConfigDir creates a .slack/ directory in projectDirPath and returns the path
func CreateProjectConfigDirDotGitIgnoreFile ¶
func CreateProjectConfigDirDotGitIgnoreFile(fs afero.Fs, projectDirPath string) (path string, err error)
CreateProjectConfigDirDotGitIgnoreFile creates a new .gitignore file located in the project's config directory (e.g. project-name/.slack/.gitignore). Returns a os.ErrExists when the file already exists
func CreateProjectConfigJSONFile ¶
CreateProjectConfigJSONFile creates a project-level config.json file or returns error if exists
func CreateProjectHooksJSONFile ¶
func CreateProjectHooksJSONFile(fs afero.Fs, projectDirPath string, data []byte) (path string, err error)
CreateProjectHooksJSONFile writes data to a new project hooks.json file
func GetContextEnterpriseID ¶
func GetContextTeamDomain ¶
func GetContextTeamID ¶
func GetContextToken ¶
func GetContextUserID ¶
func GetProjectConfigDirDotGitIgnoreFilePath ¶
GetProjectConfigDirDotGitIgnoreFilePath returns the file path to the .gitignore file located in the project's config directory (e.g. project-name/.slack/.gitignore)
func GetProjectConfigDirPath ¶
GetProjectConfigDirPath returns the path to the project's config directory
func GetProjectConfigJSONFilePath ¶
GetProjectConfigJSONFilePath returns the path to the project's config file
func GetProjectDirPath ¶
GetProjectDirPath returns the path to the project directory or an error if not a Slack project TODO(@mbrooks) Standardize the definition of a validate project directory and merge with `cmdutil.ValidProjectDirectoryOrExit`
func GetProjectHooksJSONFilePath ¶
GetProjectHooksJSONFilePath returns the path to the project's hooks file
func ProjectConfigJSONFileExists ¶
ProjectConfigJSONFileExists returns true if the .slack/config.json file exists
func SetContextEnterpriseID ¶
func SetContextTeamDomain ¶
func SetManifestSource ¶
SetManifestSource saves the manifest source preference for the project
Types ¶
type Config ¶
type Config struct {
Flags *pflag.FlagSet // Flags contains the entire set of flags for a command
// TODO: maybe these metrics-specific bits move to the tracking package now?
// Command invoked by user (for metrics)
Command string
// Command invoked with any aliases resolved (for metrics)
CommandCanonical string
// Raw flags (for metrics)
RawFlags []string
// Command flags
APIHostFlag string
APIHostResolved string
AppFlag string
AutoRequestAAAFlag bool
ConfigDirFlag string
DebugEnabled bool
DeprecatedDevAppFlag bool
DeprecatedDevFlag bool
DeprecatedWorkspaceFlag string
DisableTelemetryFlag bool
ForceFlag bool
LogstashHostResolved string
RuntimeFlag string
RuntimeName string
RuntimeVersion string
SkipUpdateFlag bool
SlackDevFlag bool
SlackTestTraceFlag bool
TeamFlag string
TokenFlag string
NoColor bool
Version string
// Feature experiments
ExperimentsFlag []string
// Eventually this will also load the global and project slack config files
DomainAuthTokens string
ManifestEnv map[string]string
// ProjectID is uuid for the project
ProjectID string
// SystemID is the uuid for the user's system profile
SystemID string
// TrustUnknownSources is a user defined preference from the global slack config file
// Set true to ignore CLI warning to user about unknown code sources
TrustUnknownSources bool
// ProjectConfig is the project-level configuration
ProjectConfig ProjectConfigManager
// SystemConfig is the system-level (user home) configuration
SystemConfig SystemConfigManager
// contains filtered or unexported fields
}
func (*Config) DeprecatedFlagSubstitutions ¶
DeprecatedFlagSubstitutions displays warnings when using deprecated flags and provides alternatives when possible
func (*Config) GetDotEnvFileVariables ¶
GetDotEnvFileVariables collects only the variables in the .env file
func (*Config) GetExperiments ¶
func (c *Config) GetExperiments() []experiment.Experiment
GetExperiments returns the set of active experiments
func (*Config) GetSurveyConfig ¶
GetSurveyConfig returns the survey for the given survey ID. It combines survey config at the project-level and system-level. If the survey ID does not exist, an error is returned.
func (*Config) InitializeGlobalFlags ¶
InitializeGlobalFlags configures flags and creates links from cmd to config
func (*Config) LoadEnvironmentVariables ¶
LoadEnvironmentVariables sets flags based on their environment variable value
Note: Values are not loaded from the .env file. Use: `GetDotEnvFileVariables`
func (*Config) LoadExperiments ¶
func (c *Config) LoadExperiments( ctx context.Context, printDebug func(ctx context.Context, format string, a ...interface{}), )
LoadExperiments parses experiments from the command flags and configuration files and stores the findings in Config
func (*Config) SkipLocalFs ¶
SkipLocalFs returns if app and auth information is passed by flag and indicates that local files should not be used
func (*Config) WithExperimentOn ¶
func (c *Config) WithExperimentOn(experimentToCheck experiment.Experiment) bool
WithExperimentOn checks whether an experiment is currently toggled on
type ManifestConfig ¶
type ManifestConfig struct {
// Source of the manifest using either "local" or "remote" values
Source string `json:"source,omitempty"`
}
type ManifestSource ¶
type ManifestSource string
const ( ManifestSourceLocal ManifestSource = "local" ManifestSourceRemote ManifestSource = "remote" )
func (ManifestSource) Equals ¶
func (ms ManifestSource) Equals(is ManifestSource) bool
Equals returns true if the manifest source is the same
func (ManifestSource) Exists ¶
func (ms ManifestSource) Exists() bool
Exists returns true if the manifest source is set
func (ManifestSource) Human ¶
func (ms ManifestSource) Human() string
Human returns the string value as a human-friendly name
func (ManifestSource) String ¶
func (ms ManifestSource) String() string
String returns the string value of a manifest source
type ProjectConfig ¶
type ProjectConfig struct {
Experiments []experiment.Experiment `json:"experiments,omitempty"`
Manifest *ManifestConfig `json:"manifest,omitempty"`
ProjectID string `json:"project_id,omitempty"`
Surveys map[string]SurveyConfig `json:"surveys,omitempty"`
// contains filtered or unexported fields
}
ProjectConfig is the project-level config file
func NewProjectConfig ¶
func NewProjectConfig(fs afero.Fs, os types.Os) *ProjectConfig
NewProjectConfig read and writes to the project-level configuration file
func ReadProjectConfigFile ¶
ReadProjectConfigFile reads the project-level config.json file
func (*ProjectConfig) Cache ¶
func (c *ProjectConfig) Cache() cache.Cacher
Cache loads the cached project values
func (*ProjectConfig) GetManifestSource ¶
func (c *ProjectConfig) GetManifestSource(ctx context.Context) (ManifestSource, error)
GetManifestSource finds the manifest source preference for the project
func (*ProjectConfig) GetProjectID ¶
func (c *ProjectConfig) GetProjectID(ctx context.Context) (string, error)
GetProjectID reads the project_id from the project-level config file
func (*ProjectConfig) GetSurveyConfig ¶
func (c *ProjectConfig) GetSurveyConfig(ctx context.Context, name string) (SurveyConfig, error)
GetSurveyConfig reads the survey for the given survey ID from the project-level config file
func (*ProjectConfig) InitProjectID ¶
func (c *ProjectConfig) InitProjectID(ctx context.Context, overwriteExistingProjectID bool) (string, error)
InitProjectID will set the project_id in the project-level config when it's unset and then returns the project_id.
func (*ProjectConfig) SetProjectID ¶
SetProjectID sets the project_id to a random UUID string in the project-level config file
func (*ProjectConfig) SetSurveyConfig ¶
func (c *ProjectConfig) SetSurveyConfig(ctx context.Context, name string, surveyConfig SurveyConfig) error
SetSurveyConfig writes the survey for the given survey ID from the project-level config file
type ProjectConfigManager ¶
type ProjectConfigManager interface {
InitProjectID(ctx context.Context, overwriteExistingProjectID bool) (string, error)
GetProjectID(ctx context.Context) (string, error)
SetProjectID(ctx context.Context, projectID string) (string, error)
GetManifestSource(ctx context.Context) (ManifestSource, error)
GetSurveyConfig(ctx context.Context, name string) (SurveyConfig, error)
SetSurveyConfig(ctx context.Context, name string, surveyConfig SurveyConfig) error
Cache() cache.Cacher
}
ProjectConfigManager is the interface for interacting with the project config
type ProjectConfigMock ¶
func NewProjectConfigMock ¶
func NewProjectConfigMock() *ProjectConfigMock
func (*ProjectConfigMock) AddDefaultMocks ¶
func (m *ProjectConfigMock) AddDefaultMocks()
func (*ProjectConfigMock) Cache ¶
func (m *ProjectConfigMock) Cache() cache.Cacher
Cache returns a persistent mock cache
func (*ProjectConfigMock) GetManifestSource ¶
func (m *ProjectConfigMock) GetManifestSource(ctx context.Context) (ManifestSource, error)
func (*ProjectConfigMock) GetProjectID ¶
func (m *ProjectConfigMock) GetProjectID(ctx context.Context) (string, error)
func (*ProjectConfigMock) GetSurveyConfig ¶
func (m *ProjectConfigMock) GetSurveyConfig(ctx context.Context, id string) (SurveyConfig, error)
func (*ProjectConfigMock) InitProjectID ¶
func (*ProjectConfigMock) SetProjectID ¶
func (*ProjectConfigMock) SetSurveyConfig ¶
func (m *ProjectConfigMock) SetSurveyConfig(ctx context.Context, id string, surveyConfig SurveyConfig) error
type SurveyConfig ¶
type SurveyConfig struct {
AskedAt string `json:"asked_at"`
CompletedAt string `json:"completed_at"`
}
SurveyConfig tracks information related to user surveys in the system-level or project-level config
type SystemConfig ¶
type SystemConfig struct {
Experiments []experiment.Experiment `json:"experiments,omitempty"`
LastUpdateCheckedAt time.Time `json:"last_update_checked_at,omitempty"`
Surveys map[string]SurveyConfig `json:"surveys,omitempty"`
SystemID string `json:"system_id,omitempty"`
TrustUnknownSources bool `json:"trust_unknown_sources,omitempty"`
// contains filtered or unexported fields
}
SystemConfig contains the system-level config file
func NewSystemConfig ¶
func NewSystemConfig(fs afero.Fs, os types.Os) *SystemConfig
NewSystemConfig read and writes to the system-level configuration directory
func (*SystemConfig) GetLastUpdateCheckedAt ¶
GetLastUpdateCheckedAt reads the time of the LastUpdateCheckedAt property in UserConfig file
func (*SystemConfig) GetSurveyConfig ¶
func (c *SystemConfig) GetSurveyConfig(ctx context.Context, name string) (SurveyConfig, error)
GetSurveyConfig reads the survey for the given survey ID from the project-level config file
func (*SystemConfig) GetSystemID ¶
func (c *SystemConfig) GetSystemID(ctx context.Context) (string, error)
GetSystemID reads the system_id from the user-level config file
func (*SystemConfig) GetTrustUnknownSources ¶
func (c *SystemConfig) GetTrustUnknownSources(ctx context.Context) (bool, error)
GetTrustUnknownSources reads the TrustUnknownSources property from the user-level config file
func (*SystemConfig) InitSystemID ¶
func (c *SystemConfig) InitSystemID(ctx context.Context) (string, error)
InitSystemID sets the system_id in the user-level config to a random SHA256 string when it's currently unset
func (*SystemConfig) LogsDir ¶
func (c *SystemConfig) LogsDir(ctx context.Context) (string, error)
LogsDir returns the logs directory path stored in the system configuration directory When the directory doesn't exist, then it will create it
func (*SystemConfig) SetCustomConfigDirPath ¶
func (c *SystemConfig) SetCustomConfigDirPath(customConfigDirPath string)
SetCustomConfigDirPath sanitizes and sets a custom system config directory path
func (*SystemConfig) SetLastUpdateCheckedAt ¶
func (c *SystemConfig) SetLastUpdateCheckedAt(ctx context.Context, lastUpdateCheckedAt time.Time) (path string, err error)
SetLastUpdateCheckedAt writes the lastUpdateCheckAt time to the UserConfig file. When successful, the config file path is returned.
func (*SystemConfig) SetSurveyConfig ¶
func (c *SystemConfig) SetSurveyConfig(ctx context.Context, name string, surveyConfig SurveyConfig) error
SetSurveyConfig writes the survey for the given survey ID from the system-level config file
func (*SystemConfig) SetSystemID ¶
SetSystemID sets the system_id to a random SHA256 string in the user-level config file
func (*SystemConfig) SetTrustUnknownSources ¶
func (c *SystemConfig) SetTrustUnknownSources(ctx context.Context, value bool) error
SetTrustUnknownSources sets the trust_unknown_sources property to a the user-level config file
func (*SystemConfig) SlackConfigDir ¶
func (c *SystemConfig) SlackConfigDir(ctx context.Context) (string, error)
SlackConfigDir returns a folder/directory location for storing auth credentials and other config info. It should return a new hidden folder in the home directory where possible.
func (*SystemConfig) UserConfig ¶
func (c *SystemConfig) UserConfig(ctx context.Context) (*SystemConfig, error)
UserConfig returns the system-level config.json file contents
type SystemConfigManager ¶
type SystemConfigManager interface {
SetCustomConfigDirPath(customConfigDirPath string)
UserConfig(ctx context.Context) (*SystemConfig, error)
SlackConfigDir(ctx context.Context) (string, error)
LogsDir(ctx context.Context) (string, error)
GetTrustUnknownSources(ctx context.Context) (bool, error)
SetTrustUnknownSources(ctx context.Context, value bool) error
GetLastUpdateCheckedAt(ctx context.Context) (time.Time, error)
SetLastUpdateCheckedAt(ctx context.Context, lastUpdateCheckedAt time.Time) (path string, err error)
InitSystemID(ctx context.Context) (string, error)
GetSystemID(ctx context.Context) (string, error)
SetSystemID(ctx context.Context, systemID string) (string, error)
GetSurveyConfig(ctx context.Context, id string) (SurveyConfig, error)
SetSurveyConfig(ctx context.Context, id string, surveyConfig SurveyConfig) error
// contains filtered or unexported methods
}
SystemConfigManager is the interface for interacting with the system config
type SystemConfigMock ¶
func (*SystemConfigMock) GetLastUpdateCheckedAt ¶
func (*SystemConfigMock) GetSurveyConfig ¶
func (m *SystemConfigMock) GetSurveyConfig(ctx context.Context, id string) (SurveyConfig, error)
func (*SystemConfigMock) GetSystemID ¶
func (m *SystemConfigMock) GetSystemID(ctx context.Context) (string, error)
func (*SystemConfigMock) GetTrustUnknownSources ¶
func (m *SystemConfigMock) GetTrustUnknownSources(ctx context.Context) (bool, error)
func (*SystemConfigMock) InitSystemID ¶
func (m *SystemConfigMock) InitSystemID(ctx context.Context) (string, error)
func (*SystemConfigMock) LogsDir ¶
func (m *SystemConfigMock) LogsDir(ctx context.Context) (string, error)
func (*SystemConfigMock) SetCustomConfigDirPath ¶
func (m *SystemConfigMock) SetCustomConfigDirPath(customConfigDirPath string)
func (*SystemConfigMock) SetLastUpdateCheckedAt ¶
func (*SystemConfigMock) SetSurveyConfig ¶
func (m *SystemConfigMock) SetSurveyConfig(ctx context.Context, id string, surveyConfig SurveyConfig) error
func (*SystemConfigMock) SetSystemID ¶
func (*SystemConfigMock) SetTrustUnknownSources ¶
func (m *SystemConfigMock) SetTrustUnknownSources(ctx context.Context, value bool) error
func (*SystemConfigMock) SlackConfigDir ¶
func (m *SystemConfigMock) SlackConfigDir(ctx context.Context) (string, error)
func (*SystemConfigMock) UserConfig ¶
func (m *SystemConfigMock) UserConfig(ctx context.Context) (*SystemConfig, error)