fix: avoid overwriting non version env vars
See coop-cloud/organising#630
This commit is contained in:
parent
827edcb0da
commit
518c5795f4
@ -258,7 +258,7 @@ EXAMPLE:
|
|||||||
app.Recipe.Version = chaosVersion
|
app.Recipe.Version = chaosVersion
|
||||||
}
|
}
|
||||||
log.Debugf("choosing %s as version to save to env file", app.Recipe.Version)
|
log.Debugf("choosing %s as version to save to env file", app.Recipe.Version)
|
||||||
if err := app.WriteRecipeVersion(app.Recipe.Version); err != nil {
|
if err := app.WriteRecipeVersion(app.Recipe.Version, false); err != nil {
|
||||||
log.Fatalf("writing new recipe version in env file: %s", err)
|
log.Fatalf("writing new recipe version in env file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ var appNewCommand = cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("choosing %s as version to save to env file", version)
|
log.Debugf("choosing %s as version to save to env file", version)
|
||||||
if err := app.WriteRecipeVersion(version); err != nil {
|
if err := app.WriteRecipeVersion(version, false); err != nil {
|
||||||
log.Fatalf("writing new recipe version in env file: %s", err)
|
log.Fatalf("writing new recipe version in env file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ EXAMPLE:
|
|||||||
|
|
||||||
app.Recipe.Version = chosenDowngrade
|
app.Recipe.Version = chosenDowngrade
|
||||||
log.Debugf("choosing %s as version to save to env file", app.Recipe.Version)
|
log.Debugf("choosing %s as version to save to env file", app.Recipe.Version)
|
||||||
if err := app.WriteRecipeVersion(app.Recipe.Version); err != nil {
|
if err := app.WriteRecipeVersion(app.Recipe.Version, false); err != nil {
|
||||||
log.Fatalf("writing new recipe version in env file: %s", err)
|
log.Fatalf("writing new recipe version in env file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ EXAMPLE:
|
|||||||
|
|
||||||
app.Recipe.Version = chosenUpgrade
|
app.Recipe.Version = chosenUpgrade
|
||||||
log.Debugf("choosing %s as version to save to env file", app.Recipe.Version)
|
log.Debugf("choosing %s as version to save to env file", app.Recipe.Version)
|
||||||
if err := app.WriteRecipeVersion(app.Recipe.Version); err != nil {
|
if err := app.WriteRecipeVersion(app.Recipe.Version, false); err != nil {
|
||||||
log.Fatalf("writing new recipe version in env file: %s", err)
|
log.Fatalf("writing new recipe version in env file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,7 +569,7 @@ func ReadAbraShCmdNames(abraSh string) ([]string, error) {
|
|||||||
return cmdNames, nil
|
return cmdNames, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a App) WriteRecipeVersion(version string) error {
|
func (a App) WriteRecipeVersion(version string, dryRun bool) error {
|
||||||
file, err := os.Open(a.Path)
|
file, err := os.Open(a.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -581,7 +581,7 @@ func (a App) WriteRecipeVersion(version string) error {
|
|||||||
lines := []string{}
|
lines := []string{}
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
if !strings.Contains(line, "RECIPE=") && !strings.Contains(line, "TYPE") {
|
if !strings.HasPrefix(line, "RECIPE=") && !strings.HasPrefix(line, "TYPE=") {
|
||||||
lines = append(lines, line)
|
lines = append(lines, line)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -606,8 +606,12 @@ func (a App) WriteRecipeVersion(version string) error {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.WriteFile(a.Path, []byte(strings.Join(lines, "\n")), os.ModePerm); err != nil {
|
if !dryRun {
|
||||||
log.Fatal(err)
|
if err := os.WriteFile(a.Path, []byte(strings.Join(lines, "\n")), os.ModePerm); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Debugf("skipping writing version %s because dry run", version)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !skipped {
|
if !skipped {
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"coopcloud.tech/abra/pkg/envfile"
|
"coopcloud.tech/abra/pkg/envfile"
|
||||||
"coopcloud.tech/abra/pkg/recipe"
|
"coopcloud.tech/abra/pkg/recipe"
|
||||||
testPkg "coopcloud.tech/abra/pkg/test"
|
testPkg "coopcloud.tech/abra/pkg/test"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetAllFoldersInDirectory(t *testing.T) {
|
func TestGetAllFoldersInDirectory(t *testing.T) {
|
||||||
@ -43,13 +44,7 @@ func TestReadEnv(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(env, testPkg.ExpectedAppEnv) {
|
if !reflect.DeepEqual(env, testPkg.ExpectedAppEnv) {
|
||||||
t.Fatalf(
|
t.Fatal("did not get expected application settings")
|
||||||
"did not get expected application settings. Expected: DOMAIN=%s RECIPE=%s; Got: DOMAIN=%s RECIPE=%s",
|
|
||||||
testPkg.ExpectedAppEnv["DOMAIN"],
|
|
||||||
testPkg.ExpectedAppEnv["RECIPE"],
|
|
||||||
env["DOMAIN"],
|
|
||||||
env["RECIPE"],
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,3 +223,21 @@ func TestEnvVarModifiersIncluded(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNoOverwriteNonVersionEnvVars(t *testing.T) {
|
||||||
|
app, err := appPkg.GetApp(testPkg.ExpectedAppFiles, testPkg.AppName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := app.WriteRecipeVersion("1.3.12", true); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
app, err = appPkg.GetApp(testPkg.ExpectedAppFiles, testPkg.AppName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NotEqual(t, app.Env["SMTP_AUTHTYPE"], "login:1.3.12")
|
||||||
|
}
|
||||||
|
@ -27,8 +27,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var ExpectedAppEnv = envfile.AppEnv{
|
var ExpectedAppEnv = envfile.AppEnv{
|
||||||
"DOMAIN": "ecloud.evil.corp",
|
"DOMAIN": "ecloud.evil.corp",
|
||||||
"RECIPE": "ecloud",
|
"RECIPE": "ecloud",
|
||||||
|
"SMTP_AUTHTYPE": "login",
|
||||||
}
|
}
|
||||||
|
|
||||||
var ExpectedApp = appPkg.App{
|
var ExpectedApp = appPkg.App{
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
RECIPE=ecloud
|
RECIPE=ecloud
|
||||||
DOMAIN=ecloud.evil.corp
|
DOMAIN=ecloud.evil.corp
|
||||||
|
SMTP_AUTHTYPE=login
|
||||||
|
Loading…
x
Reference in New Issue
Block a user