Rename mitigation into mesure
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
@@ -116,11 +116,11 @@ WHERE %s
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Controls) LoadByMitigationID(
|
||||
func (c *Controls) LoadByMesureID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
mitigationID gid.GID,
|
||||
mesureID gid.GID,
|
||||
cursor *page.Cursor[ControlOrderField],
|
||||
) error {
|
||||
q := `
|
||||
@@ -137,9 +137,9 @@ WITH ctrl AS (
|
||||
FROM
|
||||
controls c
|
||||
INNER JOIN
|
||||
controls_mitigations cm ON c.id = cm.control_id
|
||||
controls_mesures cm ON c.id = cm.control_id
|
||||
WHERE
|
||||
cm.mitigation_id = @mitigation_id
|
||||
cm.mesure_id = @mesure_id
|
||||
)
|
||||
SELECT
|
||||
id,
|
||||
@@ -157,7 +157,7 @@ WHERE %s
|
||||
`
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.NamedArgs{"mitigation_id": mitigationID}
|
||||
args := pgx.NamedArgs{"mesure_id": mesureID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
@@ -200,9 +200,9 @@ WITH ctrl AS (
|
||||
LEFT JOIN
|
||||
risks_policies rp ON cp.policy_id = rp.policy_id
|
||||
LEFT JOIN
|
||||
controls_mitigations cm ON c.id = cm.control_id
|
||||
controls_mesures cm ON c.id = cm.control_id
|
||||
LEFT JOIN
|
||||
risks_mitigations rm ON (rm.mitigation_id = cm.mitigation_id)
|
||||
risks_mesures rm ON (rm.mesure_id = cm.mesure_id)
|
||||
WHERE
|
||||
rp.risk_id = @risk_id OR rm.risk_id = @risk_id
|
||||
)
|
||||
|
||||
@@ -26,80 +26,80 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
ControlMitigation struct {
|
||||
ControlID gid.GID `db:"control_id"`
|
||||
MitigationID gid.GID `db:"mitigation_id"`
|
||||
TenantID gid.TenantID `db:"tenant_id"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
ControlMesure struct {
|
||||
ControlID gid.GID `db:"control_id"`
|
||||
MesureID gid.GID `db:"mesure_id"`
|
||||
TenantID gid.TenantID `db:"tenant_id"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
}
|
||||
|
||||
ControlMitigations []*ControlMitigation
|
||||
ControlMesures []*ControlMesure
|
||||
)
|
||||
|
||||
func (cm ControlMitigation) Upsert(
|
||||
func (cm ControlMesure) Upsert(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO
|
||||
controls_mitigations (
|
||||
controls_mesures (
|
||||
control_id,
|
||||
mitigation_id,
|
||||
mesure_id,
|
||||
tenant_id,
|
||||
created_at
|
||||
)
|
||||
VALUES (
|
||||
@control_id,
|
||||
@mitigation_id,
|
||||
@mesure_id,
|
||||
@tenant_id,
|
||||
@created_at
|
||||
)
|
||||
ON CONFLICT (control_id, mitigation_id) DO NOTHING;
|
||||
ON CONFLICT (control_id, mesure_id) DO NOTHING;
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"control_id": cm.ControlID,
|
||||
"mitigation_id": cm.MitigationID,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"created_at": cm.CreatedAt,
|
||||
"control_id": cm.ControlID,
|
||||
"mesure_id": cm.MesureID,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"created_at": cm.CreatedAt,
|
||||
}
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
return err
|
||||
}
|
||||
|
||||
func (cm ControlMitigation) Insert(
|
||||
func (cm ControlMesure) Insert(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO
|
||||
controls_mitigations (
|
||||
controls_mesures (
|
||||
control_id,
|
||||
mitigation_id,
|
||||
mesure_id,
|
||||
tenant_id,
|
||||
created_at
|
||||
)
|
||||
VALUES (
|
||||
@control_id,
|
||||
@mitigation_id,
|
||||
@mesure_id,
|
||||
@tenant_id,
|
||||
@created_at
|
||||
);
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"control_id": cm.ControlID,
|
||||
"mitigation_id": cm.MitigationID,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"created_at": cm.CreatedAt,
|
||||
"control_id": cm.ControlID,
|
||||
"mesure_id": cm.MesureID,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"created_at": cm.CreatedAt,
|
||||
}
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
return err
|
||||
}
|
||||
|
||||
func (cm ControlMitigation) Delete(
|
||||
func (cm ControlMesure) Delete(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
@@ -107,16 +107,16 @@ func (cm ControlMitigation) Delete(
|
||||
q := `
|
||||
DELETE
|
||||
FROM
|
||||
controls_mitigations
|
||||
controls_mesures
|
||||
WHERE
|
||||
%s
|
||||
AND control_id = @control_id
|
||||
AND mitigation_id = @mitigation_id;
|
||||
AND mesure_id = @mesure_id;
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"control_id": cm.ControlID,
|
||||
"mitigation_id": cm.MitigationID,
|
||||
"control_id": cm.ControlID,
|
||||
"mesure_id": cm.MesureID,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
@@ -125,39 +125,39 @@ WHERE
|
||||
return err
|
||||
}
|
||||
|
||||
func (cms *ControlMitigations) LoadByMitigationID(
|
||||
func (cms *ControlMesures) LoadByMesureID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
mitigationID gid.GID,
|
||||
mesureID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
control_id,
|
||||
mitigation_id,
|
||||
mesure_id,
|
||||
tenant_id,
|
||||
created_at
|
||||
FROM
|
||||
control_mitigations
|
||||
controls_mesures
|
||||
WHERE
|
||||
%s
|
||||
AND mitigation_id = @mitigation_id
|
||||
AND mesure_id = @mesure_id
|
||||
`
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"mitigation_id": mitigationID}
|
||||
args := pgx.StrictNamedArgs{"mesure_id": mesureID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query control_mitigations: %w", err)
|
||||
return fmt.Errorf("cannot query control_mesures: %w", err)
|
||||
}
|
||||
|
||||
controlMitigations, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[ControlMitigation])
|
||||
controlMesures, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[ControlMesure])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect control_mitigations: %w", err)
|
||||
return fmt.Errorf("cannot collect control_mesures: %w", err)
|
||||
}
|
||||
|
||||
*cms = controlMitigations
|
||||
*cms = controlMesures
|
||||
return nil
|
||||
}
|
||||
@@ -17,7 +17,7 @@ package coredata
|
||||
const (
|
||||
OrganizationEntityType uint16 = iota
|
||||
FrameworkEntityType
|
||||
MitigationEntityType
|
||||
MesureEntityType
|
||||
TaskEntityType
|
||||
EvidenceEntityType
|
||||
_ControlStateTransitionEntityType // UNUSED
|
||||
|
||||
@@ -28,41 +28,41 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
Mitigation struct {
|
||||
ID gid.GID `db:"id"`
|
||||
TenantID gid.TenantID `db:"tenant_id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
Category string `db:"category"`
|
||||
Name string `db:"name"`
|
||||
Description string `db:"description"`
|
||||
Importance MitigationImportance `db:"importance"`
|
||||
State MitigationState `db:"state"`
|
||||
ReferenceID string `db:"reference_id"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
Mesure struct {
|
||||
ID gid.GID `db:"id"`
|
||||
TenantID gid.TenantID `db:"tenant_id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
Category string `db:"category"`
|
||||
Name string `db:"name"`
|
||||
Description string `db:"description"`
|
||||
Importance MesureImportance `db:"importance"`
|
||||
State MesureState `db:"state"`
|
||||
ReferenceID string `db:"reference_id"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
Mitigations []*Mitigation
|
||||
Mesures []*Mesure
|
||||
)
|
||||
|
||||
func (c Mitigation) CursorKey(orderBy MitigationOrderField) page.CursorKey {
|
||||
func (m Mesure) CursorKey(orderBy MesureOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case MitigationOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(c.ID, c.CreatedAt)
|
||||
case MesureOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(m.ID, m.CreatedAt)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (c *Mitigations) LoadByRiskID(
|
||||
func (m *Mesures) LoadByRiskID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
riskID gid.GID,
|
||||
cursor *page.Cursor[MitigationOrderField],
|
||||
cursor *page.Cursor[MesureOrderField],
|
||||
) error {
|
||||
q := `
|
||||
WITH mtgtns AS (
|
||||
WITH msrs AS (
|
||||
SELECT
|
||||
m.id,
|
||||
m.tenant_id,
|
||||
@@ -76,9 +76,9 @@ WITH mtgtns AS (
|
||||
m.created_at,
|
||||
m.updated_at
|
||||
FROM
|
||||
mitigations m
|
||||
mesures m
|
||||
INNER JOIN
|
||||
risks_mitigations rm ON m.id = rm.mitigation_id
|
||||
risks_mesures rm ON m.id = rm.mesure_id
|
||||
WHERE
|
||||
rm.risk_id = @risk_id
|
||||
)
|
||||
@@ -95,7 +95,7 @@ SELECT
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
mtgtns
|
||||
msrs
|
||||
WHERE %s
|
||||
AND %s
|
||||
`
|
||||
@@ -107,25 +107,25 @@ WHERE %s
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query mitigations: %w", err)
|
||||
return fmt.Errorf("cannot query mesures: %w", err)
|
||||
}
|
||||
|
||||
mitigations, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Mitigation])
|
||||
mesures, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Mesure])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect mitigations: %w", err)
|
||||
return fmt.Errorf("cannot collect mesures: %w", err)
|
||||
}
|
||||
|
||||
*c = mitigations
|
||||
*m = mesures
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Mitigations) LoadByControlID(
|
||||
func (m *Mesures) LoadByControlID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
controlID gid.GID,
|
||||
cursor *page.Cursor[MitigationOrderField],
|
||||
cursor *page.Cursor[MesureOrderField],
|
||||
) error {
|
||||
q := `
|
||||
WITH mtgtns AS (
|
||||
@@ -142,9 +142,9 @@ WITH mtgtns AS (
|
||||
m.created_at,
|
||||
m.updated_at
|
||||
FROM
|
||||
mitigations m
|
||||
mesures m
|
||||
INNER JOIN
|
||||
controls_mitigations cm ON m.id = cm.mitigation_id
|
||||
controls_mesures cm ON m.id = cm.mesure_id
|
||||
WHERE
|
||||
cm.control_id = @control_id
|
||||
)
|
||||
@@ -173,25 +173,25 @@ WHERE %s
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query mitigations: %w", err)
|
||||
return fmt.Errorf("cannot query mesures: %w", err)
|
||||
}
|
||||
|
||||
mitigations, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Mitigation])
|
||||
mesures, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Mesure])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect mitigations: %w", err)
|
||||
return fmt.Errorf("cannot collect mesures: %w", err)
|
||||
}
|
||||
|
||||
*c = mitigations
|
||||
*m = mesures
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Mitigations) LoadByOrganizationID(
|
||||
func (m *Mesures) LoadByOrganizationID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[MitigationOrderField],
|
||||
cursor *page.Cursor[MesureOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
@@ -207,7 +207,7 @@ SELECT
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
mitigations
|
||||
mesures
|
||||
WHERE
|
||||
%s
|
||||
AND organization_id = @organization_id
|
||||
@@ -221,24 +221,24 @@ WHERE
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query mitigations: %w", err)
|
||||
return fmt.Errorf("cannot query mesures: %w", err)
|
||||
}
|
||||
|
||||
mitigations, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Mitigation])
|
||||
mesures, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Mesure])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect mitigations: %w", err)
|
||||
return fmt.Errorf("cannot collect mesures: %w", err)
|
||||
}
|
||||
|
||||
*c = mitigations
|
||||
*m = mesures
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Mitigation) LoadByID(
|
||||
func (m *Mesure) LoadByID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
mitigationID gid.GID,
|
||||
mesureID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
@@ -254,41 +254,41 @@ SELECT
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
mitigations
|
||||
mesures
|
||||
WHERE
|
||||
%s
|
||||
AND id = @mitigation_id
|
||||
AND id = @mesure_id
|
||||
LIMIT 1;
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"mitigation_id": mitigationID}
|
||||
args := pgx.StrictNamedArgs{"mesure_id": mesureID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query mitigations: %w", err)
|
||||
return fmt.Errorf("cannot query mesures: %w", err)
|
||||
}
|
||||
|
||||
mitigation, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[Mitigation])
|
||||
mesure, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[Mesure])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect mitigations: %w", err)
|
||||
return fmt.Errorf("cannot collect mesures: %w", err)
|
||||
}
|
||||
|
||||
*c = mitigation
|
||||
*m = mesure
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Mitigation) Upsert(
|
||||
func (m *Mesure) Upsert(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO
|
||||
mitigations (
|
||||
mesures (
|
||||
tenant_id,
|
||||
id,
|
||||
organization_id,
|
||||
@@ -303,7 +303,7 @@ INSERT INTO
|
||||
)
|
||||
VALUES (
|
||||
@tenant_id,
|
||||
@mitigation_id,
|
||||
@mesure_id,
|
||||
@organization_id,
|
||||
@category,
|
||||
@name,
|
||||
@@ -335,41 +335,41 @@ RETURNING
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"mitigation_id": c.ID,
|
||||
"organization_id": c.OrganizationID,
|
||||
"category": c.Category,
|
||||
"name": c.Name,
|
||||
"importance": c.Importance,
|
||||
"state": c.State,
|
||||
"description": c.Description,
|
||||
"reference_id": c.ReferenceID,
|
||||
"created_at": c.CreatedAt,
|
||||
"updated_at": c.UpdatedAt,
|
||||
"mesure_id": m.ID,
|
||||
"organization_id": m.OrganizationID,
|
||||
"category": m.Category,
|
||||
"name": m.Name,
|
||||
"importance": m.Importance,
|
||||
"state": m.State,
|
||||
"description": m.Description,
|
||||
"reference_id": m.ReferenceID,
|
||||
"created_at": m.CreatedAt,
|
||||
"updated_at": m.UpdatedAt,
|
||||
}
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query mitigations: %w", err)
|
||||
return fmt.Errorf("cannot query mesures: %w", err)
|
||||
}
|
||||
|
||||
mitigation, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[Mitigation])
|
||||
mesure, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[Mesure])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect mitigations: %w", err)
|
||||
return fmt.Errorf("cannot collect mesures: %w", err)
|
||||
}
|
||||
|
||||
*c = mitigation
|
||||
*m = mesure
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Mitigation) Insert(
|
||||
func (m Mesure) Insert(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO
|
||||
mitigations (
|
||||
mesures (
|
||||
tenant_id,
|
||||
id,
|
||||
organization_id,
|
||||
@@ -384,7 +384,7 @@ INSERT INTO
|
||||
)
|
||||
VALUES (
|
||||
@tenant_id,
|
||||
@mitigation_id,
|
||||
@mesure_id,
|
||||
@organization_id,
|
||||
@category,
|
||||
@name,
|
||||
@@ -399,28 +399,28 @@ VALUES (
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"mitigation_id": c.ID,
|
||||
"organization_id": c.OrganizationID,
|
||||
"category": c.Category,
|
||||
"name": c.Name,
|
||||
"description": c.Description,
|
||||
"reference_id": c.ReferenceID,
|
||||
"created_at": c.CreatedAt,
|
||||
"updated_at": c.UpdatedAt,
|
||||
"state": c.State,
|
||||
"importance": c.Importance,
|
||||
"mesure_id": m.ID,
|
||||
"organization_id": m.OrganizationID,
|
||||
"category": m.Category,
|
||||
"name": m.Name,
|
||||
"description": m.Description,
|
||||
"reference_id": m.ReferenceID,
|
||||
"created_at": m.CreatedAt,
|
||||
"updated_at": m.UpdatedAt,
|
||||
"state": m.State,
|
||||
"importance": m.Importance,
|
||||
}
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Mitigation) Update(
|
||||
func (m *Mesure) Update(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE mitigations
|
||||
UPDATE mesures
|
||||
SET
|
||||
name = @name,
|
||||
description = @description,
|
||||
@@ -429,18 +429,18 @@ SET
|
||||
importance = @importance,
|
||||
updated_at = @updated_at
|
||||
WHERE %s
|
||||
AND id = @mitigation_id
|
||||
AND id = @mesure_id
|
||||
`
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.NamedArgs{
|
||||
"mitigation_id": c.ID,
|
||||
"name": c.Name,
|
||||
"description": c.Description,
|
||||
"category": c.Category,
|
||||
"state": c.State,
|
||||
"importance": c.Importance,
|
||||
"updated_at": c.UpdatedAt,
|
||||
"mesure_id": m.ID,
|
||||
"name": m.Name,
|
||||
"description": m.Description,
|
||||
"category": m.Category,
|
||||
"state": m.State,
|
||||
"importance": m.Importance,
|
||||
"updated_at": m.UpdatedAt,
|
||||
}
|
||||
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
@@ -20,48 +20,48 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type MitigationImportance uint8
|
||||
type MesureImportance uint8
|
||||
|
||||
const (
|
||||
MitigationImportanceMandatory MitigationImportance = iota
|
||||
MitigationImportancePreferred
|
||||
MitigationImportanceAdvanced
|
||||
MesureImportanceMandatory MesureImportance = iota
|
||||
MesureImportancePreferred
|
||||
MesureImportanceAdvanced
|
||||
)
|
||||
|
||||
func (i MitigationImportance) String() string {
|
||||
func (i MesureImportance) String() string {
|
||||
return []string{"MANDATORY", "PREFERRED", "ADVANCED"}[i]
|
||||
}
|
||||
|
||||
func (i *MitigationImportance) Scan(value interface{}) error {
|
||||
func (i *MesureImportance) Scan(value interface{}) error {
|
||||
switch v := value.(type) {
|
||||
case uint8:
|
||||
*i = MitigationImportance(v)
|
||||
*i = MesureImportance(v)
|
||||
case string:
|
||||
switch v {
|
||||
case "MANDATORY":
|
||||
*i = MitigationImportanceMandatory
|
||||
*i = MesureImportanceMandatory
|
||||
case "PREFERRED":
|
||||
*i = MitigationImportancePreferred
|
||||
*i = MesureImportancePreferred
|
||||
case "ADVANCED":
|
||||
*i = MitigationImportanceAdvanced
|
||||
*i = MesureImportanceAdvanced
|
||||
default:
|
||||
return fmt.Errorf("invalid MitigationImportance value: %q", v)
|
||||
return fmt.Errorf("invalid MesureImportance value: %q", v)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unsupported type for MitigationImportance: %T", value)
|
||||
return fmt.Errorf("unsupported type for MesureImportance: %T", value)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i MitigationImportance) Value() (driver.Value, error) {
|
||||
func (i MesureImportance) Value() (driver.Value, error) {
|
||||
return i.String(), nil
|
||||
}
|
||||
|
||||
func (i MitigationImportance) MarshalJSON() ([]byte, error) {
|
||||
func (i MesureImportance) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(i.String())
|
||||
}
|
||||
|
||||
func (i *MitigationImportance) UnmarshalJSON(data []byte) error {
|
||||
func (i *MesureImportance) UnmarshalJSON(data []byte) error {
|
||||
var s string
|
||||
if err := json.Unmarshal(data, &s); err != nil {
|
||||
return err
|
||||
@@ -69,18 +69,18 @@ func (i *MitigationImportance) UnmarshalJSON(data []byte) error {
|
||||
|
||||
switch s {
|
||||
case "MANDATORY":
|
||||
*i = MitigationImportanceMandatory
|
||||
*i = MesureImportanceMandatory
|
||||
case "PREFERRED":
|
||||
*i = MitigationImportancePreferred
|
||||
*i = MesureImportancePreferred
|
||||
case "ADVANCED":
|
||||
*i = MitigationImportanceAdvanced
|
||||
*i = MesureImportanceAdvanced
|
||||
default:
|
||||
return fmt.Errorf("invalid MitigationImportance value: %q", s)
|
||||
return fmt.Errorf("invalid MesureImportance value: %q", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *MitigationImportance) UnmarshalText(text []byte) error {
|
||||
func (i *MesureImportance) UnmarshalText(text []byte) error {
|
||||
var s string
|
||||
if err := json.Unmarshal(text, &s); err != nil {
|
||||
return err
|
||||
@@ -88,13 +88,13 @@ func (i *MitigationImportance) UnmarshalText(text []byte) error {
|
||||
|
||||
switch s {
|
||||
case "MANDATORY":
|
||||
*i = MitigationImportanceMandatory
|
||||
*i = MesureImportanceMandatory
|
||||
case "PREFERRED":
|
||||
*i = MitigationImportancePreferred
|
||||
*i = MesureImportancePreferred
|
||||
case "ADVANCED":
|
||||
*i = MitigationImportanceAdvanced
|
||||
*i = MesureImportanceAdvanced
|
||||
default:
|
||||
return fmt.Errorf("invalid MitigationImportance value: %q", s)
|
||||
return fmt.Errorf("invalid MesureImportance value: %q", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -15,26 +15,26 @@
|
||||
package coredata
|
||||
|
||||
type (
|
||||
MitigationOrderField string
|
||||
MesureOrderField string
|
||||
)
|
||||
|
||||
const (
|
||||
MitigationOrderFieldCreatedAt MitigationOrderField = "CREATED_AT"
|
||||
MesureOrderFieldCreatedAt MesureOrderField = "CREATED_AT"
|
||||
)
|
||||
|
||||
func (p MitigationOrderField) Column() string {
|
||||
func (p MesureOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p MitigationOrderField) String() string {
|
||||
func (p MesureOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p MitigationOrderField) MarshalText() ([]byte, error) {
|
||||
func (p MesureOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *MitigationOrderField) UnmarshalText(text []byte) error {
|
||||
*p = MitigationOrderField(text)
|
||||
func (p *MesureOrderField) UnmarshalText(text []byte) error {
|
||||
*p = MesureOrderField(text)
|
||||
return nil
|
||||
}
|
||||
84
pkg/coredata/mesure_state.go
Normal file
84
pkg/coredata/mesure_state.go
Normal file
@@ -0,0 +1,84 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type (
|
||||
MesureState uint8
|
||||
)
|
||||
|
||||
const (
|
||||
MesureStateNotStarted MesureState = iota
|
||||
MesureStateInProgress
|
||||
MesureStateNotApplicable
|
||||
MesureStateImplemented
|
||||
)
|
||||
|
||||
func (ms MesureState) MarshalText() ([]byte, error) {
|
||||
return []byte(ms.String()), nil
|
||||
}
|
||||
|
||||
func (ms *MesureState) UnmarshalText(data []byte) error {
|
||||
val := string(data)
|
||||
|
||||
switch val {
|
||||
case MesureStateNotStarted.String():
|
||||
*ms = MesureStateNotStarted
|
||||
case MesureStateInProgress.String():
|
||||
*ms = MesureStateInProgress
|
||||
case MesureStateNotApplicable.String():
|
||||
*ms = MesureStateNotApplicable
|
||||
case MesureStateImplemented.String():
|
||||
*ms = MesureStateImplemented
|
||||
default:
|
||||
return fmt.Errorf("invalid MesureState value: %q", val)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ms MesureState) String() string {
|
||||
var val string
|
||||
|
||||
switch ms {
|
||||
case MesureStateNotStarted:
|
||||
val = "NOT_STARTED"
|
||||
case MesureStateInProgress:
|
||||
val = "IN_PROGRESS"
|
||||
case MesureStateNotApplicable:
|
||||
val = "NOT_APPLICABLE"
|
||||
case MesureStateImplemented:
|
||||
val = "IMPLEMENTED"
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
func (ms *MesureState) Scan(value any) error {
|
||||
val, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid scan source for MesureState, expected string got %T", value)
|
||||
}
|
||||
|
||||
return ms.UnmarshalText([]byte(val))
|
||||
}
|
||||
|
||||
func (ms MesureState) Value() (driver.Value, error) {
|
||||
return ms.String(), nil
|
||||
}
|
||||
2
pkg/coredata/migrations/20250412T175500Z.sql
Normal file
2
pkg/coredata/migrations/20250412T175500Z.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE mitigations RENAME TO mesures;
|
||||
|
||||
2
pkg/coredata/migrations/20250412T180400Z.sql
Normal file
2
pkg/coredata/migrations/20250412T180400Z.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE risks_mitigations RENAME TO risks_mesures;
|
||||
ALTER TABLE risks_mesures RENAME COLUMN mitigation_id TO mesure_id;
|
||||
2
pkg/coredata/migrations/20250412T182100Z.sql
Normal file
2
pkg/coredata/migrations/20250412T182100Z.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE controls_mitigations RENAME TO controls_mesures;
|
||||
ALTER TABLE controls_mesures RENAME COLUMN mitigation_id TO mesure_id;
|
||||
1
pkg/coredata/migrations/20250412T210000Z.sql
Normal file
1
pkg/coredata/migrations/20250412T210000Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE tasks RENAME COLUMN mitigation_id TO mesure_id;
|
||||
@@ -1,84 +0,0 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type (
|
||||
MitigationState uint8
|
||||
)
|
||||
|
||||
const (
|
||||
MitigationStateNotStarted MitigationState = iota
|
||||
MitigationStateInProgress
|
||||
MitigationStateNotApplicable
|
||||
MitigationStateImplemented
|
||||
)
|
||||
|
||||
func (cs MitigationState) MarshalText() ([]byte, error) {
|
||||
return []byte(cs.String()), nil
|
||||
}
|
||||
|
||||
func (cs *MitigationState) UnmarshalText(data []byte) error {
|
||||
val := string(data)
|
||||
|
||||
switch val {
|
||||
case MitigationStateNotStarted.String():
|
||||
*cs = MitigationStateNotStarted
|
||||
case MitigationStateInProgress.String():
|
||||
*cs = MitigationStateInProgress
|
||||
case MitigationStateNotApplicable.String():
|
||||
*cs = MitigationStateNotApplicable
|
||||
case MitigationStateImplemented.String():
|
||||
*cs = MitigationStateImplemented
|
||||
default:
|
||||
return fmt.Errorf("invalid MitigationState value: %q", val)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cs MitigationState) String() string {
|
||||
var val string
|
||||
|
||||
switch cs {
|
||||
case MitigationStateNotStarted:
|
||||
val = "NOT_STARTED"
|
||||
case MitigationStateInProgress:
|
||||
val = "IN_PROGRESS"
|
||||
case MitigationStateNotApplicable:
|
||||
val = "NOT_APPLICABLE"
|
||||
case MitigationStateImplemented:
|
||||
val = "IMPLEMENTED"
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
func (cs *MitigationState) Scan(value any) error {
|
||||
val, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid scan source for MitigationState, expected string got %T", value)
|
||||
}
|
||||
|
||||
return cs.UnmarshalText([]byte(val))
|
||||
}
|
||||
|
||||
func (cs MitigationState) Value() (driver.Value, error) {
|
||||
return cs.String(), nil
|
||||
}
|
||||
@@ -62,11 +62,11 @@ func (r *Risk) ResidualSeverity() float64 {
|
||||
return r.ResidualLikelihood * r.ResidualImpact
|
||||
}
|
||||
|
||||
func (r *Risks) LoadByMitigationID(
|
||||
func (r *Risks) LoadByMesureID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
mitigationID gid.GID,
|
||||
mesureID gid.GID,
|
||||
cursor *page.Cursor[RiskOrderField],
|
||||
) error {
|
||||
q := `
|
||||
@@ -87,9 +87,9 @@ WITH rsks AS (
|
||||
FROM
|
||||
risks r
|
||||
INNER JOIN
|
||||
risks_mitigations rm ON r.id = rm.risk_id
|
||||
risks_mesures rm ON r.id = rm.risk_id
|
||||
WHERE
|
||||
rm.mitigation_id = @mitigation_id
|
||||
rm.mesure_id = @mesure_id
|
||||
)
|
||||
SELECT
|
||||
id,
|
||||
@@ -111,7 +111,7 @@ WHERE %s
|
||||
`
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.NamedArgs{"mitigation_id": mitigationID}
|
||||
args := pgx.NamedArgs{"mesure_id": mesureID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
|
||||
@@ -26,48 +26,48 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
RiskMitigation struct {
|
||||
RiskID gid.GID `db:"risk_id"`
|
||||
MitigationID gid.GID `db:"mitigation_id"`
|
||||
TenantID gid.TenantID `db:"tenant_id"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
RiskMesure struct {
|
||||
RiskID gid.GID `db:"risk_id"`
|
||||
MesureID gid.GID `db:"mesure_id"`
|
||||
TenantID gid.TenantID `db:"tenant_id"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
}
|
||||
|
||||
RiskMitigations []*RiskMitigation
|
||||
RiskMesures []*RiskMesure
|
||||
)
|
||||
|
||||
func (rm RiskMitigation) Insert(
|
||||
func (rm RiskMesure) Insert(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO
|
||||
risks_mitigations (
|
||||
risks_mesures (
|
||||
risk_id,
|
||||
mitigation_id,
|
||||
mesure_id,
|
||||
tenant_id,
|
||||
created_at
|
||||
)
|
||||
VALUES (
|
||||
@risk_id,
|
||||
@mitigation_id,
|
||||
@mesure_id,
|
||||
@tenant_id,
|
||||
@created_at
|
||||
);
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"risk_id": rm.RiskID,
|
||||
"mitigation_id": rm.MitigationID,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"created_at": rm.CreatedAt,
|
||||
"risk_id": rm.RiskID,
|
||||
"mesure_id": rm.MesureID,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"created_at": rm.CreatedAt,
|
||||
}
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
return err
|
||||
}
|
||||
|
||||
func (rm RiskMitigation) Delete(
|
||||
func (rm RiskMesure) Delete(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
@@ -75,18 +75,18 @@ func (rm RiskMitigation) Delete(
|
||||
q := `
|
||||
DELETE
|
||||
FROM
|
||||
risks_mitigations
|
||||
risks_mesures
|
||||
WHERE
|
||||
%s
|
||||
AND risk_id = @risk_id
|
||||
AND mitigation_id = @mitigation_id;
|
||||
AND mesure_id = @mesure_id;
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"risk_id": rm.RiskID,
|
||||
"mitigation_id": rm.MitigationID,
|
||||
"risk_id": rm.RiskID,
|
||||
"mesure_id": rm.MesureID,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
type (
|
||||
Task struct {
|
||||
ID gid.GID `db:"id"`
|
||||
MitigationID gid.GID `db:"mitigation_id"`
|
||||
MesureID gid.GID `db:"mesure_id"`
|
||||
Name string `db:"name"`
|
||||
Description string `db:"description"`
|
||||
State TaskState `db:"state"`
|
||||
@@ -62,7 +62,7 @@ func (c *Task) LoadByID(
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
mitigation_id,
|
||||
mesure_id,
|
||||
name,
|
||||
description,
|
||||
state,
|
||||
@@ -109,7 +109,7 @@ INSERT INTO
|
||||
tasks (
|
||||
tenant_id,
|
||||
id,
|
||||
mitigation_id,
|
||||
mesure_id,
|
||||
name,
|
||||
description,
|
||||
reference_id,
|
||||
@@ -122,7 +122,7 @@ INSERT INTO
|
||||
VALUES (
|
||||
@tenant_id,
|
||||
@task_id,
|
||||
@mitigation_id,
|
||||
@mesure_id,
|
||||
@name,
|
||||
@description,
|
||||
@reference_id,
|
||||
@@ -137,7 +137,7 @@ VALUES (
|
||||
args := pgx.StrictNamedArgs{
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"task_id": c.ID,
|
||||
"mitigation_id": c.MitigationID,
|
||||
"mesure_id": c.MesureID,
|
||||
"name": c.Name,
|
||||
"description": c.Description,
|
||||
"reference_id": c.ReferenceID,
|
||||
@@ -161,7 +161,7 @@ INSERT INTO
|
||||
tasks (
|
||||
tenant_id,
|
||||
id,
|
||||
mitigation_id,
|
||||
mesure_id,
|
||||
name,
|
||||
description,
|
||||
reference_id,
|
||||
@@ -174,7 +174,7 @@ INSERT INTO
|
||||
VALUES (
|
||||
@tenant_id,
|
||||
@task_id,
|
||||
@mitigation_id,
|
||||
@mesure_id,
|
||||
@name,
|
||||
@description,
|
||||
@reference_id,
|
||||
@@ -184,13 +184,13 @@ VALUES (
|
||||
@created_at,
|
||||
@updated_at
|
||||
)
|
||||
ON CONFLICT (mitigation_id, reference_id) DO UPDATE SET
|
||||
ON CONFLICT (mesure_id, reference_id) DO UPDATE SET
|
||||
name = @name,
|
||||
description = @description,
|
||||
updated_at = @updated_at
|
||||
RETURNING
|
||||
id,
|
||||
mitigation_id,
|
||||
mesure_id,
|
||||
name,
|
||||
description,
|
||||
reference_id,
|
||||
@@ -204,7 +204,7 @@ RETURNING
|
||||
args := pgx.StrictNamedArgs{
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"task_id": c.ID,
|
||||
"mitigation_id": c.MitigationID,
|
||||
"mesure_id": c.MesureID,
|
||||
"name": c.Name,
|
||||
"description": c.Description,
|
||||
"reference_id": c.ReferenceID,
|
||||
@@ -229,17 +229,17 @@ RETURNING
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Tasks) LoadByMitigationID(
|
||||
func (c *Tasks) LoadByMesureID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
mitigationID gid.GID,
|
||||
mesureID gid.GID,
|
||||
cursor *page.Cursor[TaskOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
mitigation_id,
|
||||
mesure_id,
|
||||
name,
|
||||
description,
|
||||
state,
|
||||
@@ -252,12 +252,12 @@ FROM
|
||||
tasks
|
||||
WHERE
|
||||
%s
|
||||
AND mitigation_id = @mitigation_id
|
||||
AND mesure_id = @mesure_id
|
||||
AND %s
|
||||
`
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"mitigation_id": mitigationID}
|
||||
args := pgx.StrictNamedArgs{"mesure_id": mesureID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, cursor.SQLArguments())
|
||||
|
||||
@@ -323,7 +323,7 @@ WHERE %s
|
||||
AND id = @task_id
|
||||
RETURNING
|
||||
id,
|
||||
mitigation_id,
|
||||
mesure_id,
|
||||
name,
|
||||
description,
|
||||
reference_id,
|
||||
@@ -371,7 +371,7 @@ WHERE %s
|
||||
AND id = @task_id
|
||||
RETURNING
|
||||
id,
|
||||
mitigation_id,
|
||||
mesure_id,
|
||||
name,
|
||||
description,
|
||||
reference_id,
|
||||
|
||||
Reference in New Issue
Block a user