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

Function validateImportRequest

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

Source from the content-addressed store, hash-verified

211}
212
213export async function validateImportRequest(
214 headers: RawRequestDefaultExpression['headers']
215): Promise<IServiceClientWithProject> {
216 const clientId = headers['openpanel-client-id'] as string;
217 const clientSecret = (headers['openpanel-client-secret'] as string) || '';
218
219 if (
220 !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(
221 clientId
222 )
223 ) {
224 throw new Error('Import: Client ID must be a valid UUIDv4');
225 }
226
227 const client = await getClientByIdCached(clientId);
228
229 if (!client) {
230 throw new Error('Import: Invalid client id');
231 }
232
233 if (!client.secret) {
234 throw new Error('Import: Client has no secret');
235 }
236
237 if (client.type === ClientType.write) {
238 throw new Error('Import: Client is not allowed to import');
239 }
240
241 if (!(await verifyPassword(clientSecret, client.secret))) {
242 throw new Error('Import: Invalid client secret');
243 }
244
245 return client;
246}
247
248export async function validateManageRequest(
249 headers: RawRequestDefaultExpression['headers']

Callers 1

importRouterFunction · 0.90

Calls 1

verifyPasswordFunction · 0.90

Tested by

no test coverage detected