Browse Source

Merge "[Decrypt] - Added Decrypt before doc upload"

changes/78/643678/1
Zuul 3 months ago
parent
commit
cb78976fbb

+ 6
- 1
pegleg/engine/util/shipyard_helper.py View File

@@ -20,6 +20,7 @@ import yaml
20 20
 
21 21
 from pegleg.engine.exceptions import PeglegBaseException
22 22
 from pegleg.engine.util import files
23
+from pegleg.engine.util.pegleg_secret_management import PeglegSecretManagement
23 24
 
24 25
 from shipyard_client.api_client.shipyard_api_client import ShipyardClient
25 26
 from shipyard_client.api_client.shipyardclient_context import \
@@ -86,7 +87,11 @@ class ShipyardHelper(object):
86 87
             else:
87 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 96
             try:
92 97
                 self.validate_auth_vars()

+ 18
- 5
tests/unit/engine/util/test_shipyard_helper.py View File

@@ -25,7 +25,20 @@ from pegleg.engine.util.shipyard_helper import ShipyardClient
25 25
 
26 26
 # Dummy data to be used as collected documents
27 27
 DATA = {'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)
38
+def set_env_vars(monkeypatch):
39
+    monkeypatch.setenv("PEGLEG_PASSPHRASE", "1234567890123456789012345678")
40
+    monkeypatch.setenv("PEGLEG_SALT", "1234567890")
41
+
29 42
 
30 43
 class context():
31 44
     obj = {}
@@ -37,7 +50,7 @@ class FakeResponse():
37 50
 def _get_context():
38 51
     ctx = context()
39 52
     ctx.obj = {}
40
-    auth_vars =  {
53
+    auth_vars = {
41 54
         'project_domain_name': 'projDomainTest',
42 55
         'user_domain_name': 'userDomainTest',
43 56
         'project_name': 'projectTest',
@@ -55,7 +68,7 @@ def _get_context():
55 68
 def _get_bad_context():
56 69
     ctx = context()
57 70
     ctx.obj = {}
58
-    auth_vars =  {
71
+    auth_vars = {
59 72
         'project_domain_name': 'projDomainTest',
60 73
         'user_domain_name': 'userDomainTest',
61 74
         'project_name': 'projectTest',
@@ -99,7 +112,6 @@ def test_upload_documents(*args):
99 112
 
100 113
     context = _get_context()
101 114
     shipyard_helper = ShipyardHelper(context)
102
-
103 115
     with mock.patch('pegleg.engine.util.shipyard_helper.ShipyardClient',
104 116
                     autospec=True) as mock_shipyard:
105 117
         mock_api_client = mock_shipyard.return_value
@@ -108,7 +120,8 @@ def test_upload_documents(*args):
108 120
 
109 121
         # Validate Shipyard call to post configdocs was invoked with correct
110 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 125
         mock_api_client.post_configdocs.assert_called_once()
113 126
 
114 127
 @mock.patch('pegleg.engine.util.files.collect_files_by_repo', autospec=True,

Loading…
Cancel
Save