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

Commit 3682e9b

Browse files
committed
*Update ExecProvider to use safe_get()
*Update unit tests to use ConfigNode() instead of dict()
1 parent 7d1e449 commit 3682e9b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

config/exec_provider.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,21 @@ class ExecProvider(object):
3232
"""
3333

3434
def __init__(self, exec_config):
35+
"""
36+
exec_config must be of type ConfigNode because we depend on
37+
safe_get(self, key) to correctly handle optional exec provider
38+
config parameters.
39+
"""
3540
for key in ['command', 'apiVersion']:
3641
if key not in exec_config:
3742
raise ConfigException(
3843
'exec: malformed request. missing key \'%s\'' % key)
3944
self.api_version = exec_config['apiVersion']
4045
self.args = [exec_config['command']]
41-
if 'args' in exec_config:
46+
if exec_config.safe_get('args'):
4247
self.args.extend(exec_config['args'])
4348
self.env = os.environ.copy()
44-
if 'env' in exec_config:
49+
if exec_config.safe_get('env'):
4550
additional_vars = {}
4651
for item in exec_config['env']:
4752
name = item['name']

config/exec_provider_test.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919

2020
from .config_exception import ConfigException
2121
from .exec_provider import ExecProvider
22+
from .kube_config import ConfigNode
2223

2324

2425
class ExecProviderTest(unittest.TestCase):
2526

2627
def setUp(self):
27-
self.input_ok = {
28-
'command': 'aws-iam-authenticator token -i dummy',
29-
'apiVersion': 'client.authentication.k8s.io/v1beta1'
30-
}
28+
self.input_ok = ConfigNode('test', {
29+
'command': 'aws-iam-authenticator',
30+
'args': ['token', '-i', 'dummy'],
31+
'apiVersion': 'client.authentication.k8s.io/v1beta1',
32+
'env': None
33+
})
3134
self.output_ok = """
3235
{
3336
"apiVersion": "client.authentication.k8s.io/v1beta1",
@@ -39,7 +42,9 @@ def setUp(self):
3942
"""
4043

4144
def test_missing_input_keys(self):
42-
exec_configs = [{}, {'command': ''}, {'apiVersion': ''}]
45+
exec_configs = [ConfigNode('test1', {}),
46+
ConfigNode('test2', {'command': ''}),
47+
ConfigNode('test3', {'apiVersion': ''})]
4348
for exec_config in exec_configs:
4449
with self.assertRaises(ConfigException) as context:
4550
ExecProvider(exec_config)

0 commit comments

Comments
 (0)