You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by dm...@apache.org on 2019/11/29 13:35:46 UTC
[incubator-dlab] branch develop updated: SSO keycloak clients for
project removing implemented for all clouds
This is an automated email from the ASF dual-hosted git repository.
dmysakovets pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
The following commit(s) were added to refs/heads/develop by this push:
new 29c2395 SSO keycloak clients for project removing implemented for all clouds
new 3da9ea8 Merge pull request #464 from bodnarmykola/notebooks-sso
29c2395 is described below
commit 29c2395342176f4761c1a6396bc8f44a5d7bbeda
Author: Mykola_Bodnar1 <bo...@gmail.com>
AuthorDate: Fri Nov 29 15:18:04 2019 +0200
SSO keycloak clients for project removing implemented for all clouds
---
.../src/general/scripts/aws/project_terminate.py | 24 ++++++++++++---
.../src/general/scripts/azure/project_terminate.py | 36 ++++++++++++++++++++++
.../src/general/scripts/gcp/project_terminate.py | 36 ++++++++++++++++++++++
3 files changed, 92 insertions(+), 4 deletions(-)
diff --git a/infrastructure-provisioning/src/general/scripts/aws/project_terminate.py b/infrastructure-provisioning/src/general/scripts/aws/project_terminate.py
index 6a0de8d..deee78d 100644
--- a/infrastructure-provisioning/src/general/scripts/aws/project_terminate.py
+++ b/infrastructure-provisioning/src/general/scripts/aws/project_terminate.py
@@ -133,20 +133,36 @@ if __name__ == "__main__":
# sys.exit(1)
try:
- print('[CONFIGURE KEYCLOAK]')
- logging.info('[CONFIGURE KEYCLOAK]')
+ print('[KEYCLOAK PROJECT CLIENT DELETE]')
+ logging.info('[KEYCLOAK PROJECT CLIENT DELETE]')
keycloak_auth_server_url = '{}/realms/master/protocol/openid-connect/token'.format(
os.environ['keycloak_auth_server_url'])
+ keycloak_client_url = '{0}/admin/realms/{1}/clients'.format(os.environ['keycloak_auth_server_url'],
+ os.environ['keycloak_realm_name'])
+
keycloak_auth_data = {
"username": os.environ['keycloak_user'],
"password": os.environ['keycloak_user_password'],
"grant_type": "password",
"client_id": "admin-cli",
}
- keycloak_client_delete_url = '{0}/admin/realms/{1}/clients/{2}'.format(os.environ['keycloak_auth_server_url'], os.environ['keycloak_realm_name'],
- project_conf['service_base_name'] + '-' + project_conf['project_name'])
+
+ client_params = {
+ "clientId": project_conf['service_base_name'] + '-' + project_conf['project_name'],
+ }
+
keycloak_token = requests.post(keycloak_auth_server_url, data=keycloak_auth_data).json()
+ keycloak_get_id_client = requests.get(keycloak_client_url, data=keycloak_auth_data, params=client_params,
+ headers={"Authorization": "Bearer " + keycloak_token.get("access_token"),
+ "Content-Type": "application/json"})
+ json_keycloak_client_id = json.loads(keycloak_get_id_client.text)
+ keycloak_id_client = json_keycloak_client_id[0]['id']
+
+ keycloak_client_delete_url = '{0}/admin/realms/{1}/clients/{2}'.format(os.environ['keycloak_auth_server_url'],
+ os.environ['keycloak_realm_name'],
+ keycloak_id_client)
+
keycloak_client = requests.delete(keycloak_client_delete_url, headers={"Authorization": "Bearer " + keycloak_token.get("access_token"),
"Content-Type": "application/json"})
except Exception as err:
diff --git a/infrastructure-provisioning/src/general/scripts/azure/project_terminate.py b/infrastructure-provisioning/src/general/scripts/azure/project_terminate.py
index f1f07a0..1f4b4a9 100644
--- a/infrastructure-provisioning/src/general/scripts/azure/project_terminate.py
+++ b/infrastructure-provisioning/src/general/scripts/azure/project_terminate.py
@@ -26,6 +26,7 @@ import sys, time, os
from dlab.fab import *
from dlab.meta_lib import *
from dlab.actions_lib import *
+import requests
def terminate_edge_node(resource_group_name, service_base_name, project_tag, subnet_name, vpc_name):
@@ -159,6 +160,41 @@ if __name__ == "__main__":
sys.exit(1)
try:
+ print('[KEYCLOAK PROJECT CLIENT DELETE]')
+ logging.info('[KEYCLOAK PROJECT CLIENT DELETE]')
+ keycloak_auth_server_url = '{}/realms/master/protocol/openid-connect/token'.format(os.environ['keycloak_auth_server_url'])
+ keycloak_client_url = '{0}/admin/realms/{1}/clients'.format(os.environ['keycloak_auth_server_url'], os.environ['keycloak_realm_name'])
+
+ keycloak_auth_data = {
+ "username": os.environ['keycloak_user'],
+ "password": os.environ['keycloak_user_password'],
+ "grant_type": "password",
+ "client_id": "admin-cli",
+ }
+
+ client_params = {
+ "clientId": project_conf['service_base_name'] + '-' + os.environ['project_name'],
+ }
+
+ keycloak_token = requests.post(keycloak_auth_server_url, data=keycloak_auth_data).json()
+
+ keycloak_get_id_client = requests.get(keycloak_client_url, data=keycloak_auth_data, params=client_params,
+ headers={"Authorization": "Bearer " + keycloak_token.get("access_token"),
+ "Content-Type": "application/json"})
+ json_keycloak_client_id = json.loads(keycloak_get_id_client.text)
+ keycloak_id_client = json_keycloak_client_id[0]['id']
+
+ keycloak_client_delete_url = '{0}/admin/realms/{1}/clients/{2}'.format(os.environ['keycloak_auth_server_url'],
+ os.environ['keycloak_realm_name'],
+ keycloak_id_client)
+
+ keycloak_client = requests.delete(keycloak_client_delete_url,
+ headers={"Authorization": "Bearer " + keycloak_token.get("access_token"),
+ "Content-Type": "application/json"})
+ except Exception as err:
+ print("Failed to remove project client from Keycloak", str(err))
+
+ try:
with open("/root/result.json", 'w') as result:
res = {"service_base_name": os.environ['conf_service_base_name'],
"project_name": project_conf['project_name'],
diff --git a/infrastructure-provisioning/src/general/scripts/gcp/project_terminate.py b/infrastructure-provisioning/src/general/scripts/gcp/project_terminate.py
index 280f3c3..e6d06fb 100644
--- a/infrastructure-provisioning/src/general/scripts/gcp/project_terminate.py
+++ b/infrastructure-provisioning/src/general/scripts/gcp/project_terminate.py
@@ -26,6 +26,7 @@ from dlab.fab import *
from dlab.meta_lib import *
import sys, time, os
from dlab.actions_lib import *
+import requests
def terminate_edge_node(project_name, service_base_name, region, zone):
@@ -152,6 +153,41 @@ if __name__ == "__main__":
sys.exit(1)
try:
+ print('[KEYCLOAK PROJECT CLIENT DELETE]')
+ logging.info('[KEYCLOAK PROJECT CLIENT DELETE]')
+ keycloak_auth_server_url = '{}/realms/master/protocol/openid-connect/token'.format(os.environ['keycloak_auth_server_url'])
+ keycloak_client_url = '{0}/admin/realms/{1}/clients'.format(os.environ['keycloak_auth_server_url'], os.environ['keycloak_realm_name'])
+
+ keycloak_auth_data = {
+ "username": os.environ['keycloak_user'],
+ "password": os.environ['keycloak_user_password'],
+ "grant_type": "password",
+ "client_id": "admin-cli",
+ }
+
+ client_params = {
+ "clientId": project_conf['service_base_name'] + '-' + os.environ['project_name'],
+ }
+
+ keycloak_token = requests.post(keycloak_auth_server_url, data=keycloak_auth_data).json()
+
+ keycloak_get_id_client = requests.get(keycloak_client_url, data=keycloak_auth_data, params=client_params,
+ headers={"Authorization": "Bearer " + keycloak_token.get("access_token"),
+ "Content-Type": "application/json"})
+ json_keycloak_client_id = json.loads(keycloak_get_id_client.text)
+ keycloak_id_client = json_keycloak_client_id[0]['id']
+
+ keycloak_client_delete_url = '{0}/admin/realms/{1}/clients/{2}'.format(os.environ['keycloak_auth_server_url'],
+ os.environ['keycloak_realm_name'],
+ keycloak_id_client)
+
+ keycloak_client = requests.delete(keycloak_client_delete_url,
+ headers={"Authorization": "Bearer " + keycloak_token.get("access_token"),
+ "Content-Type": "application/json"})
+ except Exception as err:
+ print("Failed to remove project client from Keycloak", str(err))
+
+ try:
with open("/root/result.json", 'w') as result:
res = {"service_base_name": edge_conf['service_base_name'],
"project_name": edge_conf['project_name'],
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org