Skip to content

Commit

Permalink
add short cut for allowStateCommand check
Browse files Browse the repository at this point in the history
  • Loading branch information
c4po committed Apr 2, 2024
1 parent c431ee4 commit bf4656a
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions internal/wrapper/checkargs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,28 @@ func checkStateCommand(args []string, version *semver.Version) error {
STATE_COMMAND_VAR := "TF_DEMUX_ALLOW_STATE_COMMANDS"

errorMsg := func(command string, suggestion string) error {
return fmt.Errorf("refusing to execute '%s' command - use a '%s' configuration block instead, or set %s=true.", command, suggestion, STATE_COMMAND_VAR)
return fmt.Errorf("refusing to execute '%s' command - use a '%s' configuration block instead, or set %s=true", command, suggestion, STATE_COMMAND_VAR)
}

if allowStateCommand(STATE_COMMAND_VAR) {
return nil
}

if checkArgsExists(args, "import") >= 0 &&
versionImport.Check(version) {
if allowStateCommand(STATE_COMMAND_VAR) {
return nil
} else {
return errorMsg("import", "import")
}
return errorMsg("import", "import")
}

if checkArgsExists(args, "state") >= 0 &&
checkArgsExists(args, "mv") >= 0 &&
versionMoved.Check(version) {
if allowStateCommand(STATE_COMMAND_VAR) {
return nil
} else {
return errorMsg("state mv", "moved")
}
return errorMsg("state mv", "moved")
}

if checkArgsExists(args, "state") >= 0 &&
checkArgsExists(args, "rm") >= 0 &&
versionRemoved.Check(version) {
if allowStateCommand(STATE_COMMAND_VAR) {
return nil
} else {
return errorMsg("state rm", "removed")
}
return errorMsg("state rm", "removed")
}

return nil
Expand Down

0 comments on commit bf4656a

Please sign in to comment.