Skip to content

Add REST API key endpoints and bootstrap endpoint (issue #207)#209

Open
stalep wants to merge 1 commit into
Hyperfoil:mainfrom
stalep:issue_207_apikey_rest
Open

Add REST API key endpoints and bootstrap endpoint (issue #207)#209
stalep wants to merge 1 commit into
Hyperfoil:mainfrom
stalep:issue_207_apikey_rest

Conversation

@stalep

@stalep stalep commented Jul 17, 2026

Copy link
Copy Markdown
Member

New REST endpoints for API key management:
POST /api/apikey — create key for authenticated user (returns raw key as text/plain)
GET /api/apikey — list authenticated user's keys
PUT /api/apikey/{id}/revoke — revoke a key (ownership check: must own key or be admin)

Bootstrap endpoint for first-time setup:
POST /api/bootstrap — creates admin user + API key when no users exist
Returns BootstrapResponse with username and raw key
Returns 409 if any user already exists

This enables external clients (Jenkins plugin, CI/CD tools) to:

  1. Bootstrap h5m with security enabled (POST /api/bootstrap)
  2. Use the returned API key for authenticated operations
  3. Manage additional API keys via REST

New files:

  • api/ApiKeyRequest.java — request DTO (description field)
  • api/ApiKeyResponse.java — response DTO (id, description, dates, status)
  • api/BootstrapResponse.java — bootstrap response (username, apiKey)
  • rest/ApiKeyResource.java — API key CRUD endpoints
  • rest/BootstrapResource.java — one-time bootstrap endpoint

@stalep
stalep requested review from barreiro, Copilot and willr3 July 17, 2026 11:00
@stalep
stalep removed the request for review from Copilot July 17, 2026 11:01

@barreiro barreiro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this can be simplified to just the essential (create / list / revoke). see my comments.

*
* @param description human-readable label for the key (e.g., "Jenkins CI", "local testing")
*/
public record ApiKeyRequest(String description) {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I acknowledge the use of a request object, but I don't think is needed in this case

Comment thread src/main/java/io/hyperfoil/tools/h5m/api/ApiKeyResponse.java Outdated
Comment thread src/main/java/io/hyperfoil/tools/h5m/api/BootstrapResponse.java Outdated
Comment thread src/main/java/io/hyperfoil/tools/h5m/rest/BootstrapResource.java Outdated
Comment thread src/main/java/io/hyperfoil/tools/h5m/rest/ApiKeyResource.java Outdated
Comment thread src/main/java/io/hyperfoil/tools/h5m/rest/ApiKeyResource.java Outdated
Comment thread src/main/java/io/hyperfoil/tools/h5m/rest/BootstrapResource.java Outdated
@stalep
stalep force-pushed the issue_207_apikey_rest branch 2 times, most recently from 3815269 to e43f62f Compare July 19, 2026 08:55
REST endpoints for API key management:
  POST /api/apikey              — create key for authenticated user (returns raw key as text/plain)
  GET  /api/apikey              — list authenticated user's keys (List<ApiKey>)
  PUT  /api/apikey/{id}/revoke  — revoke a key (ownership check: must own key or be admin)

Startup bootstrap for automated environments:
  Set h5m.bootstrap.api-key (or H5M_BOOTSTRAP_API_KEY env var) to a known
  key value. On startup, if no users exist, BootstrapService creates an
  admin user with an API key matching the configured value. Logs a warning
  if the bootstrap user still exists on subsequent startups.

Entity rename: ApiKey -> ApiKeyEntity (consistent with FolderEntity,
NodeEntity, ValueEntity convention). The api.ApiKey record is now the
DTO returned by the REST endpoints.

New files:
- api/ApiKeyRequest.java — request DTO (description field)
- api/ApiKey.java — response DTO (id, description, dates, status)
- rest/ApiKeyResource.java — API key CRUD endpoints
- svc/BootstrapService.java — startup bootstrap with configurable API key
- svc/ApiKeyService.createWithKey() — create key with specific raw value
@stalep
stalep force-pushed the issue_207_apikey_rest branch from e43f62f to 30a7929 Compare July 19, 2026 11:56
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