mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Compatibility of gce.py (Google Cloud Ansible inventory) with Python 3 (#26032)
* Compatibility of gce.py (inventory) with Python 3 * Revert './secrets.py' file check (will import 'secrets' from PYTHONPATH) Instead of checking if secrets.py exists in the current directory, this commit will make gce import 'secrets' from one of PYTHONPATH's paths. There are 2 possibilities: 1. secrets.py will be used if secrets.GCE_PARAMS and secrets.GCE_KEYWORD_PARAMS are declared. 2. secrets.py will be ignored if secrets.GCE_PARAMS and secrets.GCE_KEYWORD_PARAMS aren't declared. This could happen in Python >=3.6 where a module named 'secrets' could be imported if a custom secrets.py doesn't exist in PYTHONPATH. Check out https://www.python.org/dev/peps/pep-0506/ and https://docs.python.org/3/library/secrets.html for more information.
This commit is contained in:
parent
9ab9945cf3
commit
e45d5b7e8e
1 changed files with 8 additions and 4 deletions
|
@ -92,7 +92,10 @@ import argparse
|
|||
|
||||
from time import time
|
||||
|
||||
import ConfigParser
|
||||
if sys.version_info >= (3, 0):
|
||||
import configparser
|
||||
else:
|
||||
import ConfigParser as configparser
|
||||
|
||||
import logging
|
||||
logging.getLogger('libcloud.common.google').addHandler(logging.NullHandler())
|
||||
|
@ -213,7 +216,7 @@ class GceInventory(object):
|
|||
# This provides empty defaults to each key, so that environment
|
||||
# variable configuration (as opposed to INI configuration) is able
|
||||
# to work.
|
||||
config = ConfigParser.SafeConfigParser(defaults={
|
||||
config = configparser.SafeConfigParser(defaults={
|
||||
'gce_service_account_email_address': '',
|
||||
'gce_service_account_pem_file_path': '',
|
||||
'gce_project_id': '',
|
||||
|
@ -271,10 +274,11 @@ class GceInventory(object):
|
|||
# exists.
|
||||
secrets_path = self.config.get('gce', 'libcloud_secrets')
|
||||
secrets_found = False
|
||||
|
||||
try:
|
||||
import secrets
|
||||
args = list(getattr(secrets, 'GCE_PARAMS', []))
|
||||
kwargs = getattr(secrets, 'GCE_KEYWORD_PARAMS', {})
|
||||
args = list(secrets.GCE_PARAMS)
|
||||
kwargs = secrets.GCE_KEYWORD_PARAMS
|
||||
secrets_found = True
|
||||
except:
|
||||
pass
|
||||
|
|
Loading…
Reference in a new issue