summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsirajudeen <sirajudeen.yasin@gmail.com>2019-02-05 23:19:38 -0700
committerSirajudeen <sirajudeen.yasin@gmail.com>2019-02-06 17:56:12 +0000
commit67a7cf78fdb6175823427ec2a85e565d7bdc46dc (patch)
tree4193bf71e4dde8a96274d841459265ebff2f5277
parent4b00a4340c65280177b4efd7d2430e06258e964e (diff)
[Decrypt] - Added Decrypt before doc upload
1. with this PS `pegleg upload` command will check if the doc is encrypted, if found to be encrypted it will decrypt and then upload to shipyard. Change-Id: I86ff46d6fc8a166f628030f8cc03b4f80e58eebf
Notes
Notes (review): Code-Review+1: Arijit Bose <imarijitbose@gmail.com> Code-Review+1: Drew Walters <drewwalters96@gmail.com> Code-Review+1: Nishant Kumar <nishant.e.kumar@ericsson.com> Code-Review+1: chittibabu <cg329x@att.com> Code-Review+1: Alexander Hughes <Alexander.Hughes@pm.me> Code-Review+1: Ahmad Mahmoudi <am495p@att.com> Code-Review+2: Scott Hussey <sthussey@att.com> Code-Review+2: Kaspars Skels <kaspars.skels@gmail.com> Workflow+1: Kaspars Skels <kaspars.skels@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 12 Mar 2019 20:58:30 +0000 Reviewed-on: https://review.openstack.org/635097 Project: openstack/airship-pegleg Branch: refs/heads/master
-rw-r--r--pegleg/engine/util/shipyard_helper.py7
-rw-r--r--tests/unit/engine/util/test_shipyard_helper.py23
2 files changed, 24 insertions, 6 deletions
diff --git a/pegleg/engine/util/shipyard_helper.py b/pegleg/engine/util/shipyard_helper.py
index 07de7ea..39f98b6 100644
--- a/pegleg/engine/util/shipyard_helper.py
+++ b/pegleg/engine/util/shipyard_helper.py
@@ -20,6 +20,7 @@ import yaml
20 20
21from pegleg.engine.exceptions import PeglegBaseException 21from pegleg.engine.exceptions import PeglegBaseException
22from pegleg.engine.util import files 22from pegleg.engine.util import files
23from pegleg.engine.util.pegleg_secret_management import PeglegSecretManagement
23 24
24from shipyard_client.api_client.shipyard_api_client import ShipyardClient 25from shipyard_client.api_client.shipyard_api_client import ShipyardClient
25from shipyard_client.api_client.shipyardclient_context import \ 26from shipyard_client.api_client.shipyardclient_context import \
@@ -86,7 +87,11 @@ class ShipyardHelper(object):
86 else: 87 else:
87 buffer_mode = 'append' 88 buffer_mode = 'append'
88 89
89 data = yaml.safe_dump_all(collected_documents[document]) 90 # Decrypt the documents if encrypted
91 pegleg_secret_mgmt = PeglegSecretManagement(
92 docs=collected_documents[document])
93 decrypted_documents = pegleg_secret_mgmt.get_decrypted_secrets()
94 data = yaml.safe_dump_all(decrypted_documents)
90 95
91 try: 96 try:
92 self.validate_auth_vars() 97 self.validate_auth_vars()
diff --git a/tests/unit/engine/util/test_shipyard_helper.py b/tests/unit/engine/util/test_shipyard_helper.py
index ac5c316..aa1929e 100644
--- a/tests/unit/engine/util/test_shipyard_helper.py
+++ b/tests/unit/engine/util/test_shipyard_helper.py
@@ -25,7 +25,20 @@ from pegleg.engine.util.shipyard_helper import ShipyardClient
25 25
26# Dummy data to be used as collected documents 26# Dummy data to be used as collected documents
27DATA = {'test-repo': 27DATA = {'test-repo':
28 {'test-data': 'RandomData'}} 28 [{'schema': 'pegleg/SiteDefinition/v1',
29 'metadata': {'schema': 'metadata/Document/v1',
30 'layeringDefinition': {'abstract': False,
31 'layer': 'site'},
32 'name': 'site-name',
33 'storagePolicy': 'cleartext'},
34 'data': {'site_type': 'foundry'}}]}
35
36
37@pytest.fixture(autouse=True)
38def set_env_vars(monkeypatch):
39 monkeypatch.setenv("PEGLEG_PASSPHRASE", "1234567890123456789012345678")
40 monkeypatch.setenv("PEGLEG_SALT", "1234567890")
41
29 42
30class context(): 43class context():
31 obj = {} 44 obj = {}
@@ -37,7 +50,7 @@ class FakeResponse():
37def _get_context(): 50def _get_context():
38 ctx = context() 51 ctx = context()
39 ctx.obj = {} 52 ctx.obj = {}
40 auth_vars = { 53 auth_vars = {
41 'project_domain_name': 'projDomainTest', 54 'project_domain_name': 'projDomainTest',
42 'user_domain_name': 'userDomainTest', 55 'user_domain_name': 'userDomainTest',
43 'project_name': 'projectTest', 56 'project_name': 'projectTest',
@@ -55,7 +68,7 @@ def _get_context():
55def _get_bad_context(): 68def _get_bad_context():
56 ctx = context() 69 ctx = context()
57 ctx.obj = {} 70 ctx.obj = {}
58 auth_vars = { 71 auth_vars = {
59 'project_domain_name': 'projDomainTest', 72 'project_domain_name': 'projDomainTest',
60 'user_domain_name': 'userDomainTest', 73 'user_domain_name': 'userDomainTest',
61 'project_name': 'projectTest', 74 'project_name': 'projectTest',
@@ -99,7 +112,6 @@ def test_upload_documents(*args):
99 112
100 context = _get_context() 113 context = _get_context()
101 shipyard_helper = ShipyardHelper(context) 114 shipyard_helper = ShipyardHelper(context)
102
103 with mock.patch('pegleg.engine.util.shipyard_helper.ShipyardClient', 115 with mock.patch('pegleg.engine.util.shipyard_helper.ShipyardClient',
104 autospec=True) as mock_shipyard: 116 autospec=True) as mock_shipyard:
105 mock_api_client = mock_shipyard.return_value 117 mock_api_client = mock_shipyard.return_value
@@ -108,7 +120,8 @@ def test_upload_documents(*args):
108 120
109 # Validate Shipyard call to post configdocs was invoked with correct 121 # Validate Shipyard call to post configdocs was invoked with correct
110 # collection name and buffer mode. 122 # collection name and buffer mode.
111 mock_api_client.post_configdocs.assert_called_with('test-repo', None, ANY) 123 mock_api_client.post_configdocs.assert_called_with('test-repo',
124 None, ANY)
112 mock_api_client.post_configdocs.assert_called_once() 125 mock_api_client.post_configdocs.assert_called_once()
113 126
114@mock.patch('pegleg.engine.util.files.collect_files_by_repo', autospec=True, 127@mock.patch('pegleg.engine.util.files.collect_files_by_repo', autospec=True,