summaryrefslogtreecommitdiff
path: root/src/conf_mode
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@sentrium.io>2020-02-03 19:05:55 -0600
committerJohn Estabrook <jestabro@sentrium.io>2020-02-04 06:15:18 -0600
commiteff95db0fbd75bc7fe06272f5816121f1773549f (patch)
treec6b1fb5860fba8a414f34c206a47d603b5f93fb0 /src/conf_mode
parent1b3a7598bd7d6958d0a915299ba1957c4e79485a (diff)
downloadvyos-1x-eff95db0fbd75bc7fe06272f5816121f1773549f.tar.gz
vyos-1x-eff95db0fbd75bc7fe06272f5816121f1773549f.zip
http api T2013: remove default key if user api_keys are set
Diffstat (limited to 'src/conf_mode')
-rwxr-xr-xsrc/conf_mode/http-api.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/conf_mode/http-api.py b/src/conf_mode/http-api.py
index 9c062f0aa..0c2e029e9 100755
--- a/src/conf_mode/http-api.py
+++ b/src/conf_mode/http-api.py
@@ -20,6 +20,7 @@ import sys
import os
import subprocess
import json
+from copy import deepcopy
import vyos.defaults
from vyos.config import Config
@@ -35,7 +36,13 @@ dependencies = [
]
def get_config():
- http_api = vyos.defaults.api_data
+ http_api = deepcopy(vyos.defaults.api_data)
+ x = http_api.get('api_keys')
+ if x is None:
+ default_key = None
+ else:
+ default_key = x[0]
+ keys_added = False
conf = Config()
if not conf.exists('service https api'):
@@ -59,6 +66,11 @@ def get_config():
key = conf.return_value('keys id {0} key'.format(name))
new_key = { 'id': name, 'key': key }
http_api['api_keys'].append(new_key)
+ keys_added = True
+
+ if keys_added and default_key:
+ if default_key in http_api['api_keys']:
+ http_api['api_keys'].remove(default_key)
return http_api