Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PUP-5704) allow array commands in exec resource #8660

Merged
merged 1 commit into from Jun 30, 2021

Conversation

gimmyxd
Copy link
Contributor

@gimmyxd gimmyxd commented Jun 28, 2021

This change updates the exec resource to accept arrays as command.
The new behavior is enabled for the following parameters: :comand, :onlyif, :unless, :refresh.

Changing the command to accept an array:

command: "/bin/echo *"         # executes through shell
command: ["/bin/echo *"]       # non-existing command "bin/echo *"
command: ["/bin/echo *", "*"]  # non-existing command "bin/echo *"
command: ["/bin/echo", "*"]    # executes directly

onlyif/unless: '/bin/echo *'                                  # executes one command through shell
onlyif/unless: ['/bin/echo', '*']            				  # this is handled as two separated commands: '/bin/echo'(1), '*'(2)
onlyif/unless: ['/bin/echo *', '/bin/echo $SHELL']            # executes two commands through shell
onlyif/unless: [["/bin/echo", "*"]]                           # executes one command directly
onlyif/unless: [["/bin/echo", "*"], ["/bin/echo", "$SHELL"]]  # executes two commands directly

@gimmyxd gimmyxd changed the base branch from main to 6.x June 28, 2021 07:55
@gimmyxd gimmyxd marked this pull request as ready for review June 28, 2021 09:40
@gimmyxd gimmyxd requested review from a team June 28, 2021 09:40
Copy link
Contributor

@GabrielNagy GabrielNagy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code looks good to me, had some documentation and test comments

lib/puppet/type/exec.rb Show resolved Hide resolved
lib/puppet/type/exec.rb Show resolved Hide resolved
lib/puppet/type/exec.rb Show resolved Hide resolved
lib/puppet/type/exec.rb Show resolved Hide resolved
lib/puppet/provider/exec/posix.rb Outdated Show resolved Hide resolved
lib/puppet/provider/exec/posix.rb Outdated Show resolved Hide resolved
spec/unit/type/exec_spec.rb Outdated Show resolved Hide resolved
Copy link

@felixdoerre felixdoerre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this PR already looks great. Do we want to have additional test cases that test having arrays in the other parameters (refresh, unless, onlyif) or did I just miss them?

spec/unit/type/exec_spec.rb Outdated Show resolved Hide resolved
This change updates the exec resource to accept
arrays as command. The new behaviour is enabled for
the following parameters: `:comand`, `:onlyif`,
`:unless`, `:refresh`.

```
Changing the command to accept an array:

command: "/bin/echo *"         # executes through shell
command: ["/bin/echo *"]       # non-existing command "bin/echo *"
command: ["/bin/echo *", "*"]  # non-existing command "bin/echo *"
command: ["/bin/echo", "*"]    # executes directly

onlyif/unless: '/bin/echo *'                                  # executes one command through shell
onlyif/unless: ['/bin/echo *', '/bin/echo $SHELL']            # executes two commands through shell
onlyif/unless: [["/bin/echo", "*"]]                           # executes one command directly
onlyif/unless: [["/bin/echo", "*"], ["/bin/echo", "$SHELL"]]  # executes two commands directly
```
@ciprianbadescu ciprianbadescu merged commit b64a83b into puppetlabs:6.x Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants