You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by is...@apache.org on 2020/12/17 17:03:57 UTC

[airavata-custos] branch develop updated: Add python samples for KV secret management

This is an automated email from the ASF dual-hosted git repository.

isjarana pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git


The following commit(s) were added to refs/heads/develop by this push:
     new c1a5b20  Add python samples for KV secret management
     new 0e2d9ca  Merge pull request #129 from isururanawaka/pythonSDK
c1a5b20 is described below

commit c1a5b20568427c3fe873f8fcd33fd7af1bd11497
Author: Isuru Ranawaka <ir...@gmail.com>
AuthorDate: Thu Dec 17 12:03:05 2020 -0500

    Add python samples for KV secret management
---
 .../clients/resource_secret_management_client.py   |  4 +-
 .../custos/samples/resource_secert_management.py   | 80 ++++++++++++++++++++++
 2 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/custos-client-sdks/custos-python-sdk/custos/clients/resource_secret_management_client.py b/custos-client-sdks/custos-python-sdk/custos/clients/resource_secret_management_client.py
index fafb447..1b41dbc 100644
--- a/custos-client-sdks/custos-python-sdk/custos/clients/resource_secret_management_client.py
+++ b/custos-client-sdks/custos-python-sdk/custos/clients/resource_secret_management_client.py
@@ -166,12 +166,12 @@ class ResourceSecretManagementClient(object):
             logger.exception("Error occurred while updating KV credential")
             raise
 
-    def delete_KV_credential(self, token, user_token, client_id, key, value):
+    def delete_KV_credential(self, token, user_token, client_id, key):
         try:
             token = "Bearer " + token
             metadata = (('authorization', token),('user_token', user_token),)
             secret_metadata = SecretMetadata(client_id=client_id)
-            request = KVCredential(key=key, value=value, metadata=secret_metadata)
+            request = KVCredential(key=key, metadata=secret_metadata)
 
             msg = self.resource_sec_client.deleteKVCredential(request=request, metadata=metadata)
             return MessageToJson(msg)
diff --git a/custos-client-sdks/custos-python-sdk/custos/samples/resource_secert_management.py b/custos-client-sdks/custos-python-sdk/custos/samples/resource_secert_management.py
new file mode 100644
index 0000000..f2568cb
--- /dev/null
+++ b/custos-client-sdks/custos-python-sdk/custos/samples/resource_secert_management.py
@@ -0,0 +1,80 @@
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#
+import logging
+from custos.clients.user_management_client import UserManagementClient
+from custos.clients.identity_management_client import IdentityManagementClient
+from custos.clients.super_tenant_management_client import SuperTenantManagementClient
+from custos.clients.resource_secret_management_client import ResourceSecretManagementClient
+from google.protobuf.json_format import MessageToDict
+
+from custos.transport.settings import CustosServerClientSettings
+import custos.clients.utils.utilities as utl
+
+logger = logging.getLogger(__name__)
+
+logger.setLevel(logging.DEBUG)
+# create console handler with a higher log level
+handler = logging.StreamHandler()
+handler.setLevel(logging.DEBUG)
+
+custos_settings = CustosServerClientSettings()
+# load APIServerClient with default configuration
+client = UserManagementClient(custos_settings)
+id_client = IdentityManagementClient(custos_settings)
+resource_secret_client = ResourceSecretManagementClient(custos_settings)
+
+token = utl.get_token(custos_settings)
+
+admin_client = SuperTenantManagementClient(custos_settings)
+
+
+def user_login():
+    response = id_client.token(token=
+                               token,
+                               username="USERNAME",
+                               password="PASSWORD",
+                               grant_type="password")
+    dict_obj = MessageToDict(response)
+    return dict_obj['access_token']
+
+
+def setKVCredential():
+    token = user_login()
+    resp = resource_secret_client.set_KV_credential(token=token, user_token=token,
+                                                    client_id='CHANGE_ME', key='Your key',
+                                                    value='Your Value')
+    print(resp)
+
+
+def getKVCredential():
+    token = user_login()
+    resp = resource_secret_client.get_KV_credential(token=token, user_token=token,
+                                                    client_id='CHANGE_ME', key='Your key')
+    print(resp)
+
+
+def updateKVCredential():
+    token = user_login()
+    resp = resource_secret_client.update_KV_credential(token=token, user_token=token,
+                                                       client_id='CHANGE_ME', key='Your key')
+    print(resp)
+
+
+def deleteKVCredential():
+    token = user_login()
+    resp = resource_secret_client.delete_KV_credential(token=token, user_token=token,
+                                                       client_id='CHANGE_ME', key='Your key')
+    print(resp)