Documentation
¶
Overview ¶
Package config provides the global configuration for Ocular.
Index ¶
- Variables
- func Init()
- func InitEnv()
- func InitLogger(level, format string, globalFields ...zap.Field)
- func IsEnvironmentIn(envs ...Environment) bool
- func ReadKubeConfig() io.Reader
- func WriteConfig(w io.Writer, format string) error
- type Config
- type Environment
- type ResourceConfig
- type SecretResourceConfig
Constants ¶
This section is empty.
Variables ¶
var ( // Version is the version of the application. Version = "dev" // BuildTime is the date when the application was built. BuildTime = "unknown" // Commit is the commit hash of the application. Commit = "unknown" )
Functions ¶
func InitLogger ¶
InitLogger initializes the logger for the application. It sets the logging level and format based on the configuration. It also replaces the global logger with the new logger.
func IsEnvironmentIn ¶
func IsEnvironmentIn(envs ...Environment) bool
IsEnvironmentIn checks if the current environment is one of the provided environments.
func ReadKubeConfig ¶
ReadKubeConfig reads the kubeconfig file from the specified path. If the path is empty, it defaults to $HOME/.kube/config. If no file is found in either locations, it will return nil.
Types ¶
type Config ¶
type Config struct {
// Environment is the environment that Ocular is running in.
Environment string `json:"environment" yaml:"environment"`
// API is the configuration for the API server.
API struct {
// TLS is the configuration for TLS.
TLS struct {
// Enabled is whether TLS is enabled for the API.
Enabled bool `json:"enabled" yaml:"enabled"`
// CertPath is the path to the TLS certificate.
CertPath string `json:"certpath" yaml:"certpath"`
// KeyPath is the path to the TLS key.
KeyPath string `json:"keypath" yaml:"keypath"`
} `json:"tls"`
// Port is the port that the API server will listen on.
Port int `json:"port" yaml:"port"`
// Host is the hostname of the API server.
Host string `json:"host" yaml:"host"`
} `json:"api" yaml:"api"`
// Logging is the configuration for the logger.
Logging struct {
// Level is the logging level.
Level string `json:"level"`
Format string `json:"format"`
} `json:"logging" yaml:"logging"`
// Crawlers is the configuration for crawler resources.
Crawlers ResourceConfig `json:"crawlers" yaml:"crawlers"`
// Downloaders is the configuration for downloader resources.
Downloaders ResourceConfig `json:"downloaders" yaml:"downloaders"`
// Uploaders is the configuration for uploader resources.
Uploaders ResourceConfig `json:"uploaders" yaml:"uploaders"`
// Profiles is the configuration for the profiles.
Profiles ResourceConfig `json:"profiles" yaml:"profiles"`
// Secrets is the configuration for the secrets.
Secrets SecretResourceConfig `json:"secrets" yaml:"secrets"`
// Extractor is the configuration for the extractor container, responsible for
// transmitting files between scanners and uploaders.
Extractor schemas.UserContainer `json:"extractor" yaml:"extractor"`
// Runtime is the configuration for the runtime environment.
Runtime struct {
Requests struct {
// CPU is the CPU request for the container.
CPU string `json:"cpu" yaml:"cpu"`
// Memory is the memory request for the container.
Memory string `json:"memory" yaml:"memory"`
} `json:"requests" yaml:"requests"`
Limits struct {
// CPU is the CPU limit for the container.
CPU string `json:"cpu" yaml:"cpu"`
// Memory is the memory limit for the container.
Memory string `json:"memory" yaml:"memory"`
}
Labels map[string]string `json:"labels" yaml:"labels" mapstructure:"labels"`
// ImagePullSecrets is a list of image pull secrets that will be attached to
// all jobs created by Ocular.
ImagePullSecrets []string `json:"imagePullSecrets,omitempty" yaml:"imagePullSecrets,omitempty,flow" mapstructure:"imagePullSecrets"`
// JobTTL is the time to live for jobs created by Ocular.
JobTTL time.Duration `json:"jobTTL" yaml:"jobTTL" mapstructure:"jobTTL"`
// UploadersServiceAccount is the service account that will be used by the uploader pods of a pipeline.
UploadersServiceAccount string `json:"uploadersServiceAccount,omitempty" yaml:"uploadersServiceAccount,omitempty" mapstructure:"uploadersServiceAccount"`
// ScannersServiceAccount is the service account that will be used by the scanner pods of a pipeline.
// This will also be used by the downloader in the scanner job.
ScannersServiceAccount string `json:"scannersServiceAccount,omitempty" yaml:"scannersServiceAccount,omitempty" mapstructure:"scannersServiceAccount"`
// CrawlersServiceAccount is the service account that will be used by the search jobs.
CrawlersServiceAccount string `json:"crawlersServiceAccount,omitempty" yaml:"crawlersServiceAccount,omitempty" mapstructure:"crawlersServiceAccount"`
} `json:"runtime" yaml:"runtime" mapstructure:"runtime"`
// ClusterAccess is the configuration for the cluster contexts
// that are used by Ocular. A 'ClusterAccess' represents a connection
// to a cluster (via client-go's ClientSet) and a namespace.
// Contexts are read both from a kubeconfig file and from the
// mounted service account token in the pod.
ClusterAccess struct {
CheckValidity bool `json:"checkValidity" yaml:"checkValidity"`
ServiceAccount struct {
Enabled bool `json:"enabled" yaml:"enabled"`
Namespace string `json:"namespace" yaml:"namespace"`
} `json:"serviceAccount" yaml:"serviceAccount"`
Kubeconfig struct {
Path string `json:"path" yaml:"path"`
} `json:"kubeconfig" yaml:"kubeconfig"`
} `json:"clusterAccess" yaml:"clusterAccess"`
}
Config is the structure for the global configuration file for Ocular. It is loaded from a config file at startup time, and values can be overridden by environment variables. The config file is expected to be in YAML format. Environment variables are expected to be prefixed with "OCULAR_", all capital and use underscores to separate nested keys. For example, the key "api.tls.enabled" can be overridden by the environment variable "OCULAR_API_TLS_ENABLED".
var State Config
State is the global configuration state for Ocular.
type Environment ¶
type Environment = uint8
Environment represents the different environments the application can run in. It is used to determine the current environment based on the configuration file.
const ( // EnvProduction represents the production environment. EnvProduction Environment = iota // EnvStaging represents the staging environment. This // ideally should be result in a configuration identical to production, // but mainly used for metadata purposes. EnvStaging // EnvDevelopment represents the development environment. EnvDevelopment // EnvTest represents the test environment (both unit and integration). EnvTest )
type ResourceConfig ¶
type ResourceConfig struct {
ConfigMapName string `json:"configMapName" yaml:"configMapName" mapstructure:"configMapName"`
}
ResourceConfig is the configuration for a resource type in Ocular. It contains the name of the ConfigMap that stores the resource definitions.
type SecretResourceConfig ¶
type SecretResourceConfig struct {
// SecretName is the name of the secret that stores the resource definitions.
SecretName string `json:"secretName" yaml:"secretName" mapstructure:"secretName"`
}