Remove deadcode

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-03-13 16:50:35 +01:00
parent 7fd4221199
commit ef76a8d2e1
76 changed files with 137 additions and 4424 deletions

View File

@@ -566,46 +566,3 @@ WHERE
return nil
}
func (sacs *ApplicabilityStatements) CountByControlID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
controlID gid.GID,
) (int, error) {
q := `
WITH soac_ctrl AS (
SELECT
soac.id,
soac.organization_id,
soac.tenant_id
FROM
applicability_statements soac
INNER JOIN
states_of_applicability soa ON soac.state_of_applicability_id = soa.id
WHERE
soac.%[1]s
AND soac.control_id = @control_id
AND soa.snapshot_id IS NULL
)
SELECT
COUNT(id)
FROM
soac_ctrl
WHERE
%[1]s;
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"control_id": controlID}
maps.Copy(args, scope.SQLArguments())
row := conn.QueryRow(ctx, q, args)
var count int
if err := row.Scan(&count); err != nil {
return 0, fmt.Errorf("cannot scan count: %w", err)
}
return count, nil
}

View File

@@ -385,44 +385,6 @@ WHERE
return nil
}
func (a *Audits) CountByControlID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
controlID gid.GID,
) (int, error) {
q := `
WITH audits_by_control AS (
SELECT
a.id,
a.tenant_id
FROM
audits a
INNER JOIN
controls_audits ca ON a.id = ca.audit_id
WHERE
ca.control_id = @control_id
)
SELECT
COUNT(id)
FROM
audits_by_control
WHERE %s
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"control_id": controlID}
maps.Copy(args, scope.SQLArguments())
row := conn.QueryRow(ctx, q, args)
var count int
if err := row.Scan(&count); err != nil {
return 0, fmt.Errorf("cannot scan count: %w", err)
}
return count, nil
}
func (a *Audits) LoadByControlID(
ctx context.Context,

View File

@@ -39,15 +39,6 @@ type (
CachedCertificates []*CachedCertificate
)
func NewCachedCertificate(domain string, domainID gid.GID) *CachedCertificate {
now := time.Now()
return &CachedCertificate{
Domain: domain,
CustomDomainID: domainID,
CachedAt: now,
}
}
func (cc *CachedCertificate) LoadByDomain(ctx context.Context, conn pg.Conn, domain string) error {
q := `
SELECT

View File

@@ -397,32 +397,3 @@ WHERE %s
return nil
}
func (c *ComplianceFrameworks) CountByTrustCenterID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
trustCenterID gid.GID,
) (int, error) {
q := `
SELECT
COUNT(*)
FROM
compliance_frameworks
WHERE
%s
AND trust_center_id = @trust_center_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"trust_center_id": trustCenterID}
maps.Copy(args, scope.SQLArguments())
var count int
err := conn.QueryRow(ctx, q, args).Scan(&count)
if err != nil {
return 0, fmt.Errorf("cannot count compliance frameworks: %w", err)
}
return count, nil
}

View File

@@ -72,44 +72,6 @@ func (c *Connector) AuthorizationAttributes(ctx context.Context, conn pg.Conn) (
return map[string]string{"organization_id": organizationID.String()}, nil
}
func (c *Connectors) LoadByOrganizationID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
organizationID gid.GID,
cursor *page.Cursor[ConnectorOrderField],
encryptionKey cipher.EncryptionKey,
filter *ConnectorFilter,
) error {
if err := c.loadByOrganizationIDWithPagination(ctx, conn, scope, organizationID, cursor, filter); err != nil {
return fmt.Errorf("cannot load connectors by organization ID: %w", err)
}
if err := c.decryptConnections(encryptionKey); err != nil {
return fmt.Errorf("cannot decrypt connections: %w", err)
}
return nil
}
func (c *Connectors) LoadAllByOrganizationID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
organizationID gid.GID,
encryptionKey cipher.EncryptionKey,
) error {
if err := c.loadAllByOrganizationID(ctx, conn, scope, organizationID); err != nil {
return fmt.Errorf("cannot load all connectors by organization ID: %w", err)
}
if err := c.decryptConnections(encryptionKey); err != nil {
return fmt.Errorf("cannot decrypt connections: %w", err)
}
return nil
}
func (c *Connectors) LoadAllByOrganizationIDProtocolAndProvider(
ctx context.Context,
conn pg.Conn,

View File

@@ -696,52 +696,6 @@ LIMIT 1;
return nil
}
func (c *Controls) LoadByIDs(
ctx context.Context,
conn pg.Conn,
scope Scoper,
controlIDs []gid.GID,
) error {
if len(controlIDs) == 0 {
*c = Controls{}
return nil
}
q := `
SELECT
id,
section_title,
framework_id,
organization_id,
name,
description,
best_practice,
created_at,
updated_at
FROM
controls
WHERE
%s
AND id = ANY(@control_ids)
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"control_ids": controlIDs}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query controls: %w", err)
}
controls, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Control])
if err != nil {
return fmt.Errorf("cannot collect controls: %w", err)
}
*c = controls
return nil
}
func (c Control) Insert(
ctx context.Context,
conn pg.Conn,
@@ -866,49 +820,6 @@ WHERE %s
return nil
}
func (c *Controls) CountByAuditID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
auditID gid.GID,
filter *ControlFilter,
) (int, error) {
q := `
WITH ctrl AS (
SELECT
c.id,
c.tenant_id,
c.search_vector
FROM
controls c
INNER JOIN
controls_audits ca ON c.id = ca.control_id
WHERE
ca.audit_id = @audit_id
)
SELECT
COUNT(id)
FROM
ctrl
WHERE %s
AND %s
`
q = fmt.Sprintf(q, scope.SQLFragment(), filter.SQLFragment())
args := pgx.NamedArgs{"audit_id": auditID}
maps.Copy(args, scope.SQLArguments())
maps.Copy(args, filter.SQLArguments())
row := conn.QueryRow(ctx, q, args)
var count int
if err := row.Scan(&count); err != nil {
return 0, fmt.Errorf("cannot scan count: %w", err)
}
return count, nil
}
func (c *Controls) LoadByAuditID(
ctx context.Context,
conn pg.Conn,
@@ -976,49 +887,6 @@ WHERE %s
return nil
}
func (c *Controls) CountBySnapshotID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
snapshotID gid.GID,
filter *ControlFilter,
) (int, error) {
q := `
WITH ctrl AS (
SELECT
c.id,
c.tenant_id,
c.search_vector
FROM
controls c
INNER JOIN
controls_snapshots cs ON c.id = cs.control_id
WHERE
cs.snapshot_id = @snapshot_id
)
SELECT
COUNT(id)
FROM
ctrl
WHERE %s
AND %s
`
q = fmt.Sprintf(q, scope.SQLFragment(), filter.SQLFragment())
args := pgx.NamedArgs{"snapshot_id": snapshotID}
maps.Copy(args, scope.SQLArguments())
maps.Copy(args, filter.SQLArguments())
row := conn.QueryRow(ctx, q, args)
var count int
if err := row.Scan(&count); err != nil {
return 0, fmt.Errorf("cannot scan count: %w", err)
}
return count, nil
}
func (c *Controls) LoadBySnapshotID(
ctx context.Context,
conn pg.Conn,

View File

@@ -99,74 +99,3 @@ WHERE
return err
}
func (cas *ControlAudits) LoadByControlID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
controlID gid.GID,
) error {
q := `
SELECT
control_id,
audit_id,
created_at
FROM
controls_audits
WHERE
%s
AND control_id = @control_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"control_id": controlID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query control_audits: %w", err)
}
controlAudits, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[ControlAudit])
if err != nil {
return fmt.Errorf("cannot collect control_audits: %w", err)
}
*cas = controlAudits
return nil
}
func (cas *ControlAudits) LoadByAuditID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
auditID gid.GID,
) error {
q := `
SELECT
control_id,
audit_id,
created_at
FROM
controls_audits
WHERE
%s
AND audit_id = @audit_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"audit_id": auditID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query control_audits: %w", err)
}
controlAudits, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[ControlAudit])
if err != nil {
return fmt.Errorf("cannot collect control_audits: %w", err)
}
*cas = controlAudits
return nil
}

View File

@@ -100,43 +100,6 @@ WHERE
return err
}
func (cms *ControlMeasures) LoadByMeasureID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
measureID gid.GID,
) error {
q := `
SELECT
control_id,
measure_id,
tenant_id,
created_at
FROM
controls_measures
WHERE
%s
AND measure_id = @measure_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"measure_id": measureID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query control_measures: %w", err)
}
controlMeasures, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[ControlMeasure])
if err != nil {
return fmt.Errorf("cannot collect control_measures: %w", err)
}
*cms = controlMeasures
return nil
}
type ControlWithRisk struct {
ControlID gid.GID `db:"control_id"`
}

View File

@@ -95,78 +95,6 @@ WHERE
return err
}
func (cos *ControlObligations) LoadByControlID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
controlID gid.GID,
) error {
q := `
SELECT
control_id,
obligation_id,
created_at
FROM
controls_obligations
WHERE
%s
AND control_id = @control_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"control_id": controlID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query control_obligations: %w", err)
}
controlObligations, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[ControlObligation])
if err != nil {
return fmt.Errorf("cannot collect control_obligations: %w", err)
}
*cos = controlObligations
return nil
}
func (cos *ControlObligations) LoadByObligationID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
obligationID gid.GID,
) error {
q := `
SELECT
control_id,
obligation_id,
created_at
FROM
controls_obligations
WHERE
%s
AND obligation_id = @obligation_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"obligation_id": obligationID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query control_obligations: %w", err)
}
controlObligations, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[ControlObligation])
if err != nil {
return fmt.Errorf("cannot collect control_obligations: %w", err)
}
*cos = controlObligations
return nil
}
func (cos *ControlObligations) CountByControlID(
ctx context.Context,
conn pg.Conn,

View File

@@ -99,74 +99,3 @@ WHERE
return err
}
func (css *ControlSnapshots) LoadByControlID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
controlID gid.GID,
) error {
q := `
SELECT
control_id,
snapshot_id,
created_at
FROM
controls_snapshots
WHERE
%s
AND control_id = @control_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"control_id": controlID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query controls_snapshots: %w", err)
}
controlSnapshots, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[ControlSnapshot])
if err != nil {
return fmt.Errorf("cannot collect controls_snapshots: %w", err)
}
*css = controlSnapshots
return nil
}
func (css *ControlSnapshots) LoadBySnapshotID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
snapshotID gid.GID,
) error {
q := `
SELECT
control_id,
snapshot_id,
created_at
FROM
controls_snapshots
WHERE
%s
AND snapshot_id = @snapshot_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"snapshot_id": snapshotID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query controls_snapshots: %w", err)
}
controlSnapshots, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[ControlSnapshot])
if err != nil {
return fmt.Errorf("cannot collect controls_snapshots: %w", err)
}
*css = controlSnapshots
return nil
}

View File

@@ -14,11 +14,6 @@
package coredata
import (
"database/sql/driver"
"fmt"
)
type CustomDomainVerificationStatus string
const (
@@ -26,41 +21,3 @@ const (
CustomDomainVerificationStatusVerified CustomDomainVerificationStatus = "VERIFIED"
CustomDomainVerificationStatusFailed CustomDomainVerificationStatus = "FAILED"
)
func (s CustomDomainVerificationStatus) MarshalText() ([]byte, error) {
return []byte(s.String()), nil
}
func (s *CustomDomainVerificationStatus) UnmarshalText(data []byte) error {
val := string(data)
switch val {
case CustomDomainVerificationStatusPending.String():
*s = CustomDomainVerificationStatusPending
case CustomDomainVerificationStatusVerified.String():
*s = CustomDomainVerificationStatusVerified
case CustomDomainVerificationStatusFailed.String():
*s = CustomDomainVerificationStatusFailed
default:
return fmt.Errorf("invalid CustomDomainVerificationStatus value: %q", val)
}
return nil
}
func (s CustomDomainVerificationStatus) String() string {
return string(s)
}
func (s *CustomDomainVerificationStatus) Scan(value any) error {
val, ok := value.(string)
if !ok {
return fmt.Errorf("invalid scan source for CustomDomainVerificationStatus, expected string got %T", value)
}
return s.UnmarshalText([]byte(val))
}
func (s CustomDomainVerificationStatus) Value() (driver.Value, error) {
return s.String(), nil
}

View File

@@ -241,53 +241,6 @@ LIMIT 1;
return nil
}
func (f *Frameworks) LoadByIDs(
ctx context.Context,
conn pg.Conn,
scope Scoper,
frameworkIDs []gid.GID,
) error {
if len(frameworkIDs) == 0 {
*f = Frameworks{}
return nil
}
q := `
SELECT
id,
organization_id,
reference_id,
name,
description,
light_logo_file_id,
dark_logo_file_id,
created_at,
updated_at
FROM
frameworks
WHERE
%s
AND id = ANY(@framework_ids)
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"framework_ids": frameworkIDs}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query frameworks: %w", err)
}
frameworks, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Framework])
if err != nil {
return fmt.Errorf("cannot collect frameworks: %w", err)
}
*f = frameworks
return nil
}
func (f Framework) Insert(
ctx context.Context,
conn pg.Conn,

View File

@@ -18,7 +18,6 @@ import (
"context"
"errors"
"fmt"
"maps"
"strings"
"time"
@@ -54,84 +53,6 @@ func (i Identity) CursorKey(orderBy IdentityOrderField) page.CursorKey {
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
}
func (i *Identities) LoadByOrganizationID(
ctx context.Context,
conn pg.Conn,
organizationID gid.GID,
cursor *page.Cursor[IdentityOrderField],
) error {
q := `
SELECT
id,
email_address,
full_name,
hashed_password,
email_address_verified,
saml_subject,
created_at,
updated_at
FROM
identities
WHERE
id IN (
SELECT identity_id FROM iam_memberships WHERE organization_id = @organization_id
)
AND %s
`
q = fmt.Sprintf(q, cursor.SQLFragment())
args := pgx.StrictNamedArgs{"organization_id": organizationID}
maps.Copy(args, cursor.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query identities: %w", err)
}
identities, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Identity])
if err != nil {
return fmt.Errorf("cannot collect identities: %w", err)
}
*i = identities
return nil
}
func (i *Identities) CountByOrganizationID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
organizationID gid.GID,
) (int, error) {
q := `
SELECT
COUNT(*)
FROM
identities
WHERE
id IN (
SELECT identity_id FROM iam_memberships WHERE organization_id = @organization_id AND %s
)
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"organization_id": organizationID}
maps.Copy(args, scope.SQLArguments())
row := conn.QueryRow(ctx, q, args)
var count int
err := row.Scan(&count)
if err != nil {
return 0, fmt.Errorf("cannot count identities: %w", err)
}
return count, nil
}
// Tenant id scope is not applied because we want to access identities across all tenants for authentication purposes.
func (i *Identity) LoadByEmail(
ctx context.Context,

View File

@@ -17,7 +17,6 @@ package coredata
import (
"context"
"fmt"
"maps"
"time"
"github.com/jackc/pgx/v5"
@@ -36,46 +35,6 @@ type (
MeetingAttendees []*MeetingAttendee
)
func (ma *MeetingAttendees) LoadByMeetingID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
meetingID gid.GID,
) error {
q := `
SELECT
meeting_id,
attendee_profile_id,
organization_id,
created_at
FROM
meeting_attendees
WHERE
%s
AND meeting_id = @meeting_id
ORDER BY
created_at ASC
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"meeting_id": meetingID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query meeting attendees: %w", err)
}
attendees, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[MeetingAttendee])
if err != nil {
return fmt.Errorf("cannot collect meeting attendees: %w", err)
}
*ma = attendees
return nil
}
func (ma *MeetingAttendees) Merge(
ctx context.Context,
conn pg.Conn,

View File

@@ -183,169 +183,6 @@ WHERE
return nil
}
func (o *Organizations) LoadAllByIdentityID(
ctx context.Context,
conn pg.Conn,
identityID gid.GID,
) error {
q := `
WITH identity_org AS (
SELECT
organization_id
FROM
iam_memberships
WHERE
identity_id = @identity_id
)
SELECT
tenant_id,
id,
name,
description,
website_url,
email,
headquarter_address,
custom_domain_id,
logo_file_id,
horizontal_logo_file_id,
created_at,
updated_at
FROM
organizations
INNER JOIN
identity_org ON organizations.id = identity_org.organization_id
ORDER BY
name ASC
`
args := pgx.StrictNamedArgs{"identity_id": identityID}
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query organizations: %w", err)
}
organizations, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Organization])
if err != nil {
return fmt.Errorf("cannot collect organizations: %w", err)
}
*o = organizations
return nil
}
func (o *Organizations) LoadAllByIdentityIDWithRole(
ctx context.Context,
conn pg.Conn,
identityID gid.GID,
role MembershipRole,
) error {
q := `
WITH identity_org AS (
SELECT
organization_id
FROM
iam_memberships
WHERE
identity_id = @identity_id
AND role = @role
)
SELECT
tenant_id,
id,
name,
description,
website_url,
email,
headquarter_address,
custom_domain_id,
logo_file_id,
horizontal_logo_file_id,
created_at,
updated_at
FROM
organizations
INNER JOIN
identity_org ON organizations.id = identity_org.organization_id
ORDER BY
name ASC
`
args := pgx.StrictNamedArgs{
"identity_id": identityID,
"role": role,
}
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query organizations: %w", err)
}
organizations, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Organization])
if err != nil {
return fmt.Errorf("cannot collect organizations: %w", err)
}
*o = organizations
return nil
}
func (o *Organizations) LoadAllByPersonalAPIKeyID(
ctx context.Context,
conn pg.Conn,
personalAPIKeyID gid.GID,
) error {
q := `
WITH personal_api_key_org AS (
SELECT
am.organization_id
FROM
iam_personal_api_key_memberships akm
INNER JOIN
iam_memberships am ON akm.membership_id = am.id
WHERE
akm.personal_api_key_id = @personal_api_key_id
)
SELECT
tenant_id,
id,
name,
description,
website_url,
email,
headquarter_address,
custom_domain_id,
logo_file_id,
horizontal_logo_file_id,
created_at,
updated_at
FROM
organizations
INNER JOIN
personal_api_key_org ON organizations.id = personal_api_key_org.organization_id
ORDER BY
name ASC
`
args := pgx.StrictNamedArgs{"personal_api_key_id": personalAPIKeyID}
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query organizations: %w", err)
}
organizations, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Organization])
if err != nil {
return fmt.Errorf("cannot collect organizations: %w", err)
}
*o = organizations
return nil
}
func (o *Organization) Insert(
ctx context.Context,
conn pg.Conn,
@@ -509,49 +346,3 @@ LIMIT 1
return nil
}
func (o *Organizations) BatchLoadByID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
organizationIDs []gid.GID,
) error {
q := `
SELECT
tenant_id,
id,
name,
logo_file_id,
horizontal_logo_file_id,
description,
website_url,
email,
headquarter_address,
custom_domain_id,
created_at,
updated_at
FROM
organizations
WHERE
%s
AND id = ANY(@organization_ids)
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"organization_ids": organizationIDs}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query organizations: %w", err)
}
organizations, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Organization])
if err != nil {
return fmt.Errorf("cannot collect organizations: %w", err)
}
*o = organizations
return nil
}

View File

@@ -55,63 +55,6 @@ VALUES (@id, @organization_id, @created_at, @expires_at)
return nil
}
func (s *SAMLRequest) Load(
ctx context.Context,
conn pg.Conn,
requestID string,
organizationID gid.GID,
) error {
query := `
SELECT id, organization_id, created_at, expires_at
FROM iam_saml_requests
WHERE id = @id AND organization_id = @organization_id
LIMIT 1
`
args := pgx.NamedArgs{
"id": requestID,
"organization_id": organizationID,
}
rows, err := conn.Query(ctx, query, args)
if err != nil {
return fmt.Errorf("cannot query saml_requests: %w", err)
}
req, err := pgx.CollectOneRow(rows, pgx.RowToStructByName[SAMLRequest])
if err == pgx.ErrNoRows {
return ErrResourceNotFound
}
if err != nil {
return fmt.Errorf("cannot collect saml_request: %w", err)
}
*s = req
return nil
}
func (s *SAMLRequest) IsExpired(now time.Time) bool {
return now.After(s.ExpiresAt) || now.Equal(s.ExpiresAt)
}
func (s *SAMLRequest) Delete(
ctx context.Context,
conn pg.Conn,
) error {
query := `
DELETE FROM iam_saml_requests
WHERE id = @id
`
_, err := conn.Exec(ctx, query, pgx.NamedArgs{"id": s.ID})
if err != nil {
return fmt.Errorf("cannot delete saml_request: %w", err)
}
return nil
}
func LoadValidRequestIDsForOrganization(
ctx context.Context,
conn pg.Conn,