mirror of
https://github.com/coder/coder.git
synced 2026-06-03 21:18:24 +00:00
adb7521066
# Generate RBAC scope name constants This PR adds a new generated file `coderd/rbac/scopes_constants_gen.go` that contains typed constants for all RBAC scope names in the format `Scope<Resource><Action>`. For example, `ScopeWorkspaceRead` for the scope "workspace:read". These constants make it easier to reference specific scopes in code without using string literals, improving type safety and making refactoring easier. The PR: - Adds a new template file `scripts/typegen/scopenames.gotmpl` - Updates the typegen script to support generating scope name constants - Updates the Makefile to include the new generated file in build targets
37 lines
1.2 KiB
Go Template
37 lines
1.2 KiB
Go Template
// Code generated by: go run ./scripts/typegen rbac scopenames; DO NOT EDIT.
|
|
package rbac
|
|
|
|
// ScopeName constants generated from policy.RBACPermissions.
|
|
// These represent low-level "<resource>:<action>" scope names.
|
|
// Built-in non-low-level scopes like "all" and "application_connect" remain
|
|
// declared in code, not here, to avoid duplication.
|
|
|
|
const (
|
|
{{- range $def := . }}
|
|
{{- $Res := pascalCaseName $def.Type }}
|
|
{{- range $act := actionsOf $def }}
|
|
Scope{{$Res}}{{ pascalCaseName $act }} ScopeName = "{{ $def.Type }}:{{ $act }}"
|
|
{{- end }}
|
|
{{- end }}
|
|
)
|
|
|
|
// Valid reports whether the ScopeName matches one of the known scope values.
|
|
// This includes both builtin scope names and generated low-level scopes.
|
|
// Builtins are sourced from rbac.BuiltinScopeNames() at generation time to
|
|
// ensure changes in rbac/scopes.go remain in sync here.
|
|
func (e ScopeName) Valid() bool {
|
|
switch e {
|
|
case {{ allCaseList . }}:
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// AllScopeNameValues returns a slice containing all known scope values,
|
|
// including builtin and generated low-level scopes.
|
|
func AllScopeNameValues() []ScopeName {
|
|
return []ScopeName{
|
|
{{ allCaseList . }},
|
|
}
|
|
}
|