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,
|
||||
|
||||
@@ -76,9 +76,9 @@ func (s ControlService) ListForPolicyID(
|
||||
return page.NewPage(controls, cursor), nil
|
||||
}
|
||||
|
||||
func (s ControlService) ListForMitigationID(
|
||||
func (s ControlService) ListForMesureID(
|
||||
ctx context.Context,
|
||||
mitigationID gid.GID,
|
||||
mesureID gid.GID,
|
||||
cursor *page.Cursor[coredata.ControlOrderField],
|
||||
) (*page.Page[*coredata.Control, coredata.ControlOrderField], error) {
|
||||
var controls coredata.Controls
|
||||
@@ -86,7 +86,7 @@ func (s ControlService) ListForMitigationID(
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return controls.LoadByMitigationID(ctx, conn, s.svc.scope, mitigationID, cursor)
|
||||
return controls.LoadByMesureID(ctx, conn, s.svc.scope, mesureID, cursor)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -97,42 +97,42 @@ func (s ControlService) ListForMitigationID(
|
||||
return page.NewPage(controls, cursor), nil
|
||||
}
|
||||
|
||||
func (s ControlService) CreateMitigationMapping(
|
||||
func (s ControlService) CreateMesureMapping(
|
||||
ctx context.Context,
|
||||
controlID gid.GID,
|
||||
mitigationID gid.GID,
|
||||
mesureID gid.GID,
|
||||
) error {
|
||||
controlMitigation := &coredata.ControlMitigation{
|
||||
ControlID: controlID,
|
||||
MitigationID: mitigationID,
|
||||
TenantID: s.svc.scope.GetTenantID(),
|
||||
CreatedAt: time.Now(),
|
||||
controlMesure := &coredata.ControlMesure{
|
||||
ControlID: controlID,
|
||||
MesureID: mesureID,
|
||||
TenantID: s.svc.scope.GetTenantID(),
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
return s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return controlMitigation.Insert(ctx, conn, s.svc.scope)
|
||||
return controlMesure.Insert(ctx, conn, s.svc.scope)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (s ControlService) DeleteMitigationMapping(
|
||||
func (s ControlService) DeleteMesureMapping(
|
||||
ctx context.Context,
|
||||
controlID gid.GID,
|
||||
mitigationID gid.GID,
|
||||
mesureID gid.GID,
|
||||
) error {
|
||||
controlMitigation := &coredata.ControlMitigation{
|
||||
ControlID: controlID,
|
||||
MitigationID: mitigationID,
|
||||
TenantID: s.svc.scope.GetTenantID(),
|
||||
CreatedAt: time.Now(),
|
||||
controlMesure := &coredata.ControlMesure{
|
||||
ControlID: controlID,
|
||||
MesureID: mesureID,
|
||||
TenantID: s.svc.scope.GetTenantID(),
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
return s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return controlMitigation.Delete(ctx, conn, s.svc.scope)
|
||||
return controlMesure.Delete(ctx, conn, s.svc.scope)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
383
pkg/probo/mesure_service.go
Normal file
383
pkg/probo/mesure_service.go
Normal file
@@ -0,0 +1,383 @@
|
||||
// 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 probo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/getprobo/probo/pkg/coredata"
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
"go.gearno.de/crypto/uuid"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
type (
|
||||
MesureService struct {
|
||||
svc *TenantService
|
||||
}
|
||||
|
||||
CreateMesureRequest struct {
|
||||
OrganizationID gid.GID
|
||||
Name string
|
||||
Description string
|
||||
Category string
|
||||
Importance coredata.MesureImportance
|
||||
}
|
||||
|
||||
UpdateMesureRequest struct {
|
||||
ID gid.GID
|
||||
Name *string
|
||||
Description *string
|
||||
Category *string
|
||||
State *coredata.MesureState
|
||||
Importance *coredata.MesureImportance
|
||||
}
|
||||
|
||||
ImportMesureRequest struct {
|
||||
Mesures []struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Category string `json:"category"`
|
||||
Importance coredata.MesureImportance `json:"importance"`
|
||||
ReferenceID string `json:"reference-id"`
|
||||
Standards []struct {
|
||||
Framework string `json:"framework"`
|
||||
Control string `json:"control"`
|
||||
} `json:"standards"`
|
||||
Tasks []struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
ReferenceID string `json:"reference-id"`
|
||||
RequestedEvidences []struct {
|
||||
ReferenceID string `json:"reference-id"`
|
||||
Type coredata.EvidenceType `json:"type"`
|
||||
Name string `json:"name"`
|
||||
} `json:"requested-evidences"`
|
||||
} `json:"tasks"`
|
||||
} `json:"mesures"`
|
||||
}
|
||||
)
|
||||
|
||||
func (s MesureService) ListForRiskID(
|
||||
ctx context.Context,
|
||||
riskID gid.GID,
|
||||
cursor *page.Cursor[coredata.MesureOrderField],
|
||||
) (*page.Page[*coredata.Mesure, coredata.MesureOrderField], error) {
|
||||
var mesures coredata.Mesures
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return mesures.LoadByRiskID(ctx, conn, s.svc.scope, riskID, cursor)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return page.NewPage(mesures, cursor), nil
|
||||
}
|
||||
|
||||
func (s MesureService) ListForControlID(
|
||||
ctx context.Context,
|
||||
controlID gid.GID,
|
||||
cursor *page.Cursor[coredata.MesureOrderField],
|
||||
) (*page.Page[*coredata.Mesure, coredata.MesureOrderField], error) {
|
||||
var mesures coredata.Mesures
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return mesures.LoadByControlID(ctx, conn, s.svc.scope, controlID, cursor)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return page.NewPage(mesures, cursor), nil
|
||||
}
|
||||
|
||||
func (s MesureService) Get(
|
||||
ctx context.Context,
|
||||
mesureID gid.GID,
|
||||
) (*coredata.Mesure, error) {
|
||||
mesure := &coredata.Mesure{}
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return mesure.LoadByID(ctx, conn, s.svc.scope, mesureID)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mesure, nil
|
||||
}
|
||||
|
||||
func (s MesureService) Import(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
req ImportMesureRequest,
|
||||
) (*page.Page[*coredata.Mesure, coredata.MesureOrderField], error) {
|
||||
importedMesures := coredata.Mesures{}
|
||||
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(tx pg.Conn) error {
|
||||
for i := range req.Mesures {
|
||||
now := time.Now()
|
||||
|
||||
mesureID, err := gid.NewGID(organizationID.TenantID(), coredata.MesureEntityType)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create global id: %w", err)
|
||||
}
|
||||
|
||||
mesure := &coredata.Mesure{
|
||||
ID: mesureID,
|
||||
OrganizationID: organizationID,
|
||||
Name: req.Mesures[i].Name,
|
||||
Description: req.Mesures[i].Description,
|
||||
Category: req.Mesures[i].Category,
|
||||
State: coredata.MesureStateNotStarted,
|
||||
ReferenceID: req.Mesures[i].ReferenceID,
|
||||
Importance: req.Mesures[i].Importance,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
importedMesures = append(importedMesures, mesure)
|
||||
|
||||
if err := mesure.Upsert(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot upsert mesure: %w", err)
|
||||
}
|
||||
|
||||
for j := range req.Mesures[i].Tasks {
|
||||
taskID, err := gid.NewGID(organizationID.TenantID(), coredata.TaskEntityType)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create global id: %w", err)
|
||||
}
|
||||
|
||||
task := &coredata.Task{
|
||||
ID: taskID,
|
||||
MesureID: mesure.ID,
|
||||
Name: req.Mesures[i].Tasks[j].Name,
|
||||
Description: req.Mesures[i].Tasks[j].Description,
|
||||
ReferenceID: req.Mesures[i].Tasks[j].ReferenceID,
|
||||
State: coredata.TaskStateTodo,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
if err := task.Upsert(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot upsert task: %w", err)
|
||||
}
|
||||
|
||||
for k := range req.Mesures[i].Tasks[j].RequestedEvidences {
|
||||
evidenceID, err := gid.NewGID(organizationID.TenantID(), coredata.EvidenceEntityType)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create global id: %w", err)
|
||||
}
|
||||
|
||||
evidence := &coredata.Evidence{
|
||||
State: coredata.EvidenceStateRequested,
|
||||
ID: evidenceID,
|
||||
TaskID: task.ID,
|
||||
ReferenceID: req.Mesures[i].Tasks[j].RequestedEvidences[k].ReferenceID,
|
||||
Type: req.Mesures[i].Tasks[j].RequestedEvidences[k].Type,
|
||||
Description: req.Mesures[i].Tasks[j].RequestedEvidences[k].Name,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
if err := evidence.Upsert(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot upsert evidence: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, standard := range req.Mesures[i].Standards {
|
||||
framework := &coredata.Framework{}
|
||||
if err := framework.LoadByReferenceID(ctx, tx, s.svc.scope, standard.Framework); err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
control := &coredata.Control{}
|
||||
if err := control.LoadByFrameworkIDAndReferenceID(ctx, tx, s.svc.scope, framework.ID, standard.Control); err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
controlMesure := &coredata.ControlMesure{
|
||||
ControlID: control.ID,
|
||||
MesureID: mesure.ID,
|
||||
CreatedAt: now,
|
||||
}
|
||||
|
||||
if err := controlMesure.Upsert(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot insert control mesure: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot import mesures: %w", err)
|
||||
}
|
||||
|
||||
cursor := page.NewCursor(
|
||||
len(importedMesures),
|
||||
nil,
|
||||
page.Head,
|
||||
page.OrderBy[coredata.MesureOrderField]{
|
||||
Field: coredata.MesureOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionAsc,
|
||||
},
|
||||
)
|
||||
|
||||
return page.NewPage(importedMesures, cursor), nil
|
||||
}
|
||||
|
||||
func (s MesureService) Update(
|
||||
ctx context.Context,
|
||||
req UpdateMesureRequest,
|
||||
) (*coredata.Mesure, error) {
|
||||
mesure := &coredata.Mesure{ID: req.ID}
|
||||
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
if err := mesure.LoadByID(ctx, conn, s.svc.scope, req.ID); err != nil {
|
||||
return fmt.Errorf("cannot load mesure: %w", err)
|
||||
}
|
||||
|
||||
if req.Name != nil {
|
||||
mesure.Name = *req.Name
|
||||
}
|
||||
|
||||
if req.Description != nil {
|
||||
mesure.Description = *req.Description
|
||||
}
|
||||
|
||||
if req.Category != nil {
|
||||
mesure.Category = *req.Category
|
||||
}
|
||||
|
||||
if req.State != nil {
|
||||
mesure.State = *req.State
|
||||
}
|
||||
|
||||
if req.Importance != nil {
|
||||
mesure.Importance = *req.Importance
|
||||
}
|
||||
|
||||
mesure.UpdatedAt = time.Now()
|
||||
|
||||
if err := mesure.Update(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot update mesure: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mesure, nil
|
||||
}
|
||||
|
||||
func (s MesureService) ListForOrganizationID(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[coredata.MesureOrderField],
|
||||
) (*page.Page[*coredata.Mesure, coredata.MesureOrderField], error) {
|
||||
var mesures coredata.Mesures
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return mesures.LoadByOrganizationID(
|
||||
ctx,
|
||||
conn,
|
||||
s.svc.scope,
|
||||
organizationID,
|
||||
cursor,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return page.NewPage(mesures, cursor), nil
|
||||
}
|
||||
|
||||
func (s MesureService) Create(
|
||||
ctx context.Context,
|
||||
req CreateMesureRequest,
|
||||
) (*coredata.Mesure, error) {
|
||||
now := time.Now()
|
||||
mesureID, err := gid.NewGID(s.svc.scope.GetTenantID(), coredata.MesureEntityType)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot create mesure global id: %w", err)
|
||||
}
|
||||
|
||||
referenceID, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot generate reference id: %w", err)
|
||||
}
|
||||
|
||||
mesure := &coredata.Mesure{
|
||||
ID: mesureID,
|
||||
OrganizationID: req.OrganizationID,
|
||||
Name: req.Name,
|
||||
Description: req.Description,
|
||||
Category: req.Category,
|
||||
ReferenceID: "custom-mesure-" + referenceID.String(),
|
||||
State: coredata.MesureStateNotStarted,
|
||||
Importance: req.Importance,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
err = s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
if err := mesure.Insert(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot insert mesure: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mesure, nil
|
||||
}
|
||||
@@ -1,383 +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 probo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/getprobo/probo/pkg/coredata"
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
"go.gearno.de/crypto/uuid"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
type (
|
||||
MitigationService struct {
|
||||
svc *TenantService
|
||||
}
|
||||
|
||||
CreateMitigationRequest struct {
|
||||
OrganizationID gid.GID
|
||||
Name string
|
||||
Description string
|
||||
Category string
|
||||
Importance coredata.MitigationImportance
|
||||
}
|
||||
|
||||
UpdateMitigationRequest struct {
|
||||
ID gid.GID
|
||||
Name *string
|
||||
Description *string
|
||||
Category *string
|
||||
State *coredata.MitigationState
|
||||
Importance *coredata.MitigationImportance
|
||||
}
|
||||
|
||||
ImportMitigationRequest struct {
|
||||
Mitigations []struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Category string `json:"category"`
|
||||
Importance coredata.MitigationImportance `json:"importance"`
|
||||
ReferenceID string `json:"reference-id"`
|
||||
Standards []struct {
|
||||
Framework string `json:"framework"`
|
||||
Control string `json:"control"`
|
||||
} `json:"standards"`
|
||||
Tasks []struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
ReferenceID string `json:"reference-id"`
|
||||
RequestedEvidences []struct {
|
||||
ReferenceID string `json:"reference-id"`
|
||||
Type coredata.EvidenceType `json:"type"`
|
||||
Name string `json:"name"`
|
||||
} `json:"requested-evidences"`
|
||||
} `json:"tasks"`
|
||||
} `json:"mitigations"`
|
||||
}
|
||||
)
|
||||
|
||||
func (s MitigationService) ListForRiskID(
|
||||
ctx context.Context,
|
||||
riskID gid.GID,
|
||||
cursor *page.Cursor[coredata.MitigationOrderField],
|
||||
) (*page.Page[*coredata.Mitigation, coredata.MitigationOrderField], error) {
|
||||
var mitigations coredata.Mitigations
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return mitigations.LoadByRiskID(ctx, conn, s.svc.scope, riskID, cursor)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return page.NewPage(mitigations, cursor), nil
|
||||
}
|
||||
|
||||
func (s MitigationService) ListForControlID(
|
||||
ctx context.Context,
|
||||
controlID gid.GID,
|
||||
cursor *page.Cursor[coredata.MitigationOrderField],
|
||||
) (*page.Page[*coredata.Mitigation, coredata.MitigationOrderField], error) {
|
||||
var mitigations coredata.Mitigations
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return mitigations.LoadByControlID(ctx, conn, s.svc.scope, controlID, cursor)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return page.NewPage(mitigations, cursor), nil
|
||||
}
|
||||
|
||||
func (s MitigationService) Get(
|
||||
ctx context.Context,
|
||||
mitigationID gid.GID,
|
||||
) (*coredata.Mitigation, error) {
|
||||
mitigation := &coredata.Mitigation{}
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return mitigation.LoadByID(ctx, conn, s.svc.scope, mitigationID)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mitigation, nil
|
||||
}
|
||||
|
||||
func (s MitigationService) Import(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
req ImportMitigationRequest,
|
||||
) (*page.Page[*coredata.Mitigation, coredata.MitigationOrderField], error) {
|
||||
importedMitigations := coredata.Mitigations{}
|
||||
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(tx pg.Conn) error {
|
||||
for i := range req.Mitigations {
|
||||
now := time.Now()
|
||||
|
||||
mitigationID, err := gid.NewGID(organizationID.TenantID(), coredata.MitigationEntityType)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create global id: %w", err)
|
||||
}
|
||||
|
||||
mitigation := &coredata.Mitigation{
|
||||
ID: mitigationID,
|
||||
OrganizationID: organizationID,
|
||||
Name: req.Mitigations[i].Name,
|
||||
Description: req.Mitigations[i].Description,
|
||||
Category: req.Mitigations[i].Category,
|
||||
State: coredata.MitigationStateNotStarted,
|
||||
ReferenceID: req.Mitigations[i].ReferenceID,
|
||||
Importance: req.Mitigations[i].Importance,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
importedMitigations = append(importedMitigations, mitigation)
|
||||
|
||||
if err := mitigation.Upsert(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot upsert mitigation: %w", err)
|
||||
}
|
||||
|
||||
for j := range req.Mitigations[i].Tasks {
|
||||
taskID, err := gid.NewGID(organizationID.TenantID(), coredata.TaskEntityType)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create global id: %w", err)
|
||||
}
|
||||
|
||||
task := &coredata.Task{
|
||||
ID: taskID,
|
||||
MitigationID: mitigation.ID,
|
||||
Name: req.Mitigations[i].Tasks[j].Name,
|
||||
Description: req.Mitigations[i].Tasks[j].Description,
|
||||
ReferenceID: req.Mitigations[i].Tasks[j].ReferenceID,
|
||||
State: coredata.TaskStateTodo,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
if err := task.Upsert(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot upsert task: %w", err)
|
||||
}
|
||||
|
||||
for k := range req.Mitigations[i].Tasks[j].RequestedEvidences {
|
||||
evidenceID, err := gid.NewGID(organizationID.TenantID(), coredata.EvidenceEntityType)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create global id: %w", err)
|
||||
}
|
||||
|
||||
evidence := &coredata.Evidence{
|
||||
State: coredata.EvidenceStateRequested,
|
||||
ID: evidenceID,
|
||||
TaskID: task.ID,
|
||||
ReferenceID: req.Mitigations[i].Tasks[j].RequestedEvidences[k].ReferenceID,
|
||||
Type: req.Mitigations[i].Tasks[j].RequestedEvidences[k].Type,
|
||||
Description: req.Mitigations[i].Tasks[j].RequestedEvidences[k].Name,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
if err := evidence.Upsert(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot upsert evidence: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, standard := range req.Mitigations[i].Standards {
|
||||
framework := &coredata.Framework{}
|
||||
if err := framework.LoadByReferenceID(ctx, tx, s.svc.scope, standard.Framework); err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
control := &coredata.Control{}
|
||||
if err := control.LoadByFrameworkIDAndReferenceID(ctx, tx, s.svc.scope, framework.ID, standard.Control); err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
controlMitigation := &coredata.ControlMitigation{
|
||||
ControlID: control.ID,
|
||||
MitigationID: mitigation.ID,
|
||||
CreatedAt: now,
|
||||
}
|
||||
|
||||
if err := controlMitigation.Upsert(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot insert control mitigation: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot import mitigations: %w", err)
|
||||
}
|
||||
|
||||
cursor := page.NewCursor(
|
||||
len(importedMitigations),
|
||||
nil,
|
||||
page.Head,
|
||||
page.OrderBy[coredata.MitigationOrderField]{
|
||||
Field: coredata.MitigationOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionAsc,
|
||||
},
|
||||
)
|
||||
|
||||
return page.NewPage(importedMitigations, cursor), nil
|
||||
}
|
||||
|
||||
func (s MitigationService) Update(
|
||||
ctx context.Context,
|
||||
req UpdateMitigationRequest,
|
||||
) (*coredata.Mitigation, error) {
|
||||
mitigation := &coredata.Mitigation{ID: req.ID}
|
||||
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
if err := mitigation.LoadByID(ctx, conn, s.svc.scope, req.ID); err != nil {
|
||||
return fmt.Errorf("cannot load mitigation: %w", err)
|
||||
}
|
||||
|
||||
if req.Name != nil {
|
||||
mitigation.Name = *req.Name
|
||||
}
|
||||
|
||||
if req.Description != nil {
|
||||
mitigation.Description = *req.Description
|
||||
}
|
||||
|
||||
if req.Category != nil {
|
||||
mitigation.Category = *req.Category
|
||||
}
|
||||
|
||||
if req.State != nil {
|
||||
mitigation.State = *req.State
|
||||
}
|
||||
|
||||
if req.Importance != nil {
|
||||
mitigation.Importance = *req.Importance
|
||||
}
|
||||
|
||||
mitigation.UpdatedAt = time.Now()
|
||||
|
||||
if err := mitigation.Update(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot update mitigation: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mitigation, nil
|
||||
}
|
||||
|
||||
func (s MitigationService) ListForOrganizationID(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[coredata.MitigationOrderField],
|
||||
) (*page.Page[*coredata.Mitigation, coredata.MitigationOrderField], error) {
|
||||
var mitigations coredata.Mitigations
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return mitigations.LoadByOrganizationID(
|
||||
ctx,
|
||||
conn,
|
||||
s.svc.scope,
|
||||
organizationID,
|
||||
cursor,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return page.NewPage(mitigations, cursor), nil
|
||||
}
|
||||
|
||||
func (s MitigationService) Create(
|
||||
ctx context.Context,
|
||||
req CreateMitigationRequest,
|
||||
) (*coredata.Mitigation, error) {
|
||||
now := time.Now()
|
||||
mitigationID, err := gid.NewGID(s.svc.scope.GetTenantID(), coredata.MitigationEntityType)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot create mitigation global id: %w", err)
|
||||
}
|
||||
|
||||
referenceID, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot generate reference id: %w", err)
|
||||
}
|
||||
|
||||
mitigation := &coredata.Mitigation{
|
||||
ID: mitigationID,
|
||||
OrganizationID: req.OrganizationID,
|
||||
Name: req.Name,
|
||||
Description: req.Description,
|
||||
Category: req.Category,
|
||||
ReferenceID: "custom-mitigation-" + referenceID.String(),
|
||||
State: coredata.MitigationStateNotStarted,
|
||||
Importance: req.Importance,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
err = s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
if err := mitigation.Insert(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot insert mitigation: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mitigation, nil
|
||||
}
|
||||
@@ -66,7 +66,7 @@ func (s OrganizationService) Create(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
if err := organization.Insert(ctx, conn); err != nil {
|
||||
return fmt.Errorf("cannot insert mitigation: %w", err)
|
||||
return fmt.Errorf("cannot insert organization: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -55,9 +55,9 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (s RiskService) ListForMitigationID(
|
||||
func (s RiskService) ListForMesureID(
|
||||
ctx context.Context,
|
||||
mitigationID gid.GID,
|
||||
mesureID gid.GID,
|
||||
cursor *page.Cursor[coredata.RiskOrderField],
|
||||
) (*page.Page[*coredata.Risk, coredata.RiskOrderField], error) {
|
||||
var risks coredata.Risks
|
||||
@@ -65,7 +65,7 @@ func (s RiskService) ListForMitigationID(
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return risks.LoadByMitigationID(ctx, conn, s.svc.scope, mitigationID, cursor)
|
||||
return risks.LoadByMesureID(ctx, conn, s.svc.scope, mesureID, cursor)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -116,42 +116,42 @@ func (s RiskService) DeletePolicyMapping(
|
||||
)
|
||||
}
|
||||
|
||||
func (s RiskService) CreateMitigationMapping(
|
||||
func (s RiskService) CreateMesureMapping(
|
||||
ctx context.Context,
|
||||
riskID gid.GID,
|
||||
mitigationID gid.GID,
|
||||
mesureID gid.GID,
|
||||
) error {
|
||||
riskMitigation := &coredata.RiskMitigation{
|
||||
RiskID: riskID,
|
||||
MitigationID: mitigationID,
|
||||
TenantID: s.svc.scope.GetTenantID(),
|
||||
CreatedAt: time.Now(),
|
||||
riskMesure := &coredata.RiskMesure{
|
||||
RiskID: riskID,
|
||||
MesureID: mesureID,
|
||||
TenantID: s.svc.scope.GetTenantID(),
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
return s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return riskMitigation.Insert(ctx, conn, s.svc.scope)
|
||||
return riskMesure.Insert(ctx, conn, s.svc.scope)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (s RiskService) DeleteMitigationMapping(
|
||||
func (s RiskService) DeleteMesureMapping(
|
||||
ctx context.Context,
|
||||
riskID gid.GID,
|
||||
mitigationID gid.GID,
|
||||
mesureID gid.GID,
|
||||
) error {
|
||||
riskMitigation := &coredata.RiskMitigation{
|
||||
RiskID: riskID,
|
||||
MitigationID: mitigationID,
|
||||
TenantID: s.svc.scope.GetTenantID(),
|
||||
CreatedAt: time.Now(),
|
||||
riskMesure := &coredata.RiskMesure{
|
||||
RiskID: riskID,
|
||||
MesureID: mesureID,
|
||||
TenantID: s.svc.scope.GetTenantID(),
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
return s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return riskMitigation.Delete(ctx, conn, s.svc.scope)
|
||||
return riskMesure.Delete(ctx, conn, s.svc.scope)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ type (
|
||||
scope coredata.Scoper
|
||||
|
||||
Frameworks *FrameworkService
|
||||
Mitigations *MitigationService
|
||||
Mesures *MesureService
|
||||
Tasks *TaskService
|
||||
Evidences *EvidenceService
|
||||
Organizations *OrganizationService
|
||||
@@ -80,7 +80,7 @@ func (s *Service) WithTenant(tenantID gid.TenantID) *TenantService {
|
||||
}
|
||||
|
||||
tenantService.Frameworks = &FrameworkService{svc: tenantService}
|
||||
tenantService.Mitigations = &MitigationService{svc: tenantService}
|
||||
tenantService.Mesures = &MesureService{svc: tenantService}
|
||||
tenantService.Tasks = &TaskService{svc: tenantService}
|
||||
tenantService.Evidences = &EvidenceService{svc: tenantService}
|
||||
tenantService.Peoples = &PeopleService{svc: tenantService}
|
||||
|
||||
@@ -32,7 +32,7 @@ type (
|
||||
}
|
||||
|
||||
CreateTaskRequest struct {
|
||||
MitigationID gid.GID
|
||||
MesureID gid.GID
|
||||
Name string
|
||||
Description string
|
||||
TimeEstimate *time.Duration
|
||||
@@ -65,7 +65,7 @@ func (s TaskService) Create(
|
||||
|
||||
task := &coredata.Task{
|
||||
ID: taskID,
|
||||
MitigationID: req.MitigationID,
|
||||
MesureID: req.MesureID,
|
||||
Name: req.Name,
|
||||
Description: req.Description,
|
||||
TimeEstimate: req.TimeEstimate,
|
||||
@@ -215,9 +215,9 @@ func (s TaskService) Delete(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s TaskService) ListForMitigationID(
|
||||
func (s TaskService) ListForMesureID(
|
||||
ctx context.Context,
|
||||
mitigationID gid.GID,
|
||||
mesureID gid.GID,
|
||||
cursor *page.Cursor[coredata.TaskOrderField],
|
||||
) (*page.Page[*coredata.Task, coredata.TaskOrderField], error) {
|
||||
var tasks coredata.Tasks
|
||||
@@ -225,11 +225,11 @@ func (s TaskService) ListForMitigationID(
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return tasks.LoadByMitigationID(
|
||||
return tasks.LoadByMesureID(
|
||||
ctx,
|
||||
conn,
|
||||
s.svc.scope,
|
||||
mitigationID,
|
||||
mesureID,
|
||||
cursor,
|
||||
)
|
||||
},
|
||||
|
||||
@@ -39,23 +39,23 @@ enum OrderDirection
|
||||
DESC @goEnum(value: "github.com/getprobo/probo/pkg/page.OrderDirectionDesc")
|
||||
}
|
||||
|
||||
enum MitigationState
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.MitigationState") {
|
||||
enum MesureState
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.MesureState") {
|
||||
NOT_STARTED
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MitigationStateNotStarted"
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MesureStateNotStarted"
|
||||
)
|
||||
IN_PROGRESS
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MitigationStateInProgress"
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MesureStateInProgress"
|
||||
)
|
||||
NOT_APPLICABLE
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MitigationStateNotApplicable"
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MesureStateNotApplicable"
|
||||
)
|
||||
IMPLEMENTED
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MitigationStateImplemented"
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MesureStateImplemented"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -91,21 +91,19 @@ enum PeopleKind
|
||||
)
|
||||
}
|
||||
|
||||
enum MitigationImportance
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/coredata.MitigationImportance"
|
||||
) {
|
||||
enum MesureImportance
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.MesureImportance") {
|
||||
MANDATORY
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MitigationImportanceMandatory"
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MesureImportanceMandatory"
|
||||
)
|
||||
PREFERRED
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MitigationImportancePreferred"
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MesureImportancePreferred"
|
||||
)
|
||||
ADVANCED
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MitigationImportanceAdvanced"
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MesureImportanceAdvanced"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -213,13 +211,11 @@ enum ControlOrderField
|
||||
)
|
||||
}
|
||||
|
||||
enum MitigationOrderField
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/coredata.MitigationOrderField"
|
||||
) {
|
||||
enum MesureOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.MesureOrderField") {
|
||||
CREATED_AT
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MitigationOrderFieldCreatedAt"
|
||||
value: "github.com/getprobo/probo/pkg/coredata.MesureOrderFieldCreatedAt"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -307,12 +303,12 @@ input ControlOrder
|
||||
field: ControlOrderField!
|
||||
}
|
||||
|
||||
input MitigationOrder
|
||||
input MesureOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.MitigationOrderBy"
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.MesureOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: MitigationOrderField!
|
||||
field: MesureOrderField!
|
||||
}
|
||||
|
||||
input TaskOrder
|
||||
@@ -406,13 +402,13 @@ type Organization implements Node {
|
||||
orderBy: PolicyOrder
|
||||
): PolicyConnection! @goField(forceResolver: true)
|
||||
|
||||
mitigations(
|
||||
mesures(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: MitigationOrder
|
||||
): MitigationConnection! @goField(forceResolver: true)
|
||||
orderBy: MesureOrder
|
||||
): MesureConnection! @goField(forceResolver: true)
|
||||
|
||||
risks(
|
||||
first: Int
|
||||
@@ -516,13 +512,13 @@ type Control implements Node {
|
||||
name: String!
|
||||
description: String!
|
||||
|
||||
mitigations(
|
||||
mesures(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: MitigationOrder
|
||||
): MitigationConnection! @goField(forceResolver: true)
|
||||
orderBy: MesureOrder
|
||||
): MesureConnection! @goField(forceResolver: true)
|
||||
|
||||
policies(
|
||||
first: Int
|
||||
@@ -536,13 +532,13 @@ type Control implements Node {
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type Mitigation implements Node {
|
||||
type Mesure implements Node {
|
||||
id: ID!
|
||||
category: String!
|
||||
name: String!
|
||||
description: String!
|
||||
state: MitigationState!
|
||||
importance: MitigationImportance!
|
||||
state: MesureState!
|
||||
importance: MesureImportance!
|
||||
|
||||
tasks(
|
||||
first: Int
|
||||
@@ -641,13 +637,13 @@ type Risk implements Node {
|
||||
|
||||
owner: People @goField(forceResolver: true)
|
||||
|
||||
mitigations(
|
||||
mesures(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: MitigationOrder
|
||||
): MitigationConnection! @goField(forceResolver: true)
|
||||
orderBy: MesureOrder
|
||||
): MesureConnection! @goField(forceResolver: true)
|
||||
|
||||
policies(
|
||||
first: Int
|
||||
@@ -748,14 +744,14 @@ type ControlEdge {
|
||||
node: Control!
|
||||
}
|
||||
|
||||
type MitigationConnection {
|
||||
edges: [MitigationEdge!]!
|
||||
type MesureConnection {
|
||||
edges: [MesureEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
type MitigationEdge {
|
||||
type MesureEdge {
|
||||
cursor: CursorKey!
|
||||
node: Mitigation!
|
||||
node: Mesure!
|
||||
}
|
||||
|
||||
type TaskConnection {
|
||||
@@ -847,21 +843,21 @@ type Mutation {
|
||||
importFramework(input: ImportFrameworkInput!): ImportFrameworkPayload!
|
||||
deleteFramework(input: DeleteFrameworkInput!): DeleteFrameworkPayload!
|
||||
|
||||
# Mitigation mutations
|
||||
createMitigation(input: CreateMitigationInput!): CreateMitigationPayload!
|
||||
updateMitigation(input: UpdateMitigationInput!): UpdateMitigationPayload!
|
||||
importMitigation(input: ImportMitigationInput!): ImportMitigationPayload!
|
||||
# Mesure mutations
|
||||
createMesure(input: CreateMesureInput!): CreateMesurePayload!
|
||||
updateMesure(input: UpdateMesureInput!): UpdateMesurePayload!
|
||||
importMesure(input: ImportMesureInput!): ImportMesurePayload!
|
||||
|
||||
# Control mutations
|
||||
createControlMitigationMapping(
|
||||
input: CreateControlMitigationMappingInput!
|
||||
): CreateControlMitigationMappingPayload!
|
||||
createControlMesureMapping(
|
||||
input: CreateControlMesureMappingInput!
|
||||
): CreateControlMesureMappingPayload!
|
||||
createControlPolicyMapping(
|
||||
input: CreateControlPolicyMappingInput!
|
||||
): CreateControlPolicyMappingPayload!
|
||||
deleteControlMitigationMapping(
|
||||
input: DeleteControlMitigationMappingInput!
|
||||
): DeleteControlMitigationMappingPayload!
|
||||
deleteControlMesureMapping(
|
||||
input: DeleteControlMesureMappingInput!
|
||||
): DeleteControlMesureMappingPayload!
|
||||
deleteControlPolicyMapping(
|
||||
input: DeleteControlPolicyMappingInput!
|
||||
): DeleteControlPolicyMappingPayload!
|
||||
@@ -877,12 +873,12 @@ type Mutation {
|
||||
createRisk(input: CreateRiskInput!): CreateRiskPayload!
|
||||
updateRisk(input: UpdateRiskInput!): UpdateRiskPayload!
|
||||
deleteRisk(input: DeleteRiskInput!): DeleteRiskPayload!
|
||||
createRiskMitigationMapping(
|
||||
input: CreateRiskMitigationMappingInput!
|
||||
): CreateRiskMitigationMappingPayload!
|
||||
deleteRiskMitigationMapping(
|
||||
input: DeleteRiskMitigationMappingInput!
|
||||
): DeleteRiskMitigationMappingPayload!
|
||||
createRiskMesureMapping(
|
||||
input: CreateRiskMesureMappingInput!
|
||||
): CreateRiskMesureMappingPayload!
|
||||
deleteRiskMesureMapping(
|
||||
input: DeleteRiskMesureMappingInput!
|
||||
): DeleteRiskMesureMappingPayload!
|
||||
|
||||
createRiskPolicyMapping(
|
||||
input: CreateRiskPolicyMappingInput!
|
||||
@@ -1019,30 +1015,30 @@ input DeleteFrameworkInput {
|
||||
frameworkId: ID!
|
||||
}
|
||||
|
||||
input CreateMitigationInput {
|
||||
input CreateMesureInput {
|
||||
organizationId: ID!
|
||||
name: String!
|
||||
description: String!
|
||||
category: String!
|
||||
importance: MitigationImportance!
|
||||
importance: MesureImportance!
|
||||
}
|
||||
|
||||
input UpdateMitigationInput {
|
||||
input UpdateMesureInput {
|
||||
id: ID!
|
||||
name: String
|
||||
description: String
|
||||
category: String
|
||||
state: MitigationState
|
||||
importance: MitigationImportance
|
||||
state: MesureState
|
||||
importance: MesureImportance
|
||||
}
|
||||
|
||||
input ImportMitigationInput {
|
||||
input ImportMesureInput {
|
||||
organizationId: ID!
|
||||
file: Upload!
|
||||
}
|
||||
|
||||
input CreateTaskInput {
|
||||
mitigationId: ID!
|
||||
mesureId: ID!
|
||||
name: String!
|
||||
description: String!
|
||||
timeEstimate: Duration
|
||||
@@ -1070,9 +1066,9 @@ input UnassignTaskInput {
|
||||
taskId: ID!
|
||||
}
|
||||
|
||||
input CreateControlMitigationMappingInput {
|
||||
input CreateControlMesureMappingInput {
|
||||
controlId: ID!
|
||||
mitigationId: ID!
|
||||
mesureId: ID!
|
||||
}
|
||||
|
||||
input CreateControlPolicyMappingInput {
|
||||
@@ -1080,9 +1076,9 @@ input CreateControlPolicyMappingInput {
|
||||
policyId: ID!
|
||||
}
|
||||
|
||||
input DeleteControlMitigationMappingInput {
|
||||
input DeleteControlMesureMappingInput {
|
||||
controlId: ID!
|
||||
mitigationId: ID!
|
||||
mesureId: ID!
|
||||
}
|
||||
|
||||
input DeleteControlPolicyMappingInput {
|
||||
@@ -1118,14 +1114,14 @@ input DeleteRiskInput {
|
||||
riskId: ID!
|
||||
}
|
||||
|
||||
input CreateRiskMitigationMappingInput {
|
||||
input CreateRiskMesureMappingInput {
|
||||
riskId: ID!
|
||||
mitigationId: ID!
|
||||
mesureId: ID!
|
||||
}
|
||||
|
||||
input DeleteRiskMitigationMappingInput {
|
||||
input DeleteRiskMesureMappingInput {
|
||||
riskId: ID!
|
||||
mitigationId: ID!
|
||||
mesureId: ID!
|
||||
}
|
||||
|
||||
input CreateRiskPolicyMappingInput {
|
||||
@@ -1267,16 +1263,16 @@ type DeleteFrameworkPayload {
|
||||
deletedFrameworkId: ID!
|
||||
}
|
||||
|
||||
type CreateMitigationPayload {
|
||||
mitigationEdge: MitigationEdge!
|
||||
type CreateMesurePayload {
|
||||
mesureEdge: MesureEdge!
|
||||
}
|
||||
|
||||
type UpdateMitigationPayload {
|
||||
mitigation: Mitigation!
|
||||
type UpdateMesurePayload {
|
||||
mesure: Mesure!
|
||||
}
|
||||
|
||||
type ImportMitigationPayload {
|
||||
mitigationEdges: [MitigationEdge!]!
|
||||
type ImportMesurePayload {
|
||||
mesureEdges: [MesureEdge!]!
|
||||
}
|
||||
|
||||
type CreateTaskPayload {
|
||||
@@ -1299,7 +1295,7 @@ type UnassignTaskPayload {
|
||||
task: Task!
|
||||
}
|
||||
|
||||
type CreateControlMitigationMappingPayload {
|
||||
type CreateControlMesureMappingPayload {
|
||||
success: Boolean!
|
||||
}
|
||||
|
||||
@@ -1307,7 +1303,7 @@ type CreateControlPolicyMappingPayload {
|
||||
success: Boolean!
|
||||
}
|
||||
|
||||
type DeleteControlMitigationMappingPayload {
|
||||
type DeleteControlMesureMappingPayload {
|
||||
success: Boolean!
|
||||
}
|
||||
|
||||
@@ -1327,11 +1323,11 @@ type DeleteRiskPayload {
|
||||
deletedRiskId: ID!
|
||||
}
|
||||
|
||||
type CreateRiskMitigationMappingPayload {
|
||||
type CreateRiskMesureMappingPayload {
|
||||
success: Boolean!
|
||||
}
|
||||
|
||||
type DeleteRiskMitigationMappingPayload {
|
||||
type DeleteRiskMesureMappingPayload {
|
||||
success: Boolean!
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -20,31 +20,31 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
MitigationOrderBy OrderBy[coredata.MitigationOrderField]
|
||||
MesureOrderBy OrderBy[coredata.MesureOrderField]
|
||||
)
|
||||
|
||||
func NewMitigationConnection(p *page.Page[*coredata.Mitigation, coredata.MitigationOrderField]) *MitigationConnection {
|
||||
var edges = make([]*MitigationEdge, len(p.Data))
|
||||
func NewMesureConnection(p *page.Page[*coredata.Mesure, coredata.MesureOrderField]) *MesureConnection {
|
||||
var edges = make([]*MesureEdge, len(p.Data))
|
||||
|
||||
for i := range edges {
|
||||
edges[i] = NewMitigationEdge(p.Data[i], p.Cursor.OrderBy.Field)
|
||||
edges[i] = NewMesureEdge(p.Data[i], p.Cursor.OrderBy.Field)
|
||||
}
|
||||
|
||||
return &MitigationConnection{
|
||||
return &MesureConnection{
|
||||
Edges: edges,
|
||||
PageInfo: NewPageInfo(p),
|
||||
}
|
||||
}
|
||||
|
||||
func NewMitigationEdge(c *coredata.Mitigation, orderBy coredata.MitigationOrderField) *MitigationEdge {
|
||||
return &MitigationEdge{
|
||||
func NewMesureEdge(c *coredata.Mesure, orderBy coredata.MesureOrderField) *MesureEdge {
|
||||
return &MesureEdge{
|
||||
Cursor: c.CursorKey(orderBy),
|
||||
Node: NewMitigation(c),
|
||||
Node: NewMesure(c),
|
||||
}
|
||||
}
|
||||
|
||||
func NewMitigation(c *coredata.Mitigation) *Mitigation {
|
||||
return &Mitigation{
|
||||
func NewMesure(c *coredata.Mesure) *Mesure {
|
||||
return &Mesure{
|
||||
ID: c.ID,
|
||||
Category: c.Category,
|
||||
Name: c.Name,
|
||||
@@ -37,14 +37,14 @@ type ConfirmEmailPayload struct {
|
||||
}
|
||||
|
||||
type Control struct {
|
||||
ID gid.GID `json:"id"`
|
||||
ReferenceID string `json:"referenceId"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Mitigations *MitigationConnection `json:"mitigations"`
|
||||
Policies *PolicyConnection `json:"policies"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
ID gid.GID `json:"id"`
|
||||
ReferenceID string `json:"referenceId"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Mesures *MesureConnection `json:"mesures"`
|
||||
Policies *PolicyConnection `json:"policies"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (Control) IsNode() {}
|
||||
@@ -60,12 +60,12 @@ type ControlEdge struct {
|
||||
Node *Control `json:"node"`
|
||||
}
|
||||
|
||||
type CreateControlMitigationMappingInput struct {
|
||||
ControlID gid.GID `json:"controlId"`
|
||||
MitigationID gid.GID `json:"mitigationId"`
|
||||
type CreateControlMesureMappingInput struct {
|
||||
ControlID gid.GID `json:"controlId"`
|
||||
MesureID gid.GID `json:"mesureId"`
|
||||
}
|
||||
|
||||
type CreateControlMitigationMappingPayload struct {
|
||||
type CreateControlMesureMappingPayload struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
@@ -101,16 +101,16 @@ type CreateFrameworkPayload struct {
|
||||
FrameworkEdge *FrameworkEdge `json:"frameworkEdge"`
|
||||
}
|
||||
|
||||
type CreateMitigationInput struct {
|
||||
OrganizationID gid.GID `json:"organizationId"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Category string `json:"category"`
|
||||
Importance coredata.MitigationImportance `json:"importance"`
|
||||
type CreateMesureInput struct {
|
||||
OrganizationID gid.GID `json:"organizationId"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Category string `json:"category"`
|
||||
Importance coredata.MesureImportance `json:"importance"`
|
||||
}
|
||||
|
||||
type CreateMitigationPayload struct {
|
||||
MitigationEdge *MitigationEdge `json:"mitigationEdge"`
|
||||
type CreateMesurePayload struct {
|
||||
MesureEdge *MesureEdge `json:"mesureEdge"`
|
||||
}
|
||||
|
||||
type CreateOrganizationInput struct {
|
||||
@@ -158,12 +158,12 @@ type CreateRiskInput struct {
|
||||
ResidualImpact *float64 `json:"residualImpact,omitempty"`
|
||||
}
|
||||
|
||||
type CreateRiskMitigationMappingInput struct {
|
||||
RiskID gid.GID `json:"riskId"`
|
||||
MitigationID gid.GID `json:"mitigationId"`
|
||||
type CreateRiskMesureMappingInput struct {
|
||||
RiskID gid.GID `json:"riskId"`
|
||||
MesureID gid.GID `json:"mesureId"`
|
||||
}
|
||||
|
||||
type CreateRiskMitigationMappingPayload struct {
|
||||
type CreateRiskMesureMappingPayload struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ type CreateRiskPolicyMappingPayload struct {
|
||||
}
|
||||
|
||||
type CreateTaskInput struct {
|
||||
MitigationID gid.GID `json:"mitigationId"`
|
||||
MesureID gid.GID `json:"mesureId"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
TimeEstimate *time.Duration `json:"timeEstimate,omitempty"`
|
||||
@@ -220,12 +220,12 @@ type CreateVendorPayload struct {
|
||||
VendorEdge *VendorEdge `json:"vendorEdge"`
|
||||
}
|
||||
|
||||
type DeleteControlMitigationMappingInput struct {
|
||||
ControlID gid.GID `json:"controlId"`
|
||||
MitigationID gid.GID `json:"mitigationId"`
|
||||
type DeleteControlMesureMappingInput struct {
|
||||
ControlID gid.GID `json:"controlId"`
|
||||
MesureID gid.GID `json:"mesureId"`
|
||||
}
|
||||
|
||||
type DeleteControlMitigationMappingPayload struct {
|
||||
type DeleteControlMesureMappingPayload struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
@@ -282,12 +282,12 @@ type DeleteRiskInput struct {
|
||||
RiskID gid.GID `json:"riskId"`
|
||||
}
|
||||
|
||||
type DeleteRiskMitigationMappingInput struct {
|
||||
RiskID gid.GID `json:"riskId"`
|
||||
MitigationID gid.GID `json:"mitigationId"`
|
||||
type DeleteRiskMesureMappingInput struct {
|
||||
RiskID gid.GID `json:"riskId"`
|
||||
MesureID gid.GID `json:"mesureId"`
|
||||
}
|
||||
|
||||
type DeleteRiskMitigationMappingPayload struct {
|
||||
type DeleteRiskMesureMappingPayload struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
@@ -397,13 +397,13 @@ type ImportFrameworkPayload struct {
|
||||
FrameworkEdge *FrameworkEdge `json:"frameworkEdge"`
|
||||
}
|
||||
|
||||
type ImportMitigationInput struct {
|
||||
type ImportMesureInput struct {
|
||||
OrganizationID gid.GID `json:"organizationId"`
|
||||
File graphql.Upload `json:"file"`
|
||||
}
|
||||
|
||||
type ImportMitigationPayload struct {
|
||||
MitigationEdges []*MitigationEdge `json:"mitigationEdges"`
|
||||
type ImportMesurePayload struct {
|
||||
MesureEdges []*MesureEdge `json:"mesureEdges"`
|
||||
}
|
||||
|
||||
type InviteUserInput struct {
|
||||
@@ -416,49 +416,49 @@ type InviteUserPayload struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type Mitigation struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Category string `json:"category"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
State coredata.MitigationState `json:"state"`
|
||||
Importance coredata.MitigationImportance `json:"importance"`
|
||||
Tasks *TaskConnection `json:"tasks"`
|
||||
Risks *RiskConnection `json:"risks"`
|
||||
Controls *ControlConnection `json:"controls"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
type Mesure struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Category string `json:"category"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
State coredata.MesureState `json:"state"`
|
||||
Importance coredata.MesureImportance `json:"importance"`
|
||||
Tasks *TaskConnection `json:"tasks"`
|
||||
Risks *RiskConnection `json:"risks"`
|
||||
Controls *ControlConnection `json:"controls"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (Mitigation) IsNode() {}
|
||||
func (this Mitigation) GetID() gid.GID { return this.ID }
|
||||
func (Mesure) IsNode() {}
|
||||
func (this Mesure) GetID() gid.GID { return this.ID }
|
||||
|
||||
type MitigationConnection struct {
|
||||
Edges []*MitigationEdge `json:"edges"`
|
||||
PageInfo *PageInfo `json:"pageInfo"`
|
||||
type MesureConnection struct {
|
||||
Edges []*MesureEdge `json:"edges"`
|
||||
PageInfo *PageInfo `json:"pageInfo"`
|
||||
}
|
||||
|
||||
type MitigationEdge struct {
|
||||
type MesureEdge struct {
|
||||
Cursor page.CursorKey `json:"cursor"`
|
||||
Node *Mitigation `json:"node"`
|
||||
Node *Mesure `json:"node"`
|
||||
}
|
||||
|
||||
type Mutation struct {
|
||||
}
|
||||
|
||||
type Organization struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
LogoURL *string `json:"logoUrl,omitempty"`
|
||||
Users *UserConnection `json:"users"`
|
||||
Frameworks *FrameworkConnection `json:"frameworks"`
|
||||
Vendors *VendorConnection `json:"vendors"`
|
||||
Peoples *PeopleConnection `json:"peoples"`
|
||||
Policies *PolicyConnection `json:"policies"`
|
||||
Mitigations *MitigationConnection `json:"mitigations"`
|
||||
Risks *RiskConnection `json:"risks"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
LogoURL *string `json:"logoUrl,omitempty"`
|
||||
Users *UserConnection `json:"users"`
|
||||
Frameworks *FrameworkConnection `json:"frameworks"`
|
||||
Vendors *VendorConnection `json:"vendors"`
|
||||
Peoples *PeopleConnection `json:"peoples"`
|
||||
Policies *PolicyConnection `json:"policies"`
|
||||
Mesures *MesureConnection `json:"mesures"`
|
||||
Risks *RiskConnection `json:"risks"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (Organization) IsNode() {}
|
||||
@@ -569,7 +569,7 @@ type Risk struct {
|
||||
ResidualImpact float64 `json:"residualImpact"`
|
||||
ResidualSeverity float64 `json:"residualSeverity"`
|
||||
Owner *People `json:"owner,omitempty"`
|
||||
Mitigations *MitigationConnection `json:"mitigations"`
|
||||
Mesures *MesureConnection `json:"mesures"`
|
||||
Policies *PolicyConnection `json:"policies"`
|
||||
Controls *ControlConnection `json:"controls"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
@@ -637,17 +637,17 @@ type UpdateFrameworkPayload struct {
|
||||
Framework *Framework `json:"framework"`
|
||||
}
|
||||
|
||||
type UpdateMitigationInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Category *string `json:"category,omitempty"`
|
||||
State *coredata.MitigationState `json:"state,omitempty"`
|
||||
Importance *coredata.MitigationImportance `json:"importance,omitempty"`
|
||||
type UpdateMesureInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Category *string `json:"category,omitempty"`
|
||||
State *coredata.MesureState `json:"state,omitempty"`
|
||||
Importance *coredata.MesureImportance `json:"importance,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateMitigationPayload struct {
|
||||
Mitigation *Mitigation `json:"mitigation"`
|
||||
type UpdateMesurePayload struct {
|
||||
Mesure *Mesure `json:"mesure"`
|
||||
}
|
||||
|
||||
type UpdateOrganizationInput struct {
|
||||
|
||||
@@ -20,16 +20,16 @@ import (
|
||||
"github.com/vektah/gqlparser/v2/gqlerror"
|
||||
)
|
||||
|
||||
// Mitigations is the resolver for the mitigations field.
|
||||
func (r *controlResolver) Mitigations(ctx context.Context, obj *types.Control, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.MitigationOrderBy) (*types.MitigationConnection, error) {
|
||||
// Mesures is the resolver for the mesures field.
|
||||
func (r *controlResolver) Mesures(ctx context.Context, obj *types.Control, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.MesureOrderBy) (*types.MesureConnection, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.MitigationOrderField]{
|
||||
Field: coredata.MitigationOrderFieldCreatedAt,
|
||||
pageOrderBy := page.OrderBy[coredata.MesureOrderField]{
|
||||
Field: coredata.MesureOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.MitigationOrderField]{
|
||||
pageOrderBy = page.OrderBy[coredata.MesureOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
@@ -37,12 +37,12 @@ func (r *controlResolver) Mitigations(ctx context.Context, obj *types.Control, f
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := svc.Mitigations.ListForControlID(ctx, obj.ID, cursor)
|
||||
page, err := svc.Mesures.ListForControlID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list mitigations: %w", err)
|
||||
return nil, fmt.Errorf("cannot list mesures: %w", err)
|
||||
}
|
||||
|
||||
return types.NewMitigationConnection(page), nil
|
||||
return types.NewMesureConnection(page), nil
|
||||
}
|
||||
|
||||
// Policies is the resolver for the policies field.
|
||||
@@ -113,7 +113,7 @@ func (r *frameworkResolver) Controls(ctx context.Context, obj *types.Framework,
|
||||
}
|
||||
|
||||
// Tasks is the resolver for the tasks field.
|
||||
func (r *mitigationResolver) Tasks(ctx context.Context, obj *types.Mitigation, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.TaskOrderBy) (*types.TaskConnection, error) {
|
||||
func (r *mesureResolver) Tasks(ctx context.Context, obj *types.Mesure, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.TaskOrderBy) (*types.TaskConnection, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.TaskOrderField]{
|
||||
@@ -129,16 +129,16 @@ func (r *mitigationResolver) Tasks(ctx context.Context, obj *types.Mitigation, f
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := svc.Tasks.ListForMitigationID(ctx, obj.ID, cursor)
|
||||
page, err := svc.Tasks.ListForMesureID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list mitigation tasks: %w", err)
|
||||
return nil, fmt.Errorf("cannot list mesure tasks: %w", err)
|
||||
}
|
||||
|
||||
return types.NewTaskConnection(page), nil
|
||||
}
|
||||
|
||||
// Risks is the resolver for the risks field.
|
||||
func (r *mitigationResolver) Risks(ctx context.Context, obj *types.Mitigation, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.RiskOrderBy) (*types.RiskConnection, error) {
|
||||
func (r *mesureResolver) Risks(ctx context.Context, obj *types.Mesure, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.RiskOrderBy) (*types.RiskConnection, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.RiskOrderField]{
|
||||
@@ -154,16 +154,16 @@ func (r *mitigationResolver) Risks(ctx context.Context, obj *types.Mitigation, f
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := svc.Risks.ListForMitigationID(ctx, obj.ID, cursor)
|
||||
page, err := svc.Risks.ListForMesureID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list mitigation risks: %w", err)
|
||||
return nil, fmt.Errorf("cannot list mesure risks: %w", err)
|
||||
}
|
||||
|
||||
return types.NewRiskConnection(page), nil
|
||||
}
|
||||
|
||||
// Controls is the resolver for the controls field.
|
||||
func (r *mitigationResolver) Controls(ctx context.Context, obj *types.Mitigation, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ControlOrderBy) (*types.ControlConnection, error) {
|
||||
func (r *mesureResolver) Controls(ctx context.Context, obj *types.Mesure, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ControlOrderBy) (*types.ControlConnection, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.ControlOrderField]{
|
||||
@@ -179,9 +179,9 @@ func (r *mitigationResolver) Controls(ctx context.Context, obj *types.Mitigation
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := svc.Controls.ListForMitigationID(ctx, obj.ID, cursor)
|
||||
page, err := svc.Controls.ListForMesureID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list mitigation controls: %w", err)
|
||||
return nil, fmt.Errorf("cannot list mesure controls: %w", err)
|
||||
}
|
||||
|
||||
return types.NewControlConnection(page), nil
|
||||
@@ -518,11 +518,11 @@ func (r *mutationResolver) DeleteFramework(ctx context.Context, input types.Dele
|
||||
}, nil
|
||||
}
|
||||
|
||||
// // CreateMitigation is the resolver for the createMitigation field.
|
||||
func (r *mutationResolver) CreateMitigation(ctx context.Context, input types.CreateMitigationInput) (*types.CreateMitigationPayload, error) {
|
||||
// // CreateMesure is the resolver for the createMesure field.
|
||||
func (r *mutationResolver) CreateMesure(ctx context.Context, input types.CreateMesureInput) (*types.CreateMesurePayload, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.OrganizationID.TenantID())
|
||||
|
||||
mitigation, err := svc.Mitigations.Create(ctx, probo.CreateMitigationRequest{
|
||||
mesure, err := svc.Mesures.Create(ctx, probo.CreateMesureRequest{
|
||||
OrganizationID: input.OrganizationID,
|
||||
Name: input.Name,
|
||||
Description: input.Description,
|
||||
@@ -530,19 +530,19 @@ func (r *mutationResolver) CreateMitigation(ctx context.Context, input types.Cre
|
||||
Importance: input.Importance,
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot create mitigation: %w", err))
|
||||
panic(fmt.Errorf("cannot create mesure: %w", err))
|
||||
}
|
||||
|
||||
return &types.CreateMitigationPayload{
|
||||
MitigationEdge: types.NewMitigationEdge(mitigation, coredata.MitigationOrderFieldCreatedAt),
|
||||
return &types.CreateMesurePayload{
|
||||
MesureEdge: types.NewMesureEdge(mesure, coredata.MesureOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateMitigation is the resolver for the updateMitigation field.
|
||||
func (r *mutationResolver) UpdateMitigation(ctx context.Context, input types.UpdateMitigationInput) (*types.UpdateMitigationPayload, error) {
|
||||
// UpdateMesure is the resolver for the updateMesure field.
|
||||
func (r *mutationResolver) UpdateMesure(ctx context.Context, input types.UpdateMesureInput) (*types.UpdateMesurePayload, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.ID.TenantID())
|
||||
|
||||
mitigation, err := svc.Mitigations.Update(ctx, probo.UpdateMitigationRequest{
|
||||
mesure, err := svc.Mesures.Update(ctx, probo.UpdateMesureRequest{
|
||||
ID: input.ID,
|
||||
Name: input.Name,
|
||||
Description: input.Description,
|
||||
@@ -551,48 +551,48 @@ func (r *mutationResolver) UpdateMitigation(ctx context.Context, input types.Upd
|
||||
State: input.State,
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot update mitigation: %w", err))
|
||||
panic(fmt.Errorf("cannot update mesure: %w", err))
|
||||
}
|
||||
|
||||
return &types.UpdateMitigationPayload{
|
||||
Mitigation: types.NewMitigation(mitigation),
|
||||
return &types.UpdateMesurePayload{
|
||||
Mesure: types.NewMesure(mesure),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ImportMitigation is the resolver for the importMitigation field.
|
||||
func (r *mutationResolver) ImportMitigation(ctx context.Context, input types.ImportMitigationInput) (*types.ImportMitigationPayload, error) {
|
||||
// ImportMesure is the resolver for the importMesure field.
|
||||
func (r *mutationResolver) ImportMesure(ctx context.Context, input types.ImportMesureInput) (*types.ImportMesurePayload, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.OrganizationID.TenantID())
|
||||
|
||||
var req probo.ImportMitigationRequest
|
||||
if err := json.NewDecoder(input.File.File).Decode(&req.Mitigations); err != nil {
|
||||
return nil, fmt.Errorf("cannot unmarshal mitigation: %w", err)
|
||||
var req probo.ImportMesureRequest
|
||||
if err := json.NewDecoder(input.File.File).Decode(&req.Mesures); err != nil {
|
||||
return nil, fmt.Errorf("cannot unmarshal mesure: %w", err)
|
||||
}
|
||||
|
||||
mitigations, err := svc.Mitigations.Import(ctx, input.OrganizationID, req)
|
||||
mesures, err := svc.Mesures.Import(ctx, input.OrganizationID, req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot import mitigation: %w", err)
|
||||
return nil, fmt.Errorf("cannot import mesure: %w", err)
|
||||
}
|
||||
|
||||
mitigationEdges := make([]*types.MitigationEdge, len(mitigations.Data))
|
||||
for i, mitigation := range mitigations.Data {
|
||||
mitigationEdges[i] = types.NewMitigationEdge(mitigation, coredata.MitigationOrderFieldCreatedAt)
|
||||
mesureEdges := make([]*types.MesureEdge, len(mesures.Data))
|
||||
for i, mesure := range mesures.Data {
|
||||
mesureEdges[i] = types.NewMesureEdge(mesure, coredata.MesureOrderFieldCreatedAt)
|
||||
}
|
||||
|
||||
return &types.ImportMitigationPayload{
|
||||
MitigationEdges: mitigationEdges,
|
||||
return &types.ImportMesurePayload{
|
||||
MesureEdges: mesureEdges,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CreateControlMitigationMapping is the resolver for the createControlMitigationMapping field.
|
||||
func (r *mutationResolver) CreateControlMitigationMapping(ctx context.Context, input types.CreateControlMitigationMappingInput) (*types.CreateControlMitigationMappingPayload, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.MitigationID.TenantID())
|
||||
// CreateControlMesureMapping is the resolver for the createControlMesureMapping field.
|
||||
func (r *mutationResolver) CreateControlMesureMapping(ctx context.Context, input types.CreateControlMesureMappingInput) (*types.CreateControlMesureMappingPayload, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.MesureID.TenantID())
|
||||
|
||||
err := svc.Controls.CreateMitigationMapping(ctx, input.ControlID, input.MitigationID)
|
||||
err := svc.Controls.CreateMesureMapping(ctx, input.ControlID, input.MesureID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot create control mitigation mapping: %w", err))
|
||||
panic(fmt.Errorf("cannot create control mesure mapping: %w", err))
|
||||
}
|
||||
|
||||
return &types.CreateControlMitigationMappingPayload{
|
||||
return &types.CreateControlMesureMappingPayload{
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
@@ -611,16 +611,16 @@ func (r *mutationResolver) CreateControlPolicyMapping(ctx context.Context, input
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DeleteControlMitigationMapping is the resolver for the deleteControlMitigationMapping field.
|
||||
func (r *mutationResolver) DeleteControlMitigationMapping(ctx context.Context, input types.DeleteControlMitigationMappingInput) (*types.DeleteControlMitigationMappingPayload, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.MitigationID.TenantID())
|
||||
// DeleteControlMesureMapping is the resolver for the deleteControlMesureMapping field.
|
||||
func (r *mutationResolver) DeleteControlMesureMapping(ctx context.Context, input types.DeleteControlMesureMappingInput) (*types.DeleteControlMesureMappingPayload, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.MesureID.TenantID())
|
||||
|
||||
err := svc.Controls.DeleteMitigationMapping(ctx, input.ControlID, input.MitigationID)
|
||||
err := svc.Controls.DeleteMesureMapping(ctx, input.ControlID, input.MesureID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot delete control mitigation mapping: %w", err))
|
||||
panic(fmt.Errorf("cannot delete control mesure mapping: %w", err))
|
||||
}
|
||||
|
||||
return &types.DeleteControlMitigationMappingPayload{
|
||||
return &types.DeleteControlMesureMappingPayload{
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
@@ -641,10 +641,10 @@ func (r *mutationResolver) DeleteControlPolicyMapping(ctx context.Context, input
|
||||
|
||||
// CreateTask is the resolver for the createTask field.
|
||||
func (r *mutationResolver) CreateTask(ctx context.Context, input types.CreateTaskInput) (*types.CreateTaskPayload, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.MitigationID.TenantID())
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.MesureID.TenantID())
|
||||
|
||||
task, err := svc.Tasks.Create(ctx, probo.CreateTaskRequest{
|
||||
MitigationID: input.MitigationID,
|
||||
MesureID: input.MesureID,
|
||||
Name: input.Name,
|
||||
Description: input.Description,
|
||||
TimeEstimate: input.TimeEstimate,
|
||||
@@ -788,30 +788,30 @@ func (r *mutationResolver) DeleteRisk(ctx context.Context, input types.DeleteRis
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CreateRiskMitigationMapping is the resolver for the createRiskMitigationMapping field.
|
||||
func (r *mutationResolver) CreateRiskMitigationMapping(ctx context.Context, input types.CreateRiskMitigationMappingInput) (*types.CreateRiskMitigationMappingPayload, error) {
|
||||
// CreateRiskMesureMapping is the resolver for the createRiskMesureMapping field.
|
||||
func (r *mutationResolver) CreateRiskMesureMapping(ctx context.Context, input types.CreateRiskMesureMappingInput) (*types.CreateRiskMesureMappingPayload, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.RiskID.TenantID())
|
||||
|
||||
err := svc.Risks.CreateMitigationMapping(ctx, input.RiskID, input.MitigationID)
|
||||
err := svc.Risks.CreateMesureMapping(ctx, input.RiskID, input.MesureID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot create risk mitigation mapping: %w", err))
|
||||
panic(fmt.Errorf("cannot create risk mesure mapping: %w", err))
|
||||
}
|
||||
|
||||
return &types.CreateRiskMitigationMappingPayload{
|
||||
return &types.CreateRiskMesureMappingPayload{
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DeleteRiskMitigationMapping is the resolver for the deleteRiskMitigationMapping field.
|
||||
func (r *mutationResolver) DeleteRiskMitigationMapping(ctx context.Context, input types.DeleteRiskMitigationMappingInput) (*types.DeleteRiskMitigationMappingPayload, error) {
|
||||
// DeleteRiskMesureMapping is the resolver for the deleteRiskMesureMapping field.
|
||||
func (r *mutationResolver) DeleteRiskMesureMapping(ctx context.Context, input types.DeleteRiskMesureMappingInput) (*types.DeleteRiskMesureMappingPayload, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.RiskID.TenantID())
|
||||
|
||||
err := svc.Risks.DeleteMitigationMapping(ctx, input.RiskID, input.MitigationID)
|
||||
err := svc.Risks.DeleteMesureMapping(ctx, input.RiskID, input.MesureID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot delete risk mitigation mapping: %w", err))
|
||||
panic(fmt.Errorf("cannot delete risk mesure mapping: %w", err))
|
||||
}
|
||||
|
||||
return &types.DeleteRiskMitigationMappingPayload{
|
||||
return &types.DeleteRiskMesureMappingPayload{
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
@@ -1162,16 +1162,16 @@ func (r *organizationResolver) Policies(ctx context.Context, obj *types.Organiza
|
||||
return types.NewPolicyConnection(page), nil
|
||||
}
|
||||
|
||||
// Mitigations is the resolver for the mitigations field.
|
||||
func (r *organizationResolver) Mitigations(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.MitigationOrderBy) (*types.MitigationConnection, error) {
|
||||
// Mesures is the resolver for the mesures field.
|
||||
func (r *organizationResolver) Mesures(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.MesureOrderBy) (*types.MesureConnection, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.MitigationOrderField]{
|
||||
Field: coredata.MitigationOrderFieldCreatedAt,
|
||||
pageOrderBy := page.OrderBy[coredata.MesureOrderField]{
|
||||
Field: coredata.MesureOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.MitigationOrderField]{
|
||||
pageOrderBy = page.OrderBy[coredata.MesureOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
@@ -1179,12 +1179,12 @@ func (r *organizationResolver) Mitigations(ctx context.Context, obj *types.Organ
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := svc.Mitigations.ListForOrganizationID(ctx, obj.ID, cursor)
|
||||
page, err := svc.Mesures.ListForOrganizationID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot list organization mitigations: %w", err))
|
||||
panic(fmt.Errorf("cannot list organization mesures: %w", err))
|
||||
}
|
||||
|
||||
return types.NewMitigationConnection(page), nil
|
||||
return types.NewMesureConnection(page), nil
|
||||
}
|
||||
|
||||
// Risks is the resolver for the risks field.
|
||||
@@ -1288,13 +1288,13 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
|
||||
}
|
||||
|
||||
return types.NewFramework(framework), nil
|
||||
case coredata.MitigationEntityType:
|
||||
mitigation, err := svc.Mitigations.Get(ctx, id)
|
||||
case coredata.MesureEntityType:
|
||||
mesure, err := svc.Mesures.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get mitigation: %w", err))
|
||||
panic(fmt.Errorf("cannot get mesure: %w", err))
|
||||
}
|
||||
|
||||
return types.NewMitigation(mitigation), nil
|
||||
return types.NewMesure(mesure), nil
|
||||
case coredata.TaskEntityType:
|
||||
task, err := svc.Tasks.Get(ctx, id)
|
||||
if err != nil {
|
||||
@@ -1372,16 +1372,16 @@ func (r *riskResolver) Owner(ctx context.Context, obj *types.Risk) (*types.Peopl
|
||||
return types.NewPeople(owner), nil
|
||||
}
|
||||
|
||||
// Mitigations is the resolver for the mitigations field.
|
||||
func (r *riskResolver) Mitigations(ctx context.Context, obj *types.Risk, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.MitigationOrderBy) (*types.MitigationConnection, error) {
|
||||
// Mesures is the resolver for the mesures field.
|
||||
func (r *riskResolver) Mesures(ctx context.Context, obj *types.Risk, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.MesureOrderBy) (*types.MesureConnection, error) {
|
||||
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.MitigationOrderField]{
|
||||
Field: coredata.MitigationOrderFieldCreatedAt,
|
||||
pageOrderBy := page.OrderBy[coredata.MesureOrderField]{
|
||||
Field: coredata.MesureOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.MitigationOrderField]{
|
||||
pageOrderBy = page.OrderBy[coredata.MesureOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
@@ -1389,12 +1389,12 @@ func (r *riskResolver) Mitigations(ctx context.Context, obj *types.Risk, first *
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := svc.Mitigations.ListForRiskID(ctx, obj.ID, cursor)
|
||||
page, err := svc.Mesures.ListForRiskID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot list risk mitigations: %w", err))
|
||||
panic(fmt.Errorf("cannot list risk mesures: %w", err))
|
||||
}
|
||||
|
||||
return types.NewMitigationConnection(page), nil
|
||||
return types.NewMesureConnection(page), nil
|
||||
}
|
||||
|
||||
// Policies is the resolver for the policies field.
|
||||
@@ -1617,8 +1617,8 @@ func (r *Resolver) Evidence() schema.EvidenceResolver { return &evidenceResolver
|
||||
// Framework returns schema.FrameworkResolver implementation.
|
||||
func (r *Resolver) Framework() schema.FrameworkResolver { return &frameworkResolver{r} }
|
||||
|
||||
// Mitigation returns schema.MitigationResolver implementation.
|
||||
func (r *Resolver) Mitigation() schema.MitigationResolver { return &mitigationResolver{r} }
|
||||
// Mesure returns schema.MesureResolver implementation.
|
||||
func (r *Resolver) Mesure() schema.MesureResolver { return &mesureResolver{r} }
|
||||
|
||||
// Mutation returns schema.MutationResolver implementation.
|
||||
func (r *Resolver) Mutation() schema.MutationResolver { return &mutationResolver{r} }
|
||||
@@ -1652,7 +1652,7 @@ func (r *Resolver) Viewer() schema.ViewerResolver { return &viewerResolver{r} }
|
||||
type controlResolver struct{ *Resolver }
|
||||
type evidenceResolver struct{ *Resolver }
|
||||
type frameworkResolver struct{ *Resolver }
|
||||
type mitigationResolver struct{ *Resolver }
|
||||
type mesureResolver struct{ *Resolver }
|
||||
type mutationResolver struct{ *Resolver }
|
||||
type organizationResolver struct{ *Resolver }
|
||||
type policyResolver struct{ *Resolver }
|
||||
|
||||
Reference in New Issue
Block a user