screwdriver-api 8.0.184 → 8.0.186

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "8.0.184",
3
+ "version": "8.0.186",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -112,7 +112,7 @@
112
112
  "screwdriver-command-validator": "^5.0.0",
113
113
  "screwdriver-config-parser": "^12.2.3",
114
114
  "screwdriver-coverage-bookend": "^3.0.0",
115
- "screwdriver-coverage-sonar": "^5.0.0",
115
+ "screwdriver-coverage-sonar": "^6.0.0",
116
116
  "screwdriver-data-schema": "^26.1.0",
117
117
  "screwdriver-datastore-sequelize": "^10.1.0",
118
118
  "screwdriver-executor-base": "^11.0.0",
@@ -4,6 +4,7 @@ const boom = require('@hapi/boom');
4
4
  const joi = require('joi');
5
5
  const jwt = require('jsonwebtoken');
6
6
  const { v4: uuidv4 } = require('uuid');
7
+ const logger = require('screwdriver-logger');
7
8
  const contextsRoute = require('./contexts');
8
9
  const crumbRoute = require('./crumb');
9
10
  const keyRoute = require('./key');
@@ -124,16 +125,19 @@ const authPlugin = {
124
125
  const { apiTokenId } = credentials.auth;
125
126
 
126
127
  if (!apiTokenId) {
128
+ logger.info(`[API Token Access] Invalid API Token.`);
127
129
  throw boom.forbidden(`Your token is invalid`);
128
130
  }
129
131
 
130
132
  const token = await tokenFactory.get({ id: apiTokenId });
131
133
 
132
134
  if (!token) {
135
+ logger.info(`[API Token Access] Invalid API Token.`);
133
136
  throw boom.forbidden(`Your token is invalid`);
134
137
  }
135
138
 
136
139
  if (token.expiresAt && new Date(token.expiresAt) < new Date()) {
140
+ logger.info(`[API Token Access][TokenId:${apiTokenId}] Expired Token Access.`);
137
141
  throw boom.forbidden(`Your token is expired: token id ${apiTokenId}`);
138
142
  }
139
143
 
@@ -146,10 +150,17 @@ const authPlugin = {
146
150
  throw boom.badImplementation(`Invalid required permission: "${requiredPermission}"`);
147
151
  }
148
152
 
153
+ const endpoint = request.route.path;
154
+
149
155
  if (!actualPermissionLevel || actualPermissionLevel < requiredPermissionLevel) {
156
+ logger.info(
157
+ `[API Token Access][TokenId:${apiTokenId}][${endpoint}] Invalid permission Token Access. This endpoint requires "${requiredPermission}" permission. This token has "${actualPermission}"`
158
+ );
150
159
  throw boom.forbidden(`This endpoint requires "${requiredPermission}" permission`);
151
160
  }
152
161
 
162
+ logger.info(`[API Token Access][TokenId:${apiTokenId}][${endpoint}] Success API Token access.`);
163
+
153
164
  return h.continue;
154
165
  });
155
166