Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,13 @@ declare namespace Stardog {
*/
function token(conn: Connection): Promise<HTTP.Body>;

/**
* Returns the username for the given connection.
*
* @param {Connection} conn the Stardog server connection
*/
function whoAmI(conn: Connection): Promise<HTTP.Body>;

interface Permission {
action: Action,
resourceType: ResourceType,
Expand Down
8 changes: 8 additions & 0 deletions lib/user/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ const token = conn => {
}).then(httpBody);
};

const whoAmI = conn => {
const headers = conn.headers();
return fetch(conn.request('admin', 'status', 'whoami'), {
headers,
}).then(httpBody);
};

module.exports = {
assignPermission,
changePassword,
Expand All @@ -188,4 +195,5 @@ module.exports = {
superUser,
token,
valid,
whoAmI,
};
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,9 @@
]
}
},
"prettier": {
"singleQuote": true,
"trailingComma": "es5"
},
"stardog-version": ">=7.0.0"
}
19 changes: 19 additions & 0 deletions test/whoAmI.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-env jest */

const { user } = require('../lib');
const { ConnectionFactory } = require('./setup-database');

describe('whoAmI', () => {
let conn;

beforeEach(() => {
conn = ConnectionFactory();
});

it("should return the current user's username.", () =>
user.whoAmI(conn).then(res => {
expect(res.status).toEqual(200);
expect(conn.username).toBeTruthy();
expect(res.body).toEqual(conn.username);
}));
});