( headers: RawRequestDefaultExpression['headers'] )
| 176 | } |
| 177 | |
| 178 | export async function validateExportRequest( |
| 179 | headers: RawRequestDefaultExpression['headers'] |
| 180 | ): Promise<IServiceClientWithProject> { |
| 181 | const clientId = headers['openpanel-client-id'] as string; |
| 182 | const clientSecret = (headers['openpanel-client-secret'] as string) || ''; |
| 183 | |
| 184 | if ( |
| 185 | !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test( |
| 186 | clientId |
| 187 | ) |
| 188 | ) { |
| 189 | throw new Error('Export: Client ID must be a valid UUIDv4'); |
| 190 | } |
| 191 | |
| 192 | const client = await getClientByIdCached(clientId); |
| 193 | |
| 194 | if (!client) { |
| 195 | throw new Error('Export: Invalid client id'); |
| 196 | } |
| 197 | |
| 198 | if (!client.secret) { |
| 199 | throw new Error('Export: Client has no secret'); |
| 200 | } |
| 201 | |
| 202 | if (client.type === ClientType.write) { |
| 203 | throw new Error('Export: Client is not allowed to export'); |
| 204 | } |
| 205 | |
| 206 | if (!(await verifyPassword(clientSecret, client.secret))) { |
| 207 | throw new Error('Export: Invalid client secret'); |
| 208 | } |
| 209 | |
| 210 | return client; |
| 211 | } |
| 212 | |
| 213 | export async function validateImportRequest( |
| 214 | headers: RawRequestDefaultExpression['headers'] |
no test coverage detected