1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

contrib(inventory): fix Scaleway inventory used w/env variable token (#35701)

In order to authenticate with the Scaleway API for the contrib dynamic
inventory Scaleway the environment variable SCALEWAY_TOKEN was read
only if a value was set in the configuration .ini file.

This PR fixes that allowing to read only the environment variable
without needing to set a token in the configuration file.

Closes #35693
This commit is contained in:
Paul B 2018-02-05 09:32:49 +01:00 committed by John R Barker
parent 0de810fdf7
commit ccdc93ab59
2 changed files with 10 additions and 2 deletions

View file

@ -14,6 +14,9 @@ regions = par1
# in order to generate inventory output.
#
[auth]
# Token to authenticate with Scaleway's API.
# If not defined will read the SCALEWAY_TOKEN environment variable
#
api_token = mysecrettoken

View file

@ -152,8 +152,13 @@ def generate_inv_from_api(config):
try:
inventory['all'] = copy.deepcopy(EMPTY_GROUP)
auth_token = env_or_param(
'SCALEWAY_TOKEN', config.get('auth', 'api_token'))
if config.has_option('auth', 'api_token'):
auth_token = config.get('auth', 'api_token')
auth_token = env_or_param('SCALEWAY_TOKEN', param=auth_token)
if auth_token is None:
sys.stderr.write('ERROR: missing authentication token for Scaleway API')
sys.exit(1)
if config.has_option('compute', 'regions'):
regions = config.get('compute', 'regions')
if regions == 'all':