(ctx context.Context, flags *RootFlags)
| 216 | } |
| 217 | |
| 218 | func (c *AdminUsersCreateCmd) Run(ctx context.Context, flags *RootFlags) error { |
| 219 | plan, err := newAdminUserCreatePlan(adminUserCreateInput{ |
| 220 | Email: c.Email, |
| 221 | GivenName: c.GivenName, |
| 222 | FamilyName: c.FamilyName, |
| 223 | Password: c.Password, |
| 224 | ChangePwd: c.ChangePwd, |
| 225 | OrgUnit: c.OrgUnit, |
| 226 | Suspended: c.Suspended, |
| 227 | Archived: c.Archived, |
| 228 | RecoveryEmail: c.RecoveryEmail, |
| 229 | RecoveryPhone: c.RecoveryPhone, |
| 230 | HashFunction: c.HashFunction, |
| 231 | Admin: c.Admin, |
| 232 | }) |
| 233 | if err != nil { |
| 234 | return err |
| 235 | } |
| 236 | if dryRunErr := dryRunExit(ctx, flags, "admin.users.create", plan.dryRunPayload()); dryRunErr != nil { |
| 237 | return dryRunErr |
| 238 | } |
| 239 | |
| 240 | account, err := requireAdminAccount(flags) |
| 241 | if err != nil { |
| 242 | return err |
| 243 | } |
| 244 | |
| 245 | password := plan.Password |
| 246 | if plan.GeneratePassword { |
| 247 | password, err = generateAdminUserPassword(16) |
| 248 | if err != nil { |
| 249 | return fmt.Errorf("generate password: %w", err) |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | svc, err := adminDirectoryService(ctx, account) |
| 254 | if err != nil { |
| 255 | return wrapAdminDirectoryError(err, account) |
| 256 | } |
| 257 | |
| 258 | created, err := svc.Users.Insert(plan.insertRequest(password)).Context(ctx).Do() |
| 259 | if err != nil { |
| 260 | return wrapAdminDirectoryError(err, account) |
| 261 | } |
| 262 | if plan.StatePatch != nil { |
| 263 | userKey := created.PrimaryEmail |
| 264 | if strings.TrimSpace(userKey) == "" { |
| 265 | userKey = plan.Email |
| 266 | } |
| 267 | updated, patchErr := patchAdminUserState(ctx, svc, userKey, plan.StatePatch) |
| 268 | if patchErr != nil { |
| 269 | return wrapAdminDirectoryError(patchErr, account) |
| 270 | } |
| 271 | created = updated |
| 272 | } |
| 273 | |
| 274 | if outfmt.IsJSON(ctx) { |
| 275 | result := map[string]any{ |
nothing calls this directly
no test coverage detected