Add 'environment' package
This commit adds a new environment package that manages all calls to the underlying operating system.
This commit is contained in:
parent
822c70cd69
commit
f19619ef9f
60 changed files with 539 additions and 308 deletions
|
|
@ -21,7 +21,7 @@ func (instances *Instances) Create(slug string) (wisski WissKI, err error) {
|
|||
wisski.instances = instances
|
||||
|
||||
// make sure that the slug is valid!
|
||||
slug, err = stringparser.ParseSlug(slug)
|
||||
slug, err = stringparser.ParseSlug(instances.Environment, slug)
|
||||
if err != nil {
|
||||
return wisski, errInvalidSlug
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ func (wisski WissKI) Provision(io stream.IOStream) error {
|
|||
|
||||
// create the basic st!
|
||||
st := wisski.Barrel()
|
||||
if err := st.Install(io, component.InstallationContext{}); err != nil {
|
||||
if err := st.Install(wisski.instances.Core.Environment, io, component.InstallationContext{}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@ package instances
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
_ "embed"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
"golang.org/x/exp/maps"
|
||||
"golang.org/x/exp/slices"
|
||||
|
|
@ -51,7 +50,7 @@ func (wisski *WissKI) ExportPathbuilders(dest string) error {
|
|||
for _, name := range names {
|
||||
pbxml := []byte(pathbuilders[name])
|
||||
name := filepath.Join(dest, fmt.Sprintf("%s.xml", name))
|
||||
if err := os.WriteFile(name, pbxml, fs.ModePerm); err != nil {
|
||||
if err := environment.WriteFile(wisski.instances.Core.Environment, name, pbxml, environment.DefaultFilePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package instances
|
|||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
|
|
@ -14,7 +13,7 @@ import (
|
|||
// NoPrefix checks if this WissKI instance is excluded from generating prefixes.
|
||||
// TODO: Move this to the database!
|
||||
func (wisski *WissKI) NoPrefix() bool {
|
||||
return fsx.IsFile(filepath.Join(wisski.FilesystemBase, "prefixes.skip"))
|
||||
return fsx.IsFile(wisski.instances.Environment, filepath.Join(wisski.FilesystemBase, "prefixes.skip"))
|
||||
}
|
||||
|
||||
var errPrefixExecFailed = errors.New("PrefixConfig: Failed to call list_uri_prefixes")
|
||||
|
|
@ -41,8 +40,8 @@ func (wisski *WissKI) PrefixConfig() (config string, err error) {
|
|||
|
||||
// custom prefixes
|
||||
prefixPath := filepath.Join(wisski.FilesystemBase, "prefixes")
|
||||
if fsx.IsFile(prefixPath) {
|
||||
prefix, err := os.Open(prefixPath)
|
||||
if fsx.IsFile(wisski.instances.Environment, prefixPath) {
|
||||
prefix, err := wisski.instances.Core.Environment.Open(prefixPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package instances
|
|||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/component"
|
||||
|
|
@ -16,6 +15,7 @@ func (wisski WissKI) Barrel() component.StackWithResources {
|
|||
return component.StackWithResources{
|
||||
Stack: component.Stack{
|
||||
Dir: wisski.FilesystemBase,
|
||||
Env: wisski.instances.Environment,
|
||||
},
|
||||
|
||||
Resources: barrelResources,
|
||||
|
|
@ -35,8 +35,7 @@ func (wisski WissKI) Barrel() component.StackWithResources {
|
|||
"GLOBAL_AUTHORIZED_KEYS_FILE": wisski.instances.Config.GlobalAuthorizedKeysFile,
|
||||
},
|
||||
|
||||
MakeDirsPerm: fs.ModeDir | fs.ModePerm,
|
||||
MakeDirs: []string{"data", ".composer"},
|
||||
MakeDirs: []string{"data", ".composer"},
|
||||
|
||||
TouchFiles: []string{
|
||||
filepath.Join("data", "authorized_keys"),
|
||||
|
|
@ -52,6 +51,7 @@ func (wisski WissKI) Reserve() component.StackWithResources {
|
|||
return component.StackWithResources{
|
||||
Stack: component.Stack{
|
||||
Dir: wisski.FilesystemBase,
|
||||
Env: wisski.instances.Environment,
|
||||
},
|
||||
|
||||
Resources: reserveResources,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue