(ctx context.Context)
| 12 | ) |
| 13 | |
| 14 | func (d *Driver) getInstanceRoles(ctx context.Context) ([]*storepb.InstanceRole, error) { |
| 15 | query := ` |
| 16 | SELECT r.rolname, r.rolsuper, r.rolinherit, r.rolcreaterole, r.rolcreatedb, r.rolcanlogin, r.rolreplication, r.rolvaliduntil, r.rolbypassrls |
| 17 | FROM pg_catalog.pg_roles r |
| 18 | WHERE r.rolname !~ '^pg_'; |
| 19 | ` |
| 20 | var instanceRoles []*storepb.InstanceRole |
| 21 | rows, err := d.db.QueryContext(ctx, query) |
| 22 | if err != nil { |
| 23 | return nil, util.FormatErrorWithQuery(err, query) |
| 24 | } |
| 25 | defer rows.Close() |
| 26 | for rows.Next() { |
| 27 | var role string |
| 28 | var super, inherit, createRole, createDB, canLogin, replication, bypassRLS bool |
| 29 | var rolValidUntil sql.NullString |
| 30 | if err := rows.Scan( |
| 31 | &role, |
| 32 | &super, |
| 33 | &inherit, |
| 34 | &createRole, |
| 35 | &createDB, |
| 36 | &canLogin, |
| 37 | &replication, |
| 38 | &rolValidUntil, |
| 39 | &bypassRLS, |
| 40 | ); err != nil { |
| 41 | return nil, err |
| 42 | } |
| 43 | if pgparser.IsSystemUser(role) { |
| 44 | continue |
| 45 | } |
| 46 | |
| 47 | var attributes []string |
| 48 | if super { |
| 49 | attributes = append(attributes, "Superuser") |
| 50 | } |
| 51 | if !inherit { |
| 52 | attributes = append(attributes, "No inheritance") |
| 53 | } |
| 54 | if createRole { |
| 55 | attributes = append(attributes, "Create role") |
| 56 | } |
| 57 | if createDB { |
| 58 | attributes = append(attributes, "Create DB") |
| 59 | } |
| 60 | if !canLogin { |
| 61 | attributes = append(attributes, "Cannot login") |
| 62 | } |
| 63 | if replication { |
| 64 | attributes = append(attributes, "Replication") |
| 65 | } |
| 66 | if rolValidUntil.Valid { |
| 67 | attributes = append(attributes, fmt.Sprintf("Password valid until %s", rolValidUntil.String)) |
| 68 | } |
| 69 | if bypassRLS { |
| 70 | attributes = append(attributes, "Bypass RLS+") |
| 71 | } |
no test coverage detected