screwdriver-api 8.0.110 → 8.0.111
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 +1 -1
- package/plugins/users/get.js +61 -0
- package/plugins/users/index.js +2 -1
package/package.json
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const boom = require('@hapi/boom');
|
|
4
|
+
const joi = require('joi');
|
|
5
|
+
const schema = require('screwdriver-data-schema');
|
|
6
|
+
const getSchema = schema.models.user.base.get;
|
|
7
|
+
const usernameSchema = schema.models.user.base.extract('username');
|
|
8
|
+
const scmContextSchema = schema.models.pipeline.base.extract('scmContext');
|
|
9
|
+
|
|
10
|
+
module.exports = () => ({
|
|
11
|
+
method: 'GET',
|
|
12
|
+
path: '/users/{username}',
|
|
13
|
+
options: {
|
|
14
|
+
description: 'Get an user by SCM username and SCM context',
|
|
15
|
+
notes: 'Returns an user by SCM username and SCM context',
|
|
16
|
+
tags: ['api', 'users'],
|
|
17
|
+
auth: {
|
|
18
|
+
strategies: ['token'],
|
|
19
|
+
scope: ['admin', '!guest']
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
handler: async (request, h) => {
|
|
23
|
+
const { username } = request.params;
|
|
24
|
+
const { userFactory } = request.server.app;
|
|
25
|
+
const { scmContext, includeUserToken } = request.query;
|
|
26
|
+
|
|
27
|
+
const user = await userFactory.get({
|
|
28
|
+
username,
|
|
29
|
+
scmContext
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!user) {
|
|
33
|
+
throw boom.notFound(`User ${username} does not exist for the scmContext ${scmContext}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (includeUserToken) {
|
|
37
|
+
const profile = request.server.plugins.auth.generateProfile({
|
|
38
|
+
username: user.username,
|
|
39
|
+
scmContext: user.scmContext,
|
|
40
|
+
scope: ['user']
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
user.userToken = request.server.plugins.auth.generateToken(profile);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return h.response(user);
|
|
47
|
+
},
|
|
48
|
+
response: {
|
|
49
|
+
schema: getSchema
|
|
50
|
+
},
|
|
51
|
+
validate: {
|
|
52
|
+
params: joi.object({
|
|
53
|
+
username: usernameSchema
|
|
54
|
+
}),
|
|
55
|
+
query: joi.object({
|
|
56
|
+
scmContext: scmContextSchema.required(),
|
|
57
|
+
includeUserToken: joi.boolean().optional()
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
package/plugins/users/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const getSettingsRoute = require('./settings/get');
|
|
4
4
|
const updateSettingsRoute = require('./settings/update');
|
|
5
5
|
const removeSettingsRoute = require('./settings/delete');
|
|
6
|
+
const getUserRoute = require('./get');
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Users API Plugin
|
|
@@ -12,7 +13,7 @@ const removeSettingsRoute = require('./settings/delete');
|
|
|
12
13
|
const usersPlugin = {
|
|
13
14
|
name: 'users',
|
|
14
15
|
async register(server) {
|
|
15
|
-
server.route([getSettingsRoute(), updateSettingsRoute(), removeSettingsRoute()]);
|
|
16
|
+
server.route([getSettingsRoute(), updateSettingsRoute(), removeSettingsRoute(), getUserRoute()]);
|
|
16
17
|
}
|
|
17
18
|
};
|
|
18
19
|
|