MCPcopy Index your code
hub / github.com/coder/coder / main

Function main

scripts/check-scopes/main.go:23–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21var dumpPathFlag = flag.String("dump", defaultDumpPath, "path to dump.sql (defaults to coderd/database/dump.sql)")
22
23func 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.
62func expectedFromRBAC() map[string]struct{} {

Callers

nothing calls this directly

Calls 4

expectedFromRBACFunction · 0.85
enumValuesFromDumpFunction · 0.85
ExitMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected