()
| 21 | var dumpPathFlag = flag.String("dump", defaultDumpPath, "path to dump.sql (defaults to coderd/database/dump.sql)") |
| 22 | |
| 23 | func main() { |
| 24 | flag.Parse() |
| 25 | |
| 26 | want := expectedFromRBAC() |
| 27 | have, err := enumValuesFromDump(*dumpPathFlag) |
| 28 | if err != nil { |
| 29 | _, _ = fmt.Fprintf(os.Stderr, "check-scopes: error reading dump: %v\n", err) |
| 30 | os.Exit(2) |
| 31 | } |
| 32 | |
| 33 | // Compute missing: want - have |
| 34 | var missing []string |
| 35 | for k := range want { |
| 36 | if _, ok := have[k]; !ok { |
| 37 | missing = append(missing, k) |
| 38 | } |
| 39 | } |
| 40 | slices.Sort(missing) |
| 41 | |
| 42 | if len(missing) == 0 { |
| 43 | _, _ = fmt.Println("check-scopes: OK — all RBAC <resource>:<action> values exist in api_key_scope enum") |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | _, _ = fmt.Fprintln(os.Stderr, "check-scopes: missing enum values:") |
| 48 | for _, m := range missing { |
| 49 | _, _ = fmt.Fprintf(os.Stderr, " - %s\n", m) |
| 50 | } |
| 51 | _, _ = fmt.Fprintln(os.Stderr) |
| 52 | _, _ = fmt.Fprintln(os.Stderr, "To fix: add a DB migration extending the enum, e.g.:") |
| 53 | for _, m := range missing { |
| 54 | _, _ = fmt.Fprintf(os.Stderr, " ALTER TYPE api_key_scope ADD VALUE IF NOT EXISTS '%s';\n", m) |
| 55 | } |
| 56 | _, _ = fmt.Fprintln(os.Stderr) |
| 57 | _, _ = fmt.Fprintln(os.Stderr, "Also decide if each new scope is external (exposed in the `externalLowLevel` in coderd/rbac/scopes_catalog.go) or internal-only.") |
| 58 | os.Exit(1) |
| 59 | } |
| 60 | |
| 61 | // expectedFromRBAC returns the set of scope names the DB enum must support. |
| 62 | func expectedFromRBAC() map[string]struct{} { |
nothing calls this directly
no test coverage detected