Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitadb7521

Browse files
authored
feat: generate RBAC scope name constants (#19896)
# Generate RBAC scope name constantsThis 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
1 parent5ff503b commitadb7521

File tree

5 files changed

+545
-0
lines changed

5 files changed

+545
-0
lines changed

‎Makefile‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ GEN_FILES := \
646646
$(SITE_GEN_FILES)\
647647
coderd/rbac/object_gen.go\
648648
codersdk/rbacresources_gen.go\
649+
coderd/rbac/scopes_constants_gen.go\
649650
docs/admin/integrations/prometheus.md\
650651
docs/reference/cli/index.md\
651652
docs/admin/security/audit-logs.md\
@@ -695,6 +696,7 @@ gen/mark-fresh:
695696
site/src/api/typesGenerated.ts\
696697
coderd/rbac/object_gen.go\
697698
codersdk/rbacresources_gen.go\
699+
coderd/rbac/scopes_constants_gen.go\
698700
site/src/api/rbacresourcesGenerated.ts\
699701
site/src/api/countriesGenerated.ts\
700702
docs/admin/integrations/prometheus.md\
@@ -842,6 +844,15 @@ coderd/rbac/object_gen.go: scripts/typegen/rbacobject.gotmpl scripts/typegen/mai
842844
rmdir -v"$$tempdir"
843845
touch"$@"
844846

847+
coderd/rbac/scopes_constants_gen.go: scripts/typegen/scopenames.gotmpl scripts/typegen/main.go coderd/rbac/policy/policy.go
848+
# Generate typed low-level ScopeName constants from RBACPermissions
849+
# Write to a temp file first to avoid truncating the package during build
850+
# since the generator imports the rbac package.
851+
tempfile=$(shell mktemp /tmp/scopes_constants_gen.XXXXXX)
852+
go run ./scripts/typegen/main.go rbac scopenames>"$$tempfile"
853+
mv -v"$$tempfile" coderd/rbac/scopes_constants_gen.go
854+
touch"$@"
855+
845856
codersdk/rbacresources_gen.go: scripts/typegen/codersdk.gotmpl scripts/typegen/main.go coderd/rbac/object.go coderd/rbac/policy/policy.go
846857
# Do no overwrite codersdk/rbacresources_gen.go directly, as it would make the file empty, breaking
847858
# the `codersdk` package and any parallel build targets.

‎coderd/rbac/scopes.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package rbac
22

33
import (
44
"fmt"
5+
"slices"
56
"strings"
67

78
"github.com/google/uuid"
@@ -107,6 +108,18 @@ var builtinScopes = map[ScopeName]Scope{
107108
},
108109
}
109110

111+
// BuiltinScopeNames returns the list of built-in high-level scope names
112+
// defined in this package (e.g., "all", "application_connect"). The result
113+
// is sorted for deterministic ordering in code generation and tests.
114+
funcBuiltinScopeNames() []ScopeName {
115+
names:=make([]ScopeName,0,len(builtinScopes))
116+
forname:=rangebuiltinScopes {
117+
names=append(names,name)
118+
}
119+
slices.Sort(names)
120+
returnnames
121+
}
122+
110123
typeExpandableScopeinterface {
111124
Expand() (Scope,error)
112125
// Name is for logging and tracing purposes, we want to know the human

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp