@@ -77,6 +77,7 @@ func (e *AccessEntry) AuthorizationAttributes(ctx context.Context, conn pg.Queri
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query access entry authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -139,6 +140,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect access entry: %w", err)
|
||||
}
|
||||
|
||||
@@ -243,6 +245,7 @@ VALUES (
|
||||
"created_at": e.CreatedAt,
|
||||
"updated_at": e.UpdatedAt,
|
||||
}
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot insert access_entry: %w", err)
|
||||
@@ -529,6 +532,7 @@ func (e *AccessEntry) LoadOrganizationID(
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return gid.GID{}, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return gid.GID{}, fmt.Errorf("cannot load organization id for access entry: %w", err)
|
||||
}
|
||||
|
||||
@@ -731,13 +735,16 @@ WHERE %s
|
||||
defer rows.Close()
|
||||
|
||||
var result []BaselineAccountEntry
|
||||
|
||||
for rows.Next() {
|
||||
var entry BaselineAccountEntry
|
||||
if err := rows.Scan(&entry.AccountKey, &entry.Email, &entry.FullName); err != nil {
|
||||
return nil, fmt.Errorf("cannot scan baseline entry: %w", err)
|
||||
}
|
||||
|
||||
result = append(result, entry)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("cannot iterate baseline entries: %w", err)
|
||||
}
|
||||
@@ -795,13 +802,16 @@ ORDER BY
|
||||
defer rows.Close()
|
||||
|
||||
var result []MembershipAccount
|
||||
|
||||
for rows.Next() {
|
||||
var account MembershipAccount
|
||||
if err := rows.Scan(&account.ID, &account.Email, &account.FullName, &account.State, &account.Role, &account.CreatedAt); err != nil {
|
||||
return nil, fmt.Errorf("cannot scan membership account: %w", err)
|
||||
}
|
||||
|
||||
result = append(result, account)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("cannot iterate membership accounts: %w", err)
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ func (a AccessEntryAccountType) String() string {
|
||||
|
||||
func (a *AccessEntryAccountType) Scan(value any) error {
|
||||
var str string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
str = v
|
||||
@@ -56,6 +57,7 @@ func (a *AccessEntryAccountType) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("cannot parse AccessEntryAccountType: invalid value %q", str)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -36,17 +36,20 @@ func TestAccessEntryAccountTypeScan(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var got AccessEntryAccountType
|
||||
|
||||
err := got.Scan(tt.input)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("Scan(%v) expected error", tt.input)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Scan(%v) returned error: %v", tt.input, err)
|
||||
}
|
||||
|
||||
if got != tt.want {
|
||||
t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
@@ -61,6 +64,7 @@ func TestAccessEntryAccountTypeValue(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Value() returned error: %v", err)
|
||||
}
|
||||
|
||||
if got != "USER" {
|
||||
t.Fatalf("Value() = %q, want %q", got, "USER")
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ func (d AccessEntryDecision) String() string {
|
||||
|
||||
func (d *AccessEntryDecision) Scan(value any) error {
|
||||
var str string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
str = v
|
||||
@@ -58,6 +59,7 @@ func (d *AccessEntryDecision) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("cannot parse AccessEntryDecision: invalid value %q", str)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ func (h *AccessEntryDecisionHistory) AuthorizationAttributes(
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot load authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -39,17 +39,20 @@ func TestAccessEntryDecisionScan(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var got AccessEntryDecision
|
||||
|
||||
err := got.Scan(tt.input)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("Scan(%v) expected error", tt.input)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Scan(%v) returned error: %v", tt.input, err)
|
||||
}
|
||||
|
||||
if got != tt.want {
|
||||
t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
@@ -78,6 +81,7 @@ func TestAccessEntryDecisionValue(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Value() returned error: %v", err)
|
||||
}
|
||||
|
||||
if got != tt.want {
|
||||
t.Fatalf("Value() = %q, want %q", got, tt.want)
|
||||
}
|
||||
|
||||
@@ -89,18 +89,23 @@ func (f *AccessEntryFilter) SQLArguments() pgx.StrictNamedArgs {
|
||||
if f.Decision != nil {
|
||||
args["filter_decision"] = string(*f.Decision)
|
||||
}
|
||||
|
||||
if f.Flag != nil {
|
||||
args["filter_flag"] = string(*f.Flag)
|
||||
}
|
||||
|
||||
if f.IncrementalTag != nil {
|
||||
args["filter_incremental_tag"] = string(*f.IncrementalTag)
|
||||
}
|
||||
|
||||
if f.IsAdmin != nil {
|
||||
args["filter_is_admin"] = *f.IsAdmin
|
||||
}
|
||||
|
||||
if f.AuthMethod != nil {
|
||||
args["filter_auth_method"] = string(*f.AuthMethod)
|
||||
}
|
||||
|
||||
if f.AccountType != nil {
|
||||
args["filter_account_type"] = string(*f.AccountType)
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ func (f AccessEntryFlag) String() string {
|
||||
|
||||
func (f *AccessEntryFlag) Scan(value any) error {
|
||||
var str string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
str = v
|
||||
@@ -88,6 +89,7 @@ func (f *AccessEntryFlag) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("cannot parse AccessEntryFlag: invalid value %q", str)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -40,17 +40,20 @@ func TestAccessEntryFlagScan(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var got AccessEntryFlag
|
||||
|
||||
err := got.Scan(tt.input)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("Scan(%v) expected error", tt.input)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Scan(%v) returned error: %v", tt.input, err)
|
||||
}
|
||||
|
||||
if got != tt.want {
|
||||
t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
@@ -65,6 +68,7 @@ func TestAccessEntryFlagValue(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Value() returned error: %v", err)
|
||||
}
|
||||
|
||||
if got != "NONE" {
|
||||
t.Fatalf("Value() = %q, want %q", got, "NONE")
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ func (t AccessEntryIncrementalTag) String() string {
|
||||
|
||||
func (t *AccessEntryIncrementalTag) Scan(value any) error {
|
||||
var str string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
str = v
|
||||
|
||||
@@ -37,17 +37,20 @@ func TestAccessEntryIncrementalTagScan(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var got AccessEntryIncrementalTag
|
||||
|
||||
err := got.Scan(tt.input)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("Scan(%v) expected error", tt.input)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Scan(%v) returned error: %v", tt.input, err)
|
||||
}
|
||||
|
||||
if got != tt.want {
|
||||
t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
@@ -62,6 +65,7 @@ func TestAccessEntryIncrementalTagValue(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Value() returned error: %v", err)
|
||||
}
|
||||
|
||||
if got != "NEW" {
|
||||
t.Fatalf("Value() = %q, want %q", got, "NEW")
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ func (p AccessEntryOrderField) Column() string {
|
||||
case AccessEntryOrderFieldCreatedAt:
|
||||
return "created_at"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", p))
|
||||
}
|
||||
|
||||
@@ -37,6 +38,7 @@ func (p AccessEntryOrderField) IsValid() bool {
|
||||
case AccessEntryOrderFieldCreatedAt:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -53,5 +55,6 @@ func (p *AccessEntryOrderField) UnmarshalText(text []byte) error {
|
||||
if !p.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid AccessEntryOrderField", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -62,14 +62,19 @@ GROUP BY decision;
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var decision AccessEntryDecision
|
||||
var count int
|
||||
var (
|
||||
decision AccessEntryDecision
|
||||
count int
|
||||
)
|
||||
|
||||
if err := rows.Scan(&decision, &count); err != nil {
|
||||
return fmt.Errorf("cannot scan decision count: %w", err)
|
||||
}
|
||||
|
||||
s.DecisionCounts[decision] = count
|
||||
s.TotalCount += count
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return fmt.Errorf("cannot iterate decision counts: %w", err)
|
||||
}
|
||||
@@ -91,13 +96,18 @@ GROUP BY f;
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var flag AccessEntryFlag
|
||||
var count int
|
||||
var (
|
||||
flag AccessEntryFlag
|
||||
count int
|
||||
)
|
||||
|
||||
if err := rows.Scan(&flag, &count); err != nil {
|
||||
return fmt.Errorf("cannot scan flag count: %w", err)
|
||||
}
|
||||
|
||||
s.FlagCounts[flag] = count
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return fmt.Errorf("cannot iterate flag counts: %w", err)
|
||||
}
|
||||
@@ -119,13 +129,18 @@ GROUP BY incremental_tag;
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var tag AccessEntryIncrementalTag
|
||||
var count int
|
||||
var (
|
||||
tag AccessEntryIncrementalTag
|
||||
count int
|
||||
)
|
||||
|
||||
if err := rows.Scan(&tag, &count); err != nil {
|
||||
return fmt.Errorf("cannot scan incremental tag count: %w", err)
|
||||
}
|
||||
|
||||
s.IncrementalTagCounts[tag] = count
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return fmt.Errorf("cannot iterate incremental tag counts: %w", err)
|
||||
}
|
||||
@@ -169,14 +184,19 @@ GROUP BY decision;
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var decision AccessEntryDecision
|
||||
var count int
|
||||
var (
|
||||
decision AccessEntryDecision
|
||||
count int
|
||||
)
|
||||
|
||||
if err := rows.Scan(&decision, &count); err != nil {
|
||||
return fmt.Errorf("cannot scan decision count: %w", err)
|
||||
}
|
||||
|
||||
s.DecisionCounts[decision] = count
|
||||
s.TotalCount += count
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return fmt.Errorf("cannot iterate decision counts: %w", err)
|
||||
}
|
||||
@@ -199,13 +219,18 @@ GROUP BY f;
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var flag AccessEntryFlag
|
||||
var count int
|
||||
var (
|
||||
flag AccessEntryFlag
|
||||
count int
|
||||
)
|
||||
|
||||
if err := rows.Scan(&flag, &count); err != nil {
|
||||
return fmt.Errorf("cannot scan flag count: %w", err)
|
||||
}
|
||||
|
||||
s.FlagCounts[flag] = count
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return fmt.Errorf("cannot iterate flag counts: %w", err)
|
||||
}
|
||||
@@ -228,13 +253,18 @@ GROUP BY incremental_tag;
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var tag AccessEntryIncrementalTag
|
||||
var count int
|
||||
var (
|
||||
tag AccessEntryIncrementalTag
|
||||
count int
|
||||
)
|
||||
|
||||
if err := rows.Scan(&tag, &count); err != nil {
|
||||
return fmt.Errorf("cannot scan incremental tag count: %w", err)
|
||||
}
|
||||
|
||||
s.IncrementalTagCounts[tag] = count
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return fmt.Errorf("cannot iterate incremental tag counts: %w", err)
|
||||
}
|
||||
|
||||
@@ -52,19 +52,23 @@ func newTestPgClient(t *testing.T) *pg.Client {
|
||||
// registry every time to avoid "duplicate collector" panics when tests
|
||||
// run in parallel.
|
||||
opts := []pg.Option{pg.WithRegisterer(prometheus.NewRegistry())}
|
||||
|
||||
if u.Host != "" {
|
||||
host := u.Host
|
||||
if u.Port() == "" {
|
||||
host = net.JoinHostPort(u.Hostname(), "5432")
|
||||
}
|
||||
|
||||
opts = append(opts, pg.WithAddr(host))
|
||||
}
|
||||
|
||||
if u.User != nil {
|
||||
opts = append(opts, pg.WithUser(u.User.Username()))
|
||||
if password, ok := u.User.Password(); ok {
|
||||
opts = append(opts, pg.WithPassword(password))
|
||||
}
|
||||
}
|
||||
|
||||
if len(u.Path) > 1 {
|
||||
opts = append(opts, pg.WithDatabase(u.Path[1:]))
|
||||
}
|
||||
@@ -146,15 +150,19 @@ func seedAccessEntryFixture(t *testing.T, ctx context.Context, client *pg.Client
|
||||
if _, err := tx.Exec(ctx, `DELETE FROM access_entries WHERE access_review_campaign_id = $1`, campaignID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(ctx, `DELETE FROM access_review_campaigns WHERE id = $1`, campaignID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(ctx, `DELETE FROM access_sources WHERE id = $1`, sourceID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(ctx, `DELETE FROM organizations WHERE id = $1`, organizationID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
})
|
||||
@@ -231,6 +239,7 @@ func TestAccessEntry_Upsert_FreezesDecidedFields(t *testing.T) {
|
||||
DecidedAt: &decisionTime,
|
||||
UpdatedAt: decisionTime,
|
||||
}
|
||||
|
||||
require.NoError(t, client.WithTx(ctx, func(ctx context.Context, tx pg.Tx) error {
|
||||
return decided.Update(ctx, tx, fx.scope)
|
||||
}))
|
||||
@@ -267,12 +276,14 @@ func TestAccessEntry_Upsert_FreezesDecidedFields(t *testing.T) {
|
||||
CreatedAt: t2,
|
||||
UpdatedAt: t2,
|
||||
}
|
||||
|
||||
require.NoError(t, client.WithTx(ctx, func(ctx context.Context, tx pg.Tx) error {
|
||||
return refresh.Upsert(ctx, tx, fx.scope)
|
||||
}))
|
||||
|
||||
// Step 4: Load and assert the freeze semantics.
|
||||
loaded := &coredata.AccessEntry{}
|
||||
|
||||
require.NoError(t, client.WithConn(ctx, func(ctx context.Context, conn pg.Querier) error {
|
||||
return loaded.LoadByID(ctx, conn, fx.scope, entryID)
|
||||
}))
|
||||
@@ -341,6 +352,7 @@ func TestAccessEntry_Upsert_RefreshesSourceTrackingFields(t *testing.T) {
|
||||
CreatedAt: t0,
|
||||
UpdatedAt: t0,
|
||||
}
|
||||
|
||||
require.NoError(t, client.WithTx(ctx, func(ctx context.Context, tx pg.Tx) error {
|
||||
return first.Upsert(ctx, tx, fx.scope)
|
||||
}))
|
||||
@@ -366,11 +378,13 @@ func TestAccessEntry_Upsert_RefreshesSourceTrackingFields(t *testing.T) {
|
||||
CreatedAt: t1,
|
||||
UpdatedAt: t1,
|
||||
}
|
||||
|
||||
require.NoError(t, client.WithTx(ctx, func(ctx context.Context, tx pg.Tx) error {
|
||||
return second.Upsert(ctx, tx, fx.scope)
|
||||
}))
|
||||
|
||||
loaded := &coredata.AccessEntry{}
|
||||
|
||||
require.NoError(t, client.WithConn(ctx, func(ctx context.Context, conn pg.Querier) error {
|
||||
return loaded.LoadByID(ctx, conn, fx.scope, entryID)
|
||||
}))
|
||||
@@ -428,11 +442,13 @@ func TestAccessEntry_Upsert_InsertsActiveAccount(t *testing.T) {
|
||||
CreatedAt: t0,
|
||||
UpdatedAt: t0,
|
||||
}
|
||||
|
||||
require.NoError(t, client.WithTx(ctx, func(ctx context.Context, tx pg.Tx) error {
|
||||
return entry.Upsert(ctx, tx, fx.scope)
|
||||
}))
|
||||
|
||||
loaded := &coredata.AccessEntry{}
|
||||
|
||||
require.NoError(t, client.WithConn(ctx, func(ctx context.Context, conn pg.Querier) error {
|
||||
return loaded.LoadByID(ctx, conn, fx.scope, entryID)
|
||||
}))
|
||||
|
||||
@@ -61,6 +61,7 @@ func (c *AccessReviewCampaign) AuthorizationAttributes(ctx context.Context, conn
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query access review campaign authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -107,6 +108,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect access review campaign: %w", err)
|
||||
}
|
||||
|
||||
@@ -163,6 +165,7 @@ VALUES (
|
||||
"created_at": c.CreatedAt,
|
||||
"updated_at": c.UpdatedAt,
|
||||
}
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot insert access_review_campaign: %w", err)
|
||||
@@ -357,6 +360,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect access review campaign: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ func (p AccessReviewCampaignOrderField) Column() string {
|
||||
case AccessReviewCampaignOrderFieldCreatedAt:
|
||||
return "created_at"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", p))
|
||||
}
|
||||
|
||||
@@ -37,6 +38,7 @@ func (p AccessReviewCampaignOrderField) IsValid() bool {
|
||||
case AccessReviewCampaignOrderFieldCreatedAt:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -53,5 +55,6 @@ func (p *AccessReviewCampaignOrderField) UnmarshalText(text []byte) error {
|
||||
if !p.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid AccessReviewCampaignOrderField", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -127,6 +127,7 @@ FOR UPDATE
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot lock campaign: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ INSERT INTO access_review_campaign_source_fetches (
|
||||
"created_at": f.CreatedAt,
|
||||
"updated_at": f.UpdatedAt,
|
||||
}
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot insert campaign source fetch: %w", err)
|
||||
@@ -197,6 +198,7 @@ LIMIT 1
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect campaign source fetch: %w", err)
|
||||
}
|
||||
|
||||
@@ -293,6 +295,7 @@ FOR UPDATE SKIP LOCKED
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrNoAccessReviewCampaignSourceFetchAvailable
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect campaign source fetch: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ func (s AccessReviewCampaignSourceFetchStatus) String() string {
|
||||
|
||||
func (s *AccessReviewCampaignSourceFetchStatus) Scan(value any) error {
|
||||
var str string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
str = v
|
||||
|
||||
@@ -22,12 +22,15 @@ func TestAccessReviewCampaignSourceFetchStatusIsTerminal(t *testing.T) {
|
||||
if AccessReviewCampaignSourceFetchStatusQueued.IsTerminal() {
|
||||
t.Fatalf("QUEUED should not be terminal")
|
||||
}
|
||||
|
||||
if AccessReviewCampaignSourceFetchStatusFetching.IsTerminal() {
|
||||
t.Fatalf("FETCHING should not be terminal")
|
||||
}
|
||||
|
||||
if !AccessReviewCampaignSourceFetchStatusSuccess.IsTerminal() {
|
||||
t.Fatalf("SUCCESS should be terminal")
|
||||
}
|
||||
|
||||
if !AccessReviewCampaignSourceFetchStatusFailed.IsTerminal() {
|
||||
t.Fatalf("FAILED should be terminal")
|
||||
}
|
||||
@@ -64,17 +67,20 @@ func TestAccessReviewCampaignSourceFetchStatusScan(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var got AccessReviewCampaignSourceFetchStatus
|
||||
|
||||
err := got.Scan(tt.input)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("Scan(%v) expected error", tt.input)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Scan(%v) returned error: %v", tt.input, err)
|
||||
}
|
||||
|
||||
if got != tt.want {
|
||||
t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ func (s AccessReviewCampaignStatus) String() string {
|
||||
|
||||
func (s *AccessReviewCampaignStatus) Scan(value any) error {
|
||||
var str string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
str = v
|
||||
@@ -58,6 +59,7 @@ func (s *AccessReviewCampaignStatus) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("cannot parse AccessReviewCampaignStatus: invalid value %q", str)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -39,17 +39,20 @@ func TestAccessReviewCampaignStatusScan(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var got AccessReviewCampaignStatus
|
||||
|
||||
err := got.Scan(tt.input)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("Scan(%v) expected error", tt.input)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Scan(%v) returned error: %v", tt.input, err)
|
||||
}
|
||||
|
||||
if got != tt.want {
|
||||
t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
@@ -78,6 +81,7 @@ func TestAccessReviewCampaignStatusValue(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Value() returned error: %v", err)
|
||||
}
|
||||
|
||||
if got != tt.want {
|
||||
t.Fatalf("Value() = %q, want %q", got, tt.want)
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ func (as *AccessSource) AuthorizationAttributes(ctx context.Context, conn pg.Que
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query access source authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -105,6 +106,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect access source: %w", err)
|
||||
}
|
||||
|
||||
@@ -158,6 +160,7 @@ VALUES (
|
||||
"created_at": as.CreatedAt,
|
||||
"updated_at": as.UpdatedAt,
|
||||
}
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot insert access_source: %w", err)
|
||||
@@ -426,9 +429,11 @@ FOR UPDATE SKIP LOCKED;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrNoAccessSourceNameSyncAvailable
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect unsynced access source: %w", err)
|
||||
}
|
||||
|
||||
*as = row
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ func (c AccessSourceCategory) String() string {
|
||||
|
||||
func (c *AccessSourceCategory) Scan(value any) error {
|
||||
var str string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
str = v
|
||||
@@ -64,6 +65,7 @@ func (c *AccessSourceCategory) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("cannot parse AccessSourceCategory: invalid value %q", str)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -38,17 +38,20 @@ func TestAccessSourceCategoryScan(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var got AccessSourceCategory
|
||||
|
||||
err := got.Scan(tt.input)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("Scan(%v) expected error", tt.input)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Scan(%v) returned error: %v", tt.input, err)
|
||||
}
|
||||
|
||||
if got != tt.want {
|
||||
t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
@@ -63,6 +66,7 @@ func TestAccessSourceCategoryValue(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Value() returned error: %v", err)
|
||||
}
|
||||
|
||||
if got != "SAAS" {
|
||||
t.Fatalf("Value() = %q, want %q", got, "SAAS")
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ func (p AccessSourceOrderField) Column() string {
|
||||
case AccessSourceOrderFieldCreatedAt:
|
||||
return "created_at"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", p))
|
||||
}
|
||||
|
||||
@@ -37,6 +38,7 @@ func (p AccessSourceOrderField) IsValid() bool {
|
||||
case AccessSourceOrderFieldCreatedAt:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -53,5 +55,6 @@ func (p *AccessSourceOrderField) UnmarshalText(text []byte) error {
|
||||
if !p.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid AccessSourceOrderField", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -88,6 +88,7 @@ func (e *AgentRun) AuthorizationAttributes(ctx context.Context, conn pg.Querier)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot load agent run authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -138,6 +139,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot load agent run: %w", err)
|
||||
}
|
||||
|
||||
@@ -191,6 +193,7 @@ FOR UPDATE;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot load agent run: %w", err)
|
||||
}
|
||||
|
||||
@@ -485,6 +488,7 @@ FOR UPDATE SKIP LOCKED;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot load pending agent run: %w", err)
|
||||
}
|
||||
|
||||
@@ -584,6 +588,7 @@ func NewPGCheckpointer(pgClient *pg.Client, opts ...PGCheckpointerOption) *PGChe
|
||||
for _, opt := range opts {
|
||||
opt(s)
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -661,6 +666,7 @@ WHERE
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot load checkpoint: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ func (p AgentRunOrderField) IsValid() bool {
|
||||
case AgentRunOrderFieldCreatedAt:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -50,6 +51,7 @@ func (p *AgentRunOrderField) UnmarshalText(text []byte) error {
|
||||
if !p.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid AgentRunOrderField", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ func (s *ApplicabilityStatement) AuthorizationAttributes(ctx context.Context, co
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query applicability statement authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -131,6 +132,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect applicability statement: %w", err)
|
||||
}
|
||||
|
||||
@@ -194,10 +196,12 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect applicability statement: %w", err)
|
||||
}
|
||||
|
||||
*sac = control
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -243,8 +247,8 @@ VALUES (
|
||||
"created_at": sac.CreatedAt,
|
||||
"updated_at": sac.UpdatedAt,
|
||||
}
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
@@ -357,6 +361,7 @@ WHERE statement_of_applicability_id IN (SELECT id FROM current_soa)
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -453,6 +458,7 @@ WHERE
|
||||
}
|
||||
|
||||
*sacs = controls
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -503,6 +509,7 @@ ORDER BY
|
||||
}
|
||||
|
||||
*sacs = controls
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -599,5 +606,6 @@ WHERE
|
||||
}
|
||||
|
||||
*sacs = controls
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -52,5 +52,6 @@ func (p *ApplicabilityStatementOrderField) UnmarshalText(text []byte) error {
|
||||
*p = ApplicabilityStatementOrderField(val)
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("invalid ApplicabilityStatementOrderField value: %q", val)
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ func (a *Asset) AuthorizationAttributes(ctx context.Context, conn pg.Querier) (m
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query asset authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -446,6 +447,7 @@ WHERE
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get asset list document ID: %w", err)
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ func (a *Audit) AuthorizationAttributes(ctx context.Context, conn pg.Querier) (m
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query audit authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -150,6 +151,7 @@ WHERE
|
||||
row := conn.QueryRow(ctx, q, args)
|
||||
|
||||
var count int
|
||||
|
||||
err := row.Scan(&count)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("cannot count audits: %w", err)
|
||||
@@ -553,6 +555,7 @@ WHERE
|
||||
row := conn.QueryRow(ctx, q, args)
|
||||
|
||||
var count int
|
||||
|
||||
err := row.Scan(&count)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("cannot count audits: %w", err)
|
||||
@@ -595,6 +598,7 @@ WHERE
|
||||
row := conn.QueryRow(ctx, q, args)
|
||||
|
||||
var count int
|
||||
|
||||
err := row.Scan(&count)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("cannot count audits: %w", err)
|
||||
|
||||
@@ -45,6 +45,7 @@ func (f *AuditFilter) SQLArguments() pgx.NamedArgs {
|
||||
for i, v := range f.trustCenterVisibilities {
|
||||
visibilities[i] = v.String()
|
||||
}
|
||||
|
||||
args["trust_center_visibilities"] = visibilities
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ func (a AuditLogActorType) IsValid() bool {
|
||||
case AuditLogActorTypeUser, AuditLogActorTypeAPIKey, AuditLogActorTypeSystem:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -48,11 +49,13 @@ func (a *AuditLogActorType) UnmarshalText(text []byte) error {
|
||||
if !a.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid AuditLogActorType", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *AuditLogActorType) Scan(value any) error {
|
||||
var s string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
s = v
|
||||
|
||||
@@ -61,6 +61,7 @@ func (e *AuditLogEntry) AuthorizationAttributes(ctx context.Context, conn pg.Que
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query audit log entry authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -159,10 +160,12 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect audit log entry: %w", err)
|
||||
}
|
||||
|
||||
*e = entry
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -211,6 +214,7 @@ WHERE
|
||||
}
|
||||
|
||||
*es = entries
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ func (p AuditLogEntryOrderField) Column() string {
|
||||
case AuditLogEntryOrderFieldCreatedAt:
|
||||
return "created_at"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", p))
|
||||
}
|
||||
|
||||
@@ -41,6 +42,7 @@ func (p AuditLogEntryOrderField) IsValid() bool {
|
||||
case AuditLogEntryOrderFieldCreatedAt:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -53,5 +55,6 @@ func (p *AuditLogEntryOrderField) UnmarshalText(text []byte) error {
|
||||
if !p.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid AuditLogEntryOrderField", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -49,5 +49,6 @@ func (p *AuditOrderField) UnmarshalText(text []byte) error {
|
||||
*p = AuditOrderField(val)
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("invalid AuditOrderField value: %q", val)
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ func (as AuditState) String() string {
|
||||
|
||||
func (as *AuditState) Scan(value any) error {
|
||||
var s string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
s = v
|
||||
@@ -68,6 +69,7 @@ func (as *AuditState) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("invalid AuditState value: %q", s)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ func (a AccessEntryAuthMethod) String() string {
|
||||
|
||||
func (a *AccessEntryAuthMethod) Scan(value any) error {
|
||||
var str string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
str = v
|
||||
@@ -68,6 +69,7 @@ func (a *AccessEntryAuthMethod) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("cannot parse AccessEntryAuthMethod: invalid value %q", str)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ func (i *BusinessImpact) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("unsupported type for BusinessImpact: %T", value)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -89,6 +90,7 @@ func (i *BusinessImpact) UnmarshalJSON(data []byte) error {
|
||||
default:
|
||||
return fmt.Errorf("invalid BusinessImpact value: %q", s)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -106,5 +108,6 @@ func (i *BusinessImpact) UnmarshalText(text []byte) error {
|
||||
default:
|
||||
return fmt.Errorf("invalid BusinessImpact value: %q", s)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ LIMIT 1
|
||||
`
|
||||
|
||||
args := pgx.NamedArgs{"domain": domain}
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query certificate cache: %w", err)
|
||||
@@ -69,6 +70,7 @@ LIMIT 1
|
||||
}
|
||||
|
||||
*cc = cache
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -136,6 +138,7 @@ func (cc *CachedCertificates) CountAll(ctx context.Context, conn pg.Querier) (in
|
||||
q := `SELECT COUNT(*) FROM cached_certificates`
|
||||
|
||||
var count int
|
||||
|
||||
err := conn.QueryRow(ctx, q, pgx.NamedArgs{}).Scan(&count)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("cannot count certificate cache: %w", err)
|
||||
|
||||
@@ -102,6 +102,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect common third party: %w", err)
|
||||
}
|
||||
|
||||
@@ -158,6 +159,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect common third party by name: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect common third party domain: %w", err)
|
||||
}
|
||||
|
||||
@@ -113,6 +114,7 @@ INSERT INTO common_third_party_domains (
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot insert common third party domain: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -41,5 +41,6 @@ func (f *CommonThirdPartyDomainFilter) SQLArguments() pgx.StrictNamedArgs {
|
||||
if len(f.domains) > 0 {
|
||||
args["filter_domains"] = f.domains
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
@@ -41,5 +41,6 @@ func (f *CommonThirdPartyFilter) SQLArguments() pgx.StrictNamedArgs {
|
||||
if f.name != nil {
|
||||
args["filter_name"] = *f.name
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect common tracker pattern: %w", err)
|
||||
}
|
||||
|
||||
@@ -130,6 +131,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect common tracker pattern: %w", err)
|
||||
}
|
||||
|
||||
@@ -340,6 +342,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot collect common tracker pattern: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ func (c ComplianceExternalURL) CursorKey(orderBy ComplianceExternalURLOrderField
|
||||
case ComplianceExternalURLOrderFieldRank:
|
||||
return page.NewCursorKey(c.ID, c.Rank)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
@@ -60,6 +61,7 @@ func (c *ComplianceExternalURL) AuthorizationAttributes(ctx context.Context, con
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query compliance external URL authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -104,6 +106,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect compliance external URL: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ func (c ComplianceFramework) CursorKey(orderBy ComplianceFrameworkOrderField) pa
|
||||
case ComplianceFrameworkOrderFieldRank:
|
||||
return page.NewCursorKey(c.ID, c.Rank)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
@@ -63,6 +64,7 @@ func (c *ComplianceFramework) AuthorizationAttributes(ctx context.Context, conn
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query compliance framework authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -107,6 +109,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect compliance framework: %w", err)
|
||||
}
|
||||
|
||||
@@ -158,6 +161,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect compliance framework: %w", err)
|
||||
}
|
||||
|
||||
@@ -214,6 +218,7 @@ RETURNING rank;
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot insert compliance framework: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -41,11 +41,13 @@ func (j *jsonRawMessageOrNull) Scan(src any) error {
|
||||
*j = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
cp := make(jsonRawMessageOrNull, len(v))
|
||||
copy(cp, v)
|
||||
*j = cp
|
||||
|
||||
return nil
|
||||
case string:
|
||||
*j = jsonRawMessageOrNull(v)
|
||||
@@ -91,6 +93,7 @@ func (c *Connector) AuthorizationAttributes(ctx context.Context, conn pg.Querier
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query connector authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -152,10 +155,12 @@ func (c *Connector) LoadOneByOrganizationIDAndProvider(
|
||||
if ci != cj {
|
||||
return ci > cj
|
||||
}
|
||||
|
||||
return connectors[i].UpdatedAt.After(connectors[j].UpdatedAt)
|
||||
})
|
||||
|
||||
*c = *connectors[0]
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -166,6 +171,7 @@ func connectorScopeCount(c *Connector) int {
|
||||
if c == nil || c.Connection == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return len(c.Connection.Scopes())
|
||||
}
|
||||
|
||||
@@ -265,6 +271,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect connector row: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ func (cp ConnectorProtocol) String() string {
|
||||
|
||||
func (cp *ConnectorProtocol) Scan(value any) error {
|
||||
var s string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
s = v
|
||||
@@ -56,6 +57,7 @@ func (cp *ConnectorProtocol) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("invalid ConnectorProtocol value: %q", s)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ func (cp ConnectorProvider) String() string {
|
||||
|
||||
func (cp *ConnectorProvider) Scan(value any) error {
|
||||
var s string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
s = v
|
||||
@@ -153,6 +154,7 @@ func (cp *ConnectorProvider) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("invalid ConnectorProvider value: %q", s)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,9 @@ func (c *Connector) SetSettings(v any) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot marshal connector settings: %w", err)
|
||||
}
|
||||
|
||||
c.RawSettings = data
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -103,8 +105,10 @@ func ConnectorSettings[T any](c *Connector) (T, error) {
|
||||
if len(c.RawSettings) == 0 || string(c.RawSettings) == "null" {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(c.RawSettings, &s); err != nil {
|
||||
return s, fmt.Errorf("cannot unmarshal connector settings: %w", err)
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ func (c *Control) AuthorizationAttributes(ctx context.Context, conn pg.Querier)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query control authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -652,6 +653,7 @@ LIMIT 1;
|
||||
|
||||
args := pgx.StrictNamedArgs{"framework_id": frameworkID, "section_title": sectionTitle}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query controls: %w", err)
|
||||
@@ -701,6 +703,7 @@ LIMIT 1;
|
||||
|
||||
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: %w", err)
|
||||
@@ -816,8 +819,8 @@ VALUES (
|
||||
"created_at": c.CreatedAt,
|
||||
"updated_at": c.UpdatedAt,
|
||||
}
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
@@ -825,6 +828,7 @@ VALUES (
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot insert control: %w", err)
|
||||
}
|
||||
|
||||
@@ -850,6 +854,7 @@ WHERE
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -893,6 +898,7 @@ WHERE %s
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot update control: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ ON CONFLICT (control_id, audit_id) DO NOTHING;
|
||||
"created_at": ca.CreatedAt,
|
||||
}
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -96,5 +97,6 @@ WHERE
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ VALUES (
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"created_at": cp.CreatedAt,
|
||||
}
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
@@ -111,6 +111,7 @@ WHERE
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ func (l ControlMaturityLevel) IsValid() bool {
|
||||
ControlMaturityLevelOptimizing:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -69,7 +70,9 @@ func (l *ControlMaturityLevel) UnmarshalText(data []byte) error {
|
||||
if !val.IsValid() {
|
||||
return fmt.Errorf("invalid ControlMaturityLevel value: %q", string(data))
|
||||
}
|
||||
|
||||
*l = val
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -78,6 +81,7 @@ func (l *ControlMaturityLevel) Scan(value any) error {
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid scan source for ControlMaturityLevel, expected string got %T", value)
|
||||
}
|
||||
|
||||
return l.UnmarshalText([]byte(val))
|
||||
}
|
||||
|
||||
|
||||
@@ -69,17 +69,20 @@ func TestControlMaturityLevelScan(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var got ControlMaturityLevel
|
||||
|
||||
err := got.Scan(tt.input)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("Scan(%v) expected error", tt.input)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Scan(%v) returned error: %v", tt.input, err)
|
||||
}
|
||||
|
||||
if got != tt.want {
|
||||
t.Fatalf("Scan(%v) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
@@ -111,6 +114,7 @@ func TestControlMaturityLevelValue(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Value() returned error: %v", err)
|
||||
}
|
||||
|
||||
if got != tt.want {
|
||||
t.Fatalf("Value() = %q, want %q", got, tt.want)
|
||||
}
|
||||
@@ -141,6 +145,7 @@ func TestControlMaturityLevelMarshalUnmarshalText(t *testing.T) {
|
||||
if err := roundtrip.UnmarshalText(data); err != nil {
|
||||
t.Fatalf("UnmarshalText(%q) returned error: %v", string(data), err)
|
||||
}
|
||||
|
||||
if roundtrip != level {
|
||||
t.Fatalf("roundtrip = %q, want %q", roundtrip, level)
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ ON CONFLICT (control_id, measure_id) DO NOTHING;
|
||||
"created_at": cm.CreatedAt,
|
||||
}
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -97,6 +98,7 @@ WHERE
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -169,5 +171,6 @@ WHERE
|
||||
}
|
||||
|
||||
*cwrs = controlsWithRisk
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ ON CONFLICT (control_id, obligation_id) DO NOTHING;
|
||||
"created_at": co.CreatedAt,
|
||||
}
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -97,6 +98,7 @@ WHERE
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -433,6 +433,7 @@ INSERT INTO cookie_banners (
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot insert cookie banner: %w", err)
|
||||
}
|
||||
|
||||
@@ -482,6 +483,7 @@ WHERE
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot update cookie banner: %w", err)
|
||||
}
|
||||
|
||||
@@ -595,6 +597,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect cookie banner: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ func (p CookieBannerOrderField) Column() string {
|
||||
case CookieBannerOrderFieldCreatedAt:
|
||||
return "created_at"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", p))
|
||||
}
|
||||
|
||||
@@ -35,6 +36,7 @@ func (p CookieBannerOrderField) IsValid() bool {
|
||||
case CookieBannerOrderFieldCreatedAt:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -47,6 +49,7 @@ func (p *CookieBannerOrderField) UnmarshalText(text []byte) error {
|
||||
if !p.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid CookieBannerOrderField", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ func (s CookieBannerState) String() string {
|
||||
|
||||
func (s *CookieBannerState) Scan(value any) error {
|
||||
var v string
|
||||
|
||||
switch val := value.(type) {
|
||||
case string:
|
||||
v = val
|
||||
@@ -56,6 +57,7 @@ func (s *CookieBannerState) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("invalid CookieBannerState value: %q", v)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect cookie banner translation: %w", err)
|
||||
}
|
||||
|
||||
@@ -146,6 +147,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect cookie banner translation: %w", err)
|
||||
}
|
||||
|
||||
@@ -243,6 +245,7 @@ INSERT INTO cookie_banner_translations (
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot insert cookie banner translation: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ func (v *CookieBannerVersion) GetSnapshot() (CookieBannerVersionSnapshot, error)
|
||||
if err := json.Unmarshal(v.Snapshot, &snapshot); err != nil {
|
||||
return snapshot, fmt.Errorf("cannot unmarshal cookie banner version snapshot: %w", err)
|
||||
}
|
||||
|
||||
return snapshot, nil
|
||||
}
|
||||
|
||||
@@ -108,7 +109,9 @@ func (v *CookieBannerVersion) SetSnapshot(snapshot CookieBannerVersionSnapshot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot marshal cookie banner version snapshot: %w", err)
|
||||
}
|
||||
|
||||
v.Snapshot = data
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -151,6 +154,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect cookie banner version: %w", err)
|
||||
}
|
||||
|
||||
@@ -280,6 +284,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect cookie banner version: %w", err)
|
||||
}
|
||||
|
||||
@@ -328,6 +333,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect cookie banner version: %w", err)
|
||||
}
|
||||
|
||||
@@ -498,6 +504,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect cookie banner version: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ func (p CookieBannerVersionOrderField) Column() string {
|
||||
case CookieBannerVersionOrderFieldCreatedAt:
|
||||
return "created_at"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", p))
|
||||
}
|
||||
|
||||
@@ -35,6 +36,7 @@ func (p CookieBannerVersionOrderField) IsValid() bool {
|
||||
case CookieBannerVersionOrderFieldCreatedAt:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -47,6 +49,7 @@ func (p *CookieBannerVersionOrderField) UnmarshalText(text []byte) error {
|
||||
if !p.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid CookieBannerVersionOrderField", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ func (s CookieBannerVersionState) String() string {
|
||||
|
||||
func (s *CookieBannerVersionState) Scan(value any) error {
|
||||
var v string
|
||||
|
||||
switch val := value.(type) {
|
||||
case string:
|
||||
v = val
|
||||
@@ -56,6 +57,7 @@ func (s *CookieBannerVersionState) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("invalid CookieBannerVersionState value: %q", v)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ func (c CookieItems) MarshalJSON() ([]byte, error) {
|
||||
if c == nil {
|
||||
return []byte("[]"), nil
|
||||
}
|
||||
|
||||
return json.Marshal([]CookieItem(c))
|
||||
}
|
||||
|
||||
@@ -68,6 +69,7 @@ func (c *CookieItems) UnmarshalJSON(data []byte) error {
|
||||
*c = CookieItems{}
|
||||
return nil
|
||||
}
|
||||
|
||||
return json.Unmarshal(data, (*[]CookieItem)(c))
|
||||
}
|
||||
|
||||
@@ -138,6 +140,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect cookie category: %w", err)
|
||||
}
|
||||
|
||||
@@ -527,6 +530,7 @@ INSERT INTO cookie_categories (
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot insert cookie category: %w", err)
|
||||
}
|
||||
|
||||
@@ -572,6 +576,7 @@ WHERE
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot update cookie category: %w", err)
|
||||
}
|
||||
|
||||
@@ -740,6 +745,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect uncategorised cookie category: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ func (p CookieCategoryOrderField) Column() string {
|
||||
case CookieCategoryOrderFieldRank:
|
||||
return "rank"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", p))
|
||||
}
|
||||
|
||||
@@ -35,6 +36,7 @@ func (p CookieCategoryOrderField) IsValid() bool {
|
||||
case CookieCategoryOrderFieldRank:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -47,6 +49,7 @@ func (p *CookieCategoryOrderField) UnmarshalText(text []byte) error {
|
||||
if !p.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid CookieCategoryOrderField", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ func (a CookieConsentAction) String() string {
|
||||
|
||||
func (a *CookieConsentAction) Scan(value any) error {
|
||||
var v string
|
||||
|
||||
switch val := value.(type) {
|
||||
case string:
|
||||
v = val
|
||||
|
||||
@@ -39,6 +39,7 @@ func (m CookieConsentMode) String() string {
|
||||
|
||||
func (m *CookieConsentMode) Scan(value any) error {
|
||||
var v string
|
||||
|
||||
switch val := value.(type) {
|
||||
case string:
|
||||
v = val
|
||||
|
||||
@@ -333,6 +333,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect consent record: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ func (p CookieConsentRecordOrderField) Column() string {
|
||||
case CookieConsentRecordOrderFieldCreatedAt:
|
||||
return "created_at"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", p))
|
||||
}
|
||||
|
||||
@@ -35,6 +36,7 @@ func (p CookieConsentRecordOrderField) IsValid() bool {
|
||||
case CookieConsentRecordOrderFieldCreatedAt:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -47,6 +49,7 @@ func (p *CookieConsentRecordOrderField) UnmarshalText(text []byte) error {
|
||||
if !p.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid CookieConsentRecordOrderField", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ func (s CookieSource) String() string {
|
||||
|
||||
func (s *CookieSource) Scan(value any) error {
|
||||
var v string
|
||||
|
||||
switch val := value.(type) {
|
||||
case string:
|
||||
v = val
|
||||
@@ -60,6 +61,7 @@ func (s *CookieSource) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("invalid CookieSource value: %q", v)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -282,6 +282,7 @@ func (ct CountryCode) String() string {
|
||||
|
||||
func (ct *CountryCode) Scan(value any) error {
|
||||
var s string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
s = v
|
||||
@@ -791,6 +792,7 @@ func (ct *CountryCode) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("invalid CountryCode value: %q", s)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -836,10 +838,12 @@ func (s *CountryCodes) scanFromString(str string) error {
|
||||
if err := ct.Scan(part); err != nil {
|
||||
return fmt.Errorf("invalid country code in array: %s", part)
|
||||
}
|
||||
|
||||
result[i] = ct
|
||||
}
|
||||
|
||||
*s = result
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ type (
|
||||
|
||||
func NewCustomDomain(tenantID gid.TenantID, domain string) *CustomDomain {
|
||||
now := time.Now()
|
||||
|
||||
return &CustomDomain{
|
||||
ID: gid.New(tenantID, CustomDomainEntityType),
|
||||
SSLStatus: CustomDomainSSLStatusPending,
|
||||
@@ -75,6 +76,7 @@ func (cd *CustomDomain) AuthorizationAttributes(ctx context.Context, conn pg.Que
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query custom domain authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -119,6 +121,7 @@ func (cd *CustomDomain) EncryptPrivateKey(privateKeyPEM []byte, encryptionKey ci
|
||||
}
|
||||
|
||||
cd.EncryptedSSLPrivateKey = encrypted
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -147,6 +150,7 @@ func (cd *CustomDomain) ParseCertificate(encryptionKey cipher.EncryptionKey) err
|
||||
}
|
||||
|
||||
cd.SSLCertificate = &tlsCert
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -460,6 +464,7 @@ INSERT INTO custom_domains (
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot insert custom domain: %w", err)
|
||||
}
|
||||
|
||||
@@ -658,6 +663,7 @@ ORDER BY
|
||||
}
|
||||
|
||||
*domains = result
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -714,6 +720,7 @@ WHERE
|
||||
}
|
||||
|
||||
*domains = result
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -765,6 +772,7 @@ WHERE
|
||||
}
|
||||
|
||||
*domains = result
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -826,5 +834,6 @@ WHERE
|
||||
}
|
||||
|
||||
*domains = result
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ WHERE
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get DPIA list document ID: %w", err)
|
||||
}
|
||||
@@ -170,6 +171,7 @@ func (dpia *DataProtectionImpactAssessment) AuthorizationAttributes(ctx context.
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query data protection impact assessment authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -200,6 +202,7 @@ WHERE
|
||||
row := conn.QueryRow(ctx, q, args)
|
||||
|
||||
var count int
|
||||
|
||||
err := row.Scan(&count)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("cannot count data protection impact assessments: %w", err)
|
||||
|
||||
@@ -41,5 +41,6 @@ func (p *DataProtectionImpactAssessmentOrderField) UnmarshalText(text []byte) er
|
||||
*p = DataProtectionImpactAssessmentOrderFieldCreatedAt
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("invalid DataProtectionImpactAssessmentOrderField value: %q", val)
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ func (p DataProtectionImpactAssessmentResidualRisk) String() string {
|
||||
|
||||
func (p *DataProtectionImpactAssessmentResidualRisk) Scan(value any) error {
|
||||
var s string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
s = v
|
||||
@@ -60,6 +61,7 @@ func (p *DataProtectionImpactAssessmentResidualRisk) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("invalid DataProtectionImpactAssessmentResidualRisk value: %q", s)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ func (i *DataSensitivity) Scan(value any) error {
|
||||
default:
|
||||
return fmt.Errorf("unsupported type for DataSensitivity: %T", value)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -95,6 +96,7 @@ func (i *DataSensitivity) UnmarshalJSON(data []byte) error {
|
||||
default:
|
||||
return fmt.Errorf("invalid DataSensitivity value: %q", s)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -118,5 +120,6 @@ func (i *DataSensitivity) UnmarshalText(text []byte) error {
|
||||
default:
|
||||
return fmt.Errorf("invalid DataSensitivity value: %q", s)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ func (d *Datum) AuthorizationAttributes(ctx context.Context, conn pg.Querier) (m
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query datum authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -178,6 +179,7 @@ WHERE
|
||||
row := conn.QueryRow(ctx, q, args)
|
||||
|
||||
var count int
|
||||
|
||||
err := row.Scan(&count)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("cannot count data: %w", err)
|
||||
@@ -419,6 +421,7 @@ WHERE
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get data document ID: %w", err)
|
||||
}
|
||||
|
||||
@@ -47,5 +47,6 @@ func (p *DatumOrderField) UnmarshalText(text []byte) error {
|
||||
*p = DatumOrderField(val)
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("invalid DatumOrderField value: %q", val)
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query document authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -287,6 +288,7 @@ WHERE
|
||||
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)
|
||||
@@ -540,6 +542,7 @@ VALUES (
|
||||
"updated_at": p.UpdatedAt,
|
||||
}
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -558,6 +561,7 @@ UPDATE documents SET deleted_at = @deleted_at WHERE %s AND id = @document_id
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -577,6 +581,7 @@ DELETE FROM documents WHERE %s AND organization_id = @organization_id
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -649,6 +654,7 @@ WHERE cp.control_id = @control_id
|
||||
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)
|
||||
@@ -749,6 +755,7 @@ WHERE rp.risk_id = @risk_id
|
||||
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)
|
||||
@@ -849,6 +856,7 @@ WHERE md.measure_id = @measure_id
|
||||
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)
|
||||
@@ -942,6 +950,7 @@ UPDATE documents SET deleted_at = @deleted_at WHERE %s AND id = ANY(@document_id
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -969,6 +978,7 @@ UPDATE documents SET status = 'ARCHIVED', archived_at = @archived_at, trust_cent
|
||||
if _, err := conn.Exec(ctx, q, args); err != nil {
|
||||
return fmt.Errorf("cannot bulk archive documents: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -995,6 +1005,7 @@ UPDATE documents SET status = 'ACTIVE', archived_at = NULL WHERE %s AND id = ANY
|
||||
if _, err := conn.Exec(ctx, q, args); err != nil {
|
||||
return fmt.Errorf("cannot bulk unarchive documents: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1106,6 +1117,7 @@ LIMIT 1
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("cannot collect approval state: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ func (dc DocumentClassification) String() string {
|
||||
case DocumentClassificationSecret:
|
||||
return "SECRET"
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("invalid DocumentClassification value: %s", string(dc)))
|
||||
}
|
||||
|
||||
@@ -58,6 +59,7 @@ func (dc *DocumentClassification) Scan(value any) error {
|
||||
}
|
||||
|
||||
var sv string
|
||||
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
sv = v
|
||||
@@ -68,6 +70,7 @@ func (dc *DocumentClassification) Scan(value any) error {
|
||||
}
|
||||
|
||||
*dc = DocumentClassification(sv)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ ORDER BY created_at ASC;
|
||||
}
|
||||
|
||||
*das = result
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -139,5 +140,6 @@ WHEN NOT MATCHED BY SOURCE
|
||||
}
|
||||
|
||||
*das = result
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ func NewDocumentFilter(query *string) *DocumentFilter {
|
||||
|
||||
func NewDocumentTrustCenterFilter() *DocumentFilter {
|
||||
published := true
|
||||
|
||||
return &DocumentFilter{
|
||||
trustCenterVisibilities: []TrustCenterVisibility{
|
||||
TrustCenterVisibilityPrivate,
|
||||
@@ -59,6 +60,7 @@ func (f *DocumentFilter) WithPublished(published *bool) *DocumentFilter {
|
||||
func (f *DocumentFilter) WithEmployeeIdentityID(identityID *gid.GID, modes ...EmployeeFilterMode) *DocumentFilter {
|
||||
f.employeeIdentityID = identityID
|
||||
f.employeeFilterModes = modes
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ func (p DocumentOrderField) Column() string {
|
||||
case DocumentOrderFieldDocumentType:
|
||||
return "document_type"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", p))
|
||||
}
|
||||
|
||||
@@ -49,6 +50,7 @@ func (p DocumentOrderField) IsValid() bool {
|
||||
DocumentOrderFieldDocumentType:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -65,5 +67,6 @@ func (p *DocumentOrderField) UnmarshalText(text []byte) error {
|
||||
if !p.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid DocumentOrderField", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ func (s DocumentStatus) IsValid() bool {
|
||||
case DocumentStatusActive, DocumentStatusArchived:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -41,6 +42,7 @@ func (s *DocumentStatus) UnmarshalText(text []byte) error {
|
||||
if !s.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid DocumentStatus", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -53,6 +55,7 @@ func (s *DocumentStatus) Scan(value any) error {
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid scan source for DocumentStatus, expected string got %T", value)
|
||||
}
|
||||
|
||||
return s.UnmarshalText([]byte(val))
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query document version authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -193,6 +194,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect document version: %w", err)
|
||||
}
|
||||
|
||||
@@ -279,6 +281,7 @@ VALUES (
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("error creating document version: %w", err)
|
||||
}
|
||||
|
||||
@@ -341,6 +344,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect document version: %w", err)
|
||||
}
|
||||
|
||||
@@ -399,6 +403,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect document version: %w", err)
|
||||
}
|
||||
|
||||
@@ -459,6 +464,7 @@ LIMIT 1;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect document version: %w", err)
|
||||
}
|
||||
|
||||
@@ -595,6 +601,7 @@ FOR UPDATE OF dv SKIP LOCKED;
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrNoDocumentPDFJobAvailable
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect document version: %w", err)
|
||||
}
|
||||
|
||||
@@ -651,6 +658,7 @@ WHERE
|
||||
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)
|
||||
|
||||
@@ -62,6 +62,7 @@ func (d *DocumentVersionApprovalDecision) AuthorizationAttributes(ctx context.Co
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query document version approval decision authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -108,6 +109,7 @@ WHERE
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect document version approval decision: %w", err)
|
||||
}
|
||||
|
||||
@@ -162,6 +164,7 @@ LIMIT 1
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect document version approval decision: %w", err)
|
||||
}
|
||||
|
||||
@@ -193,6 +196,7 @@ WHERE
|
||||
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)
|
||||
@@ -307,6 +311,7 @@ INSERT INTO document_version_approval_decisions (
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot insert document version approval decision: %w", err)
|
||||
}
|
||||
|
||||
@@ -357,6 +362,7 @@ func (ds DocumentVersionApprovalDecisions) BulkInsert(
|
||||
},
|
||||
pgx.CopyFromRows(rows),
|
||||
)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -483,6 +489,7 @@ WHERE
|
||||
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)
|
||||
|
||||
@@ -28,6 +28,7 @@ func NewDocumentVersionApprovalDecisionFilter(states []DocumentVersionApprovalDe
|
||||
if len(states) == 0 {
|
||||
states = nil
|
||||
}
|
||||
|
||||
return &DocumentVersionApprovalDecisionFilter{
|
||||
states: DocumentVersionApprovalDecisionStates(states),
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ func (e DocumentVersionApprovalDecisionOrderField) Column() string {
|
||||
case DocumentVersionApprovalDecisionOrderFieldCreatedAt:
|
||||
return "created_at"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", e))
|
||||
}
|
||||
|
||||
@@ -37,6 +38,7 @@ func (e DocumentVersionApprovalDecisionOrderField) IsValid() bool {
|
||||
case DocumentVersionApprovalDecisionOrderFieldCreatedAt:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -47,6 +49,7 @@ func (e *DocumentVersionApprovalDecisionOrderField) UnmarshalText(text []byte) e
|
||||
if !e.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid DocumentVersionApprovalDecisionOrderField", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -94,12 +94,16 @@ func (states DocumentVersionApprovalDecisionStates) Value() (driver.Value, error
|
||||
|
||||
var result strings.Builder
|
||||
result.WriteString("{")
|
||||
|
||||
for i, state := range states {
|
||||
if i > 0 {
|
||||
result.WriteString(",")
|
||||
}
|
||||
|
||||
fmt.Fprintf(&result, "%q", state.String())
|
||||
}
|
||||
|
||||
result.WriteString("}")
|
||||
|
||||
return result.String(), nil
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ func (q *DocumentVersionApprovalQuorum) AuthorizationAttributes(ctx context.Cont
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query approval quorum authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -100,6 +101,7 @@ WHERE
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect approval quorum: %w", err)
|
||||
}
|
||||
|
||||
@@ -153,6 +155,7 @@ LIMIT 1
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect last approval quorum: %w", err)
|
||||
}
|
||||
|
||||
@@ -241,6 +244,7 @@ WHERE
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
row := conn.QueryRow(ctx, query, args)
|
||||
|
||||
var count int
|
||||
if err := row.Scan(&count); err != nil {
|
||||
return 0, fmt.Errorf("cannot scan count: %w", err)
|
||||
@@ -292,6 +296,7 @@ INSERT INTO document_version_approval_quorums (
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot insert approval quorum: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ func (e DocumentVersionApprovalQuorumOrderField) Column() string {
|
||||
case DocumentVersionApprovalQuorumOrderFieldCreatedAt:
|
||||
return "created_at"
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", e))
|
||||
}
|
||||
|
||||
@@ -37,6 +38,7 @@ func (e DocumentVersionApprovalQuorumOrderField) IsValid() bool {
|
||||
case DocumentVersionApprovalQuorumOrderFieldCreatedAt:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -47,6 +49,7 @@ func (e *DocumentVersionApprovalQuorumOrderField) UnmarshalText(text []byte) err
|
||||
if !e.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid DocumentVersionApprovalQuorumOrderField", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ func (f *DocumentVersionFilter) WithStatuses(statuses ...DocumentVersionStatus)
|
||||
func (f *DocumentVersionFilter) WithEmployeeIdentityID(identityID *gid.GID, modes ...EmployeeFilterMode) *DocumentVersionFilter {
|
||||
f.employeeIdentityID = identityID
|
||||
f.employeeFilterModes = modes
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ func (dvs *DocumentVersionSignature) AuthorizationAttributes(ctx context.Context
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("cannot query document version signature authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
@@ -221,6 +222,7 @@ INSERT INTO document_version_signatures (
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot insert document version signature: %w", err)
|
||||
}
|
||||
|
||||
@@ -506,6 +508,7 @@ WHERE
|
||||
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)
|
||||
|
||||
@@ -84,12 +84,16 @@ func (states DocumentVersionSignatureStates) Value() (driver.Value, error) {
|
||||
|
||||
var result strings.Builder
|
||||
result.WriteString("{")
|
||||
|
||||
for i, state := range states {
|
||||
if i > 0 {
|
||||
result.WriteString(",")
|
||||
}
|
||||
|
||||
fmt.Fprintf(&result, "%q", state.String())
|
||||
}
|
||||
|
||||
result.WriteString("}")
|
||||
|
||||
return result.String(), nil
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ func (e DocumentWriteMode) IsValid() bool {
|
||||
case DocumentWriteModeAuthored, DocumentWriteModeGenerated:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -40,6 +41,7 @@ func (e *DocumentWriteMode) UnmarshalText(text []byte) error {
|
||||
if !e.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid DocumentWriteMode", string(text))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -211,10 +211,12 @@ LIMIT 1
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect electronic signature: %w", err)
|
||||
}
|
||||
|
||||
*es = sig
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -247,10 +249,12 @@ FOR UPDATE SKIP LOCKED
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect electronic signature: %w", err)
|
||||
}
|
||||
|
||||
*es = sig
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -286,10 +290,12 @@ FOR UPDATE SKIP LOCKED
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot collect electronic signature: %w", err)
|
||||
}
|
||||
|
||||
*es = sig
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -304,6 +310,7 @@ SET status = 'ACCEPTED', processing_started_at = NULL, updated_at = NOW()
|
||||
WHERE status = 'PROCESSING'
|
||||
AND processing_started_at < NOW() - $1::interval
|
||||
`
|
||||
|
||||
_, err := conn.Exec(ctx, q, staleAfter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot reset stale processing signatures: %w", err)
|
||||
@@ -344,12 +351,14 @@ func (es *ElectronicSignature) computeSealV1() (string, error) {
|
||||
if f == "" {
|
||||
return "", fmt.Errorf("seal field %d must not be empty", i)
|
||||
}
|
||||
|
||||
if strings.Contains(f, "\n") {
|
||||
return "", fmt.Errorf("seal field %d must not contain newline", i)
|
||||
}
|
||||
}
|
||||
|
||||
input := strings.Join(fields, "\n")
|
||||
|
||||
return hash.SHA256HexString(input), nil
|
||||
}
|
||||
|
||||
@@ -367,6 +376,7 @@ WHERE status = 'COMPLETED'
|
||||
AND certificate_processing_started_at < NOW() - $1::interval
|
||||
AND attempt_count < max_attempts
|
||||
`
|
||||
|
||||
_, err := conn.Exec(ctx, q, staleAfter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot reset stale certificate processing: %w", err)
|
||||
|
||||
@@ -174,6 +174,7 @@ func (dt ElectronicSignatureDocumentType) DisplayName() string {
|
||||
|
||||
func (dt ElectronicSignatureDocumentType) ConsentText() (string, error) {
|
||||
var docAgreement string
|
||||
|
||||
switch dt {
|
||||
case ElectronicSignatureDocumentTypeNDA:
|
||||
docAgreement = "I agree to the terms of this Non-Disclosure Agreement."
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user