fix(grant): adapt to typed grant-role enum from regenerated client · Entire
fix(grant): adapt to typed grant-role enum from regenerated client
dd3d3e3·
toothbrush·3w ago·1 file·+24 added/-2
#2122 made the v1 grant role a validated enum (reader/writer/admin), so the regenerated client types GrantProjectAccess/GrantRepoAccess Role fields as enums rather than string. Validate --role at the CLI boundary and cast to the typed value.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
e9918e472c9dView transcript
Changes
1
cmd/entire/cli
Mgrant.go+24/-2
28 unmodified lines
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
146 unmodified lines
195
196
197
198
199
200
201
202
203
204
2 unmodified lines
207
208
209
192
210
211
212
213
133 unmodified lines
347
348
349
350
351
352
353
354
355
356
357
336
358
359
360
361
28 unmodified lines
}
// validateGrantRole rejects unknown project/repo grant roles at the CLI
// boundary (reader, writer, admin) so the user gets a clear message instead of
// a server 422. The GrantProjectAccess and GrantRepoAccess input bodies use
// distinct enum types that share these values, so callers cast the validated
// string to whichever type they need.
func validateGrantRole(role string) error {
switch role {
case "reader", "writer", "admin":
return nil
default:
return fmt.Errorf("invalid --role %q: must be \"reader\", \"writer\", or \"admin\"", role)
}
}
// newGrantCmd is the hidden `entire grant` command group: manage access
// grants and org membership on the Entire control plane. Surface follows
// what the Core API exposes per resource: org and project support
146 unmodified lines
Short: "Grant access to a project",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := validateGrantRole(role); err != nil {
cmd.SilenceUsage = true
return err
}
return runCoreJSON(cmd, func(ctx context.Context, c *coreapi.Client) (any, error) {
projID, err := resolveProjectRef(ctx, c, args[0])
if err != nil {
2 unmodified lines
body := &coreapi.GrantProjectAccessInputBody{
Provider: provider,
ProviderUserId: providerUserID,
Role: role,
Role: coreapi.GrantProjectAccessInputBodyRole(role),
}
if granteeType != "" {
body.GranteeType = coreapi.NewOptGrantProjectAccessInputBodyGranteeType(coreapi.GrantProjectAccessInputBodyGranteeType(granteeType))
}
133 unmodified lines
Short: "Grant access to a repo",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := validateGrantRole(role); err != nil {
cmd.SilenceUsage = true
return err
}
return runCoreJSON(cmd, func(ctx context.Context, c *coreapi.Client) (any, error) {
body := &coreapi.GrantRepoAccessInputBody{
Provider: provider,
ProviderUserId: providerUserID,
Role: role,
Role: coreapi.GrantRepoAccessInputBodyRole(role),
}
if granteeType != "" {
body.GranteeType = coreapi.NewOptGrantRepoAccessInputBodyGranteeType(coreapi.GrantRepoAccessInputBodyGranteeType(granteeType))
}}