Skip to content

Conversation

wallrj-cyberark
Copy link
Member

@wallrj-cyberark wallrj-cyberark commented Aug 28, 2025

Stacked on #701

Trying to untangle the CyberArk dataupload API wrapper from the DataReadings API of the agent.
The conversion between DataReadings and Snapshot will be implemented in a followup PR.

  • Introduced a new Snapshot struct to represent the payload for the CyberArk Discovery and Context API.
  • Replaced the PostDataReadingsWithOptions method with PutSnapshot, which now uses the Snapshot struct and removes the dependency on api.DataReadingsPost.
  • Updated the retrievePresignedUploadURL method to accept clusterID directly instead of relying on Options.
  • Refactored tests to align with the new PutSnapshot method and Snapshot struct. Removed unused imports and legacy test cases.

Follow up PRs

Testing

I ran the data upload test with against the real API.

$ go test ./pkg/internal/cyberark/dataupload/...   -v -run RealAPI -args -testing.v 6
=== RUN   TestCyberArkClient_PutSnapshot_RealAPI
    round_trippers.go:632: I0828 13:48:33.839542] Response verb="GET" url="https://platform-discovery.integration-cyberark.cloud/api/v2/services/subdomain/tlskp-test" status="200 OK" milliseconds=325
    round_trippers.go:632: I0828 13:48:34.250080] Response verb="POST" url="https://anb5751.id.integration-cyberark.cloud/Security/StartAuthentication" status="200 OK" milliseconds=408
    identity.go:303: I0828 13:48:34.250728] made successful request to StartAuthentication source="Identity.doStartAuthentication" summary="NewPackage"
    round_trippers.go:632: I0828 13:48:34.691409] Response verb="POST" url="https://anb5751.id.integration-cyberark.cloud/Security/AdvanceAuthentication" status="200 OK" milliseconds=440
    identity.go:419: I0828 13:48:34.692008] successfully completed AdvanceAuthentication request to CyberArk Identity; login complete username="<REDACTED>"
    round_trippers.go:632: I0828 13:48:35.582159] Response verb="POST" url="https://tlskp-test.inventory.integration-cyberark.cloud/api/ingestions/kubernetes/snapshot-links" status="200 OK" milliseconds=889
    round_trippers.go:632: I0828 13:48:36.016095] Response verb="PUT" url="<REDACTED>" status="200 OK" milliseconds=433
--- PASS: TestCyberArkClient_PutSnapshot_RealAPI (2.50s)
PASS
ok      github.com/jetstack/preflight/pkg/internal/cyberark/dataupload  2.617s
```

@wallrj-cyberark wallrj-cyberark force-pushed the VC-43403-servicediscovery-inventory-api branch 3 times, most recently from 78859a8 to 1a40e3f Compare August 28, 2025 10:02
Base automatically changed from VC-43403-servicediscovery-inventory-api to master August 28, 2025 12:11
@wallrj-cyberark wallrj-cyberark force-pushed the VC-43403-dataupload-put-snapshot branch from 77f9a57 to cd8b55b Compare August 28, 2025 12:37
@wallrj-cyberark wallrj-cyberark marked this pull request as ready for review August 28, 2025 12:38
@wallrj-cyberark wallrj-cyberark force-pushed the VC-43403-dataupload-put-snapshot branch 2 times, most recently from 3ad3a61 to 878672e Compare August 28, 2025 12:47
…pshot

- Introduced a new `Snapshot` struct to represent the payload for the CyberArk
  Discovery and Context API.
- Renamed `PostDataReadingsWithOptions` to `PutSnapshot` to better reflect its
  purpose.
- Updated `retrievePresignedUploadURL` to accept `clusterID` directly instead
  of using `Options`.
- Refactored tests to use `PutSnapshot` and removed references to the old
  `PostDataReadingsWithOptions` method.

Signed-off-by: Richard Wall <[email protected]>
@wallrj-cyberark wallrj-cyberark force-pushed the VC-43403-dataupload-put-snapshot branch from 878672e to 49ca83c Compare August 28, 2025 13:00
@@ -60,20 +97,20 @@ func New(httpClient *http.Client, baseURL string, authenticateRequest func(req *
// If you omit that header, it is possible to PUT any data.
// There is a work around listed in that issue which we have shared with the
// CyberArk API team.
func (c *CyberArkClient) PostDataReadingsWithOptions(ctx context.Context, payload api.DataReadingsPost, opts Options) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing that. The Options struct was odd, it looks much better now.

@maelvls
Copy link
Member

maelvls commented Aug 28, 2025

Nothing feels off, I haven't run the tests nor tested this but the output you provided proves that the mocked tests are doing what they say they test.

@wallrj-cyberark wallrj-cyberark merged commit c2abc78 into master Aug 28, 2025
2 checks passed
@wallrj-cyberark wallrj-cyberark deleted the VC-43403-dataupload-put-snapshot branch August 28, 2025 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants