Revert default EE authfile support for inventory_import

This commit is contained in:
Alan Rominger
2021-10-29 09:27:42 -04:00
committed by Shane McDonald
parent d42fe921db
commit 0d1f8a06ce

View File

@@ -2,15 +2,12 @@
# All Rights Reserved. # All Rights Reserved.
# Python # Python
from base64 import b64encode
import json import json
import logging import logging
import os import os
import re import re
import stat
import subprocess import subprocess
import sys import sys
import tempfile
import time import time
import traceback import traceback
from collections import OrderedDict from collections import OrderedDict
@@ -81,21 +78,6 @@ class AnsibleInventoryLoader(object):
bargs.extend(['-e', '{0}={1}'.format(key, value)]) bargs.extend(['-e', '{0}={1}'.format(key, value)])
ee = get_default_execution_environment() ee = get_default_execution_environment()
if ee.credential:
if not ee.credential.has_inputs(field_names=('host', 'username', 'password')):
raise RuntimeError(f"Registry credential for execution environment `{ee}` is missing either the host, username, or password.")
host = ee.credential.get_input('host')
username = ee.credential.get_input('username')
password = ee.credential.get_input('password')
token = f"{username}:{password}"
auth_data = {'auths': {host: {'auth': b64encode(token.encode('utf-8')).decode('utf-8')}}}
self.authfile.write(json.dumps(auth_data, indent=4).encode('utf-8'))
bargs.append(f'--authfile={self.authfile.name}')
if ee.pull:
bargs.append(f'--pull={ee.pull}')
bargs.extend([ee.image]) bargs.extend([ee.image])
bargs.extend(['ansible-inventory', '-i', self.source]) bargs.extend(['ansible-inventory', '-i', self.source])
@@ -131,12 +113,9 @@ class AnsibleInventoryLoader(object):
return data return data
def load(self): def load(self):
with tempfile.NamedTemporaryFile() as f: base_args = self.get_base_args()
self.authfile = f logger.info('Reading Ansible inventory source: %s', self.source)
os.chmod(self.authfile.name, stat.S_IRUSR | stat.S_IWUSR) return self.command_to_json(base_args)
base_args = self.get_base_args()
logger.info('Reading Ansible inventory source: %s', self.source)
return self.command_to_json(base_args)
class Command(BaseCommand): class Command(BaseCommand):