-
Notifications
You must be signed in to change notification settings - Fork 240
Expand file tree
/
Copy pathroles.ts
More file actions
33 lines (28 loc) · 941 Bytes
/
roles.ts
File metadata and controls
33 lines (28 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { UserConfig } from "../config/userConfig.js";
import type { DatabaseUserRole } from "./openapi.js";
const readWriteRole: DatabaseUserRole = {
roleName: "readWriteAnyDatabase",
databaseName: "admin",
};
const readOnlyRole: DatabaseUserRole = {
roleName: "readAnyDatabase",
databaseName: "admin",
};
/**
* Get the default role name for the database user based on the Atlas Admin API
* https://www.mongodb.com/docs/atlas/mongodb-users-roles-and-privileges/
*/
export function getDefaultRoleFromConfig(config: UserConfig): DatabaseUserRole {
if (config.readOnly) {
return readOnlyRole;
}
// If any of the write tools are enabled, use readWriteAnyDatabase
if (
!config.disabledTools.includes("create") ||
!config.disabledTools.includes("update") ||
!config.disabledTools.includes("delete")
) {
return readWriteRole;
}
return readOnlyRole;
}