Skip to content

Commit 5887e98

Browse files
committed
feat(cli): add inbox email commands (MR !20486)
https://gitlab.com/escape.tech/product/-/merge_requests/20486
2 parents f1aa26f + fed8d84 commit 5887e98

8 files changed

Lines changed: 518 additions & 3 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export ESCAPE_API_KEY=your_api_key_here
3939
# Start a scan and wait for results
4040
escape-cli scans start <profile-id> --watch
4141

42+
# List emails received by a scan inbox
43+
escape-cli emails list --email test.00000000-0000-0000-0000-000000000000@scan.escape.tech
44+
4245
# Review discovered issues
4346
escape-cli issues list --severity CRITICAL,HIGH --status OPEN
4447
```
@@ -71,6 +74,7 @@ Optional inputs: `schema` (path or URL to update the API schema before the scan)
7174

7275
```text
7376
scans Run and manage security scans
77+
emails List and read scan inbox emails
7478
issues Manage and track security vulnerabilities
7579
problems View scan problems and failures
7680
profiles Configure security testing profiles

helm/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ apiVersion: v2
33
name: private-location
44
description: Escape Private Location
55
type: application
6-
version: 1.1.1
7-
appVersion: 1.1.1
6+
version: 1.2.0
7+
appVersion: 1.2.0

pkg/api/escape/emails.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package escape
2+
3+
import (
4+
"context"
5+
"errors"
6+
"fmt"
7+
"strings"
8+
"time"
9+
10+
v3 "github.com/Escape-Technologies/cli/pkg/api/v3"
11+
)
12+
13+
// ListInboxEmailsFilters holds the supported inbox email list filters.
14+
type ListInboxEmailsFilters struct {
15+
Email string
16+
IDs []string
17+
Before *time.Time
18+
After *time.Time
19+
Size int
20+
}
21+
22+
// ListInboxEmails lists inbox emails for a target scan email address.
23+
func ListInboxEmails(ctx context.Context, cursor string, filters *ListInboxEmailsFilters) (*v3.ListInboxEmails200Response, error) {
24+
if filters == nil {
25+
return nil, errors.New("email is required")
26+
}
27+
email := strings.TrimSpace(filters.Email)
28+
if email == "" {
29+
return nil, errors.New("email is required")
30+
}
31+
32+
client, err := newAPIV3Client()
33+
if err != nil {
34+
return nil, fmt.Errorf("unable to init client: %w", err)
35+
}
36+
37+
req := client.EmailsAPI.ListInboxEmails(ctx).Email(email)
38+
if cursor != "" {
39+
req = req.Cursor(cursor)
40+
}
41+
if filters.Size > 0 {
42+
req = req.Size(filters.Size)
43+
}
44+
if len(filters.IDs) > 0 {
45+
req = req.Ids(strings.Join(filters.IDs, ","))
46+
}
47+
if filters.Before != nil {
48+
req = req.Before(*filters.Before)
49+
}
50+
if filters.After != nil {
51+
req = req.After(*filters.After)
52+
}
53+
54+
data, _, err := req.Execute()
55+
if err != nil {
56+
return nil, fmt.Errorf("unable to list inbox emails: %w", err)
57+
}
58+
return data, nil
59+
}
60+
61+
// ReadInboxEmail reads the full raw content of an inbox email by ID.
62+
func ReadInboxEmail(ctx context.Context, id string) (*v3.ScanEmailDetails, error) {
63+
client, err := newAPIV3Client()
64+
if err != nil {
65+
return nil, fmt.Errorf("unable to init client: %w", err)
66+
}
67+
68+
data, _, err := client.EmailsAPI.ReadInboxEmail(ctx, id).Execute()
69+
if err != nil {
70+
return nil, fmt.Errorf("unable to read inbox email: %w", err)
71+
}
72+
return data, nil
73+
}

pkg/cli/cmd/capabilities.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ func commandSchemaRegistry() map[string]commandSchemas {
8888
"escape-cli scans watch": {output: v3.ScanDetailed1{}},
8989
"escape-cli scans issues": {output: []v3.IssueSummarized{}},
9090
"escape-cli scans targets": {output: []v3.TargetDetailed{}},
91+
"escape-cli emails list": {output: []v3.ScanEmailSummary{}},
92+
"escape-cli emails read": {output: v3.ScanEmailDetails{}},
93+
"escape-cli emails wait": {output: v3.ScanEmailDetails{}},
9194
"escape-cli authentications start": {input: v3.StartAuthenticationRequest{}, output: v3.StartAuthentication200Response{}},
9295
"escape-cli authentications get": {output: v3.GetAuthentication200Response{}},
9396
"escape-cli jobs trigger-export": {output: v3.TriggerExport200Response{}},

0 commit comments

Comments
 (0)