MCPcopy Index your code
hub / github.com/massCodeIO/massCode / parseSecurity

Function parseSecurity

src/main/http/import/openapi.ts:380–471  ·  view source on GitHub ↗
(
  root: UnknownRecord,
  operation: UnknownRecord,
  source: string,
  warnings: HttpImportWarning[],
)

Source from the content-addressed store, hash-verified

378}
379
380function parseSecurity(
381 root: UnknownRecord,
382 operation: UnknownRecord,
383 source: string,
384 warnings: HttpImportWarning[],
385): {
386 auth: HttpAuth
387 headers: HttpHeaderEntry[]
388 query: HttpQueryEntry[]
389 variables: Record<string, string>
390 } {
391 const requirements = Array.isArray(operation.security)
392 ? operation.security
393 : asArray(root.security)
394 const requirement = requirements.find(isRecord)
395 if (!requirement)
396 return { auth: { type: 'none' }, headers: [], query: [], variables: {} }
397
398 const schemes = getSecuritySchemes(root)
399 const variables: Record<string, string> = {}
400
401 for (const name of Object.keys(requirement)) {
402 const scheme = schemes[name]
403 if (!isRecord(scheme))
404 continue
405
406 if (
407 scheme.type === 'http'
408 && asString(scheme.scheme).toLowerCase() === 'bearer'
409 ) {
410 variables[name] = ''
411 return {
412 auth: { token: `{{${name}}}`, type: 'bearer' },
413 headers: [],
414 query: [],
415 variables,
416 }
417 }
418
419 if (
420 scheme.type === 'http'
421 && asString(scheme.scheme).toLowerCase() === 'basic'
422 ) {
423 variables[`${name}Username`] = ''
424 variables[`${name}Password`] = ''
425 return {
426 auth: {
427 password: `{{${name}Password}}`,
428 type: 'basic',
429 username: `{{${name}Username}}`,
430 },
431 headers: [],
432 query: [],
433 variables,
434 }
435 }
436
437 if (scheme.type === 'apiKey') {

Callers 1

parseOperationFunction · 0.85

Calls 5

addWarningFunction · 0.90
getSecuritySchemesFunction · 0.85
asArrayFunction · 0.70
isRecordFunction · 0.70
asStringFunction · 0.70

Tested by

no test coverage detected