mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-07 16:11:29 +00:00
21aeed4f4e
Phase 0 closure (Path B2, post-rewrite):
addlicense sweep — adds the canonical certctl LLC copyright + BUSL-1.1
SPDX header to every production Go file. Template:
// Copyright 2026 certctl LLC. All rights reserved.
// SPDX-License-Identifier: BUSL-1.1
Coverage: 338 / 338 production Go files (cmd/ + internal/, excluding
*_test.go and **/testdata/**). Pre-sweep coverage was 22 / 338 (6.5%);
post-sweep is 338 / 338 (100%).
Normalized 22 pre-existing legacy headers (`// Copyright (c) certctl`
+ `// SPDX-License-Identifier: BSL-1.1`) and 1 file using a
`Certctl Contributors` attribution. The legacy SPDX ID `BSL-1.1`
is non-standard; the official SPDX identifier for Business Source
License 1.1 is `BUSL-1.1` (capital U). All 338 files now share the
canonical form.
Generated via:
addlicense -c "certctl LLC" -y 2026 \
-f cowork/legal/copyright-header.tpl \
-ignore '**/testdata/**' -ignore '**/*_test.go' \
cmd/ internal/
Verification:
find cmd internal -name '*.go' -not -name '*_test.go' \
-not -path '*/testdata/*' \
-exec grep -L '^// Copyright 2026 certctl LLC' {} \; | wc -l
Returns: 0
gofmt clean. Header additions are comments only, no compile impact.
Closes: cowork/certctl-architecture-diligence-audit.html#fix-RED-4
50 lines
1.9 KiB
Go
50 lines
1.9 KiB
Go
// Copyright 2026 certctl LLC. All rights reserved.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
userdomain "github.com/certctl-io/certctl/internal/auth/user/domain"
|
|
)
|
|
|
|
// Sentinel errors for the user repository.
|
|
var (
|
|
// ErrUserNotFound: Get / GetByOIDCSubject returned no row. Phase
|
|
// 3's HandleCallback treats this as "first login for this person;
|
|
// create the row".
|
|
ErrUserNotFound = errors.New("user: not found")
|
|
|
|
// ErrUserDuplicateOIDCSubject: Create tripped the
|
|
// (oidc_provider_id, oidc_subject) UNIQUE constraint. HTTP 409.
|
|
ErrUserDuplicateOIDCSubject = errors.New("user: a user with this provider+subject already exists")
|
|
)
|
|
|
|
// UserRepository wraps the users table. Phase 3's HandleCallback
|
|
// uses GetByOIDCSubject + Create + Update on every login; the GUI's
|
|
// admin user-list surface uses ListAll + Get.
|
|
type UserRepository interface {
|
|
// Get returns one user by id. ErrUserNotFound on miss.
|
|
Get(ctx context.Context, id string) (*userdomain.User, error)
|
|
|
|
// GetByOIDCSubject is the Phase 3 hot-path lookup at login time.
|
|
// Returns the existing row if present, ErrUserNotFound otherwise.
|
|
GetByOIDCSubject(ctx context.Context, providerID, subject string) (*userdomain.User, error)
|
|
|
|
// Create persists a new user. Caller MUST have called u.Validate().
|
|
// Returns ErrUserDuplicateOIDCSubject on UNIQUE constraint trip.
|
|
Create(ctx context.Context, u *userdomain.User) error
|
|
|
|
// Update writes the mutable field set back to the row. Immutable
|
|
// fields (id, tenant_id, oidc_subject, oidc_provider_id,
|
|
// created_at) are preserved. updated_at is set to NOW() by the
|
|
// implementation.
|
|
Update(ctx context.Context, u *userdomain.User) error
|
|
|
|
// ListAll returns every user in the tenant. Order:
|
|
// created_at ASC. Used by the GUI's admin surface.
|
|
ListAll(ctx context.Context, tenantID string) ([]*userdomain.User, error)
|
|
}
|