|
1 | 1 | /* |
2 | 2 | * Implements role creation, activation, lookup, and removal workflows. |
3 | 3 | */ |
4 | | -import { matchesIdentity, normalizeRole, type Role } from '../../domain/role.js'; |
| 4 | +import { |
| 5 | + matchesIdentity, |
| 6 | + normalizeRole, |
| 7 | + validateRoleName, |
| 8 | + type Role |
| 9 | +} from '../../domain/role.js'; |
5 | 10 | import { |
6 | 11 | type AppDependencies, |
7 | 12 | type CurrentRoleDependencies, |
@@ -81,11 +86,12 @@ export async function useRole( |
81 | 86 | name: string, |
82 | 87 | options: UseRoleOptions = {} |
83 | 88 | ): Promise<UseRoleResult> { |
84 | | - const role = await dependencies.roleStore.get(name); |
| 89 | + const roleName = validateRoleName(name); |
| 90 | + const role = await dependencies.roleStore.get(roleName); |
85 | 91 | const scope = options.scope ?? 'global'; |
86 | 92 |
|
87 | 93 | if (!role) { |
88 | | - throw new ProfileNotFoundError(name); |
| 94 | + throw new ProfileNotFoundError(roleName); |
89 | 95 | } |
90 | 96 |
|
91 | 97 | if (scope === 'local') { |
@@ -178,14 +184,15 @@ export async function importCurrentRole( |
178 | 184 | dependencies: CurrentRoleDependencies, |
179 | 185 | name: string |
180 | 186 | ): Promise<ImportCurrentRoleResult> { |
| 187 | + const roleName = validateRoleName(name); |
181 | 188 | const currentIdentity = await getEffectiveCurrentIdentity(dependencies); |
182 | 189 |
|
183 | 190 | if (!currentIdentity.fullName || !currentIdentity.email) { |
184 | 191 | throw new IncompleteCurrentIdentityError(); |
185 | 192 | } |
186 | 193 |
|
187 | 194 | const role = await addRole(dependencies, { |
188 | | - name, |
| 195 | + name: roleName, |
189 | 196 | fullName: currentIdentity.fullName, |
190 | 197 | email: currentIdentity.email |
191 | 198 | }); |
@@ -246,13 +253,14 @@ export async function removeRole( |
246 | 253 | dependencies: AppDependencies, |
247 | 254 | name: string |
248 | 255 | ): Promise<Role> { |
249 | | - const role = await dependencies.roleStore.get(name); |
| 256 | + const roleName = validateRoleName(name); |
| 257 | + const role = await dependencies.roleStore.get(roleName); |
250 | 258 |
|
251 | 259 | if (!role) { |
252 | | - throw new ProfileNotFoundError(name); |
| 260 | + throw new ProfileNotFoundError(roleName); |
253 | 261 | } |
254 | 262 |
|
255 | | - await dependencies.roleStore.remove(name); |
| 263 | + await dependencies.roleStore.remove(roleName); |
256 | 264 |
|
257 | 265 | return role; |
258 | 266 | } |
0 commit comments