Remove environment.Environment struct

This commit completely removes the environment struct as it is no longer
used.
This commit is contained in:
Tom Wiesing 2023-03-02 12:52:51 +01:00
parent 3263920d6b
commit 473040a69f
No known key found for this signature in database
40 changed files with 91 additions and 146 deletions

View file

@ -10,7 +10,6 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/cli" "github.com/FAU-CDI/wisski-distillery/internal/cli"
"github.com/FAU-CDI/wisski-distillery/internal/config" "github.com/FAU-CDI/wisski-distillery/internal/config"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx" "github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/FAU-CDI/wisski-distillery/pkg/logging" "github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/tkw1536/goprogram/exit" "github.com/tkw1536/goprogram/exit"
@ -70,15 +69,11 @@ var errBootstrapCreateFile = exit.Error{
} }
func (bs cBootstrap) Run(context wisski_distillery.Context) error { func (bs cBootstrap) Run(context wisski_distillery.Context) error {
// installation environment is the native environment!
// TODO: Should this be configurable?
var env environment.Environment
root := bs.Directory root := bs.Directory
// check that we didn't get a different base directory // check that we didn't get a different base directory
{ {
got, err := cli.ReadBaseDirectory(env) got, err := cli.ReadBaseDirectory()
if err == nil && got != "" && got != root { if err == nil && got != "" && got != root {
return errBootstrapDifferent.WithMessageF(got) return errBootstrapDifferent.WithMessageF(got)
} }
@ -89,7 +84,7 @@ func (bs cBootstrap) Run(context wisski_distillery.Context) error {
if err := fsx.MkdirAll(root, fsx.DefaultDirPerm); err != nil { if err := fsx.MkdirAll(root, fsx.DefaultDirPerm); err != nil {
return errBootstrapFailedToCreateDirectory.WithMessageF(root) return errBootstrapFailedToCreateDirectory.WithMessageF(root)
} }
if err := cli.WriteBaseDirectory(env, root); err != nil { if err := cli.WriteBaseDirectory(root); err != nil {
return errBootstrapFailedToSaveDirectory.WithMessageF(root) return errBootstrapFailedToSaveDirectory.WithMessageF(root)
} }
context.Println(root) context.Println(root)
@ -105,7 +100,7 @@ func (bs cBootstrap) Run(context wisski_distillery.Context) error {
tpl.DefaultDomain = bs.Hostname tpl.DefaultDomain = bs.Hostname
// and use thge defaults // and use thge defaults
if err := tpl.SetDefaults(env); err != nil { if err := tpl.SetDefaults(); err != nil {
return errBootstrapWriteConfig.WithMessageF(err) return errBootstrapWriteConfig.WithMessageF(err)
} }
@ -154,7 +149,7 @@ func (bs cBootstrap) Run(context wisski_distillery.Context) error {
} }
// Validate configuration file! // Validate configuration file!
if err := cfg.Validate(env); err != nil { if err := cfg.Validate(); err != nil {
return err return err
} }
@ -191,7 +186,7 @@ func (bs cBootstrap) Run(context wisski_distillery.Context) error {
defer f.Close() defer f.Close()
var cfg config.Config var cfg config.Config
if err := cfg.Unmarshal(env, f); err != nil { if err := cfg.Unmarshal(f); err != nil {
return errBootstrapOpenConfig.WithMessageF(err) return errBootstrapOpenConfig.WithMessageF(err)
} }
context.Println(cfg) context.Println(cfg)

View file

@ -8,7 +8,6 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/cli" "github.com/FAU-CDI/wisski-distillery/internal/cli"
"github.com/FAU-CDI/wisski-distillery/internal/config" "github.com/FAU-CDI/wisski-distillery/internal/config"
"github.com/FAU-CDI/wisski-distillery/internal/config/legacy" "github.com/FAU-CDI/wisski-distillery/internal/config/legacy"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
) )
// ConfigMigrate is the config-migrate command // ConfigMigrate is the config-migrate command
@ -31,9 +30,6 @@ func (cfgMigrate) Description() wisski_distillery.Description {
} }
func (c cfgMigrate) Run(context wisski_distillery.Context) error { func (c cfgMigrate) Run(context wisski_distillery.Context) error {
// migration environment is the native environment!
var env environment.Environment
// open the legacy file // open the legacy file
file, err := os.Open(c.Positionals.Input) file, err := os.Open(c.Positionals.Input)
if err != nil { if err != nil {
@ -46,12 +42,12 @@ func (c cfgMigrate) Run(context wisski_distillery.Context) error {
var cfg config.Config var cfg config.Config
// migrate the legacy config // migrate the legacy config
if err := legacy.Migrate(&cfg, env, file); err != nil { if err := legacy.Migrate(&cfg, file); err != nil {
return err return err
} }
// validate it! // validate it!
if err := cfg.Validate(env); err != nil { if err := cfg.Validate(); err != nil {
return err return err
} }

View file

@ -39,7 +39,7 @@ func (s server) Run(context wisski_distillery.Context) error {
// if the caller requested a trigger, just trigger the cron tasks // if the caller requested a trigger, just trigger the cron tasks
if s.Trigger { if s.Trigger {
return dis.Control().Trigger(context.Context, context.Environment.Environment) return dis.Control().Trigger(context.Context)
} }
{ {

View file

@ -63,7 +63,7 @@ func (sp systempause) start(context wisski_distillery.Context, dis *dis.Distille
PrefixAlign: true, PrefixAlign: true,
Handler: func(item component.Installable, index int, writer io.Writer) error { Handler: func(item component.Installable, index int, writer io.Writer) error {
return item.Stack(context.Environment.Environment).Up(context.Context, writer) return item.Stack().Up(context.Context, writer)
}, },
}, dis.Installable()); err != nil { }, dis.Installable()); err != nil {
return err return err
@ -127,7 +127,7 @@ func (sp systempause) stop(context wisski_distillery.Context, dis *dis.Distiller
PrefixAlign: true, PrefixAlign: true,
Handler: func(item component.Installable, index int, writer io.Writer) error { Handler: func(item component.Installable, index int, writer io.Writer) error {
return item.Stack(context.Environment.Environment).Down(context.Context, writer) return item.Stack().Down(context.Context, writer)
}, },
}, dis.Installable()); err != nil { }, dis.Installable()); err != nil {
return err return err

View file

@ -132,7 +132,7 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
PrefixAlign: true, PrefixAlign: true,
Handler: func(item component.Installable, index int, writer io.Writer) error { Handler: func(item component.Installable, index int, writer io.Writer) error {
stack := item.Stack(context.Environment.Environment) stack := item.Stack()
if err := stack.Install(context.Context, writer, item.Context(ctx)); err != nil { if err := stack.Install(context.Context, writer, item.Context(ctx)); err != nil {
return err return err

View file

@ -9,7 +9,6 @@ import (
"strings" "strings"
"github.com/FAU-CDI/wisski-distillery/internal/bootstrap" "github.com/FAU-CDI/wisski-distillery/internal/bootstrap"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx" "github.com/FAU-CDI/wisski-distillery/pkg/fsx"
) )
@ -35,7 +34,7 @@ var errReadBaseDirectoryEmpty = errors.New("ReadBaseDirectory: Directory is empt
// Use [ParamsFromEnv] to initialize parameters completely. // Use [ParamsFromEnv] to initialize parameters completely.
// //
// It does not perform any reading of files. // It does not perform any reading of files.
func ReadBaseDirectory(env environment.Environment) (value string, err error) { func ReadBaseDirectory() (value string, err error) {
// get the path! // get the path!
path, err := MetaConfigPath() path, err := MetaConfigPath()
if err != nil { if err != nil {
@ -61,7 +60,7 @@ func ReadBaseDirectory(env environment.Environment) (value string, err error) {
} }
// WriteBaseDirectory writes the base directory to the environment, or returns an error // WriteBaseDirectory writes the base directory to the environment, or returns an error
func WriteBaseDirectory(env environment.Environment, dir string) error { func WriteBaseDirectory(dir string) error {
// get the path! // get the path!
path, err := MetaConfigPath() path, err := MetaConfigPath()
if err != nil { if err != nil {

View file

@ -7,7 +7,6 @@ import (
"path/filepath" "path/filepath"
"github.com/FAU-CDI/wisski-distillery/internal/bootstrap" "github.com/FAU-CDI/wisski-distillery/internal/bootstrap"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
) )
// Params are used to initialize the excutable. // Params are used to initialize the excutable.
@ -19,10 +18,8 @@ type Params struct {
// ParamsFromEnv creates a new set of parameters from the environment. // ParamsFromEnv creates a new set of parameters from the environment.
// Uses [ReadBaseDirectory] or falls back to [BaseDirectoryDefault]. // Uses [ReadBaseDirectory] or falls back to [BaseDirectoryDefault].
func ParamsFromEnv() (params Params, err error) { func ParamsFromEnv() (params Params, err error) {
var native environment.Environment
// try to read the base directory! // try to read the base directory!
value, err := ReadBaseDirectory(native) // TODO: Are we sure about the native environment here? value, err := ReadBaseDirectory() // TODO: Are we sure about the native environment here?
switch { switch {
case os.IsNotExist(err): case os.IsNotExist(err):
params.ConfigPath = bootstrap.BaseDirectoryDefault params.ConfigPath = bootstrap.BaseDirectoryDefault

View file

@ -12,14 +12,13 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/config/legacy/envreader" "github.com/FAU-CDI/wisski-distillery/internal/config/legacy/envreader"
"github.com/FAU-CDI/wisski-distillery/internal/config/legacy/stringparser" "github.com/FAU-CDI/wisski-distillery/internal/config/legacy/stringparser"
"github.com/FAU-CDI/wisski-distillery/internal/config/validators" "github.com/FAU-CDI/wisski-distillery/internal/config/validators"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
// Migrate parses a configuration from an old configuration. // Migrate parses a configuration from an old configuration.
func Migrate(config *config.Config, env environment.Environment, src io.Reader) error { func Migrate(config *config.Config, src io.Reader) error {
var legacy Legacy var legacy Legacy
if err := legacy.Unmarshal(env, src); err != nil { if err := legacy.Unmarshal(src); err != nil {
return nil return nil
} }
return legacy.Migrate(config) return legacy.Migrate(config)
@ -104,7 +103,7 @@ func (legacy *Legacy) Migrate(cfg *config.Config) error {
// When a key is missing, it is set to the default value. // When a key is missing, it is set to the default value.
// //
// See also [stringparser.Parse]. // See also [stringparser.Parse].
func (config *Legacy) Unmarshal(env environment.Environment, src io.Reader) error { func (config *Legacy) Unmarshal(src io.Reader) error {
// read all the values! // read all the values!
values, err := envreader.ReadAll(src) values, err := envreader.ReadAll(src)
if err != nil { if err != nil {
@ -138,7 +137,7 @@ func (config *Legacy) Unmarshal(env environment.Environment, src io.Reader) erro
} }
// parse the value! // parse the value!
if err := stringparser.Parse(env, tParser, value, vField); err != nil { if err := stringparser.Parse(tParser, value, vField); err != nil {
return errors.Errorf("Legacy.Unmarshal: Setting %q, Parser %q: %s", tEnv, tParser, err) return errors.Errorf("Legacy.Unmarshal: Setting %q, Parser %q: %s", tEnv, tParser, err)
} }
} }

View file

@ -4,14 +4,13 @@ import (
"reflect" "reflect"
"strings" "strings"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
var errUnknownParser = errors.New("unknown parser") var errUnknownParser = errors.New("unknown parser")
// Parse parses the provided value with the parser. // Parse parses the provided value with the parser.
func Parse(env environment.Environment, name, value string, vField reflect.Value) error { func Parse(name, value string, vField reflect.Value) error {
// use the validator // use the validator
parser, ok := knownParsers[strings.ToLower(name)] parser, ok := knownParsers[strings.ToLower(name)]
@ -20,7 +19,7 @@ func Parse(env environment.Environment, name, value string, vField reflect.Value
} }
// get the parsed value // get the parsed value
checked, err := parser(env, value) checked, err := parser(value)
if err != nil { if err != nil {
return err return err
} }
@ -58,8 +57,8 @@ var knownParsers map[string]Parser[any] = map[string]Parser[any]{
} }
func asGenericParser[T any](parser Parser[T]) Parser[any] { func asGenericParser[T any](parser Parser[T]) Parser[any] {
return func(env environment.Environment, s string) (value any, err error) { return func(s string) (value any, err error) {
value, err = parser(env, s) value, err = parser(s)
return return
} }
} }

View file

@ -9,7 +9,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx" "github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -20,10 +19,10 @@ import (
// Parsers can be found in this package as functions called Parse*. // Parsers can be found in this package as functions called Parse*.
// They are refered to by their name, e.g. ParseNonempty can be refered to by the name 'Nonempty'. // They are refered to by their name, e.g. ParseNonempty can be refered to by the name 'Nonempty'.
// See [Parse]. // See [Parse].
type Parser[T any] func(env environment.Environment, s string) (T, error) type Parser[T any] func(s string) (T, error)
// ParseAbspath checks that s is an absolute path and returns it as-is // ParseAbspath checks that s is an absolute path and returns it as-is
func ParseAbspath(env environment.Environment, s string) (string, error) { func ParseAbspath(s string) (string, error) {
if !fsx.IsDirectory(s) { if !fsx.IsDirectory(s) {
return "", errors.Errorf("%q does not exist or is not a directory", s) return "", errors.Errorf("%q does not exist or is not a directory", s)
} }
@ -31,7 +30,7 @@ func ParseAbspath(env environment.Environment, s string) (string, error) {
} }
// ParseFile checks that s is a valid file and returns it as-is // ParseFile checks that s is a valid file and returns it as-is
func ParseFile(env environment.Environment, s string) (string, error) { func ParseFile(s string) (string, error) {
if !fsx.IsFile(s) { if !fsx.IsFile(s) {
return "", errors.Errorf("%q does not exist or is not a regular file", s) return "", errors.Errorf("%q does not exist or is not a regular file", s)
} }
@ -41,7 +40,7 @@ func ParseFile(env environment.Environment, s string) (string, error) {
var errEmptyString = errors.New("value is empty") var errEmptyString = errors.New("value is empty")
// ParseNonEmpty checks that s is a non-empty string and returns it as-is // ParseNonEmpty checks that s is a non-empty string and returns it as-is
func ParseNonEmpty(env environment.Environment, s string) (string, error) { func ParseNonEmpty(s string) (string, error) {
if s == "" { if s == "" {
return "", errEmptyString return "", errEmptyString
} }
@ -51,7 +50,7 @@ func ParseNonEmpty(env environment.Environment, s string) (string, error) {
var regexpDomain = regexp.MustCompile(`^([a-zA-Z0-9][-a-zA-Z0-9]*\.)*[a-zA-Z0-9][-a-zA-Z0-9]*$`) // TODO: Make this regexp nicer! var regexpDomain = regexp.MustCompile(`^([a-zA-Z0-9][-a-zA-Z0-9]*\.)*[a-zA-Z0-9][-a-zA-Z0-9]*$`) // TODO: Make this regexp nicer!
// ParseValidDomain checks that s is a valid domain and returns it in lowercase // ParseValidDomain checks that s is a valid domain and returns it in lowercase
func ParseValidDomain(env environment.Environment, s string) (string, error) { func ParseValidDomain(s string) (string, error) {
if !regexpDomain.MatchString(s) { if !regexpDomain.MatchString(s) {
return "", errors.Errorf("%q is not a valid domain", s) return "", errors.Errorf("%q is not a valid domain", s)
} }
@ -59,7 +58,7 @@ func ParseValidDomain(env environment.Environment, s string) (string, error) {
} }
// ParseValidDomains checks that s is a comma-seperated list of valid domains and returns them in lower case // ParseValidDomains checks that s is a comma-seperated list of valid domains and returns them in lower case
func ParseValidDomains(env environment.Environment, s string) ([]string, error) { func ParseValidDomains(s string) ([]string, error) {
if len(s) == 0 { if len(s) == 0 {
return []string{}, nil return []string{}, nil
} }
@ -73,19 +72,19 @@ func ParseValidDomains(env environment.Environment, s string) ([]string, error)
} }
// ParseNumber parses s as a decimal integer // ParseNumber parses s as a decimal integer
func ParseNumber(env environment.Environment, s string) (int, error) { func ParseNumber(s string) (int, error) {
value, err := strconv.ParseInt(s, 10, 64) value, err := strconv.ParseInt(s, 10, 64)
return int(value), err return int(value), err
} }
// ParsePort parses s as a port // ParsePort parses s as a port
func ParsePort(env environment.Environment, s string) (uint16, error) { func ParsePort(s string) (uint16, error) {
value, err := strconv.ParseUint(s, 10, 16) value, err := strconv.ParseUint(s, 10, 16)
return uint16(value), err return uint16(value), err
} }
// ParseHttpsURL parses a string into a url that starts with 'https://' // ParseHttpsURL parses a string into a url that starts with 'https://'
func ParseHttpsURL(env environment.Environment, s string) (*url.URL, error) { func ParseHttpsURL(s string) (*url.URL, error) {
url, err := url.Parse(s) url, err := url.Parse(s)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "%q is not a valid URL", s) return nil, errors.Wrapf(err, "%q is not a valid URL", s)
@ -99,7 +98,7 @@ func ParseHttpsURL(env environment.Environment, s string) (*url.URL, error) {
var regexpEmail = regexp.MustCompile(`^([-a-zA-Z0-9]+)\@([a-zA-Z0-9][-a-zA-Z0-9]*\.)*[a-zA-Z0-9][-a-zA-Z0-9]*$`) // TODO: Make this regexp nicer! var regexpEmail = regexp.MustCompile(`^([-a-zA-Z0-9]+)\@([a-zA-Z0-9][-a-zA-Z0-9]*\.)*[a-zA-Z0-9][-a-zA-Z0-9]*$`) // TODO: Make this regexp nicer!
// ParseEmail checks that s represents an email, and then returns it as is. // ParseEmail checks that s represents an email, and then returns it as is.
func ParseEmail(env environment.Environment, s string) (string, error) { func ParseEmail(s string) (string, error) {
if s == "" { // no email provided if s == "" { // no email provided
return "", nil return "", nil
} }
@ -112,7 +111,7 @@ func ParseEmail(env environment.Environment, s string) (string, error) {
var regexpSlug = regexp.MustCompile(`^[a-zA-Z0-9][-a-zA-Z0-9]*$`) // TODO: Make this regexp nicer! var regexpSlug = regexp.MustCompile(`^[a-zA-Z0-9][-a-zA-Z0-9]*$`) // TODO: Make this regexp nicer!
// ParseSlug parses s as a slug and returns it as is. // ParseSlug parses s as a slug and returns it as is.
func ParseSlug(env environment.Environment, s string) (string, error) { func ParseSlug(s string) (string, error) {
if !regexpSlug.MatchString(s) { if !regexpSlug.MatchString(s) {
return "", errors.Errorf("%q is not a valid slug", s) return "", errors.Errorf("%q is not a valid slug", s)
} }
@ -120,6 +119,6 @@ func ParseSlug(env environment.Environment, s string) (string, error) {
} }
// ParseDuration parses a time.Duration // ParseDuration parses a time.Duration
func ParseDuration(env environment.Environment, s string) (time.Duration, error) { func ParseDuration(s string) (time.Duration, error) {
return time.ParseDuration(s) return time.ParseDuration(s)
} }

View file

@ -5,7 +5,6 @@ import (
"path/filepath" "path/filepath"
"github.com/FAU-CDI/wisski-distillery/internal/bootstrap" "github.com/FAU-CDI/wisski-distillery/internal/bootstrap"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx" "github.com/FAU-CDI/wisski-distillery/pkg/fsx"
) )
@ -34,7 +33,7 @@ func (pcfg PathsConfig) ExecutablePath() string {
} }
// UsingDistilleryExecutable checks if the current process is using the distillery executable // UsingDistilleryExecutable checks if the current process is using the distillery executable
func (pcfg PathsConfig) UsingDistilleryExecutable(env environment.Environment) bool { func (pcfg PathsConfig) UsingDistilleryExecutable() bool {
exe, err := os.Executable() exe, err := os.Executable()
if err != nil { if err != nil {
return false return false
@ -44,7 +43,7 @@ func (pcfg PathsConfig) UsingDistilleryExecutable(env environment.Environment) b
// CurrentExecutable returns the path to the current executable being used. // CurrentExecutable returns the path to the current executable being used.
// When it does not exist, falls back to the default executable. // When it does not exist, falls back to the default executable.
func (pcfg PathsConfig) CurrentExecutable(env environment.Environment) string { func (pcfg PathsConfig) CurrentExecutable() string {
exe, err := os.Executable() exe, err := os.Executable()
if err != nil || !fsx.IsFile(exe) { if err != nil || !fsx.IsFile(exe) {
return pcfg.ExecutablePath() return pcfg.ExecutablePath()

View file

@ -4,14 +4,13 @@ import (
"io" "io"
"github.com/FAU-CDI/wisski-distillery/internal/config/validators" "github.com/FAU-CDI/wisski-distillery/internal/config/validators"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/tkw1536/pkglib/validator" "github.com/tkw1536/pkglib/validator"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
// Unmarshal reads configuration from the provided io.Reader, and then validates it. // Unmarshal reads configuration from the provided io.Reader, and then validates it.
// Configuration is read in yaml format. // Configuration is read in yaml format.
func (config *Config) Unmarshal(env environment.Environment, src io.Reader) error { func (config *Config) Unmarshal(src io.Reader) error {
// read yaml! // read yaml!
{ {
decoder := yaml.NewDecoder(src) decoder := yaml.NewDecoder(src)
@ -22,12 +21,12 @@ func (config *Config) Unmarshal(env environment.Environment, src io.Reader) erro
} }
// TODO: should this be done seperatly? // TODO: should this be done seperatly?
return config.Validate(env) return config.Validate()
} }
// Validate validates this configuration file and sets appropriate defaults // Validate validates this configuration file and sets appropriate defaults
func (config *Config) Validate(env environment.Environment) error { func (config *Config) Validate() error {
return validator.Validate(config, validators.New(env)) return validator.Validate(config, validators.New())
} }
func (config *Config) Marshal(dest io.Writer) error { func (config *Config) Marshal(dest io.Writer) error {

View file

@ -7,7 +7,6 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/bootstrap" "github.com/FAU-CDI/wisski-distillery/internal/bootstrap"
"github.com/FAU-CDI/wisski-distillery/internal/passwordx" "github.com/FAU-CDI/wisski-distillery/internal/passwordx"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/tkw1536/pkglib/hostname" "github.com/tkw1536/pkglib/hostname"
"github.com/tkw1536/pkglib/password" "github.com/tkw1536/pkglib/password"
) )
@ -28,13 +27,13 @@ type Template struct {
} }
// SetDefaults sets defaults on the template // SetDefaults sets defaults on the template
func (tpl *Template) SetDefaults(env environment.Environment) (err error) { func (tpl *Template) SetDefaults() (err error) {
if tpl.RootPath == "" { if tpl.RootPath == "" {
tpl.RootPath = bootstrap.BaseDirectoryDefault tpl.RootPath = bootstrap.BaseDirectoryDefault
} }
if tpl.DefaultDomain == "" { if tpl.DefaultDomain == "" {
tpl.DefaultDomain = hostname.FQDN() // TODO: Make this environment specific tpl.DefaultDomain = hostname.FQDN()
} }
if tpl.TSAdminUser == "" { if tpl.TSAdminUser == "" {

View file

@ -1,22 +1,17 @@
package validators package validators
import ( import (
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/tkw1536/pkglib/validator" "github.com/tkw1536/pkglib/validator"
) )
// New creates a new set of standard validators for the configuration // New creates a new set of standard validators for the configuration
func New(env environment.Environment) validator.Collection { func New() validator.Collection {
coll := make(validator.Collection) coll := make(validator.Collection)
validator.Add(coll, "nonempty", ValidateNonempty) validator.Add(coll, "nonempty", ValidateNonempty)
validator.Add(coll, "directory", func(value *string, dflt string) error { validator.Add(coll, "directory", ValidateDirectory)
return ValidateDirectory(env, value, dflt) validator.Add(coll, "file", ValidateFile)
})
validator.Add(coll, "file", func(value *string, dflt string) error {
return ValidateFile(env, value, dflt)
})
validator.Add(coll, "domain", ValidateDomain) validator.Add(coll, "domain", ValidateDomain)
validator.AddSlice(coll, "domains", ",", ValidateDomain) validator.AddSlice(coll, "domains", ",", ValidateDomain)

View file

@ -1,12 +1,11 @@
package validators package validators
import ( import (
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx" "github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func ValidateFile(env environment.Environment, path *string, dflt string) error { func ValidateFile(path *string, dflt string) error {
if *path == "" { if *path == "" {
*path = dflt *path = dflt
} }
@ -16,7 +15,7 @@ func ValidateFile(env environment.Environment, path *string, dflt string) error
return nil return nil
} }
func ValidateDirectory(env environment.Environment, path *string, dflt string) error { func ValidateDirectory(path *string, dflt string) error {
if *path == "" { if *path == "" {
*path = dflt *path = dflt
} }

View file

@ -6,7 +6,6 @@ import (
"path/filepath" "path/filepath"
"github.com/FAU-CDI/wisski-distillery/internal/models" "github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx" "github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/FAU-CDI/wisski-distillery/pkg/logging" "github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -66,10 +65,9 @@ type StagingContext interface {
} }
// NewStagingContext returns a new [StagingContext] // NewStagingContext returns a new [StagingContext]
func NewStagingContext(ctx context.Context, env environment.Environment, progress io.Writer, path string, manifest chan<- string) StagingContext { func NewStagingContext(ctx context.Context, progress io.Writer, path string, manifest chan<- string) StagingContext {
return &stagingContext{ return &stagingContext{
ctx: ctx, ctx: ctx,
env: env,
progress: progress, progress: progress,
path: path, path: path,
manifest: manifest, manifest: manifest,
@ -79,7 +77,6 @@ func NewStagingContext(ctx context.Context, env environment.Environment, progres
// stagingContext implements [components.StagingContext] // stagingContext implements [components.StagingContext]
type stagingContext struct { type stagingContext struct {
ctx context.Context ctx context.Context
env environment.Environment // environment
progress io.Writer // writer to direct progress to progress io.Writer // writer to direct progress to
path string // path to send files to path string // path to send files to
manifest chan<- string // channel the manifest is sent to manifest chan<- string // channel the manifest is sent to

View file

@ -6,7 +6,6 @@ import (
"strings" "strings"
"github.com/FAU-CDI/wisski-distillery/internal/config" "github.com/FAU-CDI/wisski-distillery/internal/config"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
) )
// Components represents a logical subsystem of the distillery. // Components represents a logical subsystem of the distillery.
@ -64,6 +63,5 @@ func (cb Base) ID() string {
// Still represents the central part of a distillery. // Still represents the central part of a distillery.
// It is used inside the main distillery struct, as well as every component via [ComponentBase]. // It is used inside the main distillery struct, as well as every component via [ComponentBase].
type Still struct { type Still struct {
Environment environment.Environment // environment to use for reading / writing to and from the distillery
Config *config.Config // the configuration of the distillery Config *config.Config // the configuration of the distillery
} }

View file

@ -94,7 +94,6 @@ func (backup *Backup) run(ctx context.Context, progress io.Writer, exporter *Exp
return bc.Backup( return bc.Backup(
component.NewStagingContext( component.NewStagingContext(
ctx, ctx,
exporter.Environment,
writer, writer,
filepath.Join(backup.Description.Dest, bc.BackupName()), filepath.Join(backup.Description.Dest, bc.BackupName()),
manifest, manifest,

View file

@ -147,7 +147,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
st.Start() st.Start()
defer st.Stop() defer st.Stop()
count, err = targz.Package(exporter.Environment, archivePath, stagingDir, func(dst, src string) { count, err = targz.Package(archivePath, stagingDir, func(dst, src string) {
st.Set(0, dst) st.Set(0, dst)
}) })

View file

@ -124,7 +124,6 @@ func (snapshot *Snapshot) makeParts(ctx context.Context, progress io.Writer, sna
instance.Instance, instance.Instance,
component.NewStagingContext( component.NewStagingContext(
ctx, ctx,
snapshots.Environment,
writer, writer,
filepath.Join(snapshot.Description.Dest, sc.SnapshotName()), filepath.Join(snapshot.Description.Dest, sc.SnapshotName()),
manifest, manifest,

View file

@ -3,8 +3,6 @@ package component
import ( import (
"context" "context"
"io" "io"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
) )
// Installable implements an installable component. // Installable implements an installable component.
@ -18,7 +16,7 @@ type Installable interface {
// Stack can be used to gain access to the "docker compose" stack. // Stack can be used to gain access to the "docker compose" stack.
// //
// This should internally call [ComponentBase.MakeStack] // This should internally call [ComponentBase.MakeStack]
Stack(env environment.Environment) StackWithResources Stack() StackWithResources
// Context returns a new InstallationContext to be used during installation from the command line. // Context returns a new InstallationContext to be used during installation from the command line.
// Typically this should just pass through the parent, but might perform other tasks. // Typically this should just pass through the parent, but might perform other tasks.
@ -26,8 +24,7 @@ type Installable interface {
} }
// MakeStack registers the Installable as a stack // MakeStack registers the Installable as a stack
func MakeStack(component Installable, env environment.Environment, stack StackWithResources) StackWithResources { func MakeStack(component Installable, stack StackWithResources) StackWithResources {
stack.Env = env
stack.Dir = component.Path() stack.Dir = component.Path()
return stack return stack
} }

View file

@ -22,7 +22,7 @@ var runtimeResources embed.FS
// Update installs or updates runtime components needed by this component. // Update installs or updates runtime components needed by this component.
func (instances *Instances) Update(ctx context.Context, progress io.Writer) error { func (instances *Instances) Update(ctx context.Context, progress io.Writer) error {
err := unpack.InstallDir(instances.Still.Environment, instances.Config.Paths.RuntimeDir(), "runtime", runtimeResources, func(dst, src string) { err := unpack.InstallDir(instances.Config.Paths.RuntimeDir(), "runtime", runtimeResources, func(dst, src string) {
logging.ProgressF(progress, ctx, "[copy] %s\n", dst) logging.ProgressF(progress, ctx, "[copy] %s\n", dst)
}) })
if err != nil { if err != nil {

View file

@ -9,7 +9,6 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/bootstrap" "github.com/FAU-CDI/wisski-distillery/internal/bootstrap"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component" "github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
) )
func (control Server) Path() string { func (control Server) Path() string {
@ -19,8 +18,8 @@ func (control Server) Path() string {
//go:embed all:server server.env //go:embed all:server server.env
var resources embed.FS var resources embed.FS
func (server *Server) Stack(env environment.Environment) component.StackWithResources { func (server *Server) Stack() component.StackWithResources {
return component.MakeStack(server, env, component.StackWithResources{ return component.MakeStack(server, component.StackWithResources{
Resources: resources, Resources: resources,
ContextPath: "server", ContextPath: "server",
EnvPath: "server.env", EnvPath: "server.env",
@ -44,12 +43,12 @@ func (server *Server) Stack(env environment.Environment) component.StackWithReso
} }
// Trigger triggers the active cron run to immediatly invoke cron. // Trigger triggers the active cron run to immediatly invoke cron.
func (server *Server) Trigger(ctx context.Context, env environment.Environment) error { func (server *Server) Trigger(ctx context.Context) error {
return server.Stack(env).Kill(ctx, io.Discard, "control", syscall.SIGHUP) return server.Stack().Kill(ctx, io.Discard, "control", syscall.SIGHUP)
} }
func (server *Server) Context(parent component.InstallationContext) component.InstallationContext { func (server *Server) Context(parent component.InstallationContext) component.InstallationContext {
return component.InstallationContext{ return component.InstallationContext{
bootstrap.Executable: server.Config.Paths.CurrentExecutable(server.Environment), // TODO: Does this make sense? bootstrap.Executable: server.Config.Paths.CurrentExecutable(), // TODO: Does this make sense?
} }
} }

View file

@ -6,7 +6,6 @@ import (
"time" "time"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component" "github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
) )
type Solr struct { type Solr struct {
@ -33,8 +32,8 @@ func (*Solr) Context(parent component.InstallationContext) component.Installatio
//go:embed solr.env //go:embed solr.env
var resources embed.FS var resources embed.FS
func (solr *Solr) Stack(env environment.Environment) component.StackWithResources { func (solr *Solr) Stack() component.StackWithResources {
return component.MakeStack(solr, env, component.StackWithResources{ return component.MakeStack(solr, component.StackWithResources{
Resources: resources, Resources: resources,
ContextPath: "solr", ContextPath: "solr",

View file

@ -18,7 +18,7 @@ func (*SQL) BackupName() string {
// Backup makes a backup of all SQL databases into the path dest. // Backup makes a backup of all SQL databases into the path dest.
func (sql *SQL) Backup(scontext component.StagingContext) error { func (sql *SQL) Backup(scontext component.StagingContext) error {
return scontext.AddFile("", func(ctx context.Context, file io.Writer) error { return scontext.AddFile("", func(ctx context.Context, file io.Writer) error {
code := sql.Stack(sql.Environment).Exec(ctx, stream.NonInteractive(scontext.Progress()), "sql", "mysqldump", "--all-databases")() code := sql.Stack().Exec(ctx, stream.NonInteractive(scontext.Progress()), "sql", "mysqldump", "--all-databases")()
if code != 0 { if code != 0 {
return errSQLBackup return errSQLBackup
} }

View file

@ -23,7 +23,7 @@ func (sql *SQL) Snapshot(wisski models.Instance, scontext component.StagingConte
// SnapshotDB makes a backup of the sql database into dest. // SnapshotDB makes a backup of the sql database into dest.
func (sql *SQL) SnapshotDB(ctx context.Context, progress io.Writer, dest io.Writer, database string) error { func (sql *SQL) SnapshotDB(ctx context.Context, progress io.Writer, dest io.Writer, database string) error {
code := sql.Stack(sql.Environment).Exec(ctx, stream.NonInteractive(progress), "sql", "mysqldump", "--databases", database)() code := sql.Stack().Exec(ctx, stream.NonInteractive(progress), "sql", "mysqldump", "--databases", database)()
if code != 0 { if code != 0 {
return errSQLBackup return errSQLBackup
} }

View file

@ -6,7 +6,6 @@ import (
"time" "time"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component" "github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx" "github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/tkw1536/pkglib/lazy" "github.com/tkw1536/pkglib/lazy"
) )
@ -43,8 +42,8 @@ func (*SQL) Context(parent component.InstallationContext) component.Installation
//go:embed sql.env //go:embed sql.env
var resources embed.FS var resources embed.FS
func (sql *SQL) Stack(env environment.Environment) component.StackWithResources { func (sql *SQL) Stack() component.StackWithResources {
return component.MakeStack(sql, env, component.StackWithResources{ return component.MakeStack(sql, component.StackWithResources{
Resources: resources, Resources: resources,
ContextPath: "sql", ContextPath: "sql",

View file

@ -19,7 +19,7 @@ import (
// //
// NOTE(twiesing): This command should not be used to connect to the database or execute queries except in known situations. // NOTE(twiesing): This command should not be used to connect to the database or execute queries except in known situations.
func (sql *SQL) Shell(ctx context.Context, io stream.IOStream, argv ...string) int { func (sql *SQL) Shell(ctx context.Context, io stream.IOStream, argv ...string) int {
return sql.Stack(sql.Environment).Exec(ctx, io, "sql", "mysql", argv...)() return sql.Stack().Exec(ctx, io, "sql", "mysql", argv...)()
} }
// unsafeWaitShell waits for a connection via the database shell to succeed // unsafeWaitShell waits for a connection via the database shell to succeed

View file

@ -7,7 +7,6 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/bootstrap" "github.com/FAU-CDI/wisski-distillery/internal/bootstrap"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component" "github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
) )
func (ssh SSH2) Path() string { func (ssh SSH2) Path() string {
@ -17,8 +16,8 @@ func (ssh SSH2) Path() string {
//go:embed all:ssh2 ssh2.env //go:embed all:ssh2 ssh2.env
var resources embed.FS var resources embed.FS
func (ssh *SSH2) Stack(env environment.Environment) component.StackWithResources { func (ssh *SSH2) Stack() component.StackWithResources {
stt := component.MakeStack(ssh, env, component.StackWithResources{ stt := component.MakeStack(ssh, component.StackWithResources{
Resources: resources, Resources: resources,
ContextPath: "ssh2", ContextPath: "ssh2",
EnvPath: "ssh2.env", EnvPath: "ssh2.env",
@ -44,6 +43,6 @@ func (ssh *SSH2) Stack(env environment.Environment) component.StackWithResources
func (ssh SSH2) Context(parent component.InstallationContext) component.InstallationContext { func (ssh SSH2) Context(parent component.InstallationContext) component.InstallationContext {
return component.InstallationContext{ return component.InstallationContext{
bootstrap.Executable: ssh.Config.Paths.CurrentExecutable(ssh.Environment), // TODO: Does this make sense? bootstrap.Executable: ssh.Config.Paths.CurrentExecutable(), // TODO: Does this make sense?
} }
} }

View file

@ -9,7 +9,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/execx" "github.com/FAU-CDI/wisski-distillery/pkg/execx"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx" "github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/FAU-CDI/wisski-distillery/pkg/logging" "github.com/FAU-CDI/wisski-distillery/pkg/logging"
@ -27,7 +26,6 @@ import (
type Stack struct { type Stack struct {
Dir string // Directory this Stack is located in Dir string // Directory this Stack is located in
Env environment.Environment
DockerExecutable string // Path to the native docker executable to use DockerExecutable string // Path to the native docker executable to use
} }
@ -210,11 +208,9 @@ type InstallationContext map[string]string
// Installation is non-interactive, but will provide debugging output onto io. // Installation is non-interactive, but will provide debugging output onto io.
// InstallationContext // InstallationContext
func (is StackWithResources) Install(ctx context.Context, progress io.Writer, context InstallationContext) error { func (is StackWithResources) Install(ctx context.Context, progress io.Writer, context InstallationContext) error {
env := is.Stack.Env
if is.ContextPath != "" { if is.ContextPath != "" {
// setup the base files // setup the base files
if err := unpack.InstallDir( if err := unpack.InstallDir(
env,
is.Dir, is.Dir,
is.ContextPath, is.ContextPath,
is.Resources, is.Resources,
@ -231,7 +227,6 @@ func (is StackWithResources) Install(ctx context.Context, progress io.Writer, co
if is.EnvPath != "" && is.EnvContext != nil { if is.EnvPath != "" && is.EnvContext != nil {
logging.ProgressF(progress, ctx, "[config] %s\n", envDest) logging.ProgressF(progress, ctx, "[config] %s\n", envDest)
if err := unpack.InstallTemplate( if err := unpack.InstallTemplate(
env,
envDest, envDest,
is.EnvContext, is.EnvContext,
is.EnvPath, is.EnvPath,

View file

@ -6,7 +6,6 @@ import (
"time" "time"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component" "github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
) )
type Triplestore struct { type Triplestore struct {
@ -36,8 +35,8 @@ func (Triplestore) Context(parent component.InstallationContext) component.Insta
//go:embed triplestore.env //go:embed triplestore.env
var resources embed.FS var resources embed.FS
func (ts *Triplestore) Stack(env environment.Environment) component.StackWithResources { func (ts *Triplestore) Stack() component.StackWithResources {
return component.MakeStack(ts, env, component.StackWithResources{ return component.MakeStack(ts, component.StackWithResources{
Resources: resources, Resources: resources,
ContextPath: "triplestore", ContextPath: "triplestore",

View file

@ -5,7 +5,6 @@ import (
"path/filepath" "path/filepath"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component" "github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
) )
// Web implements the ingress gateway for the distillery. // Web implements the ingress gateway for the distillery.
@ -27,11 +26,11 @@ func (*Web) Context(parent component.InstallationContext) component.Installation
return parent return parent
} }
func (web Web) Stack(env environment.Environment) component.StackWithResources { func (web Web) Stack() component.StackWithResources {
if web.Config.HTTP.HTTPSEnabled() { if web.Config.HTTP.HTTPSEnabled() {
return web.stackHTTPS(env) return web.stackHTTPS()
} else { } else {
return web.stackHTTP(env) return web.stackHTTP()
} }
} }
@ -39,8 +38,8 @@ func (web Web) Stack(env environment.Environment) component.StackWithResources {
//go:embed web.env //go:embed web.env
var httpsResources embed.FS var httpsResources embed.FS
func (web *Web) stackHTTPS(env environment.Environment) component.StackWithResources { func (web *Web) stackHTTPS() component.StackWithResources {
return component.MakeStack(web, env, component.StackWithResources{ return component.MakeStack(web, component.StackWithResources{
Resources: httpsResources, Resources: httpsResources,
ContextPath: "web-https", ContextPath: "web-https",
EnvPath: "web.env", EnvPath: "web.env",
@ -58,8 +57,8 @@ func (web *Web) stackHTTPS(env environment.Environment) component.StackWithResou
//go:embed web.env //go:embed web.env
var httpResources embed.FS var httpResources embed.FS
func (web *Web) stackHTTP(env environment.Environment) component.StackWithResources { func (web *Web) stackHTTP() component.StackWithResources {
return component.MakeStack(web, env, component.StackWithResources{ return component.MakeStack(web, component.StackWithResources{
Resources: httpResources, Resources: httpResources,
ContextPath: "web-http", ContextPath: "web-http",
EnvPath: "web.env", EnvPath: "web.env",

View file

@ -64,6 +64,6 @@ func NewDistillery(params cli.Params, flags cli.Flags, req cli.Requirements) (di
dis.Config = &config.Config{ dis.Config = &config.Config{
ConfigPath: cfg, ConfigPath: cfg,
} }
err = dis.Config.Unmarshal(dis.Still.Environment, f) err = dis.Config.Unmarshal(f)
return return
} }

View file

@ -15,7 +15,6 @@ func (barrel *Barrel) Stack() component.StackWithResources {
return component.StackWithResources{ return component.StackWithResources{
Stack: component.Stack{ Stack: component.Stack{
Dir: barrel.FilesystemBase, Dir: barrel.FilesystemBase,
Env: barrel.Malt.Environment,
}, },
Resources: barrelResources, Resources: barrelResources,

View file

@ -22,7 +22,6 @@ func (reserve *Reserve) Stack() component.StackWithResources {
return component.StackWithResources{ return component.StackWithResources{
Stack: component.Stack{ Stack: component.Stack{
Dir: reserve.FilesystemBase, Dir: reserve.FilesystemBase,
Env: reserve.Malt.Environment,
}, },
Resources: reserveResources, Resources: reserveResources,

View file

@ -1,3 +0,0 @@
package environment
type Environment struct{}

View file

@ -9,7 +9,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx" "github.com/FAU-CDI/wisski-distillery/pkg/fsx"
) )
@ -17,7 +16,7 @@ import (
// If the destination already exists, it is truncated. // If the destination already exists, it is truncated.
// //
// onCopy, when not nil, is called for each file being copied into the archive. // onCopy, when not nil, is called for each file being copied into the archive.
func Package(env environment.Environment, dst, src string, onCopy func(rel string, src string)) (count int64, err error) { func Package(dst, src string, onCopy func(rel string, src string)) (count int64, err error) {
// create the target archive // create the target archive
archive, err := fsx.Create(dst, fsx.DefaultFilePerm) archive, err := fsx.Create(dst, fsx.DefaultFilePerm)
if err != nil { if err != nil {

View file

@ -6,7 +6,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx" "github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -20,7 +19,7 @@ var errExpectedDirectoryButGotFile = errors.New("expected a directory, but got a
// //
// If the destination path does not exist, it is created using [environment.MakeDirs] // If the destination path does not exist, it is created using [environment.MakeDirs]
// The directory is installed recursively. // The directory is installed recursively.
func InstallDir(env environment.Environment, dst string, src string, fsys fs.FS, onInstallFile func(dst, src string)) error { func InstallDir(dst string, src string, fsys fs.FS, onInstallFile func(dst, src string)) error {
// open the source file // open the source file
srcFile, err := fsys.Open(src) srcFile, err := fsys.Open(src)
if err != nil { if err != nil {
@ -45,14 +44,14 @@ func InstallDir(env environment.Environment, dst string, src string, fsys fs.FS,
// do the installation of the directory. // do the installation of the directory.
// the type cast should be safe. // the type cast should be safe.
return installDir(env, dst, srcInfo, srcFile.(fs.ReadDirFile), src, fsys, onInstallFile) return installDir(dst, srcInfo, srcFile.(fs.ReadDirFile), src, fsys, onInstallFile)
} }
// installResource installs the resource at src within fsys to dst. // installResource installs the resource at src within fsys to dst.
// //
// OnInstallFile is called for each source and destination file. // OnInstallFile is called for each source and destination file.
// OnInstallFile may be nil. // OnInstallFile may be nil.
func installResource(env environment.Environment, dst string, src string, fsys fs.FS, onInstallFile func(dst, src string)) error { func installResource(dst string, src string, fsys fs.FS, onInstallFile func(dst, src string)) error {
// open the srcFile // open the srcFile
srcFile, err := fsys.Open(src) srcFile, err := fsys.Open(src)
if err != nil { if err != nil {
@ -73,14 +72,14 @@ func installResource(env environment.Environment, dst string, src string, fsys f
// this is a directory, so the cast is safe! // this is a directory, so the cast is safe!
if srcInfo.IsDir() { if srcInfo.IsDir() {
return installDir(env, dst, srcInfo, srcFile.(fs.ReadDirFile), src, fsys, onInstallFile) return installDir(dst, srcInfo, srcFile.(fs.ReadDirFile), src, fsys, onInstallFile)
} }
// this is a regular file! // this is a regular file!
return installFile(env, dst, srcInfo, srcFile) return installFile(dst, srcInfo, srcFile)
} }
func installDir(env environment.Environment, dst string, srcInfo fs.FileInfo, srcFile fs.ReadDirFile, src string, fsys fs.FS, onInstallFile func(dst, src string)) error { func installDir(dst string, srcInfo fs.FileInfo, srcFile fs.ReadDirFile, src string, fsys fs.FS, onInstallFile func(dst, src string)) error {
// create the destination // create the destination
dstStat, dstErr := os.Stat(dst) dstStat, dstErr := os.Stat(dst)
switch { switch {
@ -107,7 +106,6 @@ func installDir(env environment.Environment, dst string, srcInfo fs.FileInfo, sr
// iterate over all the children // iterate over all the children
for _, entry := range entries { for _, entry := range entries {
if err := installResource( if err := installResource(
env,
filepath.Join(dst, entry.Name()), filepath.Join(dst, entry.Name()),
filepath.Join(src, entry.Name()), filepath.Join(src, entry.Name()),
fsys, fsys,
@ -120,7 +118,7 @@ func installDir(env environment.Environment, dst string, srcInfo fs.FileInfo, sr
return nil return nil
} }
func installFile(env environment.Environment, dst string, srcInfo fs.FileInfo, src fs.File) error { func installFile(dst string, srcInfo fs.FileInfo, src fs.File) error {
// create the file using the right mode! // create the file using the right mode!
file, err := fsx.Create(dst, srcInfo.Mode()) file, err := fsx.Create(dst, srcInfo.Mode())
if err != nil { if err != nil {

View file

@ -8,7 +8,6 @@ import (
"io/fs" "io/fs"
"strings" "strings"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx" "github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"golang.org/x/exp/maps" "golang.org/x/exp/maps"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
@ -202,7 +201,7 @@ parseloop:
// Any existing file is truncated and overwritten. // Any existing file is truncated and overwritten.
// //
// See [WriteTemplate] for possible errors. // See [WriteTemplate] for possible errors.
func InstallTemplate(env environment.Environment, dst string, context map[string]string, src string, fsys fs.FS) error { func InstallTemplate(dst string, context map[string]string, src string, fsys fs.FS) error {
// open the srcFile // open the srcFile
srcFile, err := fsys.Open(src) srcFile, err := fsys.Open(src)

View file

@ -72,7 +72,7 @@ func NewProgram() Program {
// when not running inside docker and we need a distillery // when not running inside docker and we need a distillery
// then we should warn if we are not using the distillery executable. // then we should warn if we are not using the distillery executable.
if dis := context.Environment; !context.Args.Flags.InternalInDocker && context.Description.Requirements.NeedsDistillery && !dis.Config.Paths.UsingDistilleryExecutable(dis.Environment) { if dis := context.Environment; !context.Args.Flags.InternalInDocker && context.Description.Requirements.NeedsDistillery && !dis.Config.Paths.UsingDistilleryExecutable() {
context.EPrintf(warnNoDeployWdcli, bootstrap.Executable, dis.Config.Paths.ExecutablePath()) context.EPrintf(warnNoDeployWdcli, bootstrap.Executable, dis.Config.Paths.ExecutablePath())
} }