|
9 | 9 | ) |
10 | 10 |
|
11 | 11 | const rolesPrefix = "roles/" |
| 12 | +const defaultUserPrefix = "vault" |
12 | 13 |
|
13 | 14 | func (b *backend) pathRoles() *framework.Path { |
14 | 15 | return &framework.Path{ |
@@ -47,6 +48,11 @@ func (b *backend) pathRoles() *framework.Path { |
47 | 48 | Type: framework.TypeString, |
48 | 49 | Description: "User time zone.", |
49 | 50 | }, |
| 51 | + "user_prefix": &framework.FieldSchema{ |
| 52 | + Type: framework.TypeString, |
| 53 | + Description: "Prefix for creating new users", |
| 54 | + Default: defaultUserPrefix, |
| 55 | + }, |
50 | 56 | }, |
51 | 57 | Callbacks: map[logical.Operation]framework.OperationFunc{ |
52 | 58 | logical.ReadOperation: b.rolesReadHandler, |
@@ -124,6 +130,12 @@ func (b *backend) rolesWriteHandler(ctx context.Context, req *logical.Request, d |
124 | 130 | if tzRaw, ok := getValue(data, req.Operation, "tz"); ok { |
125 | 131 | role.TZ = tzRaw.(string) |
126 | 132 | } |
| 133 | + if userPrefixRaw, ok := getValue(data, req.Operation, "user_prefix"); ok { |
| 134 | + role.UserPrefix = userPrefixRaw.(string) |
| 135 | + } |
| 136 | + if role.UserPrefix == "" { |
| 137 | + return logical.ErrorResponse("user_prefix can't be set to empty string"), nil |
| 138 | + } |
127 | 139 |
|
128 | 140 | if err := role.store(ctx, req.Storage, name); err != nil { |
129 | 141 | return nil, err |
|
0 commit comments