Skip to content

Commit 23a21b6

Browse files
author
Vikas Agarwal
committed
Fixing userId to a hard coded value for m2m calls
1 parent 1cee66e commit 23a21b6

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

config/custom-environment-variables.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,6 @@
6161
"REG_STATS": "LOOKER_API_REG_STATS_QUERY_ID",
6262
"BUDGET": "LOOKER_API_BUDGET_QUERY_ID"
6363
}
64-
}
64+
},
65+
"DEFAULT_M2M_USERID": "DEFAULT_M2M_USERID"
6566
}

config/default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,6 @@
7171
"REG_STATS": 1234,
7272
"BUDGET": 123
7373
}
74-
}
74+
},
75+
"DEFAULT_M2M_USERID": -101
7576
}

src/routes/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ router.all(
3434
),
3535
);
3636

37+
router.all(
38+
RegExp(`\\/${apiVersion}\\/.*`), (req, res, next) => {
39+
// if it is an M2M call, hard code user id to a deafult value to avoid errors
40+
// Ideally, the m2m token should have unique userId, which may not be an actual user, as well
41+
const isMachineToken = _.get(req, 'authUser.isMachine', false);
42+
if (req.authUser && !req.authUser.userId && isMachineToken) {
43+
req.authUser.userId = config.DEFAULT_M2M_USERID;
44+
}
45+
return next();
46+
},
47+
);
48+
3749
router.route('/v4/projects/metadata/projectTemplates')
3850
.get(require('./projectTemplates/list'));
3951
router.route('/v4/projects/metadata/projectTemplates/:templateId(\\d+)')

0 commit comments

Comments
 (0)