mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-12 20:18:52 +00:00
M-2 PR-C: Collapse Policy/Profile/Owner/Team services to ctx-first signatures
- Add ctx first param to 21 service-layer handler-interface methods
across policy.go (6), profile.go (5), owner.go (5), team.go (5)
- Replace 24 context.Background() call sites with received ctx; use
context.WithoutCancel(ctx) for subsidiary audit-recording ops to
preserve fire-and-forget audit semantics without inheriting caller
cancellation
- Add ctx first param to 21 handler-interface method signatures across
policies.go (6), profiles.go (5), owners.go (5), teams.go (5)
- Thread r.Context() through 21 HTTP handler sites (ListPolicies,
GetPolicy, CreatePolicy, UpdatePolicy, DeletePolicy, ListViolations,
ListProfiles, GetProfile, CreateProfile, UpdateProfile, DeleteProfile,
ListOwners, GetOwner, CreateOwner, UpdateOwner, DeleteOwner,
ListTeams, GetTeam, CreateTeam, UpdateTeam, DeleteTeam)
- Update MockPolicyService/MockProfileService/MockOwnerService/
MockTeamService mock method impls with _ context.Context first param
(Fn fields unchanged — closures do not need ctx); update mock impls
in integration/lifecycle_test.go for all four services
- Update 12 service-layer test callsites (policy_test.go ×2,
owner_test.go ×5, team_test.go ×5, profile_test.go ×13) to pass
context.Background() at the call site
Audit complete. Commit: 855124a9d9. Sections: 12. Findings: 2/7/10/4/6.
This commit is contained in:
+10
-10
@@ -126,7 +126,7 @@ func (s *TeamService) Delete(ctx context.Context, id string, actor string) error
|
||||
}
|
||||
|
||||
// ListTeams returns paginated teams (handler interface method).
|
||||
func (s *TeamService) ListTeams(page, perPage int) ([]domain.Team, int64, error) {
|
||||
func (s *TeamService) ListTeams(ctx context.Context, page, perPage int) ([]domain.Team, int64, error) {
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
@@ -134,7 +134,7 @@ func (s *TeamService) ListTeams(page, perPage int) ([]domain.Team, int64, error)
|
||||
perPage = 50
|
||||
}
|
||||
|
||||
teams, err := s.teamRepo.List(context.Background())
|
||||
teams, err := s.teamRepo.List(ctx)
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("failed to list teams: %w", err)
|
||||
}
|
||||
@@ -151,12 +151,12 @@ func (s *TeamService) ListTeams(page, perPage int) ([]domain.Team, int64, error)
|
||||
}
|
||||
|
||||
// GetTeam returns a single team (handler interface method).
|
||||
func (s *TeamService) GetTeam(id string) (*domain.Team, error) {
|
||||
return s.teamRepo.Get(context.Background(), id)
|
||||
func (s *TeamService) GetTeam(ctx context.Context, id string) (*domain.Team, error) {
|
||||
return s.teamRepo.Get(ctx, id)
|
||||
}
|
||||
|
||||
// CreateTeam creates a new team (handler interface method).
|
||||
func (s *TeamService) CreateTeam(team domain.Team) (*domain.Team, error) {
|
||||
func (s *TeamService) CreateTeam(ctx context.Context, team domain.Team) (*domain.Team, error) {
|
||||
if team.ID == "" {
|
||||
team.ID = generateID("team")
|
||||
}
|
||||
@@ -167,22 +167,22 @@ func (s *TeamService) CreateTeam(team domain.Team) (*domain.Team, error) {
|
||||
if team.UpdatedAt.IsZero() {
|
||||
team.UpdatedAt = now
|
||||
}
|
||||
if err := s.teamRepo.Create(context.Background(), &team); err != nil {
|
||||
if err := s.teamRepo.Create(ctx, &team); err != nil {
|
||||
return nil, fmt.Errorf("failed to create team: %w", err)
|
||||
}
|
||||
return &team, nil
|
||||
}
|
||||
|
||||
// UpdateTeam modifies a team (handler interface method).
|
||||
func (s *TeamService) UpdateTeam(id string, team domain.Team) (*domain.Team, error) {
|
||||
func (s *TeamService) UpdateTeam(ctx context.Context, id string, team domain.Team) (*domain.Team, error) {
|
||||
team.ID = id
|
||||
if err := s.teamRepo.Update(context.Background(), &team); err != nil {
|
||||
if err := s.teamRepo.Update(ctx, &team); err != nil {
|
||||
return nil, fmt.Errorf("failed to update team: %w", err)
|
||||
}
|
||||
return &team, nil
|
||||
}
|
||||
|
||||
// DeleteTeam removes a team (handler interface method).
|
||||
func (s *TeamService) DeleteTeam(id string) error {
|
||||
return s.teamRepo.Delete(context.Background(), id)
|
||||
func (s *TeamService) DeleteTeam(ctx context.Context, id string) error {
|
||||
return s.teamRepo.Delete(ctx, id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user