1010#
1111# *****************************************************************************
1212
13+ from mas .devops .users import MASUserUtils
14+ from botocore .exceptions import ClientError
15+ import boto3
16+ import sys
17+ import json
18+ import yaml
1319from kubernetes import client , config
1420from kubernetes .config .config_exception import ConfigException
1521import argparse
1622import logging
1723import urllib3
1824urllib3 .disable_warnings ()
19- import yaml
20- import json
21- import sys
22-
23- import boto3
24- from botocore .exceptions import ClientError
25-
26- from mas .devops .users import MASUserUtils
27-
2825
2926
3027if __name__ == "__main__" :
@@ -38,7 +35,6 @@ if __name__ == "__main__":
3835 parser .add_argument ("--admin-dashboard-port" , required = False , default = 443 )
3936 parser .add_argument ("--manage-api-port" , required = False , default = 443 )
4037
41-
4238 group = parser .add_mutually_exclusive_group (required = True )
4339 group .add_argument ("--initial-users-yaml-file" )
4440 group .add_argument ("--initial-users-secret-name" )
@@ -66,7 +62,6 @@ if __name__ == "__main__":
6662 admin_dashboard_port = args .admin_dashboard_port
6763 manage_api_port = args .manage_api_port
6864
69-
7065 logger .info ("Configuration:" )
7166 logger .info ("--------------" )
7267 logger .info (f"mas_instance_id: { mas_instance_id } " )
@@ -88,7 +83,6 @@ if __name__ == "__main__":
8883 config .load_kube_config ()
8984 logger .debug ("Loaded kubeconfig file" )
9085
91-
9286 user_utils = MASUserUtils (mas_instance_id , mas_workspace_id , client .api_client .ApiClient (), coreapi_port = coreapi_port , admin_dashboard_port = admin_dashboard_port , manage_api_port = manage_api_port )
9387
9488 if initial_users_secret_name is not None :
@@ -100,7 +94,7 @@ if __name__ == "__main__":
10094 service_name = 'secretsmanager' ,
10195 )
10296 try :
103- initial_users_secret = aws_sm_client .get_secret_value ( # pragma: allowlist secret
97+ initial_users_secret = aws_sm_client .get_secret_value ( # pragma: allowlist secret
10498 SecretId = initial_users_secret_name
10599 )
106100 except ClientError as e :
@@ -109,16 +103,15 @@ if __name__ == "__main__":
109103 sys .exit (0 )
110104
111105 raise Exception (f"Failed to fetch secret { initial_users_secret_name } : { str (e )} " )
112-
106+
113107 secret_json = json .loads (initial_users_secret ['SecretString' ])
114108 initial_users = user_utils .parse_initial_users_from_aws_secret_json (secret_json )
115109 elif initial_users_yaml_file is not None :
116110 with open (initial_users_yaml_file , 'r' ) as file :
117111 initial_users = yaml .safe_load (file )
118112 else :
119113 raise Exception ("Something unexpected happened" )
120-
121-
114+
122115 result = user_utils .create_initial_users_for_saas (initial_users )
123116
124117 # if user details were sourced from an AWS SM secret, remove the completed entries from the secret
@@ -133,14 +126,13 @@ if __name__ == "__main__":
133126 if has_updates :
134127 logger .info (f"Updating secret { initial_users_secret_name } " )
135128 try :
136- aws_sm_client .update_secret ( # pragma: allowlist secret
129+ aws_sm_client .update_secret ( # pragma: allowlist secret
137130 SecretId = initial_users_secret_name ,
138131 SecretString = json .dumps (secret_json )
139132 )
140133 except ClientError as e :
141134 raise Exception (f"Failed to update secret { initial_users_secret_name } : { str (e )} " )
142-
143135
144136 if len (result ["failed" ]) > 0 :
145- failed_user_ids = list (map (lambda u : u ["email" ], result ["failed" ]))
146- raise Exception (f"Sync failed for the following user IDs { failed_user_ids } " )
137+ failed_user_ids = list (map (lambda u : u ["email" ], result ["failed" ]))
138+ raise Exception (f"Sync failed for the following user IDs { failed_user_ids } " )
0 commit comments