mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-09 09:18:59 +00:00
5dc698307b
Mechanical sed across the main go.mod's module declaration, the f5-mock-icontrol
sub-module's go.mod, every Go file's import path (361 files), and a rebuild of
the checked-in f5-mock-icontrol binary so its embedded build-info reflects the
new module path. No behavior change.
Choice B from cowork/transfer-certctl-to-org.md, executed 2026-05-04. Choice A
(keep module path declared as github.com/shankar0123/certctl regardless of
repo URL) shipped on the day of the org transfer (2026-05-03) since we had no
external Go consumers; this commit closes that deferral.
Backward-compat: GitHub HTTP redirects continue to forward
github.com/shankar0123/certctl → github.com/certctl-io/certctl at the URL
level, but Go's module proxy uses the path declared in go.mod as the
canonical name. Pre-fix, anyone trying `go get github.com/certctl-io/certctl/...`
hit a "module path mismatch" error because go.mod said
github.com/shankar0123/certctl and the URL they fetched it from said
certctl-io/certctl. Post-fix, the canonical name and the URL agree, so
go get / go install / external Go consumers / Go-tooling integrations
work cleanly via either the new path (preferred) or the old path (which
redirects and Go follows the redirect for source fetch).
Anyone still importing the old path inside their own code keeps working
provided they update their go.mod's `require` line to match — the module
path declared in their consumer's go.sum / go.mod is the authoritative
import name, so a mass sed across their import statements is the migration
on the consumer side. No external consumers exist today.
Diff shape:
361 *.go files — import path replacement only
2 go.mod — module declaration replacement only
1 binary — deploy/test/f5-mock-icontrol/f5-mock-icontrol rebuilt
so embedded build-info reflects the new path (8618965 vs
8618933 bytes; 32-byte diff is the build-info change)
Total: 364 files, 730 insertions / 730 deletions, net-zero size, pure
mechanical substitution.
Verification:
gofmt: 17 files needed re-alignment after sed (the new path is one char
shorter than the old, so column-aligned import groups drifted). Applied
`gofmt -w` to fix.
go mod tidy: clean exit on both modules.
go vet ./...: clean exit.
go build ./...: clean exit.
go test -short -count=1 on representative packages: all green
(internal/domain, internal/validation, internal/crypto, internal/crypto/signer,
cmd/agent). Test output now reads `ok github.com/certctl-io/certctl/...`
confirming the module path resolves correctly.
binary: f5-mock-icontrol rebuilt; `strings | grep shankar0123` returns
nothing; `strings | grep certctl-io/certctl` shows the new module path
embedded in build-info.
Files intentionally NOT touched in this commit:
README.md / CHANGELOG.md / docs/ / etc. — already swept to certctl-io
URLs in commit bc6039a (the post-transfer URL refresh). This commit is
purely the Go-tooling layer.
Scarf pixels (`shankar0123.docker.scarf.sh/...`) — Scarf-account
namespace, not a Go import or GitHub repo URL. Stays.
This is a non-blocking, non-customer-impacting change. Operators pulling
container images, running `make verify`, hitting the API, or installing the
agent see no functional difference. Only Go-tooling consumers (none today)
are affected, and they're enabled — not broken — by this commit.
177 lines
5.2 KiB
Go
177 lines
5.2 KiB
Go
package postgres
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/certctl-io/certctl/internal/domain"
|
|
"github.com/certctl-io/certctl/internal/repository"
|
|
"github.com/lib/pq"
|
|
)
|
|
|
|
// SCEPProbeResultRepository is the PostgreSQL-backed implementation of
|
|
// repository.SCEPProbeResultRepository.
|
|
//
|
|
// SCEP RFC 8894 + Intune master bundle Phase 11.5. Each row is one
|
|
// completed probe run; the table accumulates history (no in-place
|
|
// updates) so the GUI can show "recent probes" without losing the prior
|
|
// snapshot's CA cert metadata.
|
|
type SCEPProbeResultRepository struct {
|
|
db *sql.DB
|
|
}
|
|
|
|
// NewSCEPProbeResultRepository creates a new Postgres-backed repo.
|
|
func NewSCEPProbeResultRepository(db *sql.DB) *SCEPProbeResultRepository {
|
|
return &SCEPProbeResultRepository{db: db}
|
|
}
|
|
|
|
// Insert persists a single probe result.
|
|
func (r *SCEPProbeResultRepository) Insert(ctx context.Context, result *domain.SCEPProbeResult) error {
|
|
if result == nil {
|
|
return fmt.Errorf("scep probe result: nil")
|
|
}
|
|
_, err := r.db.ExecContext(ctx, `
|
|
INSERT INTO scep_probe_results (
|
|
id, target_url, reachable,
|
|
advertised_caps, supports_rfc8894, supports_aes,
|
|
supports_post_operation, supports_renewal,
|
|
supports_sha256, supports_sha512,
|
|
ca_cert_subject, ca_cert_issuer,
|
|
ca_cert_not_before, ca_cert_not_after, ca_cert_expired,
|
|
ca_cert_algorithm, ca_cert_chain_length,
|
|
probed_at, probe_duration_ms, error
|
|
) VALUES (
|
|
$1, $2, $3,
|
|
$4, $5, $6,
|
|
$7, $8,
|
|
$9, $10,
|
|
$11, $12,
|
|
$13, $14, $15,
|
|
$16, $17,
|
|
$18, $19, $20
|
|
)`,
|
|
result.ID, result.TargetURL, result.Reachable,
|
|
pq.Array(result.AdvertisedCaps), result.SupportsRFC8894, result.SupportsAES,
|
|
result.SupportsPOSTOperation, result.SupportsRenewal,
|
|
result.SupportsSHA256, result.SupportsSHA512,
|
|
nullString(result.CACertSubject), nullString(result.CACertIssuer),
|
|
nullTime(result.CACertNotBefore), nullTime(result.CACertNotAfter), result.CACertExpired,
|
|
nullString(result.CACertAlgorithm), result.CACertChainLength,
|
|
result.ProbedAt, result.ProbeDurationMs, nullString(result.Error),
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("insert scep probe result: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ListRecent returns the most recent N probe results across any URL,
|
|
// ordered by probed_at descending. limit is clamped to [1, 200] to bound
|
|
// the response size — the GUI defaults to 50.
|
|
func (r *SCEPProbeResultRepository) ListRecent(ctx context.Context, limit int) ([]*domain.SCEPProbeResult, error) {
|
|
if limit <= 0 {
|
|
limit = 50
|
|
}
|
|
if limit > 200 {
|
|
limit = 200
|
|
}
|
|
rows, err := r.db.QueryContext(ctx, `
|
|
SELECT id, target_url, reachable,
|
|
advertised_caps, supports_rfc8894, supports_aes,
|
|
supports_post_operation, supports_renewal,
|
|
supports_sha256, supports_sha512,
|
|
ca_cert_subject, ca_cert_issuer,
|
|
ca_cert_not_before, ca_cert_not_after, ca_cert_expired,
|
|
ca_cert_algorithm, ca_cert_chain_length,
|
|
probed_at, probe_duration_ms, error,
|
|
created_at
|
|
FROM scep_probe_results
|
|
ORDER BY probed_at DESC
|
|
LIMIT $1`,
|
|
limit,
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("list recent scep probe results: %w", err)
|
|
}
|
|
defer rows.Close()
|
|
|
|
var out []*domain.SCEPProbeResult
|
|
for rows.Next() {
|
|
var (
|
|
row domain.SCEPProbeResult
|
|
subject sql.NullString
|
|
issuer sql.NullString
|
|
notBefore sql.NullTime
|
|
notAfter sql.NullTime
|
|
algorithm sql.NullString
|
|
errString sql.NullString
|
|
)
|
|
err := rows.Scan(
|
|
&row.ID, &row.TargetURL, &row.Reachable,
|
|
pq.Array(&row.AdvertisedCaps), &row.SupportsRFC8894, &row.SupportsAES,
|
|
&row.SupportsPOSTOperation, &row.SupportsRenewal,
|
|
&row.SupportsSHA256, &row.SupportsSHA512,
|
|
&subject, &issuer,
|
|
¬Before, ¬After, &row.CACertExpired,
|
|
&algorithm, &row.CACertChainLength,
|
|
&row.ProbedAt, &row.ProbeDurationMs, &errString,
|
|
&row.CreatedAt,
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("scan scep probe result row: %w", err)
|
|
}
|
|
if subject.Valid {
|
|
row.CACertSubject = subject.String
|
|
}
|
|
if issuer.Valid {
|
|
row.CACertIssuer = issuer.String
|
|
}
|
|
if notBefore.Valid {
|
|
row.CACertNotBefore = notBefore.Time
|
|
}
|
|
if notAfter.Valid {
|
|
row.CACertNotAfter = notAfter.Time
|
|
if !row.CACertExpired {
|
|
// Re-derive days_to_expiry on read so it reflects the
|
|
// query-time wall clock rather than the persisted
|
|
// snapshot's wall clock — operators care about how
|
|
// fresh "30d remaining" is.
|
|
hours := time.Until(notAfter.Time).Hours()
|
|
row.CACertDaysToExpiry = int(hours / 24)
|
|
}
|
|
}
|
|
if algorithm.Valid {
|
|
row.CACertAlgorithm = algorithm.String
|
|
}
|
|
if errString.Valid {
|
|
row.Error = errString.String
|
|
}
|
|
out = append(out, &row)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, fmt.Errorf("iterate scep probe results: %w", err)
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// nullString returns sql.NullString — empty becomes NULL.
|
|
func nullString(s string) sql.NullString {
|
|
if s == "" {
|
|
return sql.NullString{}
|
|
}
|
|
return sql.NullString{String: s, Valid: true}
|
|
}
|
|
|
|
// nullTime returns sql.NullTime — zero time becomes NULL.
|
|
func nullTime(t time.Time) sql.NullTime {
|
|
if t.IsZero() {
|
|
return sql.NullTime{}
|
|
}
|
|
return sql.NullTime{Time: t, Valid: true}
|
|
}
|
|
|
|
// Compile-time interface check.
|
|
var _ repository.SCEPProbeResultRepository = (*SCEPProbeResultRepository)(nil)
|