()
| 25 | } |
| 26 | |
| 27 | func generate() ([]byte, error) { |
| 28 | allNames := collectAllScopeNames() |
| 29 | publicNames := rbac.ExternalScopeNames() |
| 30 | |
| 31 | var b bytes.Buffer |
| 32 | if _, err := b.WriteString("// Code generated by scripts/apikeyscopesgen. DO NOT EDIT.\n"); err != nil { |
| 33 | return nil, err |
| 34 | } |
| 35 | if _, err := b.WriteString("package codersdk\n\n"); err != nil { |
| 36 | return nil, err |
| 37 | } |
| 38 | // NOTE: Keep all APIKeyScope constants in a single generated file. |
| 39 | // Some tooling (e.g. swaggo) can behave non-deterministically when |
| 40 | // enums are spread across multiple files: |
| 41 | // https://github.com/swaggo/swag/issues/2038 |
| 42 | // We generate everything into codersdk/apikey_scopes_gen.go as the |
| 43 | // single source of truth so doc generation remains stable. |
| 44 | |
| 45 | // Constants |
| 46 | if _, err := b.WriteString("const (\n"); err != nil { |
| 47 | return nil, err |
| 48 | } |
| 49 | // Always include legacy/deprecated aliases for backward compatibility. |
| 50 | // These are kept in generated code to ensure consistent availability |
| 51 | // across releases even if hand-written files change. |
| 52 | if _, err := b.WriteString("\t// Deprecated: use codersdk.APIKeyScopeCoderAll instead.\n"); err != nil { |
| 53 | return nil, err |
| 54 | } |
| 55 | if _, err := b.WriteString("\tAPIKeyScopeAll APIKeyScope = \"all\"\n"); err != nil { |
| 56 | return nil, err |
| 57 | } |
| 58 | if _, err := b.WriteString("\t// Deprecated: use codersdk.APIKeyScopeCoderApplicationConnect instead.\n"); err != nil { |
| 59 | return nil, err |
| 60 | } |
| 61 | if _, err := b.WriteString("\tAPIKeyScopeApplicationConnect APIKeyScope = \"application_connect\"\n"); err != nil { |
| 62 | return nil, err |
| 63 | } |
| 64 | for _, name := range allNames { |
| 65 | constName := constNameForScope(name) |
| 66 | if _, err := fmt.Fprintf(&b, "\t%s APIKeyScope = \"%s\"\n", constName, name); err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | } |
| 70 | if _, err := b.WriteString(")\n\n"); err != nil { |
| 71 | return nil, err |
| 72 | } |
| 73 | |
| 74 | // Slices |
| 75 | if _, err := b.WriteString("// PublicAPIKeyScopes lists all public low-level API key scopes.\n"); err != nil { |
| 76 | return nil, err |
| 77 | } |
| 78 | if _, err := b.WriteString("var PublicAPIKeyScopes = []APIKeyScope{\n"); err != nil { |
| 79 | return nil, err |
| 80 | } |
| 81 | for _, name := range publicNames { |
| 82 | constName := constNameForScope(name) |
| 83 | if _, err := fmt.Fprintf(&b, "\t%s,\n", constName); err != nil { |
| 84 | return nil, err |
no test coverage detected