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