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

vultr.py: Do not try to parse ini if $VULTR_API_KEY #42659

Merged
merged 1 commit into from
Jul 16, 2018

Conversation

Spredzy
Copy link
Contributor

@Spredzy Spredzy commented Jul 12, 2018

SUMMARY

In its current behavior, read_ini_config() tries to read ini file,
even thought $VULTR_API_KEY environment file has been specified.

This is due to the fact that if not all the keys (key, timeout,
retries and endpoint) are specified in the environment, then the method
goes and look for the vultr.ini file.

Since timeout, retries and endpoint have default value, it is a
perfectly valid use case to only specify key.

Before patch:

VULTR_API_KEY=XXXX ansible -m vr_ssh_key ... fails with Config file is
missing

After patch:

VULTR_API_KEY=XXXX ansible -m vr_ssh_key ... goes all the way

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME
  • module_utils/vultr.py
ANSIBLE VERSION
  • devel
ADDITIONAL INFORMATION
  • N/A

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jul 12, 2018
continue
env_conf[key] = os.environ['VULTR_API_%s' % key.upper()]

if env_conf.get('key'):
return env_conf
Copy link
Contributor

Choose a reason for hiding this comment

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

we should not return here anymore

@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label Jul 12, 2018
@Spredzy
Copy link
Contributor Author

Spredzy commented Jul 13, 2018

@resmo does the last approach looks better?

except KeyError:
config = {}

if not config.get('key'):
Copy link
Contributor

@resmo resmo Jul 16, 2018

Choose a reason for hiding this comment

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

this check is too early, it should be after the self.api_config setting and therefore check should be updated to

if not self.api_config.get('api_key'):
    self.module.fail_json(msg="The API key is not specified. Please refer to the documentation.")

In its current behavior, `read_ini_config()` tries to read ini file,
even thought $VULTR_API_KEY environment file has been specified.

This is due to the fact that if not *all* the keys (key, timeout,
retries and endpoint) are specified in the environment, then the method
goes and look for the vultr.ini file.

Since timeout, retries and endpoint have default value, it is a
perfectly valid use case to only specify key.

Before patch:

VULTR_API_KEY=XXXX ansible -m vr_ssh_key .... fails with Config file is
missing

After patch:

VULTR_API_KEY=XXXX ansible -m vr_ssh_key goes all the way
@ansibot ansibot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Jul 16, 2018
@resmo
Copy link
Contributor

resmo commented Jul 16, 2018

shipit

@ansibot ansibot added the shipit This PR is ready to be merged by Core label Jul 16, 2018
@resmo resmo merged commit 08acc74 into ansible:devel Jul 16, 2018
Spredzy added a commit to Spredzy/ansible that referenced this pull request Jul 17, 2018
mattclay pushed a commit that referenced this pull request Jul 17, 2018
@dagwieers dagwieers added the vultr Vultr community label Feb 11, 2019
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. shipit This PR is ready to be merged by Core support:core This issue/PR relates to code supported by the Ansible Engineering Team. vultr Vultr community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants