Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

ExecProvider errors when parsing null values #91

Merged
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions config/exec_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,21 @@ class ExecProvider(object):
"""

def __init__(self, exec_config):
"""
exec_config must be of type ConfigNode because we depend on
safe_get(self, key) to correctly handle optional exec provider
config parameters.
"""
for key in ['command', 'apiVersion']:
if key not in exec_config:
raise ConfigException(
'exec: malformed request. missing key \'%s\'' % key)
self.api_version = exec_config['apiVersion']
self.args = [exec_config['command']]
if 'args' in exec_config:
if exec_config.safe_get('args'):
self.args.extend(exec_config['args'])
self.env = os.environ.copy()
if 'env' in exec_config:
if exec_config.safe_get('env'):
additional_vars = {}
for item in exec_config['env']:
name = item['name']
Expand Down
15 changes: 10 additions & 5 deletions config/exec_provider_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@

from .config_exception import ConfigException
from .exec_provider import ExecProvider
from .kube_config import ConfigNode


class ExecProviderTest(unittest.TestCase):

def setUp(self):
self.input_ok = {
'command': 'aws-iam-authenticator token -i dummy',
'apiVersion': 'client.authentication.k8s.io/v1beta1'
}
self.input_ok = ConfigNode('test', {
'command': 'aws-iam-authenticator',
'args': ['token', '-i', 'dummy'],
'apiVersion': 'client.authentication.k8s.io/v1beta1',
'env': None
})
self.output_ok = """
{
"apiVersion": "client.authentication.k8s.io/v1beta1",
Expand All @@ -39,7 +42,9 @@ def setUp(self):
"""

def test_missing_input_keys(self):
exec_configs = [{}, {'command': ''}, {'apiVersion': ''}]
exec_configs = [ConfigNode('test1', {}),
ConfigNode('test2', {'command': ''}),
ConfigNode('test3', {'apiVersion': ''})]
for exec_config in exec_configs:
with self.assertRaises(ConfigException) as context:
ExecProvider(exec_config)
Expand Down