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

Add support for Prepending args in the File Provisioner #508

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jmsnll
Copy link

@jmsnll jmsnll commented Jan 15, 2025

Overview

Enhanced the sdk.ProvisionOutput to support flexible argument placement with new methods: AddArgsAtIndex,PrependArgs, and AppendArgs.

Subsequently then used these functions in the sdk.Provision module to replace AddArgs with PrependArgs and AppendArgs in the file provisioner for better control of argument placement.

Subsequently updated the following modules where AddArgs was used to use AppendArgs to maintain existing functionality.

Type of change

  • Created a new plugin
  • Improved an existing plugin
  • Fixed a bug in an existing plugin
  • Improved contributor utilities or experience

Related Issue(s)

How To Test

Pass either of the new provision.FileOption implementations (PrependArgs or AppendArgs) to a provision.FileProvisioner instance. Both the akamai and mysql plugins currently utilise this provisioner and can be updated with minimal changes to verify the behaviour.

For example, test the mysql plugin’s DatabaseCredentials provisioner as follows:

func TestDatabaseCredentialsProvisioner(t *testing.T) {
	plugintest.TestProvisioner(t, DatabaseCredentials().DefaultProvisioner, map[string]plugintest.ProvisionCase{
		"temp file": {
			ItemFields: map[sdk.FieldName]string{
				fieldname.User:     "root",
				fieldname.Password: "123456",
				fieldname.Database: "test",
				fieldname.Host:     "localhost",
				fieldname.Port:     "3306",
			},
                         # update flags here
			CommandLine: []string{"mysql", "--additonal-flag-for-demonstration"},
			ExpectedOutput: sdk.ProvisionOutput{
                                 # update flags here
				CommandLine: []string{"mysql", "--defaults-file=/tmp/my.cnf", "--additonal-flag-for-demonstration"}, 
				Files: map[string]sdk.OutputFile{
					"/tmp/my.cnf": {
						Contents: []byte(plugintest.LoadFixture(t, "mysql.cnf")),
					},
				},
			},
		},
	})
}

To test different behaviors, modify the FileOption used in the plugin’s default provisioner:

# Appending 
DefaultProvisioner: provision.TempFile(mysqlConfig, provision.Filename("my.cnf"), provision.AppendArgs("--defaults-file={{ .Path }}")),
# Prepending
DefaultProvisioner: provision.TempFile(mysqlConfig, provision.Filename("my.cnf"), provision.PrependArgs("--defaults-file={{ .Path }}")),

Changelog

Introduce PrependArgs and AppendArgs for precise command-line argument placement in file provisioners.

Copy link
Contributor

⚠️ This PR contains unsigned commits. To get your PR merged, please sign those commits (git rebase --exec 'git commit -S --amend --no-edit -n' @{upstream}) and force push them to this branch (git push --force-with-lease).

If you're new to commit signing, there are different ways to set it up:

Sign commits with gpg

Follow the steps below to set up commit signing with gpg:

  1. Generate a GPG key
  2. Add the GPG key to your GitHub account
  3. Configure git to use your GPG key for commit signing
Sign commits with ssh-agent

Follow the steps below to set up commit signing with ssh-agent:

  1. Generate an SSH key and add it to ssh-agent
  2. Add the SSH key to your GitHub account
  3. Configure git to use your SSH key for commit signing
Sign commits with 1Password

You can also sign commits using 1Password, which lets you sign commits with biometrics without the signing key leaving the local 1Password process.

Learn how to use 1Password to sign your commits.

Watch the demo

- some commands (like `age`) have positional argument which require to be placed after all flag arguments
- change allows prepending of args to after the command itself instead of just appending to the end and potentially causing issues

Signed-off-by: James Neill <[email protected]>
- accidenally changed at some point during development
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.

Support for commands with positional arguments in the File Provisioner
1 participant