MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / validateExportRequest

Function validateExportRequest

apps/api/src/utils/auth.ts:178–211  ·  view source on GitHub ↗
(
  headers: RawRequestDefaultExpression['headers']
)

Source from the content-addressed store, hash-verified

176}
177
178export 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
213export async function validateImportRequest(
214 headers: RawRequestDefaultExpression['headers']

Callers 2

exportRouterFunction · 0.90
insightsRouterFunction · 0.90

Calls 1

verifyPasswordFunction · 0.90

Tested by

no test coverage detected