2020-08-11 04:38:42 +00:00
|
|
|
package environment
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
2020-08-28 04:08:33 +00:00
|
|
|
type Settings struct {
|
2020-08-11 04:38:42 +00:00
|
|
|
Mounts []Mount
|
|
|
|
Allocations Allocations
|
|
|
|
Limits Limits
|
|
|
|
}
|
|
|
|
|
|
|
|
// Defines the actual configuration struct for the environment with all of the settings
|
|
|
|
// defined within it.
|
|
|
|
type Configuration struct {
|
|
|
|
mu sync.RWMutex
|
|
|
|
|
2020-08-28 03:28:29 +00:00
|
|
|
environmentVariables []string
|
2020-08-28 04:08:33 +00:00
|
|
|
settings Settings
|
2020-08-11 04:38:42 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 04:08:33 +00:00
|
|
|
// Returns a new environment configuration with the given settings and environment variables
|
|
|
|
// defined within it.
|
|
|
|
func NewConfiguration(s Settings, envVars []string) *Configuration {
|
2020-08-11 04:38:42 +00:00
|
|
|
return &Configuration{
|
2020-08-28 03:28:29 +00:00
|
|
|
environmentVariables: envVars,
|
2020-08-28 04:08:33 +00:00
|
|
|
settings: s,
|
2020-08-11 04:38:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-28 04:08:33 +00:00
|
|
|
// Updates the settings struct for this environment on the fly. This allows modified servers to
|
|
|
|
// automatically push those changes to the environment.
|
|
|
|
func (c *Configuration) SetSettings(s Settings) {
|
|
|
|
c.mu.Lock()
|
|
|
|
c.settings = s
|
|
|
|
c.mu.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updates the environment variables associated with this environment by replacing the entire
|
|
|
|
// array of them with a new one.
|
|
|
|
func (c *Configuration) SetEnvironmentVariables(ev []string) {
|
|
|
|
c.mu.Lock()
|
|
|
|
c.environmentVariables = ev
|
|
|
|
c.mu.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the limits assigned to this environment.
|
2020-08-11 04:38:42 +00:00
|
|
|
func (c *Configuration) Limits() Limits {
|
|
|
|
c.mu.RLock()
|
|
|
|
defer c.mu.RUnlock()
|
|
|
|
|
|
|
|
return c.settings.Limits
|
|
|
|
}
|
|
|
|
|
2020-08-28 04:08:33 +00:00
|
|
|
// Rturns the allocations associated with this environment.
|
2020-08-11 04:38:42 +00:00
|
|
|
func (c *Configuration) Allocations() Allocations {
|
|
|
|
c.mu.RLock()
|
|
|
|
defer c.mu.RUnlock()
|
|
|
|
|
|
|
|
return c.settings.Allocations
|
|
|
|
}
|
|
|
|
|
2020-08-28 04:08:33 +00:00
|
|
|
// Returns all of the mounts associated with this environment.
|
2020-08-11 04:38:42 +00:00
|
|
|
func (c *Configuration) Mounts() []Mount {
|
|
|
|
c.mu.RLock()
|
|
|
|
defer c.mu.RUnlock()
|
|
|
|
|
|
|
|
return c.settings.Mounts
|
|
|
|
}
|
|
|
|
|
2020-08-28 04:08:33 +00:00
|
|
|
// Returns the environment variables associated with this instance.
|
2020-08-11 04:38:42 +00:00
|
|
|
func (c *Configuration) EnvironmentVariables() []string {
|
|
|
|
c.mu.RLock()
|
2020-08-28 03:28:29 +00:00
|
|
|
defer c.mu.RUnlock()
|
2020-08-11 04:38:42 +00:00
|
|
|
|
2020-08-28 03:28:29 +00:00
|
|
|
return c.environmentVariables
|
2020-08-28 04:08:33 +00:00
|
|
|
}
|