The go-sdk v1.6.0 release no longer applies a default CrossOriginProtection when the field is nil in StreamableHTTPOptions, silently removing Origin header verification. Wrap the streamable handler with http.NewCrossOriginProtection().Handler(...) (the recommended replacement, since the SDK field is deprecated). Also regenerate gqlgen resolvers to track v0.17.90. Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
146 lines
4.6 KiB
Go
146 lines
4.6 KiB
Go
package trust_v1
|
|
|
|
// This file will be automatically regenerated based on the schema, any resolver
|
|
// implementations
|
|
// will be copied through when generating and any unknown code will be moved to the end.
|
|
// Code generated by github.com/99designs/gqlgen version v0.17.90
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"time"
|
|
|
|
"go.gearno.de/kit/log"
|
|
"go.probo.inc/probo/pkg/coredata"
|
|
"go.probo.inc/probo/pkg/esign"
|
|
"go.probo.inc/probo/pkg/server/api/authn"
|
|
"go.probo.inc/probo/pkg/server/api/compliancepage"
|
|
"go.probo.inc/probo/pkg/server/api/trust/v1/schema"
|
|
"go.probo.inc/probo/pkg/server/api/trust/v1/types"
|
|
"go.probo.inc/probo/pkg/server/gqlutils"
|
|
)
|
|
|
|
// AcceptElectronicSignature is the resolver for the acceptElectronicSignature field.
|
|
func (r *mutationResolver) AcceptElectronicSignature(ctx context.Context, input types.AcceptElectronicSignatureInput) (*types.AcceptElectronicSignaturePayload, error) {
|
|
var (
|
|
identity = authn.IdentityFromContext(ctx)
|
|
httpReq = gqlutils.HTTPRequestFromContext(ctx)
|
|
)
|
|
|
|
signerIP, _, _ := net.SplitHostPort(httpReq.RemoteAddr)
|
|
if signerIP == "" {
|
|
signerIP = httpReq.RemoteAddr
|
|
}
|
|
|
|
signature, err := r.esign.AcceptSignature(
|
|
ctx,
|
|
&esign.AcceptSignatureRequest{
|
|
SignatureID: input.SignatureID,
|
|
SignerFullName: identity.FullName,
|
|
SignerEmail: identity.EmailAddress,
|
|
SignerIPAddr: signerIP,
|
|
SignerUA: httpReq.UserAgent(),
|
|
},
|
|
)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot accept electronic signature", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.AcceptElectronicSignaturePayload{
|
|
Signature: types.NewElectronicSignature(signature),
|
|
}, nil
|
|
}
|
|
|
|
// RecordSigningEvent is the resolver for the recordSigningEvent field.
|
|
func (r *mutationResolver) RecordSigningEvent(ctx context.Context, input types.RecordSigningEventInput) (*types.RecordSigningEventPayload, error) {
|
|
var (
|
|
identity = authn.IdentityFromContext(ctx)
|
|
httpReq = gqlutils.HTTPRequestFromContext(ctx)
|
|
)
|
|
|
|
actorIP, _, _ := net.SplitHostPort(httpReq.RemoteAddr)
|
|
if actorIP == "" {
|
|
actorIP = httpReq.RemoteAddr
|
|
}
|
|
|
|
if err := r.esign.RecordEvent(
|
|
ctx,
|
|
&esign.RecordEventRequest{
|
|
SignatureID: input.SignatureID,
|
|
EventType: input.EventType,
|
|
EventSource: coredata.ElectronicSignatureEventSourceClient,
|
|
ActorEmail: identity.EmailAddress,
|
|
ActorIPAddr: actorIP,
|
|
ActorUA: httpReq.UserAgent(),
|
|
},
|
|
); err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot record signing event", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.RecordSigningEventPayload{Success: true}, nil
|
|
}
|
|
|
|
// FileURL is the resolver for the fileUrl field.
|
|
func (r *nonDisclosureAgreementResolver) FileURL(ctx context.Context, obj *types.NonDisclosureAgreement) (string, error) {
|
|
trustCenter := compliancepage.CompliancePageFromContext(ctx)
|
|
|
|
if identity := authn.IdentityFromContext(ctx); identity != nil && r.esign != nil {
|
|
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
|
|
|
|
access, err := trustService.TrustCenterAccesses.GetAccess(ctx, trustCenter.ID, identity.ID)
|
|
if err == nil && access.ElectronicSignatureID != nil {
|
|
fileURL, err := r.esign.GenerateSignatureFileURL(ctx, *access.ElectronicSignatureID, 15*time.Minute)
|
|
if err == nil {
|
|
return fileURL, nil
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot generate signature file URL, falling back to original NDA", log.Error(err))
|
|
}
|
|
}
|
|
|
|
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
|
|
|
|
fileURL, err := trustService.TrustCenters.GenerateNDAFileURL(ctx, trustCenter.ID, 15*time.Minute)
|
|
if err != nil {
|
|
return "", gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return fileURL, nil
|
|
}
|
|
|
|
// ViewerSignature is the resolver for the viewerSignature field.
|
|
func (r *nonDisclosureAgreementResolver) ViewerSignature(ctx context.Context, obj *types.NonDisclosureAgreement) (*types.ElectronicSignature, error) {
|
|
identity := authn.IdentityFromContext(ctx)
|
|
if identity == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
trustCenter := compliancepage.CompliancePageFromContext(ctx)
|
|
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
|
|
|
|
access, err := trustService.TrustCenterAccesses.GetAccess(ctx, trustCenter.ID, identity.ID)
|
|
if err != nil {
|
|
return nil, nil
|
|
}
|
|
|
|
if access.ElectronicSignatureID == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
sig, err := r.esign.GetSignatureByID(ctx, *access.ElectronicSignatureID)
|
|
if err != nil {
|
|
return nil, nil
|
|
}
|
|
|
|
return types.NewElectronicSignature(sig), nil
|
|
}
|
|
|
|
// NonDisclosureAgreement returns schema.NonDisclosureAgreementResolver implementation.
|
|
func (r *Resolver) NonDisclosureAgreement() schema.NonDisclosureAgreementResolver {
|
|
return &nonDisclosureAgreementResolver{r}
|
|
}
|
|
|
|
type nonDisclosureAgreementResolver struct{ *Resolver }
|