osbuild: add generator function for shell.init stage
Generates a stage from a basic nested map.
This commit is contained in:
parent
a024b923a3
commit
92bbf5fb8b
1 changed files with 18 additions and 0 deletions
|
|
@ -3,6 +3,8 @@ package osbuild
|
|||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/shell"
|
||||
)
|
||||
|
||||
const filenameRegex = "^[a-zA-Z0-9\\.\\-_]{1,250}$"
|
||||
|
|
@ -55,3 +57,19 @@ func NewShellInitStage(options *ShellInitStageOptions) *Stage {
|
|||
Options: options,
|
||||
}
|
||||
}
|
||||
|
||||
// GenShellInitStage generates an org.osbuild.shell.init stage from a basic map
|
||||
// of the form filename->key->value.
|
||||
func GenShellInitStage(initFiles []shell.InitFile) *Stage {
|
||||
options := new(ShellInitStageOptions)
|
||||
options.Files = make(map[string]ShellInitFile, len(initFiles))
|
||||
for _, file := range initFiles {
|
||||
vars := make([]EnvironmentVariable, len(file.Variables))
|
||||
for idx, envVar := range file.Variables {
|
||||
vars[idx] = EnvironmentVariable{Key: envVar.Key, Value: envVar.Value}
|
||||
}
|
||||
options.Files[file.Filename] = ShellInitFile{Env: vars}
|
||||
}
|
||||
|
||||
return NewShellInitStage(options)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue