@@ -81,6 +81,8 @@ def __init__(self, mas_instance_id: str, mas_workspace_id: str, k8s_client: clie
8181
8282 self ._manage_maxadmin_api_key = None
8383
84+ self ._mas_workspace_application_ids = None
85+
8486 @property
8587 def mas_superuser_credentials (self ):
8688 if self ._mas_superuser_credentials is None :
@@ -221,6 +223,12 @@ def manage_maxadmin_api_key(self):
221223 self ._manage_maxadmin_api_key = self .create_or_get_manage_api_key_for_user (MASUserUtils .MAXADMIN )
222224 return self ._manage_maxadmin_api_key
223225
226+ @property
227+ def mas_workspace_application_ids (self ):
228+ if self ._mas_workspace_application_ids is None :
229+ self ._mas_workspace_application_ids = list (map (lambda ma : ma ["id" ], self .get_mas_applications_in_workspace ()))
230+ return self ._mas_workspace_application_ids
231+
224232 def get_or_create_user (self , payload ):
225233 '''
226234 User is identified by payload["id"] field
@@ -735,54 +743,6 @@ def add_user_to_manage_group(self, user_id, group_name):
735743
736744 raise Exception (f"{ response .status_code } { response .text } " )
737745
738- def get_groups (self ):
739- self .logger .debug ("Getting groups" )
740- url = f"{ self .mas_api_url_internal } /groups"
741- headers = {
742- "Accept" : "application/json" ,
743- "x-access-token" : self .superuser_auth_token
744- }
745- response = requests .get (
746- url ,
747- headers = headers ,
748- verify = self .core_internal_ca_pem_file_path
749- )
750- if response .status_code == 200 :
751- return response .json ()
752- raise Exception (f"{ response .status_code } { response .text } " )
753-
754- def get_user_groups (self , user_id ):
755- self .logger .info (f"Getting groups for user { user_id } " )
756- url = f"{ self .mas_api_url_internal } /v3/users/{ user_id } /groups"
757- headers = {
758- "Accept" : "application/json" ,
759- "x-access-token" : self .superuser_auth_token
760- }
761- response = requests .get (
762- url ,
763- headers = headers ,
764- verify = self .core_internal_ca_pem_file_path
765- )
766- if response .status_code == 200 :
767- return response .json ()
768- raise Exception (f"{ response .status_code } { response .text } " )
769-
770- def get_installed_mas_applications (self ):
771- self .logger .debug ("Getting installed MAS Applications" )
772- url = f"{ self .mas_api_url_internal } /applications"
773- headers = {
774- "Accept" : "application/json" ,
775- "x-access-token" : self .superuser_auth_token
776- }
777- response = requests .get (
778- url ,
779- headers = headers ,
780- verify = self .core_internal_ca_pem_file_path
781- )
782- if response .status_code == 200 :
783- return response .json ()
784- raise Exception (f"{ response .status_code } { response .text } " )
785-
786746 def get_mas_applications_in_workspace (self ):
787747 self .logger .debug (f"Getting MAS Applications in workspace { self .mas_workspace_id } " )
788748 url = f"{ self .mas_api_url_internal } /workspaces/{ self .mas_workspace_id } /applications"
@@ -874,6 +834,10 @@ def create_initial_users_for_saas(self, initial_users):
874834 if type (secondary_users ) is not list :
875835 raise Exception ("'users.secondary' is not a list" )
876836
837+ # before we do anything, let's check all MAS applications are ready
838+ for mas_application_id in self .mas_workspace_application_ids :
839+ self .await_mas_application_availability (mas_application_id )
840+
877841 for primary_user in primary_users :
878842 self .create_initial_user_for_saas (primary_user , "PRIMARY" )
879843
@@ -955,9 +919,7 @@ def create_initial_user_for_saas(self, user, user_type):
955919 self .link_user_to_local_idp (user_id )
956920 self .add_user_to_workspace (user_id , is_workspace_admin = is_workspace_admin )
957921
958- mas_application_ids = list (map (lambda ma : ma ["id" ], self .get_mas_applications_in_workspace ()))
959-
960- for mas_application_id in mas_application_ids :
922+ for mas_application_id in self .mas_workspace_application_ids :
961923 self .await_mas_application_availability (mas_application_id )
962924 if mas_application_id == "manage" :
963925 # special case for manage; role is always "MANAGEUSER"
@@ -967,9 +929,60 @@ def create_initial_user_for_saas(self, user, user_type):
967929 role = application_role
968930 self .set_user_application_permission (user_id , mas_application_id , role )
969931
970- for mas_application_id in mas_application_ids :
932+ for mas_application_id in self . mas_workspace_application_ids :
971933 self .check_user_sync (user_id , mas_application_id )
972934
973- if "manage" in mas_application_ids :
935+ if "manage" in self . mas_workspace_application_ids :
974936 for manage_security_group in manage_security_groups :
975937 self .add_user_to_manage_group (user_id , manage_security_group )
938+
939+ # Unused (but potentially useful) methods
940+ # ----------------------------------------
941+
942+ def get_groups (self ):
943+ self .logger .debug ("Getting groups" )
944+ url = f"{ self .mas_api_url_internal } /groups"
945+ headers = {
946+ "Accept" : "application/json" ,
947+ "x-access-token" : self .superuser_auth_token
948+ }
949+ response = requests .get (
950+ url ,
951+ headers = headers ,
952+ verify = self .core_internal_ca_pem_file_path
953+ )
954+ if response .status_code == 200 :
955+ return response .json ()
956+ raise Exception (f"{ response .status_code } { response .text } " )
957+
958+ def get_installed_mas_applications (self ):
959+ self .logger .debug ("Getting installed MAS Applications" )
960+ url = f"{ self .mas_api_url_internal } /applications"
961+ headers = {
962+ "Accept" : "application/json" ,
963+ "x-access-token" : self .superuser_auth_token
964+ }
965+ response = requests .get (
966+ url ,
967+ headers = headers ,
968+ verify = self .core_internal_ca_pem_file_path
969+ )
970+ if response .status_code == 200 :
971+ return response .json ()
972+ raise Exception (f"{ response .status_code } { response .text } " )
973+
974+ def get_user_groups (self , user_id ):
975+ self .logger .info (f"Getting groups for user { user_id } " )
976+ url = f"{ self .mas_api_url_internal } /v3/users/{ user_id } /groups"
977+ headers = {
978+ "Accept" : "application/json" ,
979+ "x-access-token" : self .superuser_auth_token
980+ }
981+ response = requests .get (
982+ url ,
983+ headers = headers ,
984+ verify = self .core_internal_ca_pem_file_path
985+ )
986+ if response .status_code == 200 :
987+ return response .json ()
988+ raise Exception (f"{ response .status_code } { response .text } " )
0 commit comments