Some checks failed
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 24s
Harness Replays / detect-changes (pull_request) Successful in 20s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 25s
qa-review / approved (pull_request) Failing after 24s
security-review / approved (pull_request) Failing after 23s
gate-check-v3 / gate-check (pull_request) Successful in 40s
CI / Detect changes (pull_request) Successful in 1m14s
E2E API Smoke Test / detect-changes (pull_request) Successful in 1m4s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 1m1s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 1m3s
sop-checklist-gate / gate (pull_request) Failing after 22s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 59s
sop-tier-check / tier-check (pull_request) Successful in 21s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m31s
Harness Replays / Harness Replays (pull_request) Successful in 14s
CI / Canvas (Next.js) (pull_request) Successful in 18s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 9s
CI / Python Lint & Test (pull_request) Successful in 12s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 11s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 10s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 4m46s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 4m56s
CI / Platform (Go) (pull_request) Failing after 7m35s
CI / all-required (pull_request) Successful in 1s
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/Molecule-AI/molecule-monorepo/platform/internal/bundle"
|
|
"github.com/Molecule-AI/molecule-monorepo/platform/internal/events"
|
|
"github.com/Molecule-AI/molecule-monorepo/platform/internal/provisioner"
|
|
"github.com/docker/docker/client"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type BundleHandler struct {
|
|
broadcaster *events.Broadcaster
|
|
provisioner *provisioner.Provisioner
|
|
platformURL string
|
|
configsDir string
|
|
docker *client.Client
|
|
}
|
|
|
|
func NewBundleHandler(b *events.Broadcaster, p *provisioner.Provisioner, platformURL, configsDir string, dockerCli *client.Client) *BundleHandler {
|
|
return &BundleHandler{
|
|
broadcaster: b,
|
|
provisioner: p,
|
|
platformURL: platformURL,
|
|
configsDir: configsDir,
|
|
docker: dockerCli,
|
|
}
|
|
}
|
|
|
|
// Export handles GET /bundles/export/:id
|
|
func (h *BundleHandler) Export(c *gin.Context) {
|
|
workspaceID := c.Param("id")
|
|
ctx := c.Request.Context()
|
|
|
|
b, err := bundle.Export(ctx, workspaceID, h.configsDir, h.docker)
|
|
if err != nil {
|
|
c.JSON(http.StatusNotFound, gin.H{"error": "bundle not found"})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, b)
|
|
}
|
|
|
|
// Import handles POST /bundles/import
|
|
func (h *BundleHandler) Import(c *gin.Context) {
|
|
var b bundle.Bundle
|
|
if err := c.ShouldBindJSON(&b); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid bundle"})
|
|
return
|
|
}
|
|
if b.Schema == "" || b.Name == "" {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid bundle"})
|
|
return
|
|
}
|
|
|
|
ctx := c.Request.Context()
|
|
result := bundle.Import(ctx, &b, nil, h.broadcaster, h.provisioner, h.platformURL)
|
|
|
|
c.JSON(http.StatusCreated, result)
|
|
}
|