-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi.go
162 lines (142 loc) · 5.65 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package sanitize
import (
"context"
"errors"
"fmt"
"io"
"github.com/pangeacyber/pangea-go/pangea-sdk/v3/internal/request"
"github.com/pangeacyber/pangea-go/pangea-sdk/v3/pangea"
)
// @summary Sanitize
//
// @description Apply file sanitization actions according to specified rules.
//
// @operationId sanitize_post_v1_sanitize
//
// @example
//
// response, err := client.Sanitize(ctx, &sanitize.SanitizeRequest{
// TransferRequest: pangea.TransferRequest{
// TransferMethod: pangea.TMpostURL,
// },
// UploadedFileName: "uploaded_file",
// }, file)
func (e *sanitize) Sanitize(ctx context.Context, input *SanitizeRequest, file io.ReadSeeker) (*pangea.PangeaResponse[SanitizeResult], error) {
if input == nil {
return nil, errors.New("nil input")
}
if input.TransferMethod == pangea.TMpostURL {
params, err := pangea.GetUploadFileParams(file)
if err != nil {
return nil, err
}
input.SHA256 = params.SHA256
input.CRC32C = params.CRC32C
input.Size = pangea.Int(params.Size)
}
name := "file"
if input.TransferMethod == pangea.TMmultipart {
name = "upload"
}
fd := pangea.FileData{
File: file,
Name: name,
}
return request.DoPostWithFile(ctx, e.Client, "v1/sanitize", input, &SanitizeResult{}, fd)
}
// @summary Sanitize via presigned URL
//
// @description Apply file sanitization actions according to specified rules via
// a presigned URL.
//
// @operationId sanitize_post_v1_sanitize 2
//
// @example
//
// presignedUrl, err := client.RequestUploadURL(ctx, &sanitize.SanitizeRequest{
// TransferRequest: pangea.TransferRequest{
// TransferMethod: pangea.TMputURL,
// },
// UploadedFileName: "uploaded_file",
// })
//
// // Upload file to `presignedUrl.AcceptedResult.PutURL`.
//
// // Poll for Sanitize's result
// response, err := client.PollResultByID(ctx, *presignedUrl.RequestID, &sanitize.SanitizeResult{})
func (e *sanitize) RequestUploadURL(ctx context.Context, input *SanitizeRequest) (*pangea.PangeaResponse[SanitizeResult], error) {
if input.TransferMethod == pangea.TMmultipart || input.TransferMethod == pangea.TMdestURL || input.TransferMethod == pangea.TMsourceURL {
return nil, fmt.Errorf("transfer method [%s] is not supported in RequestUploadURL. Use Sanitize() method instead.", input.TransferMethod)
}
if input.TransferMethod == pangea.TMpostURL && (input.SHA256 == "" || input.CRC32C == "" || input.Size == nil) {
return nil, errors.New("Need to set SHA256, CRC32C and Size in order to use TMpostURL")
}
return request.GetUploadURL(ctx, e.Client, "v1/sanitize", input, &SanitizeResult{})
}
// SanitizeFile represents the SanitizeFile API request model.
type SanitizeFile struct {
ScanProvider string `json:"scan_provider,omitempty"`
}
// SanitizeContent represents the SanitizeContent API request model.
type SanitizeContent struct {
URLIntel *bool `json:"url_intel,omitempty"`
URLIntelProvider string `json:"url_intel_provider,omitempty"`
DomainIntel *bool `json:"domain_intel,omitempty"`
DomainIntelProvider string `json:"domain_intel_provider,omitempty"`
Defang *bool `json:"defang,omitempty"`
DefangThreshold *int `json:"defang_threshold,omitempty"`
Redact *bool `json:"redact,omitempty"`
RemoveAttachments *bool `json:"remove_attachments,omitempty"`
RemoveInteractive *bool `json:"remove_interactive,omitempty"`
}
// SanitizeShareOutput represents the SanitizeShareOutput API request model.
type SanitizeShareOutput struct {
Enabled *bool `json:"enabled,omitempty"`
OutputFolder string `json:"output_folder,omitempty"`
}
// SanitizeRequest represents the SanitizeRequest API request model.
type SanitizeRequest struct {
pangea.BaseRequest
pangea.TransferRequest
SourceURL string `json:"source_url,omitempty"`
ShareID string `json:"share_id,omitempty"`
File *SanitizeFile `json:"file,omitempty"`
Content *SanitizeContent `json:"content,omitempty"`
ShareOutput *SanitizeShareOutput `json:"share_output,omitempty"`
Size *int `json:"size,omitempty"`
CRC32C string `json:"crc32c,omitempty"`
SHA256 string `json:"sha256,omitempty"`
UploadedFileName string `json:"uploaded_file_name,omitempty"`
}
// DefangData represents the DefangData PangeaResponseResult.
type DefangData struct {
ExternalURLsCount int `json:"external_urls_count"`
ExternalDomainsCount int `json:"external_domains_count"`
DefangedCount int `json:"defanged_count"`
URLIntelSummary string `json:"url_intel_summary"`
DomainIntelSummary string `json:"domain_intel_summary"`
}
// RedactData represents the RedactData PangeaResponseResult.
type RedactData struct {
RedactionCount int `json:"redaction_count"`
SummaryCounts map[string]int `json:"summary_counts"`
}
// CDR represents the CDR PangeaResponseResult.
type CDR struct {
FileAttachmentsRemoved int `json:"file_attachments_removed"`
InteractiveContentsRemoved int `json:"interactive_contents_removed"`
}
// SanitizeData represents the SanitizeData PangeaResponseResult.
type SanitizeData struct {
Defang *DefangData `json:"defang,omitempty"`
Redact *RedactData `json:"redact,omitempty"`
MaliciousFile bool `json:"malicious_file"`
CDR *CDR `json:"cdr,omitempty"`
}
// SanitizeResult represents the SanitizeResult PangeaResponseResult.
type SanitizeResult struct {
DestURL *string `json:"dest_url,omitempty"`
DestShareID *string `json:"dest_share_id,omitempty"`
Data SanitizeData `json:"data"`
Parameters map[string]interface{} `json:"parameters,omitempty"`
}