@@ -60,6 +60,22 @@ def save(self, installation: Installation):
6060 )
6161 self .logger .debug (f"S3 put_object response: { response } " )
6262
63+ # per workspace
64+ entity : str = json .dumps (installation .__dict__ )
65+ response = self .s3_client .put_object (
66+ Bucket = self .bucket_name ,
67+ Body = entity ,
68+ Key = f"{ workspace_path } /installer-latest" ,
69+ )
70+ self .logger .debug (f"S3 put_object response: { response } " )
71+ response = self .s3_client .put_object (
72+ Bucket = self .bucket_name ,
73+ Body = entity ,
74+ Key = f"{ workspace_path } /installer-{ history_version } " ,
75+ )
76+ self .logger .debug (f"S3 put_object response: { response } " )
77+
78+ # per workspace per user
6379 u_id = installation .user_id or none
6480 entity : str = json .dumps (installation .__dict__ )
6581 response = self .s3_client .put_object (
@@ -84,6 +100,16 @@ def save(self, installation: Installation):
84100 )
85101 self .logger .debug (f"S3 put_object response: { response } " )
86102
103+ # per workspace
104+ entity : str = json .dumps (installation .__dict__ )
105+ response = self .s3_client .put_object (
106+ Bucket = self .bucket_name ,
107+ Body = entity ,
108+ Key = f"{ workspace_path } /installer-latest" ,
109+ )
110+ self .logger .debug (f"S3 put_object response: { response } " )
111+
112+ # per workspace per user
87113 u_id = installation .user_id or none
88114 entity : str = json .dumps (installation .__dict__ )
89115 response = self .s3_client .put_object (
@@ -94,17 +120,30 @@ def save(self, installation: Installation):
94120 self .logger .debug (f"S3 put_object response: { response } " )
95121
96122 async def async_find_bot (
97- self , * , enterprise_id : Optional [str ], team_id : Optional [str ],
123+ self ,
124+ * ,
125+ enterprise_id : Optional [str ],
126+ team_id : Optional [str ],
127+ is_enterprise_install : Optional [bool ] = False ,
98128 ) -> Optional [Bot ]:
99- return self .find_bot (enterprise_id = enterprise_id , team_id = team_id )
129+ return self .find_bot (
130+ enterprise_id = enterprise_id ,
131+ team_id = team_id ,
132+ is_enterprise_install = is_enterprise_install ,
133+ )
100134
101135 def find_bot (
102- self , * , enterprise_id : Optional [str ], team_id : Optional [str ],
136+ self ,
137+ * ,
138+ enterprise_id : Optional [str ],
139+ team_id : Optional [str ],
140+ is_enterprise_install : Optional [bool ] = False ,
103141 ) -> Optional [Bot ]:
104- # Not yet implemented: org-apps support
105142 none = "none"
106143 e_id = enterprise_id or none
107144 t_id = team_id or none
145+ if is_enterprise_install :
146+ t_id = none
108147 workspace_path = f"{ self .client_id } /{ e_id } -{ t_id } "
109148 try :
110149 fetch_response = self .s3_client .get_object (
@@ -118,3 +157,50 @@ def find_bot(
118157 message = f"Failed to find bot installation data for enterprise: { e_id } , team: { t_id } : { e } "
119158 self .logger .warning (message )
120159 return None
160+
161+ async def async_find_installation (
162+ self ,
163+ * ,
164+ enterprise_id : Optional [str ],
165+ team_id : Optional [str ],
166+ user_id : Optional [str ] = None ,
167+ is_enterprise_install : Optional [bool ] = False ,
168+ ) -> Optional [Installation ]:
169+ return self .find_installation (
170+ enterprise_id = enterprise_id ,
171+ team_id = team_id ,
172+ user_id = user_id ,
173+ is_enterprise_install = is_enterprise_install ,
174+ )
175+
176+ def find_installation (
177+ self ,
178+ * ,
179+ enterprise_id : Optional [str ],
180+ team_id : Optional [str ],
181+ user_id : Optional [str ] = None ,
182+ is_enterprise_install : Optional [bool ] = False ,
183+ ) -> Optional [Installation ]:
184+ none = "none"
185+ e_id = enterprise_id or none
186+ t_id = team_id or none
187+ if is_enterprise_install :
188+ t_id = none
189+ workspace_path = f"{ self .client_id } /{ e_id } -{ t_id } "
190+ try :
191+ key = (
192+ f"{ workspace_path } /installer-{ user_id } -latest"
193+ if user_id
194+ else f"{ workspace_path } /installer-latest"
195+ )
196+ fetch_response = self .s3_client .get_object (
197+ Bucket = self .bucket_name , Key = key ,
198+ )
199+ self .logger .debug (f"S3 get_object response: { fetch_response } " )
200+ body = fetch_response ["Body" ].read ().decode ("utf-8" )
201+ data = json .loads (body )
202+ return Installation (** data )
203+ except Exception as e : # skipcq: PYL-W0703
204+ message = f"Failed to find an installation data for enterprise: { e_id } , team: { t_id } : { e } "
205+ self .logger .warning (message )
206+ return None
0 commit comments