[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
This commit is contained in:
parent
4b00a4340c
commit
67a7cf78fd
@ -20,6 +20,7 @@ import yaml
|
|||||||
|
|
||||||
from pegleg.engine.exceptions import PeglegBaseException
|
from pegleg.engine.exceptions import PeglegBaseException
|
||||||
from pegleg.engine.util import files
|
from pegleg.engine.util import files
|
||||||
|
from pegleg.engine.util.pegleg_secret_management import PeglegSecretManagement
|
||||||
|
|
||||||
from shipyard_client.api_client.shipyard_api_client import ShipyardClient
|
from shipyard_client.api_client.shipyard_api_client import ShipyardClient
|
||||||
from shipyard_client.api_client.shipyardclient_context import \
|
from shipyard_client.api_client.shipyardclient_context import \
|
||||||
@ -86,7 +87,11 @@ class ShipyardHelper(object):
|
|||||||
else:
|
else:
|
||||||
buffer_mode = 'append'
|
buffer_mode = 'append'
|
||||||
|
|
||||||
data = yaml.safe_dump_all(collected_documents[document])
|
# Decrypt the documents if encrypted
|
||||||
|
pegleg_secret_mgmt = PeglegSecretManagement(
|
||||||
|
docs=collected_documents[document])
|
||||||
|
decrypted_documents = pegleg_secret_mgmt.get_decrypted_secrets()
|
||||||
|
data = yaml.safe_dump_all(decrypted_documents)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.validate_auth_vars()
|
self.validate_auth_vars()
|
||||||
|
@ -25,7 +25,20 @@ from pegleg.engine.util.shipyard_helper import ShipyardClient
|
|||||||
|
|
||||||
# Dummy data to be used as collected documents
|
# Dummy data to be used as collected documents
|
||||||
DATA = {'test-repo':
|
DATA = {'test-repo':
|
||||||
{'test-data': 'RandomData'}}
|
[{'schema': 'pegleg/SiteDefinition/v1',
|
||||||
|
'metadata': {'schema': 'metadata/Document/v1',
|
||||||
|
'layeringDefinition': {'abstract': False,
|
||||||
|
'layer': 'site'},
|
||||||
|
'name': 'site-name',
|
||||||
|
'storagePolicy': 'cleartext'},
|
||||||
|
'data': {'site_type': 'foundry'}}]}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def set_env_vars(monkeypatch):
|
||||||
|
monkeypatch.setenv("PEGLEG_PASSPHRASE", "1234567890123456789012345678")
|
||||||
|
monkeypatch.setenv("PEGLEG_SALT", "1234567890")
|
||||||
|
|
||||||
|
|
||||||
class context():
|
class context():
|
||||||
obj = {}
|
obj = {}
|
||||||
@ -99,7 +112,6 @@ def test_upload_documents(*args):
|
|||||||
|
|
||||||
context = _get_context()
|
context = _get_context()
|
||||||
shipyard_helper = ShipyardHelper(context)
|
shipyard_helper = ShipyardHelper(context)
|
||||||
|
|
||||||
with mock.patch('pegleg.engine.util.shipyard_helper.ShipyardClient',
|
with mock.patch('pegleg.engine.util.shipyard_helper.ShipyardClient',
|
||||||
autospec=True) as mock_shipyard:
|
autospec=True) as mock_shipyard:
|
||||||
mock_api_client = mock_shipyard.return_value
|
mock_api_client = mock_shipyard.return_value
|
||||||
@ -108,7 +120,8 @@ def test_upload_documents(*args):
|
|||||||
|
|
||||||
# Validate Shipyard call to post configdocs was invoked with correct
|
# Validate Shipyard call to post configdocs was invoked with correct
|
||||||
# collection name and buffer mode.
|
# collection name and buffer mode.
|
||||||
mock_api_client.post_configdocs.assert_called_with('test-repo', None, ANY)
|
mock_api_client.post_configdocs.assert_called_with('test-repo',
|
||||||
|
None, ANY)
|
||||||
mock_api_client.post_configdocs.assert_called_once()
|
mock_api_client.post_configdocs.assert_called_once()
|
||||||
|
|
||||||
@mock.patch('pegleg.engine.util.files.collect_files_by_repo', autospec=True,
|
@mock.patch('pegleg.engine.util.files.collect_files_by_repo', autospec=True,
|
||||||
|
Loading…
Reference in New Issue
Block a user