Skip to content

CyberArk: Get --input-file working with machinehub mode#707

Merged
wallrj-cyberark merged 1 commit intomasterfrom
VC-43403-outputmode-integration-tests
Sep 4, 2025
Merged

CyberArk: Get --input-file working with machinehub mode#707
wallrj-cyberark merged 1 commit intomasterfrom
VC-43403-outputmode-integration-tests

Conversation

@wallrj-cyberark
Copy link
Member

@wallrj-cyberark wallrj-cyberark commented Sep 3, 2025

I wanted to get the --input-path feature working with machinehub mode. It wasn't working because the cyberark snapshot conversion requires the datareadings to have concrete types, but the existing input mode just treats the data as interface{}.

I've added tests which demo the input-file working with machinehub mode. They only run if you have the ARK_ environment variables set.

  • Implemented custom JSON unmarshaling for DataReading to handle dynamic parsing of the Data field.
  • Added UnmarshalJSON for GatheredResource to support strict JSON decoding.
  • Introduced TestOutputModes to validate the --machine-hub mode with example configuration and input files.
  • Added example files config.yaml and input.json for machinehub mode testing.

Testing

Here's an example of me running the machinehub output mode test locally.

go test -v -run='TestOutputModes$' 
...

=== RUN   TestOutputModes/machinehub
    agent_test.go:71: Running child process /tmp/go-buildXXXXXXX/b001/cmd.test -test.run=^TestOutputModes/machinehub$
    agent_test.go:80: STDOUT
        I0904 10:08:41.508879 XXXXXXX run.go:58] "Starting" logger="Run" version="development" commit=""
        I0904 10:08:41.509044 XXXXXXX config.go:448] "Output mode selected" logger="Run" mode="MachineHub" reason="--machine-hub was specified"
        I0904 10:08:41.509101 XXXXXXX run.go:116] "Healthz endpoints enabled" logger="Run.APIServer" addr=":8081" path="/healthz"
        I0904 10:08:41.509121 XXXXXXX run.go:120] "Readyz endpoints enabled" logger="Run.APIServer" addr=":8081" path="/readyz"
        I0904 10:08:41.509134 XXXXXXX run.go:269] "Pod event recorder disabled" logger="Run" reason="The agent does not appear to be running in a Kubernetes cluster." detail="When running in a Kubernetes cluster the following environment variables must be set: POD_NAME, POD_NODE, POD_UID, POD_NAMESPACE"
        I0904 10:08:41.509149 XXXXXXX run.go:308] "Reading data from local file" logger="Run.gatherAndOutputData" inputPath="/path/to/examples/machinehub/input.json"
        I0904 10:08:41.509657 XXXXXXX run.go:432] "Starting" logger="Run.APIServer.ListenAndServe" addr=":8081"
        I0904 10:08:41.813165 XXXXXXX round_trippers.go:632] "Response" logger="Run.gatherAndOutputData.postData" verb="GET" url="https://platform-discovery.integration-cyberark.cloud/api/public/tenant-discovery?bySubdomain=REDACTED" status="200 OK" milliseconds=303
        I0904 10:08:42.092198 XXXXXXX round_trippers.go:632] "Response" logger="Run.gatherAndOutputData.postData" verb="POST" url="https://REDACTED.id.integration-cyberark.cloud/Security/StartAuthentication" status="200 OK" milliseconds=278
        I0904 10:08:42.092855 XXXXXXX identity.go:292] "made successful request to StartAuthentication" logger="Run.gatherAndOutputData.postData" source="Identity.doStartAuthentication" summary="NewPackage"
        I0904 10:08:42.321967 XXXXXXX round_trippers.go:632] "Response" logger="Run.gatherAndOutputData.postData" verb="POST" url="https://REDACTED.id.integration-cyberark.cloud/Security/AdvanceAuthentication" status="200 OK" milliseconds=228
        I0904 10:08:42.322694 XXXXXXX identity.go:402] "successfully completed AdvanceAuthentication request to CyberArk Identity; login complete" logger="Run.gatherAndOutputData.postData" username="REDACTED"
        I0904 10:08:42.904233 XXXXXXX round_trippers.go:632] "Response" logger="Run.gatherAndOutputData.postData" verb="POST" url="https://REDACTED.inventory.integration-cyberark.cloud/api/ingestions/kubernetes/snapshot-links" status="200 OK" milliseconds=580
        I0904 10:08:43.335732 XXXXXXX round_trippers.go:632] "Response" logger="Run.gatherAndOutputData.postData" verb="PUT" url="https://REDACTED.s3.amazonaws.com/REDACTED.snapshot?AWSAccessKeyId=REDACTED&Signature=REDACTED&x-amz-tagging=REDACTED" status="200 OK" milliseconds=431
        I0904 10:08:43.336407 XXXXXXX run.go:417] "Data sent successfully" logger="Run.gatherAndOutputData.postData"
        I0904 10:08:43.336503 XXXXXXX run.go:446] "Shutting down" logger="Run.APIServer.ListenAndServe" addr=":8081"
        I0904 10:08:43.337512 XXXXXXX run.go:461] "Shutdown complete" logger="Run.APIServer.ListenAndServe" addr=":8081"
        
    agent_test.go:81: STDERR
        
--- PASS: TestOutputModes (1.94s)
    --- PASS: TestOutputModes/localfile (0.06s)
    --- PASS: TestOutputModes/machinehub (1.88s)
PASS
ok  	github.com/jetstack/preflight/cmd	2.014s

The test is currently skipped in CI:

=== Skipped
=== SKIP: cmd TestOutputModes/machinehub (0.00s)
    agent_test.go:35: Skipping test because one of ARK_SUBDOMAIN, ARK_USERNAME or ARK_SECRET isn't set

=== SKIP: internal/cyberark TestCyberArkClient_PutSnapshot_RealAPI (0.00s)
    client_test.go:69: Skipping: missing environment variables: ARK_SUBDOMAIN, ARK_USERNAME, ARK_SECRET

=== SKIP: internal/cyberark/identity TestLoginUsernamePassword_RealAPI (0.00s)
    identity_test.go:53: Skipping test because one of ARK_SUBDOMAIN, ARK_USERNAME or ARK_SECRET isn't set

=== SKIP: pkg/client TestCyberArkClient_PostDataReadingsWithOptions_RealAPI/success (0.00s)
    client_cyberark_test.go:67: Skipping: missing environment variables: ARK_SUBDOMAIN, ARK_USERNAME, ARK_SECRET

@wallrj-cyberark wallrj-cyberark changed the title CyberArk(cmd,api): add dynamic JSON unmarshaling for DataReading and tests for machinehub mode CyberArk: Get --input-file working with machinehub mode Sep 3, 2025
@wallrj-cyberark wallrj-cyberark force-pushed the VC-43403-outputmode-integration-tests branch from 8928ca0 to 8ffabec Compare September 4, 2025 08:34
…tests for machinehub mode

- Implemented custom JSON unmarshaling for `DataReading` to handle dynamic parsing of the `Data` field.
- Added `UnmarshalJSON` for `GatheredResource` to support strict JSON decoding.
- Introduced `TestOutputModes` to validate the `--machine-hub` mode with example configuration and input files.
- Added example files `config.yaml` and `input.json` for `machinehub` mode testing.

Signed-off-by: Richard Wall <richard.wall@cyberark.com>
@wallrj-cyberark wallrj-cyberark force-pushed the VC-43403-outputmode-integration-tests branch from 8ffabec to d825569 Compare September 4, 2025 08:58
@wallrj-cyberark wallrj-cyberark merged commit 7fc0481 into master Sep 4, 2025
2 checks passed
@wallrj-cyberark wallrj-cyberark deleted the VC-43403-outputmode-integration-tests branch September 4, 2025 14:18
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