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

Allow to pass more sops arguments #47

Merged
merged 14 commits into from
Jan 14, 2021

Conversation

felixfontein
Copy link
Collaborator

Motivation

Fixes #46.

Changes description

Adds a set of options to every module and plugin which allows to pass more options that are passed to the sops executable (including an override of the sops binary path).

Additional notes

The plugin_utils/action_module.py is from https://github.com/ansible-collections/community.crypto/blob/main/plugins/plugin_utils/action_module.py and https://github.com/ansible-collections/community.crypto/blob/main/plugins/module_utils/crypto/module_backends/common.py. I hope that sooner or later this (resp. something similar) is either provided by ansible-base/ansible-core itself, or some common utility collection. For now, I think it's better to vendor the code here instead of making this collection depend on community.crypto just for this piece of utility code.

@codecov
Copy link

codecov bot commented Jan 9, 2021

Codecov Report

Merging #47 (7dccdea) into main (7933510) will decrease coverage by 24.22%.
The diff coverage is 51.98%.

Impacted file tree graph

@@             Coverage Diff             @@
##             main      #47       +/-   ##
===========================================
- Coverage   86.45%   62.23%   -24.23%     
===========================================
  Files           6        8        +2     
  Lines         347      895      +548     
  Branches       62      196      +134     
===========================================
+ Hits          300      557      +257     
- Misses         32      260      +228     
- Partials       15       78       +63     
Impacted Files Coverage Δ
plugins/plugin_utils/action_module.py 44.09% <44.09%> (ø)
plugins/module_utils/sops.py 86.27% <88.88%> (+0.56%) ⬆️
plugins/action/load_vars.py 96.29% <100.00%> (-1.21%) ⬇️
plugins/doc_fragments/sops.py 100.00% <100.00%> (ø)
plugins/lookup/sops.py 100.00% <100.00%> (ø)
plugins/modules/sops_encrypt.py 81.72% <100.00%> (+0.60%) ⬆️
plugins/vars/sops.py 88.13% <100.00%> (+0.41%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7933510...7dccdea. Read the comment docs.

@felixfontein
Copy link
Collaborator Author

ready_for_review


- name: Test fake sops binary
set_fact:
fake_sops_output: "{{ lookup('community.sops.sops', 'simple.sops.yaml', sops_binary=role_path ~ '/files/fake-sops.sh', enable_local_keyservice=True, aws_access_key_id='xxx') }}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

is ~ used as string concatenation here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that's Jinja2 standard syntax for string concatenation (https://jinja.palletsprojects.com/en/2.11.x/templates/#other-operators).

}


ENCRYPT_OPTIONS = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was wondering why dividing the options in 2 different sets. Even if they do apply only to encryption phase, would not be simpler to have them available as in the standard sops cli?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This reduces the number of options the plugins/modules that do not encrypt have (and thus makes their docs less confusing).

(output, err) = process.communicate()
exit_code = process.returncode

if module:
Copy link
Collaborator

Choose a reason for hiding this comment

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

May you clarify the usage of module here? I think I got the idea. Is something made available by ActionModuleBase?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, it's for classical AnsibleModules. The Ansible coding guidelines say that modules must never use subprocess directly, but use AnsibleModule.run_command. This implements that requirement.

@endorama
Copy link
Collaborator

I like this addition. It makes everything more complex but I see value in being able to specify options from Ansible code.

@felixfontein as a general question, I think the amount of code may deserve some dedicated unit testing, is something advisable or the current test set is considered enough? (as you manage more collections I expect you have a broader overview than me)

@felixfontein
Copy link
Collaborator Author

@endorama (more) unit tests would definitely be nice. I've tried to cover most code paths with the existing integration tests, but I didn't manage to cover everything. I think the current test coverage is already pretty good. (Of course it can always be increased :) )

@felixfontein
Copy link
Collaborator Author

(Rebased against main.)

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.

SOPS collection doesn't see environment variables set with Ansible environment keyword at the task level.
2 participants