Add vendor compliance reports
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
@@ -24,6 +24,11 @@ All notable changes to this project will be documented in this file.
|
|||||||
- New bidirectional relationships:
|
- New bidirectional relationships:
|
||||||
- Control objects now expose a `policies` field to list associated policies
|
- Control objects now expose a `policies` field to list associated policies
|
||||||
- Policy objects now expose a `controls` field to list associated controls
|
- Policy objects now expose a `controls` field to list associated controls
|
||||||
|
- Added vendor compliance reports:
|
||||||
|
- New GraphQL types `VendorComplianceReport` and related connection types
|
||||||
|
- New GraphQL mutations `uploadVendorComplianceReport` and `deleteVendorComplianceReport`
|
||||||
|
- New `complianceReports` field on the Vendor type
|
||||||
|
- Support for uploading, viewing, and managing vendor compliance documentation
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ const (
|
|||||||
MitigationEntityType
|
MitigationEntityType
|
||||||
TaskEntityType
|
TaskEntityType
|
||||||
EvidenceEntityType
|
EvidenceEntityType
|
||||||
_ControlStateTransitionEntityType
|
_ControlStateTransitionEntityType // UNUSED
|
||||||
_TaskStateTransitionEntityType
|
_TaskStateTransitionEntityType // UNUSED
|
||||||
VendorEntityType
|
VendorEntityType
|
||||||
PeopleEntityType
|
PeopleEntityType
|
||||||
_EvidenceStateTransitionEntityType
|
VendorComplianceReportEntityType
|
||||||
PolicyEntityType
|
PolicyEntityType
|
||||||
UserEntityType
|
UserEntityType
|
||||||
SessionEntityType
|
SessionEntityType
|
||||||
|
|||||||
12
pkg/coredata/migrations/20250409T081100Z.sql
Normal file
12
pkg/coredata/migrations/20250409T081100Z.sql
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
CREATE TABLE vendor_compliance_reports (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
tenant_id TEXT NOT NULL,
|
||||||
|
vendor_id TEXT NOT NULL REFERENCES vendors(id),
|
||||||
|
report_date DATE NOT NULL,
|
||||||
|
valid_until DATE,
|
||||||
|
report_name TEXT NOT NULL,
|
||||||
|
file_key TEXT NOT NULL,
|
||||||
|
file_size INTEGER NOT NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL,
|
||||||
|
updated_at TIMESTAMP NOT NULL
|
||||||
|
);
|
||||||
215
pkg/coredata/vendor_compliance_report.go
Normal file
215
pkg/coredata/vendor_compliance_report.go
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
// 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 (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"maps"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/getprobo/probo/pkg/gid"
|
||||||
|
"github.com/getprobo/probo/pkg/page"
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
|
"go.gearno.de/kit/pg"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
VendorComplianceReport struct {
|
||||||
|
ID gid.GID
|
||||||
|
VendorID gid.GID
|
||||||
|
ReportDate time.Time
|
||||||
|
ValidUntil *time.Time
|
||||||
|
ReportName string
|
||||||
|
FileKey string
|
||||||
|
FileSize int
|
||||||
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
VendorComplianceReports []*VendorComplianceReport
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c VendorComplianceReport) CursorKey(orderBy VendorComplianceReportOrderField) page.CursorKey {
|
||||||
|
switch orderBy {
|
||||||
|
case VendorComplianceReportOrderFieldReportDate:
|
||||||
|
return page.NewCursorKey(c.ID, c.ReportDate)
|
||||||
|
case VendorComplianceReportOrderFieldCreatedAt:
|
||||||
|
return page.NewCursorKey(c.ID, c.CreatedAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vcs *VendorComplianceReports) LoadForVendorID(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
vendorID gid.GID,
|
||||||
|
cursor *page.Cursor[VendorComplianceReportOrderField],
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
report_date,
|
||||||
|
valid_until,
|
||||||
|
report_name,
|
||||||
|
file_key,
|
||||||
|
file_size,
|
||||||
|
created_at,
|
||||||
|
updated_at
|
||||||
|
FROM
|
||||||
|
vendor_compliance_reports
|
||||||
|
WHERE
|
||||||
|
%s
|
||||||
|
AND vendor_id = @vendor_id
|
||||||
|
AND %s
|
||||||
|
`
|
||||||
|
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.NamedArgs{"vendor_id": vendorID}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
maps.Copy(args, cursor.SQLArguments())
|
||||||
|
|
||||||
|
rows, err := conn.Query(ctx, q, args)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot query vendor compliance reports: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
vendorComplianceReports, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[VendorComplianceReport])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot collect vendor compliance reports: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
*vcs = vendorComplianceReports
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vcr *VendorComplianceReport) LoadByID(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
vendorComplianceReportID gid.GID,
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
vendor_id,
|
||||||
|
report_date,
|
||||||
|
valid_until,
|
||||||
|
report_name,
|
||||||
|
file_key,
|
||||||
|
file_size,
|
||||||
|
created_at,
|
||||||
|
updated_at
|
||||||
|
FROM
|
||||||
|
vendor_compliance_reports
|
||||||
|
WHERE
|
||||||
|
%s
|
||||||
|
AND id = @id
|
||||||
|
LIMIT 1;
|
||||||
|
`
|
||||||
|
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.NamedArgs{"id": vendorComplianceReportID}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
|
rows, err := conn.Query(ctx, q, args)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot query vendor compliance report: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
vendorComplianceReport, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[VendorComplianceReport])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot collect vendor compliance report: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
*vcr = vendorComplianceReport
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vcr *VendorComplianceReport) Insert(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
INSERT INTO
|
||||||
|
vendor_compliance_reports (
|
||||||
|
id,
|
||||||
|
tenant_id,
|
||||||
|
vendor_id,
|
||||||
|
report_date,
|
||||||
|
valid_until,
|
||||||
|
report_name,
|
||||||
|
file_key,
|
||||||
|
file_size,
|
||||||
|
created_at,
|
||||||
|
updated_at
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
@id,
|
||||||
|
@tenant_id,
|
||||||
|
@vendor_id,
|
||||||
|
@report_date,
|
||||||
|
@valid_until,
|
||||||
|
@report_name,
|
||||||
|
@file_key,
|
||||||
|
@file_size,
|
||||||
|
@created_at,
|
||||||
|
@updated_at
|
||||||
|
)
|
||||||
|
`
|
||||||
|
args := pgx.NamedArgs{
|
||||||
|
"id": vcr.ID,
|
||||||
|
"tenant_id": scope.GetTenantID(),
|
||||||
|
"vendor_id": vcr.VendorID,
|
||||||
|
"report_date": vcr.ReportDate,
|
||||||
|
"valid_until": vcr.ValidUntil,
|
||||||
|
"report_name": vcr.ReportName,
|
||||||
|
"file_key": vcr.FileKey,
|
||||||
|
"file_size": vcr.FileSize,
|
||||||
|
"created_at": vcr.CreatedAt,
|
||||||
|
"updated_at": vcr.UpdatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := conn.Exec(ctx, q, args)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vcr *VendorComplianceReport) Delete(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
DELETE FROM
|
||||||
|
vendor_compliance_reports
|
||||||
|
WHERE
|
||||||
|
%s
|
||||||
|
AND id = @id
|
||||||
|
`
|
||||||
|
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.NamedArgs{"id": vcr.ID}
|
||||||
|
|
||||||
|
_, err := conn.Exec(ctx, q, args)
|
||||||
|
return err
|
||||||
|
}
|
||||||
41
pkg/coredata/vendor_compliance_report_order_field.go
Normal file
41
pkg/coredata/vendor_compliance_report_order_field.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
// 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
|
||||||
|
|
||||||
|
type (
|
||||||
|
VendorComplianceReportOrderField string
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
VendorComplianceReportOrderFieldReportDate VendorComplianceReportOrderField = "REPORT_DATE"
|
||||||
|
VendorComplianceReportOrderFieldCreatedAt VendorComplianceReportOrderField = "CREATED_AT"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (p VendorComplianceReportOrderField) Column() string {
|
||||||
|
return string(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p VendorComplianceReportOrderField) String() string {
|
||||||
|
return string(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p VendorComplianceReportOrderField) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(p.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *VendorComplianceReportOrderField) UnmarshalText(text []byte) error {
|
||||||
|
*p = VendorComplianceReportOrderField(text)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -38,16 +38,17 @@ type (
|
|||||||
|
|
||||||
scope coredata.Scoper
|
scope coredata.Scoper
|
||||||
|
|
||||||
Frameworks *FrameworkService
|
Frameworks *FrameworkService
|
||||||
Mitigations *MitigationService
|
Mitigations *MitigationService
|
||||||
Tasks *TaskService
|
Tasks *TaskService
|
||||||
Evidences *EvidenceService
|
Evidences *EvidenceService
|
||||||
Organizations *OrganizationService
|
Organizations *OrganizationService
|
||||||
Vendors *VendorService
|
Vendors *VendorService
|
||||||
Peoples *PeopleService
|
Peoples *PeopleService
|
||||||
Policies *PolicyService
|
Policies *PolicyService
|
||||||
Controls *ControlService
|
Controls *ControlService
|
||||||
Risks *RiskService
|
Risks *RiskService
|
||||||
|
VendorComplianceReports *VendorComplianceReportService
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -88,6 +89,6 @@ func (s *Service) WithTenant(tenantID gid.TenantID) *TenantService {
|
|||||||
tenantService.Organizations = &OrganizationService{svc: tenantService}
|
tenantService.Organizations = &OrganizationService{svc: tenantService}
|
||||||
tenantService.Controls = &ControlService{svc: tenantService}
|
tenantService.Controls = &ControlService{svc: tenantService}
|
||||||
tenantService.Risks = &RiskService{svc: tenantService}
|
tenantService.Risks = &RiskService{svc: tenantService}
|
||||||
|
tenantService.VendorComplianceReports = &VendorComplianceReportService{svc: tenantService}
|
||||||
return tenantService
|
return tenantService
|
||||||
}
|
}
|
||||||
|
|||||||
195
pkg/probo/vendor_compliance_report_service.go
Normal file
195
pkg/probo/vendor_compliance_report_service.go
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
// 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"
|
||||||
|
"io"
|
||||||
|
"mime"
|
||||||
|
"net/url"
|
||||||
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
|
"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 (
|
||||||
|
VendorComplianceReportService struct {
|
||||||
|
svc *TenantService
|
||||||
|
}
|
||||||
|
|
||||||
|
VendorComplianceReportCreateRequest struct {
|
||||||
|
File io.Reader
|
||||||
|
ReportDate time.Time
|
||||||
|
ValidUntil *time.Time
|
||||||
|
ReportName string
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s VendorComplianceReportService) ListForVendorID(
|
||||||
|
ctx context.Context,
|
||||||
|
vendorID gid.GID,
|
||||||
|
cursor *page.Cursor[coredata.VendorComplianceReportOrderField],
|
||||||
|
) (*page.Page[*coredata.VendorComplianceReport, coredata.VendorComplianceReportOrderField], error) {
|
||||||
|
var vendorComplianceReports coredata.VendorComplianceReports
|
||||||
|
|
||||||
|
err := s.svc.pg.WithConn(
|
||||||
|
ctx,
|
||||||
|
func(conn pg.Conn) error {
|
||||||
|
return vendorComplianceReports.LoadForVendorID(ctx, conn, s.svc.scope, vendorID, cursor)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return page.NewPage(vendorComplianceReports, cursor), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s VendorComplianceReportService) Upload(
|
||||||
|
ctx context.Context,
|
||||||
|
vendorID gid.GID,
|
||||||
|
req *VendorComplianceReportCreateRequest,
|
||||||
|
) (*coredata.VendorComplianceReport, error) {
|
||||||
|
objectKey, err := uuid.NewV7()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cannot generate object key: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
mimeType := mime.TypeByExtension(filepath.Ext(req.ReportName))
|
||||||
|
|
||||||
|
_, err = s.svc.s3.PutObject(ctx, &s3.PutObjectInput{
|
||||||
|
Bucket: &s.svc.bucket,
|
||||||
|
Key: aws.String(objectKey.String()),
|
||||||
|
Body: req.File,
|
||||||
|
ContentType: &mimeType,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cannot upload file to S3: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
headOutput, err := s.svc.s3.HeadObject(ctx, &s3.HeadObjectInput{
|
||||||
|
Bucket: aws.String(s.svc.bucket),
|
||||||
|
Key: aws.String(objectKey.String()),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cannot get object metadata: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
vendorComplianceReportID, err := gid.NewGID(s.svc.scope.GetTenantID(), coredata.VendorComplianceReportEntityType)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cannot generate vendor compliance report ID: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
vendorComplianceReport := &coredata.VendorComplianceReport{
|
||||||
|
ID: vendorComplianceReportID,
|
||||||
|
VendorID: vendorID,
|
||||||
|
ReportDate: req.ReportDate,
|
||||||
|
ValidUntil: req.ValidUntil,
|
||||||
|
ReportName: req.ReportName,
|
||||||
|
FileKey: objectKey.String(),
|
||||||
|
FileSize: int(*headOutput.ContentLength),
|
||||||
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.svc.pg.WithConn(
|
||||||
|
ctx,
|
||||||
|
func(conn pg.Conn) error {
|
||||||
|
return vendorComplianceReport.Insert(ctx, conn, s.svc.scope)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return vendorComplianceReport, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s VendorComplianceReportService) Get(
|
||||||
|
ctx context.Context,
|
||||||
|
vendorComplianceReportID gid.GID,
|
||||||
|
) (*coredata.VendorComplianceReport, error) {
|
||||||
|
vendorComplianceReport := &coredata.VendorComplianceReport{}
|
||||||
|
|
||||||
|
err := s.svc.pg.WithConn(
|
||||||
|
ctx,
|
||||||
|
func(conn pg.Conn) error {
|
||||||
|
return vendorComplianceReport.LoadByID(ctx, conn, s.svc.scope, vendorComplianceReportID)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cannot load vendor compliance report: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return vendorComplianceReport, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s VendorComplianceReportService) GenerateFileURL(
|
||||||
|
ctx context.Context,
|
||||||
|
vendorComplianceReportID gid.GID,
|
||||||
|
expiresIn time.Duration,
|
||||||
|
) (string, error) {
|
||||||
|
vendorComplianceReport, err := s.Get(ctx, vendorComplianceReportID)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("cannot get vendor compliance report: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
presignClient := s3.NewPresignClient(s.svc.s3)
|
||||||
|
|
||||||
|
// Use RFC 6266/5987 encoding for filename with UTF-8 support
|
||||||
|
encodedFilename := url.QueryEscape(vendorComplianceReport.ReportName)
|
||||||
|
contentDisposition := fmt.Sprintf("attachment; filename=\"%s\"; filename*=UTF-8''%s",
|
||||||
|
encodedFilename, encodedFilename)
|
||||||
|
|
||||||
|
presignedReq, err := presignClient.PresignGetObject(ctx, &s3.GetObjectInput{
|
||||||
|
Bucket: aws.String(s.svc.bucket),
|
||||||
|
Key: aws.String(vendorComplianceReport.FileKey),
|
||||||
|
ResponseContentDisposition: aws.String(contentDisposition),
|
||||||
|
}, func(opts *s3.PresignOptions) {
|
||||||
|
opts.Expires = expiresIn
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("cannot presign GetObject request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return presignedReq.URL, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s VendorComplianceReportService) Delete(
|
||||||
|
ctx context.Context,
|
||||||
|
vendorComplianceReportID gid.GID,
|
||||||
|
) error {
|
||||||
|
vendorComplianceReport := &coredata.VendorComplianceReport{ID: vendorComplianceReportID}
|
||||||
|
|
||||||
|
return s.svc.pg.WithConn(
|
||||||
|
ctx,
|
||||||
|
func(conn pg.Conn) error {
|
||||||
|
return vendorComplianceReport.Delete(ctx, conn, s.svc.scope)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -226,6 +226,20 @@ enum EvidenceOrderField
|
|||||||
CREATED_AT
|
CREATED_AT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum VendorComplianceReportOrderField
|
||||||
|
@goModel(
|
||||||
|
model: "github.com/getprobo/probo/pkg/coredata.VendorComplianceReportOrderField"
|
||||||
|
) {
|
||||||
|
REPORT_DATE
|
||||||
|
@goEnum(
|
||||||
|
value: "github.com/getprobo/probo/pkg/coredata.VendorComplianceReportOrderFieldReportDate"
|
||||||
|
)
|
||||||
|
CREATED_AT
|
||||||
|
@goEnum(
|
||||||
|
value: "github.com/getprobo/probo/pkg/coredata.VendorComplianceReportOrderFieldCreatedAt"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
enum OrganizationOrderField {
|
enum OrganizationOrderField {
|
||||||
NAME
|
NAME
|
||||||
CREATED_AT
|
CREATED_AT
|
||||||
@@ -313,6 +327,14 @@ input EvidenceOrder
|
|||||||
field: EvidenceOrderField!
|
field: EvidenceOrderField!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input VendorComplianceReportOrder
|
||||||
|
@goModel(
|
||||||
|
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.VendorComplianceReportOrderBy"
|
||||||
|
) {
|
||||||
|
direction: OrderDirection!
|
||||||
|
field: VendorComplianceReportOrderField!
|
||||||
|
}
|
||||||
|
|
||||||
input OrganizationOrder {
|
input OrganizationOrder {
|
||||||
direction: OrderDirection!
|
direction: OrderDirection!
|
||||||
field: OrganizationOrderField!
|
field: OrganizationOrderField!
|
||||||
@@ -406,6 +428,15 @@ type Vendor implements Node {
|
|||||||
id: ID!
|
id: ID!
|
||||||
name: String!
|
name: String!
|
||||||
description: String!
|
description: String!
|
||||||
|
|
||||||
|
complianceReports(
|
||||||
|
first: Int
|
||||||
|
after: CursorKey
|
||||||
|
last: Int
|
||||||
|
before: CursorKey
|
||||||
|
orderBy: VendorComplianceReportOrder
|
||||||
|
): VendorComplianceReportConnection! @goField(forceResolver: true)
|
||||||
|
|
||||||
serviceStartAt: Datetime!
|
serviceStartAt: Datetime!
|
||||||
serviceTerminationAt: Datetime
|
serviceTerminationAt: Datetime
|
||||||
serviceCriticality: ServiceCriticality!
|
serviceCriticality: ServiceCriticality!
|
||||||
@@ -417,6 +448,20 @@ type Vendor implements Node {
|
|||||||
updatedAt: Datetime!
|
updatedAt: Datetime!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type VendorComplianceReport implements Node {
|
||||||
|
id: ID!
|
||||||
|
vendor: Vendor! @goField(forceResolver: true)
|
||||||
|
reportDate: Datetime!
|
||||||
|
validUntil: Datetime
|
||||||
|
reportName: String!
|
||||||
|
|
||||||
|
fileUrl: String! @goField(forceResolver: true)
|
||||||
|
fileSize: Int!
|
||||||
|
|
||||||
|
createdAt: Datetime!
|
||||||
|
updatedAt: Datetime!
|
||||||
|
}
|
||||||
|
|
||||||
type Framework implements Node {
|
type Framework implements Node {
|
||||||
id: ID!
|
id: ID!
|
||||||
name: String!
|
name: String!
|
||||||
@@ -699,6 +744,16 @@ type RiskEdge {
|
|||||||
node: Risk!
|
node: Risk!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type VendorComplianceReportConnection {
|
||||||
|
edges: [VendorComplianceReportEdge!]!
|
||||||
|
pageInfo: PageInfo!
|
||||||
|
}
|
||||||
|
|
||||||
|
type VendorComplianceReportEdge {
|
||||||
|
cursor: CursorKey!
|
||||||
|
node: VendorComplianceReport!
|
||||||
|
}
|
||||||
|
|
||||||
# Root Types
|
# Root Types
|
||||||
type Query {
|
type Query {
|
||||||
node(id: ID!): Node!
|
node(id: ID!): Node!
|
||||||
@@ -777,6 +832,14 @@ type Mutation {
|
|||||||
createEvidence(input: CreateEvidenceInput!): CreateEvidencePayload!
|
createEvidence(input: CreateEvidenceInput!): CreateEvidencePayload!
|
||||||
deleteEvidence(input: DeleteEvidenceInput!): DeleteEvidencePayload!
|
deleteEvidence(input: DeleteEvidenceInput!): DeleteEvidencePayload!
|
||||||
|
|
||||||
|
# Vendor Compliance Report mutations
|
||||||
|
uploadVendorComplianceReport(
|
||||||
|
input: UploadVendorComplianceReportInput!
|
||||||
|
): UploadVendorComplianceReportPayload!
|
||||||
|
deleteVendorComplianceReport(
|
||||||
|
input: DeleteVendorComplianceReportInput!
|
||||||
|
): DeleteVendorComplianceReportPayload!
|
||||||
|
|
||||||
# Policy mutations
|
# Policy mutations
|
||||||
createPolicy(input: CreatePolicyInput!): CreatePolicyPayload!
|
createPolicy(input: CreatePolicyInput!): CreatePolicyPayload!
|
||||||
updatePolicy(input: UpdatePolicyInput!): UpdatePolicyPayload!
|
updatePolicy(input: UpdatePolicyInput!): UpdatePolicyPayload!
|
||||||
@@ -999,6 +1062,18 @@ input DeleteEvidenceInput {
|
|||||||
evidenceId: ID!
|
evidenceId: ID!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input UploadVendorComplianceReportInput {
|
||||||
|
vendorId: ID!
|
||||||
|
reportDate: Datetime!
|
||||||
|
validUntil: Datetime
|
||||||
|
reportName: String!
|
||||||
|
file: Upload!
|
||||||
|
}
|
||||||
|
|
||||||
|
input DeleteVendorComplianceReportInput {
|
||||||
|
reportId: ID!
|
||||||
|
}
|
||||||
|
|
||||||
input CreatePolicyInput {
|
input CreatePolicyInput {
|
||||||
organizationId: ID!
|
organizationId: ID!
|
||||||
name: String!
|
name: String!
|
||||||
@@ -1173,6 +1248,14 @@ type DeleteEvidencePayload {
|
|||||||
deletedEvidenceId: ID!
|
deletedEvidenceId: ID!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UploadVendorComplianceReportPayload {
|
||||||
|
vendorComplianceReportEdge: VendorComplianceReportEdge!
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteVendorComplianceReportPayload {
|
||||||
|
deletedVendorComplianceReportId: ID!
|
||||||
|
}
|
||||||
|
|
||||||
type CreatePolicyPayload {
|
type CreatePolicyPayload {
|
||||||
policyEdge: PolicyEdge!
|
policyEdge: PolicyEdge!
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -281,6 +281,14 @@ type DeleteTaskPayload struct {
|
|||||||
DeletedTaskID gid.GID `json:"deletedTaskId"`
|
DeletedTaskID gid.GID `json:"deletedTaskId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DeleteVendorComplianceReportInput struct {
|
||||||
|
ReportID gid.GID `json:"reportId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteVendorComplianceReportPayload struct {
|
||||||
|
DeletedVendorComplianceReportID gid.GID `json:"deletedVendorComplianceReportId"`
|
||||||
|
}
|
||||||
|
|
||||||
type DeleteVendorInput struct {
|
type DeleteVendorInput struct {
|
||||||
VendorID gid.GID `json:"vendorId"`
|
VendorID gid.GID `json:"vendorId"`
|
||||||
}
|
}
|
||||||
@@ -679,6 +687,18 @@ type UpdateVendorPayload struct {
|
|||||||
Vendor *Vendor `json:"vendor"`
|
Vendor *Vendor `json:"vendor"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UploadVendorComplianceReportInput struct {
|
||||||
|
VendorID gid.GID `json:"vendorId"`
|
||||||
|
ReportDate time.Time `json:"reportDate"`
|
||||||
|
ValidUntil *time.Time `json:"validUntil,omitempty"`
|
||||||
|
ReportName string `json:"reportName"`
|
||||||
|
File graphql.Upload `json:"file"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UploadVendorComplianceReportPayload struct {
|
||||||
|
VendorComplianceReportEdge *VendorComplianceReportEdge `json:"vendorComplianceReportEdge"`
|
||||||
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID gid.GID `json:"id"`
|
ID gid.GID `json:"id"`
|
||||||
FullName string `json:"fullName"`
|
FullName string `json:"fullName"`
|
||||||
@@ -701,23 +721,49 @@ type UserEdge struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Vendor struct {
|
type Vendor struct {
|
||||||
ID gid.GID `json:"id"`
|
ID gid.GID `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
ServiceStartAt time.Time `json:"serviceStartAt"`
|
ComplianceReports *VendorComplianceReportConnection `json:"complianceReports"`
|
||||||
ServiceTerminationAt *time.Time `json:"serviceTerminationAt,omitempty"`
|
ServiceStartAt time.Time `json:"serviceStartAt"`
|
||||||
ServiceCriticality coredata.ServiceCriticality `json:"serviceCriticality"`
|
ServiceTerminationAt *time.Time `json:"serviceTerminationAt,omitempty"`
|
||||||
RiskTier coredata.RiskTier `json:"riskTier"`
|
ServiceCriticality coredata.ServiceCriticality `json:"serviceCriticality"`
|
||||||
StatusPageURL *string `json:"statusPageUrl,omitempty"`
|
RiskTier coredata.RiskTier `json:"riskTier"`
|
||||||
TermsOfServiceURL *string `json:"termsOfServiceUrl,omitempty"`
|
StatusPageURL *string `json:"statusPageUrl,omitempty"`
|
||||||
PrivacyPolicyURL *string `json:"privacyPolicyUrl,omitempty"`
|
TermsOfServiceURL *string `json:"termsOfServiceUrl,omitempty"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
PrivacyPolicyURL *string `json:"privacyPolicyUrl,omitempty"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Vendor) IsNode() {}
|
func (Vendor) IsNode() {}
|
||||||
func (this Vendor) GetID() gid.GID { return this.ID }
|
func (this Vendor) GetID() gid.GID { return this.ID }
|
||||||
|
|
||||||
|
type VendorComplianceReport struct {
|
||||||
|
ID gid.GID `json:"id"`
|
||||||
|
Vendor *Vendor `json:"vendor"`
|
||||||
|
ReportDate time.Time `json:"reportDate"`
|
||||||
|
ValidUntil *time.Time `json:"validUntil,omitempty"`
|
||||||
|
ReportName string `json:"reportName"`
|
||||||
|
FileURL string `json:"fileUrl"`
|
||||||
|
FileSize int `json:"fileSize"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (VendorComplianceReport) IsNode() {}
|
||||||
|
func (this VendorComplianceReport) GetID() gid.GID { return this.ID }
|
||||||
|
|
||||||
|
type VendorComplianceReportConnection struct {
|
||||||
|
Edges []*VendorComplianceReportEdge `json:"edges"`
|
||||||
|
PageInfo *PageInfo `json:"pageInfo"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type VendorComplianceReportEdge struct {
|
||||||
|
Cursor page.CursorKey `json:"cursor"`
|
||||||
|
Node *VendorComplianceReport `json:"node"`
|
||||||
|
}
|
||||||
|
|
||||||
type VendorConnection struct {
|
type VendorConnection struct {
|
||||||
Edges []*VendorEdge `json:"edges"`
|
Edges []*VendorEdge `json:"edges"`
|
||||||
PageInfo *PageInfo `json:"pageInfo"`
|
PageInfo *PageInfo `json:"pageInfo"`
|
||||||
|
|||||||
56
pkg/server/api/console/v1/types/vendor_compliance_report.go
Normal file
56
pkg/server/api/console/v1/types/vendor_compliance_report.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
// 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/page"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
VendorComplianceReportOrderBy OrderBy[coredata.VendorComplianceReportOrderField]
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewVendorComplianceReportConnection(p *page.Page[*coredata.VendorComplianceReport, coredata.VendorComplianceReportOrderField]) *VendorComplianceReportConnection {
|
||||||
|
var edges = make([]*VendorComplianceReportEdge, len(p.Data))
|
||||||
|
|
||||||
|
for i := range edges {
|
||||||
|
edges[i] = NewVendorComplianceReportEdge(p.Data[i], p.Cursor.OrderBy.Field)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &VendorComplianceReportConnection{
|
||||||
|
Edges: edges,
|
||||||
|
PageInfo: NewPageInfo(p),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewVendorComplianceReportEdge(c *coredata.VendorComplianceReport, orderBy coredata.VendorComplianceReportOrderField) *VendorComplianceReportEdge {
|
||||||
|
return &VendorComplianceReportEdge{
|
||||||
|
Cursor: c.CursorKey(orderBy),
|
||||||
|
Node: NewVendorComplianceReport(c),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewVendorComplianceReport(c *coredata.VendorComplianceReport) *VendorComplianceReport {
|
||||||
|
return &VendorComplianceReport{
|
||||||
|
ID: c.ID,
|
||||||
|
ReportDate: c.ReportDate,
|
||||||
|
ValidUntil: c.ValidUntil,
|
||||||
|
ReportName: c.ReportName,
|
||||||
|
FileSize: c.FileSize,
|
||||||
|
CreatedAt: c.CreatedAt,
|
||||||
|
UpdatedAt: c.UpdatedAt,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -866,6 +866,43 @@ func (r *mutationResolver) DeleteEvidence(ctx context.Context, input types.Delet
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UploadVendorComplianceReport is the resolver for the uploadVendorComplianceReport field.
|
||||||
|
func (r *mutationResolver) UploadVendorComplianceReport(ctx context.Context, input types.UploadVendorComplianceReportInput) (*types.UploadVendorComplianceReportPayload, error) {
|
||||||
|
svc := r.GetTenantServiceIfAuthorized(ctx, input.VendorID.TenantID())
|
||||||
|
|
||||||
|
vendorComplianceReport, err := svc.VendorComplianceReports.Upload(
|
||||||
|
ctx,
|
||||||
|
input.VendorID,
|
||||||
|
&probo.VendorComplianceReportCreateRequest{
|
||||||
|
File: input.File.File,
|
||||||
|
ReportDate: input.ReportDate,
|
||||||
|
ValidUntil: input.ValidUntil,
|
||||||
|
ReportName: input.ReportName,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("failed to upload vendor compliance report: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.UploadVendorComplianceReportPayload{
|
||||||
|
VendorComplianceReportEdge: types.NewVendorComplianceReportEdge(vendorComplianceReport, coredata.VendorComplianceReportOrderFieldCreatedAt),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteVendorComplianceReport is the resolver for the deleteVendorComplianceReport field.
|
||||||
|
func (r *mutationResolver) DeleteVendorComplianceReport(ctx context.Context, input types.DeleteVendorComplianceReportInput) (*types.DeleteVendorComplianceReportPayload, error) {
|
||||||
|
svc := r.GetTenantServiceIfAuthorized(ctx, input.ReportID.TenantID())
|
||||||
|
|
||||||
|
err := svc.VendorComplianceReports.Delete(ctx, input.ReportID)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("failed to delete vendor compliance report: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.DeleteVendorComplianceReportPayload{
|
||||||
|
DeletedVendorComplianceReportID: input.ReportID,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// CreatePolicy is the resolver for the createPolicy field.
|
// CreatePolicy is the resolver for the createPolicy field.
|
||||||
func (r *mutationResolver) CreatePolicy(ctx context.Context, input types.CreatePolicyInput) (*types.CreatePolicyPayload, error) {
|
func (r *mutationResolver) CreatePolicy(ctx context.Context, input types.CreatePolicyInput) (*types.CreatePolicyPayload, error) {
|
||||||
svc := r.GetTenantServiceIfAuthorized(ctx, input.OrganizationID.TenantID())
|
svc := r.GetTenantServiceIfAuthorized(ctx, input.OrganizationID.TenantID())
|
||||||
@@ -1218,6 +1255,12 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
|
|||||||
panic(fmt.Errorf("cannot get risk: %w", err))
|
panic(fmt.Errorf("cannot get risk: %w", err))
|
||||||
}
|
}
|
||||||
return types.NewRisk(risk), nil
|
return types.NewRisk(risk), nil
|
||||||
|
case coredata.VendorComplianceReportEntityType:
|
||||||
|
vendorComplianceReport, err := svc.VendorComplianceReports.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("cannot get vendor compliance report: %w", err))
|
||||||
|
}
|
||||||
|
return types.NewVendorComplianceReport(vendorComplianceReport), nil
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1305,6 +1348,55 @@ func (r *taskResolver) Evidences(ctx context.Context, obj *types.Task, first *in
|
|||||||
return types.NewEvidenceConnection(page), nil
|
return types.NewEvidenceConnection(page), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ComplianceReports is the resolver for the complianceReports field.
|
||||||
|
func (r *vendorResolver) ComplianceReports(ctx context.Context, obj *types.Vendor, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.VendorComplianceReportOrderBy) (*types.VendorComplianceReportConnection, error) {
|
||||||
|
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||||
|
|
||||||
|
pageOrderBy := page.OrderBy[coredata.VendorComplianceReportOrderField]{
|
||||||
|
Field: coredata.VendorComplianceReportOrderFieldReportDate,
|
||||||
|
Direction: page.OrderDirectionDesc,
|
||||||
|
}
|
||||||
|
if orderBy != nil {
|
||||||
|
pageOrderBy = page.OrderBy[coredata.VendorComplianceReportOrderField]{
|
||||||
|
Field: orderBy.Field,
|
||||||
|
Direction: orderBy.Direction,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||||
|
|
||||||
|
page, err := svc.VendorComplianceReports.ListForVendorID(ctx, obj.ID, cursor)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("failed to list vendor compliance reports: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return types.NewVendorComplianceReportConnection(page), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vendor is the resolver for the vendor field.
|
||||||
|
func (r *vendorComplianceReportResolver) Vendor(ctx context.Context, obj *types.VendorComplianceReport) (*types.Vendor, error) {
|
||||||
|
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||||
|
|
||||||
|
vendor, err := svc.Vendors.Get(ctx, obj.ID)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("failed to get vendor: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return types.NewVendor(vendor), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FileURL is the resolver for the fileUrl field.
|
||||||
|
func (r *vendorComplianceReportResolver) FileURL(ctx context.Context, obj *types.VendorComplianceReport) (string, error) {
|
||||||
|
svc := r.GetTenantServiceIfAuthorized(ctx, obj.ID.TenantID())
|
||||||
|
|
||||||
|
fileURL, err := svc.VendorComplianceReports.GenerateFileURL(ctx, obj.ID, 1*time.Hour)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("failed to generate file URL: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileURL, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Organizations is the resolver for the organizations field.
|
// Organizations is the resolver for the organizations field.
|
||||||
func (r *viewerResolver) Organizations(ctx context.Context, obj *types.Viewer, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.OrganizationOrder) (*types.OrganizationConnection, error) {
|
func (r *viewerResolver) Organizations(ctx context.Context, obj *types.Viewer, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.OrganizationOrder) (*types.OrganizationConnection, error) {
|
||||||
user := UserFromContext(ctx)
|
user := UserFromContext(ctx)
|
||||||
@@ -1360,6 +1452,14 @@ func (r *Resolver) Risk() schema.RiskResolver { return &riskResolver{r} }
|
|||||||
// Task returns schema.TaskResolver implementation.
|
// Task returns schema.TaskResolver implementation.
|
||||||
func (r *Resolver) Task() schema.TaskResolver { return &taskResolver{r} }
|
func (r *Resolver) Task() schema.TaskResolver { return &taskResolver{r} }
|
||||||
|
|
||||||
|
// Vendor returns schema.VendorResolver implementation.
|
||||||
|
func (r *Resolver) Vendor() schema.VendorResolver { return &vendorResolver{r} }
|
||||||
|
|
||||||
|
// VendorComplianceReport returns schema.VendorComplianceReportResolver implementation.
|
||||||
|
func (r *Resolver) VendorComplianceReport() schema.VendorComplianceReportResolver {
|
||||||
|
return &vendorComplianceReportResolver{r}
|
||||||
|
}
|
||||||
|
|
||||||
// Viewer returns schema.ViewerResolver implementation.
|
// Viewer returns schema.ViewerResolver implementation.
|
||||||
func (r *Resolver) Viewer() schema.ViewerResolver { return &viewerResolver{r} }
|
func (r *Resolver) Viewer() schema.ViewerResolver { return &viewerResolver{r} }
|
||||||
|
|
||||||
@@ -1373,4 +1473,6 @@ type policyResolver struct{ *Resolver }
|
|||||||
type queryResolver struct{ *Resolver }
|
type queryResolver struct{ *Resolver }
|
||||||
type riskResolver struct{ *Resolver }
|
type riskResolver struct{ *Resolver }
|
||||||
type taskResolver struct{ *Resolver }
|
type taskResolver struct{ *Resolver }
|
||||||
|
type vendorResolver struct{ *Resolver }
|
||||||
|
type vendorComplianceReportResolver struct{ *Resolver }
|
||||||
type viewerResolver struct{ *Resolver }
|
type viewerResolver struct{ *Resolver }
|
||||||
|
|||||||
Reference in New Issue
Block a user