Skip to content

Add list resources API support#129

Open
miewest wants to merge 2 commits intocyberark:mainfrom
miewest:feature/list-resources
Open

Add list resources API support#129
miewest wants to merge 2 commits intocyberark:mainfrom
miewest:feature/list-resources

Conversation

@miewest
Copy link

@miewest miewest commented Mar 3, 2026

Closes #128
Builds on #127

Summary

Adds support for the Conjur List Resources API (GET /resources/{account}) to the Java SDK. This builds on the Endpoints refactor and infrastructure introduced in #127 (batch secret retrieval).

Changes

New files

  • ConjurResource.java — Model class for resources returned by the API. Includes fields for id, created_at, owner, policy, permissions, annotations, secrets, and policy_versions. Inner classes Permission and Annotation for nested objects. Helper methods getKind() and getIdentifier() to parse the {account}:{kind}:{identifier} resource ID format.

Modified files

  • Endpoints.java — Added getResourcesUri() returning {applianceUrl}/resources/{account}
  • ResourceProvider.java — Added listResources() (3 overloads) and countResources() as default interface methods for backward compatibility
  • ResourceClient.java — Full HTTP implementation: builds query parameters (kind, search, limit, offset, count), parses JSON arrays via Gson into List<ConjurResource>, handles both JSON {"count":N} and plain integer count response formats
  • Variables.java — Delegation to ResourceClient
  • Conjur.java — Convenience methods on the entry point class
  • ResourceClientTest.java — 17 new unit tests covering: list all resources, filter by kind, text search, pagination, combined parameters, empty results, 401/403 error handling, full field parsing (permissions, annotations), special character encoding in search, count with JSON format, count with plain integer format, count by kind, count with search, count 401 error, and Endpoints URI derivation

API

Conjur conjur = new Conjur();

// List all visible resources
List<ConjurResource> all = conjur.listResources();

// Filter by kind
List<ConjurResource> vars = conjur.listResources("variable");

// Search with pagination
List<ConjurResource> page = conjur.listResources("variable", "prod", 100, 0);

// Count resources
int count = conjur.countResources("variable", null);

// Access resource fields
ConjurResource r = vars.get(0);
r.getId();          // "myaccount:variable:path/to/secret"
r.getKind();        // "variable"
r.getIdentifier();  // "path/to/secret"
r.getOwner();       // "myaccount:policy:root"
r.getPermissions(); // List<Permission>
r.getAnnotations(); // List<Annotation>

Testing

  • 45 unit tests pass (44 ResourceClientTest + 1 TelemetryHeaderTest)
  • Tested against a live Conjur server: list all, filter by kind (variable/host/policy), text search, pagination (limit/offset), count, and count-vs-list consistency check all pass

miewest added 2 commits March 2, 2026 18:05
- Implemented batch secret retrieval methods in ResourceClient, Variables, and ResourceProvider.
- Enhanced Endpoints class to support batch retrieval URI.
- Added comprehensive unit tests for batch secret retrieval in ResourceClientTest.
@miewest
Copy link
Author

miewest commented Mar 3, 2026

Like the other PR, I also created a manual full integration test of this code but wasn't sure if it fit in the repo. I can add it if wanted.

@szh
Copy link
Contributor

szh commented Mar 5, 2026

Thank you for the PR! We've added it to our backlog to review.

Tracking internally as CNJR-13116.

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.

Add list resources API support

2 participants