Sha256: beb34671ca1fded435f5edbeec7ffb242714454a1130ccaf9304af3a05fb69e2

Contents?: true

Size: 1.29 KB

Versions: 21

Compression:

Stored size: 1.29 KB

Contents

function parseScheme(authorization) {
  const tokens = authorization.split(/\s/);
  if (tokens.length === 1) {
    return {
      schemeId: 'api_key',
      scheme: {
        type: 'apiKey',
        name: 'authorization',
        in: 'header',
      },
    };
  }

  const schemeId = tokens[0].toLowerCase();
  return {
    schemeId,
    scheme: {
      type: 'http',
      scheme: schemeId,
    },
  };
}

class SecuritySchemes {
  constructor() {
    this.schemes = {};
  }

  /**
   * Adds an event to the security schemes, and assigns a security scheme id.
   * If the event has no detectable security scheme, this function returns null.
   *
   * @param {Event} event
   * @returns the security scheme id for the event, or null.
   */
  addRequest(event) {
    const { authorization } = event.httpServerRequest;
    if (!authorization) {
      return null;
    }

    const { schemeId, scheme } = parseScheme(authorization);
    if (!this.schemes[schemeId]) {
      this.schemes[schemeId] = scheme;
    }
    return schemeId;
  }

  swagger() {
    return Object.keys(this.schemes)
      .sort()
      .reduce((memo, schemeId) => {
        // eslint-disable-next-line no-param-reassign
        memo[schemeId] = this.schemes[schemeId];
        return memo;
      }, {});
  }
}

module.exports = SecuritySchemes;

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
appmap-0.72.2 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.72.1 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.72.0 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.71.0 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.70.2 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.70.1 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.70.0 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.69.0 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.68.2 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.68.1 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.68.0 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.67.1 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.67.0 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.66.2 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.66.1 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.66.0 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.65.1 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.65.0 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.64.0 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js
appmap-0.63.0 ./node_modules/@appland/appmap/src/swagger/securitySchemes.js