Skip to content

fix: register missing harness-config import routes#376

Merged
ptone merged 4 commits into
GoogleCloudPlatform:mainfrom
ptone:scion/dev-import-path
Jun 9, 2026
Merged

fix: register missing harness-config import routes#376
ptone merged 4 commits into
GoogleCloudPlatform:mainfrom
ptone:scion/dev-import-path

Conversation

@ptone

@ptone ptone commented Jun 9, 2026

Copy link
Copy Markdown
Member

Summary

Fixes issue 185

  • Register the unified /api/v1/resources/import endpoint in registerRoutes() — it was defined but never wired up, so all global-scope resource imports (templates and harness-configs) returned 404
  • Add import-harness-configs sub-route in handleProjectRoutes with a new handleProjectImportHarnessConfigs handler, mirroring the existing import-templates endpoint
  • Add tests for global harness-config import, single-directory (leaf) import, and per-project import via HTTP

Test plan

  • TestHandleResourcesImport_HarnessConfigGlobal — unified endpoint with kind: harness-config and scope: global
  • TestHandleResourcesImport_SingleHarnessConfig — importing a single harness-config dir (leaf, not parent-of-dirs)
  • TestHandleProjectImportHarnessConfigs — per-project endpoint POST /api/v1/projects/{id}/import-harness-configs
  • All pre-existing harness-config bootstrap tests still pass

ptone added 2 commits June 9, 2026 00:46
The hub import screen returned HTTP 404 when importing harness-configs
because two routes were never wired up:

1. The unified `/api/v1/resources/import` endpoint handler existed but
   was not registered in registerRoutes() — global-scope imports for
   both templates and harness-configs were unreachable.

2. The per-project `/api/v1/projects/{id}/import-harness-configs`
   endpoint had no backend route or handler (only import-templates
   existed).

Add the missing route registration, implement the per-project
handleProjectImportHarnessConfigs handler, and add tests covering
global harness-config import, single-directory (leaf) import, and
per-project import.
The handleProjectImportHarnessConfigs handler was passing raw user
input to importHarnessConfigsFromRemote without URL normalization,
unlike the analogous template handler and the unified import endpoint
which both call config.NormalizeTemplateSourceURL. This meant bare
hostnames (e.g. "github.com/org/repo") would fail with a non-remote
URI error.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a new endpoint and handler for importing harness configurations directly from a remote URL or workspace path into a project's harness-config store, along with registering a unified resource import endpoint. It also includes comprehensive unit tests to verify both global and project-scoped imports. The review feedback suggests improving consistency by replacing hardcoded error code strings with predefined constants (ErrCodeUnauthorized and ErrCodeInvalidRequest) in the new handler.

Comment thread pkg/hub/handlers.go Outdated
return
}
} else {
writeError(w, http.StatusUnauthorized, "unauthorized", "Authentication required", nil)

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.

medium

Use the predefined constant ErrCodeUnauthorized instead of the hardcoded string literal "unauthorized" to maintain consistency and avoid typos.

Suggested change
writeError(w, http.StatusUnauthorized, "unauthorized", "Authentication required", nil)
writeError(w, http.StatusUnauthorized, ErrCodeUnauthorized, "Authentication required", nil)

Comment thread pkg/hub/handlers.go Outdated

var req ImportHarnessConfigsRequest
if err := readJSON(r, &req); err != nil {
writeError(w, http.StatusBadRequest, "invalid_request", "Invalid request body", nil)

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.

medium

Use the predefined constant ErrCodeInvalidRequest instead of the hardcoded string literal "invalid_request" to maintain consistency and avoid typos.

Suggested change
writeError(w, http.StatusBadRequest, "invalid_request", "Invalid request body", nil)
writeError(w, http.StatusBadRequest, ErrCodeInvalidRequest, "Invalid request body", nil)

Scion Agent (fix-import-path) added 2 commits June 9, 2026 15:21
Replace hardcoded "unauthorized" and "invalid_request" strings with
ErrCodeUnauthorized and ErrCodeInvalidRequest constants, matching
the pattern used throughout the rest of the hub handlers.
The test uses newTestStore which is defined in teststore_test.go behind
a !no_sqlite build constraint. Without the same tag, go vet -tags
no_sqlite fails with "undefined: newTestStore".
@ptone ptone merged commit 8664cf2 into GoogleCloudPlatform:main Jun 9, 2026
7 checks passed
@ptone ptone deleted the scion/dev-import-path branch June 9, 2026 15:35
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.

1 participant