Skip to content

Commit c84caf1

Browse files
committed
add missing file
1 parent 439daab commit c84caf1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/common/atlas/roles.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { UserConfig } from "../config.js";
2+
import { DatabaseUserRole } from "./openapi.js";
3+
4+
/**
5+
* Get the default role name for the database user based on the Atlas Admin API
6+
* https://www.mongodb.com/docs/atlas/mongodb-users-roles-and-privileges/
7+
*/
8+
export function getDefaultRoleFromConfig(config: UserConfig): DatabaseUserRole {
9+
if (config.readOnly) {
10+
return {
11+
roleName: "readAnyDatabase",
12+
databaseName: "admin",
13+
};
14+
}
15+
16+
// If all write tools are enabled, use readWriteAnyDatabase
17+
if (
18+
!config.disabledTools?.includes("create") &&
19+
!config.disabledTools?.includes("update") &&
20+
!config.disabledTools?.includes("delete") &&
21+
!config.disabledTools?.includes("metadata")
22+
) {
23+
return {
24+
roleName: "readWriteAnyDatabase",
25+
databaseName: "admin",
26+
};
27+
}
28+
29+
return {
30+
roleName: "readAnyDatabase",
31+
databaseName: "admin",
32+
};
33+
}

0 commit comments

Comments
 (0)