@@ -22,6 +22,11 @@ const (
2222 // maxRetrievePresignedUploadURLBodySize is the maximum allowed size for a response body from the
2323 // Retrieve Presigned Upload URL service.
2424 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"
2530)
2631
2732type CyberArkClient struct {
@@ -51,6 +56,9 @@ func NewCyberArkClient(trustedCAs *x509.CertPool, baseURL string, authenticateRe
5156 }, nil
5257}
5358
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
5462func (c * CyberArkClient ) PostDataReadingsWithOptions (ctx context.Context , payload api.DataReadingsPost , opts Options ) error {
5563 if opts .ClusterName == "" {
5664 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
6472
6573 presignedUploadURL , err := c .retrievePresignedUploadURL (ctx , hex .EncodeToString (checksum .Sum (nil )), opts )
6674 if err != nil {
67- return err
75+ return fmt . Errorf ( "while retrieving snapshot upload URL: %s" , err )
6876 }
6977
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 )
7180 if err != nil {
7281 return err
7382 }
7483
75- req .Header .Set ("Content-Type" , "application/json" )
7684 version .SetUserAgent (req )
7785
7886 res , err := c .client .Do (req )
@@ -93,7 +101,7 @@ func (c *CyberArkClient) PostDataReadingsWithOptions(ctx context.Context, payloa
93101}
94102
95103func (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 )
97105 if err != nil {
98106 return "" , err
99107 }
@@ -102,10 +110,12 @@ func (c *CyberArkClient) retrievePresignedUploadURL(ctx context.Context, checksu
102110 ClusterID string `json:"cluster_id"`
103111 ClusterDescription string `json:"cluster_description"`
104112 Checksum string `json:"checksum_sha256"`
113+ AgentVersion string `json:"agent_version"`
105114 }{
106115 ClusterID : opts .ClusterName ,
107116 ClusterDescription : opts .ClusterDescription ,
108117 Checksum : checksum ,
118+ AgentVersion : version .PreflightVersion ,
109119 }
110120
111121 encodedBody := & bytes.Buffer {}
@@ -120,7 +130,7 @@ func (c *CyberArkClient) retrievePresignedUploadURL(ctx context.Context, checksu
120130
121131 req .Header .Set ("Content-Type" , "application/json" )
122132 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 )
124134 }
125135 version .SetUserAgent (req )
126136
0 commit comments