@@ -9,11 +9,11 @@ import { DEFAULT_ROLES, DEFAULT_SYSTEM_SCHEMAS } from '../lib/constants'
9
9
import { Roles } from '../lib/interfaces'
10
10
11
11
/**
12
- * @param {boolean } [includeSystemSchemas =false] - Return system schemas as well as user schemas
12
+ * @param {boolean } [include_system_schemas =false] - Return system schemas as well as user schemas
13
13
*/
14
14
interface QueryParams {
15
- includeDefaultRoles ?: string
16
- includeSystemSchemas ?: string
15
+ include_default_roles ?: string
16
+ include_system_schemas ?: string
17
17
}
18
18
19
19
const router = Router ( )
@@ -23,11 +23,11 @@ router.get('/', async (req, res) => {
23
23
const sql = getRolesSqlize ( roles , grants )
24
24
const { data } = await RunQuery ( req . headers . pg , sql )
25
25
const query : QueryParams = req . query
26
- const includeSystemSchemas = query ?. includeSystemSchemas === 'true'
27
- const includeDefaultRoles = query ?. includeDefaultRoles === 'true'
26
+ const include_system_schemas = query ?. include_system_schemas === 'true'
27
+ const include_default_roles = query ?. include_default_roles === 'true'
28
28
let payload : Roles . Role [ ] = data
29
- if ( ! includeSystemSchemas ) payload = removeSystemSchemas ( data )
30
- if ( ! includeDefaultRoles ) payload = removeDefaultRoles ( payload )
29
+ if ( ! include_system_schemas ) payload = removeSystemSchemas ( data )
30
+ if ( ! include_default_roles ) payload = removeDefaultRoles ( payload )
31
31
32
32
return res . status ( 200 ) . json ( payload )
33
33
} catch ( error ) {
@@ -100,46 +100,46 @@ FROM
100
100
}
101
101
const createRoleSqlize = ( {
102
102
name,
103
- isSuperuser = false ,
104
- canCreateDb = false ,
105
- canCreateRole = false ,
106
- inheritRole = true ,
107
- canLogin = false ,
108
- isReplicationRole = false ,
109
- canBypassRls = false ,
110
- connectionLimit = - 1 ,
103
+ is_superuser = false ,
104
+ can_create_db = false ,
105
+ can_create_role = false ,
106
+ inherit_role = true ,
107
+ can_login = false ,
108
+ is_replication_role = false ,
109
+ can_bypass_rls = false ,
110
+ connection_limit = - 1 ,
111
111
password,
112
- validUntil ,
113
- memberOf ,
112
+ valid_until ,
113
+ member_of ,
114
114
members,
115
115
admins,
116
116
} : {
117
117
name : string
118
- isSuperuser ?: boolean
119
- canCreateDb ?: boolean
120
- canCreateRole ?: boolean
121
- inheritRole ?: boolean
122
- canLogin ?: boolean
123
- isReplicationRole ?: boolean
124
- canBypassRls ?: boolean
125
- connectionLimit ?: number
118
+ is_superuser ?: boolean
119
+ can_create_db ?: boolean
120
+ can_create_role ?: boolean
121
+ inherit_role ?: boolean
122
+ can_login ?: boolean
123
+ is_replication_role ?: boolean
124
+ can_bypass_rls ?: boolean
125
+ connection_limit ?: number
126
126
password ?: string
127
- validUntil ?: string
128
- memberOf ?: string [ ]
127
+ valid_until ?: string
128
+ member_of ?: string [ ]
129
129
members ?: string [ ]
130
130
admins ?: string [ ]
131
131
} ) => {
132
- const isSuperuserSql = isSuperuser ? 'SUPERUSER' : 'NOSUPERUSER'
133
- const canCreateDbSql = canCreateDb ? 'CREATEDB' : 'NOCREATEDB'
134
- const canCreateRoleSql = canCreateRole ? 'CREATEROLE' : 'NOCREATEROLE'
135
- const inheritRoleSql = inheritRole ? 'INHERIT' : 'NOINHERIT'
136
- const canLoginSql = canLogin ? 'LOGIN' : 'NOLOGIN'
137
- const isReplicationRoleSql = isReplicationRole ? 'REPLICATION' : 'NOREPLICATION'
138
- const canBypassRlsSql = canBypassRls ? 'BYPASSRLS' : 'NOBYPASSRLS'
139
- const connectionLimitSql = `CONNECTION LIMIT ${ connectionLimit } `
132
+ const isSuperuserSql = is_superuser ? 'SUPERUSER' : 'NOSUPERUSER'
133
+ const canCreateDbSql = can_create_db ? 'CREATEDB' : 'NOCREATEDB'
134
+ const canCreateRoleSql = can_create_role ? 'CREATEROLE' : 'NOCREATEROLE'
135
+ const inheritRoleSql = inherit_role ? 'INHERIT' : 'NOINHERIT'
136
+ const canLoginSql = can_login ? 'LOGIN' : 'NOLOGIN'
137
+ const isReplicationRoleSql = is_replication_role ? 'REPLICATION' : 'NOREPLICATION'
138
+ const canBypassRlsSql = can_bypass_rls ? 'BYPASSRLS' : 'NOBYPASSRLS'
139
+ const connectionLimitSql = `CONNECTION LIMIT ${ connection_limit } `
140
140
const passwordSql = password === undefined ? '' : `PASSWORD '${ password } '`
141
- const validUntilSql = validUntil === undefined ? '' : `VALID UNTIL '${ validUntil } '`
142
- const memberOfSql = memberOf === undefined ? '' : `IN ROLE ${ memberOf . join ( ',' ) } `
141
+ const validUntilSql = valid_until === undefined ? '' : `VALID UNTIL '${ valid_until } '`
142
+ const memberOfSql = member_of === undefined ? '' : `IN ROLE ${ member_of . join ( ',' ) } `
143
143
const membersSql = members === undefined ? '' : `ROLE ${ members . join ( ',' ) } `
144
144
const adminsSql = admins === undefined ? '' : `ADMIN ${ admins . join ( ',' ) } `
145
145
@@ -169,63 +169,63 @@ const singleRoleByNameSqlize = (roles: string, name: string) => {
169
169
const alterRoleSqlize = ( {
170
170
oldName,
171
171
name,
172
- isSuperuser ,
173
- canCreateDb ,
174
- canCreateRole ,
175
- inheritRole ,
176
- canLogin ,
177
- isReplicationRole ,
178
- canBypassRls ,
179
- connectionLimit ,
172
+ is_superuser ,
173
+ can_create_db ,
174
+ can_create_role ,
175
+ inherit_role ,
176
+ can_login ,
177
+ is_replication_role ,
178
+ can_bypass_rls ,
179
+ connection_limit ,
180
180
password,
181
- validUntil ,
181
+ valid_until ,
182
182
} : {
183
183
oldName : string
184
184
name ?: string
185
- isSuperuser ?: boolean
186
- canCreateDb ?: boolean
187
- canCreateRole ?: boolean
188
- inheritRole ?: boolean
189
- canLogin ?: boolean
190
- isReplicationRole ?: boolean
191
- canBypassRls ?: boolean
192
- connectionLimit ?: number
185
+ is_superuser ?: boolean
186
+ can_create_db ?: boolean
187
+ can_create_role ?: boolean
188
+ inherit_role ?: boolean
189
+ can_login ?: boolean
190
+ is_replication_role ?: boolean
191
+ can_bypass_rls ?: boolean
192
+ connection_limit ?: number
193
193
password ?: string
194
- validUntil ?: string
194
+ valid_until ?: string
195
195
} ) => {
196
196
const nameSql = name === undefined ? '' : `ALTER ROLE "${ oldName } " RENAME TO "${ name } ";`
197
197
let isSuperuserSql = ''
198
- if ( isSuperuser !== undefined ) {
199
- isSuperuserSql = isSuperuser ? 'SUPERUSER' : 'NOSUPERUSER'
198
+ if ( is_superuser !== undefined ) {
199
+ isSuperuserSql = is_superuser ? 'SUPERUSER' : 'NOSUPERUSER'
200
200
}
201
201
let canCreateDbSql = ''
202
- if ( canCreateDb !== undefined ) {
203
- canCreateDbSql = canCreateDb ? 'CREATEDB' : 'NOCREATEDB'
202
+ if ( can_create_db !== undefined ) {
203
+ canCreateDbSql = can_create_db ? 'CREATEDB' : 'NOCREATEDB'
204
204
}
205
205
let canCreateRoleSql = ''
206
- if ( canCreateRole !== undefined ) {
207
- canCreateRoleSql = canCreateRole ? 'CREATEROLE' : 'NOCREATEROLE'
206
+ if ( can_create_role !== undefined ) {
207
+ canCreateRoleSql = can_create_role ? 'CREATEROLE' : 'NOCREATEROLE'
208
208
}
209
209
let inheritRoleSql = ''
210
- if ( inheritRole !== undefined ) {
211
- inheritRoleSql = inheritRole ? 'INHERIT' : 'NOINHERIT'
210
+ if ( inherit_role !== undefined ) {
211
+ inheritRoleSql = inherit_role ? 'INHERIT' : 'NOINHERIT'
212
212
}
213
213
let canLoginSql = ''
214
- if ( canLogin !== undefined ) {
215
- canLoginSql = canLogin ? 'LOGIN' : 'NOLOGIN'
214
+ if ( can_login !== undefined ) {
215
+ canLoginSql = can_login ? 'LOGIN' : 'NOLOGIN'
216
216
}
217
217
let isReplicationRoleSql = ''
218
- if ( isReplicationRole !== undefined ) {
219
- isReplicationRoleSql = isReplicationRole ? 'REPLICATION' : 'NOREPLICATION'
218
+ if ( is_replication_role !== undefined ) {
219
+ isReplicationRoleSql = is_replication_role ? 'REPLICATION' : 'NOREPLICATION'
220
220
}
221
221
let canBypassRlsSql = ''
222
- if ( canBypassRls !== undefined ) {
223
- canBypassRlsSql = canBypassRls ? 'BYPASSRLS' : 'NOBYPASSRLS'
222
+ if ( can_bypass_rls !== undefined ) {
223
+ canBypassRlsSql = can_bypass_rls ? 'BYPASSRLS' : 'NOBYPASSRLS'
224
224
}
225
225
const connectionLimitSql =
226
- connectionLimit === undefined ? '' : `CONNECTION LIMIT ${ connectionLimit } `
226
+ connection_limit === undefined ? '' : `CONNECTION LIMIT ${ connection_limit } `
227
227
let passwordSql = password === undefined ? '' : `PASSWORD '${ password } '`
228
- let validUntilSql = validUntil === undefined ? '' : `VALID UNTIL '${ validUntil } '`
228
+ let validUntilSql = valid_until === undefined ? '' : `VALID UNTIL '${ valid_until } '`
229
229
230
230
return `
231
231
BEGIN;
0 commit comments