Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions openshift/helper/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import logging
import math
import os
import re
import time

Expand All @@ -26,6 +27,7 @@

@add_metaclass(ABCMeta)
class BaseObjectHelper(object):
api_client = None
model = None
properties = None
base_model_name = None
Expand Down Expand Up @@ -84,6 +86,15 @@ def set_model(self, api_version, kind):

def set_client_config(self, **auth):
""" Convenience method for updating the configuration object, and instantiating a new client """
auth_keys = ['api_key', 'ssl_ca_cert', 'cert_file', 'key_file', 'verify_ssl']

for key in auth_keys + ['kubeconfig', 'context', 'host']:
# If a key is not defined in auth, check the environment for a K8S_AUTH_ variable.
if auth.get(key) is None:
env_value = os.getenv('K8S_AUTH_{}'.format(key.upper()), None)
if env_value is not None:
auth[key] = env_value

config_file = auth.get('kubeconfig')
context = auth.get('context')

Expand All @@ -92,8 +103,6 @@ def set_client_config(self, **auth):
if auth.get('host') is not None:
self.api_client.host = auth['host']

auth_keys = ['api_key', 'ssl_ca_cert', 'cert_file', 'key_file', 'verify_ssl']

for key in auth_keys:
if auth.get(key, None) is not None:
if key == 'api_key':
Expand Down