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

Support templating of the API token #98

Merged
merged 1 commit into from
May 25, 2021

Conversation

maxtruxa
Copy link
Contributor

@maxtruxa maxtruxa commented May 24, 2021

SUMMARY

This PR adds support for templates in the API token field. This mechanism allows retrieving the password from arbitrary sources (for example, a password manager).

TODO
  • Add documentation.
  • Add tests.
ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

Inventory plugin

ADDITIONAL INFORMATION

Example script get-do-token.sh that just writes the API token to stdout:

#!/usr/bin/env sh

# You can do whatever you want here.
echo 'your-api-token-here'

Inventory config inventory_digitalocean.yml, referencing the script:

plugin: community.digitalocean.digitalocean
api_token: '{{ lookup("pipe", "./get-do-token.sh") }}'

@maxtruxa maxtruxa marked this pull request as draft May 24, 2021 21:58
@mamercad
Copy link
Collaborator

This is a neat idea, thank's for contributing.

@mamercad
Copy link
Collaborator

I wonder if there's a function we can call to trigger interpolation, like this:

plugin: community.digitalocean.digitalocean
api_token: "{{ lookup('pipe', './get-do-token.sh') }}"

@maxtruxa
Copy link
Contributor Author

Oh that is actually a much better idea. That shouldn't be too hard to implement, since it's being used all over the place in Ansible. I'll look into it later today.

@codecov
Copy link

codecov bot commented May 25, 2021

Codecov Report

Merging #98 (af81a51) into main (09bc240) will increase coverage by 2.45%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #98      +/-   ##
==========================================
+ Coverage   62.33%   64.78%   +2.45%     
==========================================
  Files          30        1      -29     
  Lines        2153       71    -2082     
  Branches      411       11     -400     
==========================================
- Hits         1342       46    -1296     
+ Misses        577       23     -554     
+ Partials      234        2     -232     
Impacted Files Coverage Δ
plugins/inventory/digitalocean.py 64.78% <100.00%> (+21.50%) ⬆️
plugins/modules/digital_ocean_volume_info.py
plugins/modules/digital_ocean_domain_info.py
plugins/modules/digital_ocean_certificate.py
plugins/modules/digital_ocean_tag_info.py
plugins/modules/digital_ocean_floating_ip.py
plugins/modules/digital_ocean_certificate_info.py
plugins/modules/digital_ocean_firewall.py
plugins/modules/digital_ocean_droplet_info.py
plugins/modules/digital_ocean_account_info.py
... and 21 more

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 09bc240...af81a51. Read the comment docs.

@maxtruxa maxtruxa changed the title WIP: Running external commands to get the API token WIP: Support templates in API tokens May 25, 2021
@maxtruxa maxtruxa changed the title WIP: Support templates in API tokens WIP: Support templating of API token May 25, 2021
@maxtruxa maxtruxa changed the title WIP: Support templating of API token WIP: Support templating of the API token May 25, 2021
@maxtruxa
Copy link
Contributor Author

@mamercad Done!

I changed the example to showcase the use of a lookup, because the old example was broken.

@maxtruxa maxtruxa changed the title WIP: Support templating of the API token Support templating of the API token May 25, 2021
@maxtruxa maxtruxa marked this pull request as ready for review May 25, 2021 13:43
Copy link
Collaborator

@mamercad mamercad left a comment

Choose a reason for hiding this comment

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

This is great -- thanks so very much! 🎉

@mamercad mamercad merged commit 3ceb8cd into ansible-collections:main May 25, 2021
@maxtruxa maxtruxa deleted the api-token-cmd branch May 26, 2021 16:38
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

2 participants