lib/Tvm.js
/**
   * Process OpenWhisk web request, generates credentials upon OpenWhisk auth validation and responds back with the credentials
   *
   * @param {object} params OpenWhisk web request params
   * @returns {Promise<object>} { body: <object>, statusCode: <number> }, if returns an error there is a body.error
   * @memberof Tvm
   */
Process OpenWhisk web request, generates credentials upon OpenWhisk auth validation and responds back with the credentials
@param {object} params OpenWhisk web request params
@returns {Promise} { body: , statusCode:  }, if returns an error there is a body.error
@memberof Tvm
Process OpenWhisk web request generates credentials upon OpenWhisk auth validation and responds back with the credentials @param { object } params OpenWhisk web request params @returns { Promise } { body : statusCode : } if returns an error there is a body . error @memberof Tvm
async processRequest (params) {
    const requestId = params.__ow_headers['x-request-id']
    logger.info('start of request Id - ' + requestId)
    try {
      if (params.disableAdobeIOApiGwTokenValidation !== 'true') {
        try {
          await this._validateAdobeIOApiGwServiceToken(params)
        } catch (e) {
          logger.warn(`Adobe I/O API Gateway service token validation failed: ${e.message} - request Id - ${requestId}`)
          return Tvm._userErrorResponse('unauthorized', 403)
        }
      }
      try {
        const rawToken = this._extractTokenFromHeader(params, 'authorization', 'Basic ')
        params.owAuth = Buffer.from(rawToken, 'base64').toString()
      } catch (e) {
        logger.warn(`failed to extract Basic auth token: ${e.message} - request Id - ${requestId}`)
        return Tvm._userErrorResponse('unauthorized', 403)
      }
      const res = this._validateRequestParams(params)
      if (res.error) {
        logger.warn(`bad request: ${res.error.message} - request Id - ${requestId}`)
        return Tvm._userErrorResponse(res.error.message, 400)
      }
      params.expirationDuration = parseInt(params.expirationDuration)
      logger.info(`trying to validate credentials: [ ${params.owNamespace}, ${params.owAuth.split(':')[0]}<hidden> ] - request Id - ${requestId}`)
      try {
        await this._validateOWCreds(params.owApihost, params.owNamespace, params.owAuth)
        await this._validateNamespaceInApprovedList(params.owNamespace, params.approvedList)
      } catch (e) {
        if (!e.code || !KNOWN_4XX_ERRORS.includes(e.code)) {
          logger.warn(`server error: ${e.message} - request Id - ${requestId}`)
          return Tvm._userErrorResponse('server error', 500)
        }
        logger.warn(`unauthorized request: ${e.message} - request Id - ${requestId}`)
        return Tvm._userErrorResponse('unauthorized request', 403)
      }
      logger.info(`request is authorized - request Id - ${requestId}`)
      const credentials = await this._generateCredentials(params)
      logger.info(`credentials generated - request Id - ${requestId}`)
      logger.info('end of request Id - ' + requestId)
      return {
        body: {
          ...credentials
        },
        statusCode: 200
      }
    } catch (e) {
      logger.error(e)
      return {
        error: {
          body: { error: 'server error' },
          statusCode: 500
        }
      }
    }
  }
async processRequest ( params ) { const requestId = params . __ow_headers [ 'x-request-id' ] logger . info ( 'start of request Id - ' + requestId ) try { if ( params . disableAdobeIOApiGwTokenValidation !== 'true' ) { try { await this . _validateAdobeIOApiGwServiceToken ( params ) } catch ( e ) { logger . warn ( ` ${ e . message } ${ requestId } ` ) return Tvm . _userErrorResponse ( 'unauthorized' , 403 ) } } try { const rawToken = this . _extractTokenFromHeader ( params , 'authorization' , 'Basic ' ) params . owAuth = Buffer . from ( rawToken , 'base64' ) . toString ( ) } catch ( e ) { logger . warn ( ` ${ e . message } ${ requestId } ` ) return Tvm . _userErrorResponse ( 'unauthorized' , 403 ) } const res = this . _validateRequestParams ( params ) if ( res . error ) { logger . warn ( ` ${ res . error . message } ${ requestId } ` ) return Tvm . _userErrorResponse ( res . error . message , 400 ) } params . expirationDuration = parseInt ( params . expirationDuration ) logger . info ( ` ${ params . owNamespace } ${ params . owAuth . split ( ':' ) [ 0 ] } ${ requestId } ` ) try { await this . _validateOWCreds ( params . owApihost , params . owNamespace , params . owAuth ) await this . _validateNamespaceInApprovedList ( params . owNamespace , params . approvedList ) } catch ( e ) { if ( ! e . code || ! KNOWN_4XX_ERRORS . includes ( e . code ) ) { logger . warn ( ` ${ e . message } ${ requestId } ` ) return Tvm . _userErrorResponse ( 'server error' , 500 ) } logger . warn ( ` ${ e . message } ${ requestId } ` ) return Tvm . _userErrorResponse ( 'unauthorized request' , 403 ) } logger . info ( ` ${ requestId } ` ) const credentials = await this . _generateCredentials ( params ) logger . info ( ` ${ requestId } ` ) logger . info ( 'end of request Id - ' + requestId ) return { body : { ... credentials } , statusCode : 200 } } catch ( e ) { logger . error ( e ) return { error : { body : { error : 'server error' } , statusCode : 500 } } } }
Process OpenWhisk web request, generates credentials upon OpenWhisk auth validation and responds back with the credentials
 @param {object} params OpenWhisk web request params
 @returns {Promise<object>} { body: <object>, statusCode: <number> }, if returns an error there is a body.error
 @memberof Tvm
Process OpenWhisk web request generates credentials upon OpenWhisk auth validation and responds back with the credentials @param { object } params OpenWhisk web request params @returns { Promise<object > } { body : <object > statusCode : <number > } if returns an error there is a body . error @memberof Tvm
// 0. validate Adobe I/O Api Gateway service token // 1. extract OpenWhisk Auth in Authorization header // 2. validation // important - parse expiryDuration to int // check if namespace/auth is valid // return 500 error if its not a known 4xx error or no e.code set // 3. generate credentials // 4. all good, no errors: return response // note the error is wrapped in the { error } object, this means that any 500 will // appear in the I/O Runtime activation logs as an application error