(ctx context.Context, in *registerDomainInput)
| 347 | } |
| 348 | |
| 349 | func (s *Server) handleRegisterDomain(ctx context.Context, in *registerDomainInput) (*domainCreateOutput, error) { |
| 350 | user, err := s.requireAccountUser(ctx) |
| 351 | if err != nil { |
| 352 | return nil, err |
| 353 | } |
| 354 | normalized, err := agent.ValidateDomain(in.Body.Domain) |
| 355 | if err != nil { |
| 356 | return nil, NewError(http.StatusBadRequest, "invalid_domain", err.Error()) |
| 357 | } |
| 358 | if s.deps.SharedDomain != "" && strings.EqualFold(normalized, s.deps.SharedDomain) { |
| 359 | return nil, NewError(http.StatusBadRequest, "reserved_domain", "reserved domain") |
| 360 | } |
| 361 | if s.deps.EnforceDomainCreate != nil { |
| 362 | if err := s.deps.EnforceDomainCreate(ctx, user.ID); err != nil { |
| 363 | if env, ok := limitEnvelope(err); ok { |
| 364 | return nil, env |
| 365 | } |
| 366 | return nil, NewError(http.StatusInternalServerError, "internal_error", "limits check failed") |
| 367 | } |
| 368 | } |
| 369 | d, err := s.deps.ClaimDomain(ctx, normalized, user.ID) |
| 370 | if err != nil { |
| 371 | if errors.Is(err, identity.ErrDomainTaken) { |
| 372 | return nil, NewError(http.StatusConflict, "domain_taken", "domain is already claimed by another account") |
| 373 | } |
| 374 | return nil, NewError(http.StatusBadRequest, "domain_unavailable", "failed to register domain") |
| 375 | } |
| 376 | if d == nil { |
| 377 | return nil, NewError(http.StatusBadRequest, "domain_unavailable", "failed to register domain") |
| 378 | } |
| 379 | return &domainCreateOutput{Body: s.domainView(d)}, nil |
| 380 | } |
| 381 | |
| 382 | type deleteDomainOutput struct{} |
| 383 |
nothing calls this directly
no test coverage detected