@@ -9,11 +9,11 @@ import { DEFAULT_ROLES, DEFAULT_SYSTEM_SCHEMAS } from '../lib/constants'
99import { Roles } from '../lib/interfaces'
1010
1111/**
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
1313 */
1414interface QueryParams {
15- includeDefaultRoles ?: string
16- includeSystemSchemas ?: string
15+ include_default_roles ?: string
16+ include_system_schemas ?: string
1717}
1818
1919const router = Router ( )
@@ -23,11 +23,11 @@ router.get('/', async (req, res) => {
2323 const sql = getRolesSqlize ( roles , grants )
2424 const { data } = await RunQuery ( req . headers . pg , sql )
2525 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'
2828 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 )
3131
3232 return res . status ( 200 ) . json ( payload )
3333 } catch ( error ) {
@@ -100,46 +100,46 @@ FROM
100100}
101101const createRoleSqlize = ( {
102102 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 ,
111111 password,
112- validUntil ,
113- memberOf ,
112+ valid_until ,
113+ member_of ,
114114 members,
115115 admins,
116116} : {
117117 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
126126 password ?: string
127- validUntil ?: string
128- memberOf ?: string [ ]
127+ valid_until ?: string
128+ member_of ?: string [ ]
129129 members ?: string [ ]
130130 admins ?: string [ ]
131131} ) => {
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 } `
140140 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 ( ',' ) } `
143143 const membersSql = members === undefined ? '' : `ROLE ${ members . join ( ',' ) } `
144144 const adminsSql = admins === undefined ? '' : `ADMIN ${ admins . join ( ',' ) } `
145145
@@ -169,63 +169,63 @@ const singleRoleByNameSqlize = (roles: string, name: string) => {
169169const alterRoleSqlize = ( {
170170 oldName,
171171 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 ,
180180 password,
181- validUntil ,
181+ valid_until ,
182182} : {
183183 oldName : string
184184 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
193193 password ?: string
194- validUntil ?: string
194+ valid_until ?: string
195195} ) => {
196196 const nameSql = name === undefined ? '' : `ALTER ROLE "${ oldName } " RENAME TO "${ name } ";`
197197 let isSuperuserSql = ''
198- if ( isSuperuser !== undefined ) {
199- isSuperuserSql = isSuperuser ? 'SUPERUSER' : 'NOSUPERUSER'
198+ if ( is_superuser !== undefined ) {
199+ isSuperuserSql = is_superuser ? 'SUPERUSER' : 'NOSUPERUSER'
200200 }
201201 let canCreateDbSql = ''
202- if ( canCreateDb !== undefined ) {
203- canCreateDbSql = canCreateDb ? 'CREATEDB' : 'NOCREATEDB'
202+ if ( can_create_db !== undefined ) {
203+ canCreateDbSql = can_create_db ? 'CREATEDB' : 'NOCREATEDB'
204204 }
205205 let canCreateRoleSql = ''
206- if ( canCreateRole !== undefined ) {
207- canCreateRoleSql = canCreateRole ? 'CREATEROLE' : 'NOCREATEROLE'
206+ if ( can_create_role !== undefined ) {
207+ canCreateRoleSql = can_create_role ? 'CREATEROLE' : 'NOCREATEROLE'
208208 }
209209 let inheritRoleSql = ''
210- if ( inheritRole !== undefined ) {
211- inheritRoleSql = inheritRole ? 'INHERIT' : 'NOINHERIT'
210+ if ( inherit_role !== undefined ) {
211+ inheritRoleSql = inherit_role ? 'INHERIT' : 'NOINHERIT'
212212 }
213213 let canLoginSql = ''
214- if ( canLogin !== undefined ) {
215- canLoginSql = canLogin ? 'LOGIN' : 'NOLOGIN'
214+ if ( can_login !== undefined ) {
215+ canLoginSql = can_login ? 'LOGIN' : 'NOLOGIN'
216216 }
217217 let isReplicationRoleSql = ''
218- if ( isReplicationRole !== undefined ) {
219- isReplicationRoleSql = isReplicationRole ? 'REPLICATION' : 'NOREPLICATION'
218+ if ( is_replication_role !== undefined ) {
219+ isReplicationRoleSql = is_replication_role ? 'REPLICATION' : 'NOREPLICATION'
220220 }
221221 let canBypassRlsSql = ''
222- if ( canBypassRls !== undefined ) {
223- canBypassRlsSql = canBypassRls ? 'BYPASSRLS' : 'NOBYPASSRLS'
222+ if ( can_bypass_rls !== undefined ) {
223+ canBypassRlsSql = can_bypass_rls ? 'BYPASSRLS' : 'NOBYPASSRLS'
224224 }
225225 const connectionLimitSql =
226- connectionLimit === undefined ? '' : `CONNECTION LIMIT ${ connectionLimit } `
226+ connection_limit === undefined ? '' : `CONNECTION LIMIT ${ connection_limit } `
227227 let passwordSql = password === undefined ? '' : `PASSWORD '${ password } '`
228- let validUntilSql = validUntil === undefined ? '' : `VALID UNTIL '${ validUntil } '`
228+ let validUntilSql = valid_until === undefined ? '' : `VALID UNTIL '${ valid_until } '`
229229
230230 return `
231231BEGIN;
0 commit comments