@@ -22,6 +22,11 @@ const (
22
22
// maxRetrievePresignedUploadURLBodySize is the maximum allowed size for a response body from the
23
23
// Retrieve Presigned Upload URL service.
24
24
maxRetrievePresignedUploadURLBodySize = 10 * 1024
25
+
26
+ // apiPathSnapshotLinks is the URL path of the snapshot-links endpoint of the inventory API.
27
+ // This endpoint returns an AWS presigned URL.
28
+ // TODO(wallrj): Link to CyberArk API documentation when it is published.
29
+ apiPathSnapshotLinks = "/api/ingestions/kubernetes/snapshot-links"
25
30
)
26
31
27
32
type CyberArkClient struct {
@@ -51,6 +56,9 @@ func NewCyberArkClient(trustedCAs *x509.CertPool, baseURL string, authenticateRe
51
56
}, nil
52
57
}
53
58
59
+ // PostDataReadingsWithOptions PUTs the supplied payload to an [AWS presigned URL] which it obtains via the CyberArk inventory API.
60
+ //
61
+ // [AWS presigned URL]: https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html
54
62
func (c * CyberArkClient ) PostDataReadingsWithOptions (ctx context.Context , payload api.DataReadingsPost , opts Options ) error {
55
63
if opts .ClusterName == "" {
56
64
return fmt .Errorf ("programmer mistake: the cluster name (aka `cluster_id` in the config file) cannot be left empty" )
@@ -64,15 +72,15 @@ func (c *CyberArkClient) PostDataReadingsWithOptions(ctx context.Context, payloa
64
72
65
73
presignedUploadURL , err := c .retrievePresignedUploadURL (ctx , hex .EncodeToString (checksum .Sum (nil )), opts )
66
74
if err != nil {
67
- return err
75
+ return fmt . Errorf ( "while retrieving snapshot upload URL: %s" , err )
68
76
}
69
77
70
- req , err := http .NewRequestWithContext (ctx , http .MethodPost , presignedUploadURL , encodedBody )
78
+ // The snapshot-links endpoint returns an AWS presigned URL which only supports the PUT verb.
79
+ req , err := http .NewRequestWithContext (ctx , http .MethodPut , presignedUploadURL , encodedBody )
71
80
if err != nil {
72
81
return err
73
82
}
74
83
75
- req .Header .Set ("Content-Type" , "application/json" )
76
84
version .SetUserAgent (req )
77
85
78
86
res , err := c .client .Do (req )
@@ -93,7 +101,7 @@ func (c *CyberArkClient) PostDataReadingsWithOptions(ctx context.Context, payloa
93
101
}
94
102
95
103
func (c * CyberArkClient ) retrievePresignedUploadURL (ctx context.Context , checksum string , opts Options ) (string , error ) {
96
- uploadURL , err := url .JoinPath (c .baseURL , "/api/data/kubernetes/upload" )
104
+ uploadURL , err := url .JoinPath (c .baseURL , apiPathSnapshotLinks )
97
105
if err != nil {
98
106
return "" , err
99
107
}
@@ -102,10 +110,12 @@ func (c *CyberArkClient) retrievePresignedUploadURL(ctx context.Context, checksu
102
110
ClusterID string `json:"cluster_id"`
103
111
ClusterDescription string `json:"cluster_description"`
104
112
Checksum string `json:"checksum_sha256"`
113
+ AgentVersion string `json:"agent_version"`
105
114
}{
106
115
ClusterID : opts .ClusterName ,
107
116
ClusterDescription : opts .ClusterDescription ,
108
117
Checksum : checksum ,
118
+ AgentVersion : version .PreflightVersion ,
109
119
}
110
120
111
121
encodedBody := & bytes.Buffer {}
@@ -120,7 +130,7 @@ func (c *CyberArkClient) retrievePresignedUploadURL(ctx context.Context, checksu
120
130
121
131
req .Header .Set ("Content-Type" , "application/json" )
122
132
if err := c .authenticateRequest (req ); err != nil {
123
- return "" , fmt .Errorf ("failed to authenticate request" )
133
+ return "" , fmt .Errorf ("failed to authenticate request: %s" , err )
124
134
}
125
135
version .SetUserAgent (req )
126
136
0 commit comments