diff options
author | 2020-07-02 11:53:47 +0200 | |
---|---|---|
committer | 2020-07-02 13:16:36 +0000 | |
commit | 67cde9e0a9a7fc6b597881faf659e0699ff92878 (patch) | |
tree | 519f6428b82c30160a899c12c8ef8b527f6b95d4 /test/security/check_for_ingress_and_nodeports.py | |
parent | 616649218a570c746f6b67759a52a7ed8e8d8581 (diff) |
Fix --conf option validation
Native Argparse library facility is used to validate
the --conf option value. In case of invalid value
error msg is printed together with usage info.
Change-Id: I43aee892699c8238176b19a5148d217b3d16102c
Issue-ID: INT-1643
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'test/security/check_for_ingress_and_nodeports.py')
-rwxr-xr-x | test/security/check_for_ingress_and_nodeports.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/test/security/check_for_ingress_and_nodeports.py b/test/security/check_for_ingress_and_nodeports.py index 7429afce9..f2b7be09e 100755 --- a/test/security/check_for_ingress_and_nodeports.py +++ b/test/security/check_for_ingress_and_nodeports.py @@ -284,7 +284,13 @@ def compare_nodeports_and_ingress(): console_compare_visualisation(scan_key,s1,s2) return num_failures - +def kube_config_exists(conf): + try: + assert path.exists(conf) + except AssertionError: + raise argparse.ArgumentTypeError(f'Fatal! K8S config {conf} does not exist') + else: + return conf if __name__ == "__main__": colorama.init() @@ -312,7 +318,8 @@ if __name__ == "__main__": ) parser.add_argument( "--conf", default='~/.kube/config', action='store', - help = 'kubernetes config file' + help = 'kubernetes config file', + type = kube_config_exists ) parser.add_argument("--verbose", default=False, action='store_true', @@ -322,11 +329,6 @@ if __name__ == "__main__": K8S_NAMESPACE = args.namespace K8S_INGRESS_NS = args.ingress_namespace VERBOSE = args.verbose - try: - assert path.exists(args.conf) - except AssertionError: - print('Fatal! K8S config',args.conf, 'does not exist',file=sys.stderr) - sys.exit(-1) config.load_kube_config(config_file=args.conf) v1 = client.CoreV1Api() v1b = client.ExtensionsV1beta1Api() |