Skip to content

Commit b32de71

Browse files
committed
Add who am i cli support
1 parent 772ac76 commit b32de71

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

serverless.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ functions:
102102
method: delete
103103
authorizer: authorizerGithub
104104

105+
whoamiGet:
106+
handler: whoamiGet.default
107+
events:
108+
- http:
109+
path: 'registry/-/whoami'
110+
method: get
111+
authorizer: authorizerGithub
112+
105113
tarGet:
106114
handler: tarGet.default
107115
events:

src/whoami/get.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default async ({ requestContext }, _, callback) =>
2+
callback(null, {
3+
statusCode: 200,
4+
body: JSON.stringify({
5+
username: requestContext.authorizer.username,
6+
}),
7+
});
8+

test/whoami/get.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* eslint-disable no-underscore-dangle */
2+
import subject from '../../src/whoami/get';
3+
4+
describe('GET /registry/-/whoami', () => {
5+
let event;
6+
let callback;
7+
8+
beforeEach(() => {
9+
callback = stub();
10+
});
11+
12+
describe('whoami', () => {
13+
beforeEach(() => {
14+
event = {
15+
requestContext: {
16+
authorizer: {
17+
username: 'foobar',
18+
},
19+
},
20+
};
21+
});
22+
23+
it('should return correct username', async () => {
24+
await subject(event, stub(), callback);
25+
26+
assert(callback.calledWithExactly(null, {
27+
statusCode: 200,
28+
body: '{"username":"foobar"}',
29+
}));
30+
});
31+
});
32+
});

webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
distTagsDelete: ['./bootstrap', './src/dist-tags/delete.js'],
1414
userPut: ['./bootstrap', './src/user/put.js'],
1515
userDelete: ['./bootstrap', './src/user/delete.js'],
16+
whoamiGet: ['./bootstrap', './src/whoami/get.js'],
1617
tarGet: ['./bootstrap', './src/tar/get.js'],
1718
},
1819
output: {

0 commit comments

Comments
 (0)