Add snapshots

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-08-19 14:28:13 +02:00
parent 9a7add8577
commit e12d04c947
49 changed files with 5560 additions and 185 deletions

View File

@@ -686,6 +686,50 @@ enum TrustCenterAccessOrderField
)
}
enum SnapshotsType
@goModel(model: "github.com/getprobo/probo/pkg/coredata.SnapshotsType") {
RISKS
@goEnum(
value: "github.com/getprobo/probo/pkg/coredata.SnapshotsTypeRisks"
)
VENDORS
@goEnum(
value: "github.com/getprobo/probo/pkg/coredata.SnapshotsTypeVendors"
)
ASSETS
@goEnum(
value: "github.com/getprobo/probo/pkg/coredata.SnapshotsTypeAssets"
)
DATA
@goEnum(
value: "github.com/getprobo/probo/pkg/coredata.SnapshotsTypeData"
)
NON_CONFORMITY_REGISTRIES
@goEnum(
value: "github.com/getprobo/probo/pkg/coredata.SnapshotsTypeNonConformityRegistries"
)
COMPLIANCE_REGISTRIES
@goEnum(
value: "github.com/getprobo/probo/pkg/coredata.SnapshotsTypeComplianceRegistries"
)
}
enum SnapshotOrderField
@goModel(model: "github.com/getprobo/probo/pkg/coredata.SnapshotOrderField") {
CREATED_AT
@goEnum(
value: "github.com/getprobo/probo/pkg/coredata.SnapshotOrderFieldCreatedAt"
)
NAME
@goEnum(
value: "github.com/getprobo/probo/pkg/coredata.SnapshotOrderFieldName"
)
TYPE
@goEnum(
value: "github.com/getprobo/probo/pkg/coredata.SnapshotOrderFieldType"
)
}
# Input Types
input UserOrder
@goModel(
@@ -841,6 +885,14 @@ input DocumentVersionOrder
field: DocumentVersionOrderField!
}
input SnapshotOrder
@goModel(
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.SnapshotOrderBy"
) {
direction: OrderDirection!
field: SnapshotOrderField!
}
input DocumentVersionFilter {
status: DocumentStatus
}
@@ -874,6 +926,10 @@ input TrustCenterFilter {
slug: String
}
input DatumFilter {
snapshotId: ID
}
# Core Types
type TrustCenter implements Node {
id: ID!
@@ -996,6 +1052,7 @@ type Organization implements Node {
last: Int
before: CursorKey
orderBy: DatumOrder
filter: DatumFilter
): DatumConnection! @goField(forceResolver: true)
audits(
@@ -1022,6 +1079,14 @@ type Organization implements Node {
orderBy: ComplianceRegistryOrder
): ComplianceRegistryConnection! @goField(forceResolver: true)
snapshots(
first: Int
after: CursorKey
last: Int
before: CursorKey
orderBy: SnapshotOrder
): SnapshotConnection! @goField(forceResolver: true)
trustCenter: TrustCenter @goField(forceResolver: true)
createdAt: Datetime!
@@ -1466,6 +1531,15 @@ type ComplianceRegistry implements Node {
updatedAt: Datetime!
}
type Snapshot implements Node {
id: ID!
organization: Organization! @goField(forceResolver: true)
name: String!
description: String
type: SnapshotsType!
createdAt: Datetime!
}
type Report implements Node {
id: ID!
objectKey: String!
@@ -1788,6 +1862,20 @@ type ComplianceRegistryEdge {
node: ComplianceRegistry!
}
type SnapshotConnection
@goModel(
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.SnapshotConnection"
) {
totalCount: Int! @goField(forceResolver: true)
edges: [SnapshotEdge!]!
pageInfo: PageInfo!
}
type SnapshotEdge {
cursor: CursorKey!
node: Snapshot!
}
# Root Types
type Query {
node(id: ID!): Node!
@@ -2038,6 +2126,10 @@ type Mutation {
deleteComplianceRegistry(
input: DeleteComplianceRegistryInput!
): DeleteComplianceRegistryPayload!
# Snapshot mutations
createSnapshot(input: CreateSnapshotInput!): CreateSnapshotPayload!
deleteSnapshot(input: DeleteSnapshotInput!): DeleteSnapshotPayload!
}
# Input Types
@@ -2593,6 +2685,17 @@ input DeleteComplianceRegistryInput {
complianceRegistryId: ID!
}
input CreateSnapshotInput {
organizationId: ID!
name: String!
description: String
type: SnapshotsType!
}
input DeleteSnapshotInput {
snapshotId: ID!
}
# Payload Types
type CreateOrganizationPayload {
organizationEdge: OrganizationEdge!
@@ -3302,3 +3405,11 @@ type UpdateComplianceRegistryPayload {
type DeleteComplianceRegistryPayload {
deletedComplianceRegistryId: ID!
}
type CreateSnapshotPayload {
snapshotEdge: SnapshotEdge!
}
type DeleteSnapshotPayload {
deletedSnapshotId: ID!
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,70 @@
// 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 types
import (
"github.com/getprobo/probo/pkg/coredata"
"github.com/getprobo/probo/pkg/gid"
"github.com/getprobo/probo/pkg/page"
)
type (
SnapshotOrderBy OrderBy[coredata.SnapshotOrderField]
SnapshotConnection struct {
TotalCount int
Edges []*SnapshotEdge
PageInfo PageInfo
Resolver any
ParentID gid.GID
}
)
func NewSnapshotConnection(
p *page.Page[*coredata.Snapshot, coredata.SnapshotOrderField],
parentType any,
parentID gid.GID,
) *SnapshotConnection {
edges := make([]*SnapshotEdge, len(p.Data))
for i, snapshot := range p.Data {
edges[i] = NewSnapshotEdge(snapshot, p.Cursor.OrderBy.Field)
}
return &SnapshotConnection{
Edges: edges,
PageInfo: *NewPageInfo(p),
Resolver: parentType,
ParentID: parentID,
}
}
func NewSnapshot(s *coredata.Snapshot) *Snapshot {
return &Snapshot{
ID: s.ID,
Name: s.Name,
Type: s.Type,
Description: s.Description,
CreatedAt: s.CreatedAt,
}
}
func NewSnapshotEdge(s *coredata.Snapshot, orderField coredata.SnapshotOrderField) *SnapshotEdge {
return &SnapshotEdge{
Node: NewSnapshot(s),
Cursor: s.CursorKey(orderField),
}
}

View File

@@ -430,6 +430,17 @@ type CreateRiskPayload struct {
RiskEdge *RiskEdge `json:"riskEdge"`
}
type CreateSnapshotInput struct {
OrganizationID gid.GID `json:"organizationId"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
Type coredata.SnapshotsType `json:"type"`
}
type CreateSnapshotPayload struct {
SnapshotEdge *SnapshotEdge `json:"snapshotEdge"`
}
type CreateTaskInput struct {
OrganizationID gid.GID `json:"organizationId"`
MeasureID *gid.GID `json:"measureId,omitempty"`
@@ -537,6 +548,10 @@ type DatumEdge struct {
Node *Datum `json:"node"`
}
type DatumFilter struct {
SnapshotID *gid.GID `json:"snapshotId,omitempty"`
}
type DeleteAssetInput struct {
AssetID gid.GID `json:"assetId"`
}
@@ -707,6 +722,14 @@ type DeleteRiskPayload struct {
DeletedRiskID gid.GID `json:"deletedRiskId"`
}
type DeleteSnapshotInput struct {
SnapshotID gid.GID `json:"snapshotId"`
}
type DeleteSnapshotPayload struct {
DeletedSnapshotID gid.GID `json:"deletedSnapshotId"`
}
type DeleteTaskInput struct {
TaskID gid.GID `json:"taskId"`
}
@@ -1039,6 +1062,7 @@ type Organization struct {
Audits *AuditConnection `json:"audits"`
NonconformityRegistries *NonconformityRegistryConnection `json:"nonconformityRegistries"`
ComplianceRegistries *ComplianceRegistryConnection `json:"complianceRegistries"`
Snapshots *SnapshotConnection `json:"snapshots"`
TrustCenter *TrustCenter `json:"trustCenter,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
@@ -1201,6 +1225,23 @@ type Session struct {
ExpiresAt time.Time `json:"expiresAt"`
}
type Snapshot struct {
ID gid.GID `json:"id"`
Organization *Organization `json:"organization"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
Type coredata.SnapshotsType `json:"type"`
CreatedAt time.Time `json:"createdAt"`
}
func (Snapshot) IsNode() {}
func (this Snapshot) GetID() gid.GID { return this.ID }
type SnapshotEdge struct {
Cursor page.CursorKey `json:"cursor"`
Node *Snapshot `json:"node"`
}
type Task struct {
ID gid.GID `json:"id"`
Name string `json:"name"`

View File

@@ -2995,6 +2995,38 @@ func (r *mutationResolver) DeleteComplianceRegistry(ctx context.Context, input t
}, nil
}
// CreateSnapshot is the resolver for the createSnapshot field.
func (r *mutationResolver) CreateSnapshot(ctx context.Context, input types.CreateSnapshotInput) (*types.CreateSnapshotPayload, error) {
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
snapshot, err := prb.Snapshots.Create(ctx, &probo.CreateSnapshotRequest{
OrganizationID: input.OrganizationID,
Name: input.Name,
Description: input.Description,
Type: input.Type,
})
if err != nil {
panic(fmt.Errorf("cannot create snapshot: %w", err))
}
return &types.CreateSnapshotPayload{
SnapshotEdge: types.NewSnapshotEdge(snapshot, coredata.SnapshotOrderFieldCreatedAt),
}, nil
}
// DeleteSnapshot is the resolver for the deleteSnapshot field.
func (r *mutationResolver) DeleteSnapshot(ctx context.Context, input types.DeleteSnapshotInput) (*types.DeleteSnapshotPayload, error) {
prb := r.ProboService(ctx, input.SnapshotID.TenantID())
if err := prb.Snapshots.Delete(ctx, input.SnapshotID); err != nil {
panic(fmt.Errorf("cannot delete snapshot: %w", err))
}
return &types.DeleteSnapshotPayload{
DeletedSnapshotID: input.SnapshotID,
}, nil
}
// Organization is the resolver for the organization field.
func (r *nonconformityRegistryResolver) Organization(ctx context.Context, obj *types.NonconformityRegistry) (*types.Organization, error) {
prb := r.ProboService(ctx, obj.ID.TenantID())
@@ -3188,8 +3220,10 @@ func (r *organizationResolver) Vendors(ctx context.Context, obj *types.Organizat
}
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
var nilSnapshotID *gid.GID = nil
vendorFilter := coredata.NewVendorFilterBySnapshotID(&nilSnapshotID)
page, err := prb.Vendors.ListForOrganizationID(ctx, obj.ID, cursor)
page, err := prb.Vendors.ListForOrganizationID(ctx, obj.ID, cursor, vendorFilter)
if err != nil {
panic(fmt.Errorf("cannot list organization vendors: %w", err))
}
@@ -3368,7 +3402,7 @@ func (r *organizationResolver) Assets(ctx context.Context, obj *types.Organizati
}
// Assets is the resolver for the assets field.
func (r *organizationResolver) Data(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.DatumOrderBy) (*types.DatumConnection, error) {
func (r *organizationResolver) Data(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.DatumOrderBy, filter *types.DatumFilter) (*types.DatumConnection, error) {
prb := r.ProboService(ctx, obj.ID.TenantID())
pageOrderBy := page.OrderBy[coredata.DatumOrderField]{
@@ -3384,7 +3418,12 @@ func (r *organizationResolver) Data(ctx context.Context, obj *types.Organization
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
page, err := prb.Data.ListForOrganizationID(ctx, obj.ID, cursor)
datumFilter := coredata.NewDatumFilterBySnapshotID(nil)
if filter != nil {
datumFilter = coredata.NewDatumFilterBySnapshotID(&filter.SnapshotID)
}
page, err := prb.Data.ListForOrganizationID(ctx, obj.ID, cursor, datumFilter)
if err != nil {
panic(fmt.Errorf("cannot list organization data: %w", err))
}
@@ -3467,6 +3506,31 @@ func (r *organizationResolver) ComplianceRegistries(ctx context.Context, obj *ty
return types.NewComplianceRegistryConnection(page, r, obj.ID), nil
}
// Snapshots is the resolver for the snapshots field.
func (r *organizationResolver) Snapshots(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.SnapshotOrderBy) (*types.SnapshotConnection, error) {
prb := r.ProboService(ctx, obj.ID.TenantID())
pageOrderBy := page.OrderBy[coredata.SnapshotOrderField]{
Field: coredata.SnapshotOrderFieldCreatedAt,
Direction: page.OrderDirectionDesc,
}
if orderBy != nil {
pageOrderBy = page.OrderBy[coredata.SnapshotOrderField]{
Field: orderBy.Field,
Direction: orderBy.Direction,
}
}
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
page, err := prb.Snapshots.ListForOrganizationID(ctx, obj.ID, cursor)
if err != nil {
panic(fmt.Errorf("cannot list organization snapshots: %w", err))
}
return types.NewSnapshotConnection(page, r, obj.ID), nil
}
// TrustCenter is the resolver for the trustCenter field.
func (r *organizationResolver) TrustCenter(ctx context.Context, obj *types.Organization) (*types.TrustCenter, error) {
prb := r.ProboService(ctx, obj.ID.TenantID())
@@ -3634,6 +3698,12 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
panic(fmt.Errorf("cannot get report: %w", err))
}
return types.NewReport(report), nil
case coredata.SnapshotEntityType:
snapshot, err := prb.Snapshots.Get(ctx, id)
if err != nil {
panic(fmt.Errorf("cannot get snapshot: %w", err))
}
return types.NewSnapshot(snapshot), nil
case coredata.TrustCenterEntityType:
trustCenter, err := prb.TrustCenters.Get(ctx, id)
if err != nil {
@@ -3823,6 +3893,39 @@ func (r *riskConnectionResolver) TotalCount(ctx context.Context, obj *types.Risk
panic(fmt.Errorf("unsupported resolver: %T", obj.Resolver))
}
// Organization is the resolver for the organization field.
func (r *snapshotResolver) Organization(ctx context.Context, obj *types.Snapshot) (*types.Organization, error) {
prb := r.ProboService(ctx, obj.ID.TenantID())
snapshot, err := prb.Snapshots.Get(ctx, obj.ID)
if err != nil {
panic(fmt.Errorf("cannot get snapshot: %w", err))
}
organization, err := prb.Organizations.Get(ctx, snapshot.OrganizationID)
if err != nil {
panic(fmt.Errorf("cannot get organization: %w", err))
}
return types.NewOrganization(organization), nil
}
// TotalCount is the resolver for the totalCount field.
func (r *snapshotConnectionResolver) TotalCount(ctx context.Context, obj *types.SnapshotConnection) (int, error) {
prb := r.ProboService(ctx, obj.ParentID.TenantID())
switch obj.Resolver.(type) {
case *organizationResolver:
count, err := prb.Snapshots.CountForOrganizationID(ctx, obj.ParentID)
if err != nil {
panic(fmt.Errorf("cannot count snapshots: %w", err))
}
return count, nil
}
panic(fmt.Errorf("unsupported resolver: %T", obj.Resolver))
}
// AssignedTo is the resolver for the assignedTo field.
func (r *taskResolver) AssignedTo(ctx context.Context, obj *types.Task) (*types.People, error) {
prb := r.ProboService(ctx, obj.ID.TenantID())
@@ -4470,6 +4573,14 @@ func (r *Resolver) Risk() schema.RiskResolver { return &riskResolver{r} }
// RiskConnection returns schema.RiskConnectionResolver implementation.
func (r *Resolver) RiskConnection() schema.RiskConnectionResolver { return &riskConnectionResolver{r} }
// Snapshot returns schema.SnapshotResolver implementation.
func (r *Resolver) Snapshot() schema.SnapshotResolver { return &snapshotResolver{r} }
// SnapshotConnection returns schema.SnapshotConnectionResolver implementation.
func (r *Resolver) SnapshotConnection() schema.SnapshotConnectionResolver {
return &snapshotConnectionResolver{r}
}
// Task returns schema.TaskResolver implementation.
func (r *Resolver) Task() schema.TaskResolver { return &taskResolver{r} }
@@ -4548,6 +4659,8 @@ type queryResolver struct{ *Resolver }
type reportResolver struct{ *Resolver }
type riskResolver struct{ *Resolver }
type riskConnectionResolver struct{ *Resolver }
type snapshotResolver struct{ *Resolver }
type snapshotConnectionResolver struct{ *Resolver }
type taskResolver struct{ *Resolver }
type taskConnectionResolver struct{ *Resolver }
type trustCenterResolver struct{ *Resolver }