Skip to content

Commit

Permalink
KSM CLI - Expand hostname abbreviations in JSON profile export (#224)
Browse files Browse the repository at this point in the history
* Expand hostname abbreviations in JSON profile export

* Update cli unit tests for JSON config hostname field
  • Loading branch information
Kytech authored Feb 24, 2022
1 parent afde1c6 commit b9eae4d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json

from keeper_secrets_manager_core.utils import base64_to_bytes
from keeper_secrets_manager_core.keeper_globals import keeper_servers


class Export:
Expand Down Expand Up @@ -59,7 +60,7 @@ def _format_json(self):
"clientId": {"key": "clientId", "isBase64": True},
"privateKey": {"key": "privateKey", "isBase64": True},
"appKey": {"key": "appKey", "isBase64": True},
"hostname": {"key": "hostname", "isBase64": False},
"hostname": {"key": "hostname", "isBase64": False, "transformMap": keeper_servers},
"serverPublicKeyId": {"key": "serverPublicKeyId", "isBase64": False}
}

Expand All @@ -72,5 +73,8 @@ def _format_json(self):
# Encode a non-url safe base64
config_dict[info["key"]] = base64.b64encode(value_bytes).decode()
else:
config_dict[info["key"]] = self.config[key]
if "transformMap" in info:
config_dict[info["key"]] = info["transformMap"].get(self.config[key], self.config[key])
else:
config_dict[info["key"]] = self.config[key]
return json.dumps(config_dict, indent=4)
6 changes: 3 additions & 3 deletions integration/keeper_secrets_manager_cli/tests/init_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_default(self):
self.assertIsNotNone(config.get("privateKey"), "private key is missing")
self.assertIsNotNone(config.get("appKey"), "app key is missing")
self.assertIsNotNone(config.get("hostname"), "hostname is missing")
self.assertEqual("US", config.get("hostname"), "hostname is not correct")
self.assertEqual("keepersecurity.com", config.get("hostname"), "hostname is not correct")
self.assertEqual(mock_config.get("appKey"), config.get("appKey"),
"app key is not correct")

Expand All @@ -97,7 +97,7 @@ def test_default(self):
self.assertIsNotNone(config.get("privateKey"), "private key is missing")
self.assertIsNotNone(config.get("appKey"), "app key is missing")
self.assertIsNotNone(config.get("hostname"), "hostname is missing")
self.assertEqual("US", config.get("hostname"), "hostname is not correct")
self.assertEqual("keepersecurity.com", config.get("hostname"), "hostname is not correct")
self.assertEqual(mock_config.get("appKey"), config.get("appKey"),
"app key is not correct")

Expand Down Expand Up @@ -169,6 +169,6 @@ def test_k8s(self):
self.assertIsNotNone(config.get("privateKey"), "private key is missing")
self.assertIsNotNone(config.get("appKey"), "app key is missing")
self.assertIsNotNone(config.get("hostname"), "hostname is missing")
self.assertEqual("US", config.get("hostname"), "hostname is not correct")
self.assertEqual("keepersecurity.com", config.get("hostname"), "hostname is not correct")
self.assertEqual(mock_config.get("appKey"), config.get("appKey"),
"app key is not correct")

0 comments on commit b9eae4d

Please sign in to comment.