-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add secrets engine to workflow engine
- Loading branch information
Showing
10 changed files
with
166 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/engine/src/contrib/tapis/middleware/engines/TapisSKSecretsEngine.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from contrib.tapis.helpers import TapisServiceAPIGateway | ||
|
||
|
||
class TapisSKSecretsEngine: | ||
def __init__(self): | ||
|
||
service_api_gateway = TapisServiceAPIGateway() | ||
self.service_client = service_api_gateway.get_client() | ||
|
||
# self._kwargs = { | ||
# "_tapis_set_x_headers_from_service": True, | ||
# "_x_tapis_tenant": ctx.args["tapis_tenant_id"].value, | ||
# "_x_tapis_user": ctx.args["tapis_pipeline_owner"].value, | ||
# "_tapis_headers": { | ||
# "X-WORKFLOW-EXECUTOR-TOKEN": ctx.args["workflow_executor_access_token"].value | ||
# } | ||
# } | ||
|
||
def __call__(self, tapis_tenant_id, sk_id): | ||
try: | ||
resp = self.service_client.sk.readSecret( | ||
secretType="user", | ||
secretName=sk_id, | ||
user="workflows", | ||
tenant=tapis_tenant_id, | ||
version=0, | ||
_tapis_set_x_headers_from_service=True | ||
) | ||
# ctx.args["tapis_tenant_id"].value | ||
return resp.secretMap.__dict__ | ||
except Exception as e: | ||
return None # TODO catch network error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import unittest | ||
|
||
from owe_python_sdk.utils import select_field | ||
|
||
|
||
class TestSDKUtils(unittest.TestCase): | ||
|
||
def testSelectField(self): | ||
# Providing no field selectors should just return the object | ||
self.assertTrue(select_field({}, []) == {}) | ||
self.assertTrue(select_field(1, []) == 1) | ||
|
||
obj = { | ||
"key": [ | ||
"arr_item", | ||
{ | ||
"shallow_key": "shallow_value", | ||
"deep_key": { | ||
"deeper_key": "deeper_value" | ||
} | ||
} | ||
] | ||
} | ||
self.assertTrue(type(select_field(obj, ["key"])) == list) | ||
self.assertTrue(select_field(obj, ["key", 0]) == "arr_item") | ||
self.assertTrue(select_field(obj, ["key", 1, "shallow_key"]) == "shallow_value") | ||
self.assertTrue(select_field(obj, ["key", 1, "deep_key", "deeper_key"]) == "deeper_value") | ||
|
||
# Must throw type error if object provided is not of type dict or list | ||
self.assertRaises(TypeError, lambda: select_field(1, ["test"])) | ||
|
||
# Must throw index error if attempting to access a non-existent index | ||
# In the case below, there is no 3rd item in the list | ||
self.assertRaises(IndexError, lambda: select_field(obj, ["key", 2])) | ||
|
||
arr = [ | ||
"arr_item", | ||
{"key": "value"} | ||
] | ||
self.assertTrue(select_field(arr, [0]) == "arr_item") | ||
self.assertTrue(select_field(arr, [1, "key"]) == "value") | ||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
cd $(dirname $0) | ||
cd ../ | ||
# TODO return with non-zero exit code if a test fails | ||
python3 -m unittest -v tests.TestServer | ||
# python3 -m unittest -v tests.TestServer | ||
|
||
python3 -m unittest -v tests.TestConditionalExpressionEvaluator | ||
python3 -m unittest -v tests.TestIOCContainerFactory | ||
python3 -m unittest -v tests.TestTaskRepository | ||
python3 -m unittest -v tests.TestTaskRepository | ||
python3 -m unittest -v tests.TestSDKUtils |