Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN CGO_ENABLED=0 go build -o /my_app
FROM alpine:3.21
WORKDIR /plugin
COPY --from=builder /my_app /my_app
COPY --from=builder /plugin/*.yaml .
COPY --from=builder /plugin/*.sql .
COPY --from=builder /plugin/*.yaml ./
COPY --from=builder /plugin/*.sql ./
EXPOSE 8080
CMD ["/my_app"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=0.0.2
VERSION=0.0.7
LOCAL_REGISTRY=localhost:5000

.PHONY: docker-release
Expand Down
36 changes: 36 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
_ "embed"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"
"os"

"github.com/cycloidio/cy-go-plugin/sentry"
Expand Down Expand Up @@ -43,6 +45,7 @@ func main() {

mux := http.NewServeMux()
mux.HandleFunc("GET /_cy/ping", ping)
mux.HandleFunc("GET /_cy/test-proxy", testProxy)
mux.HandleFunc("POST /_cy/events", events)
mux.HandleFunc("DELETE /_cy/plugin", func(w http.ResponseWriter, r *http.Request) {
if err := sentry.Clear(db); err != nil {
Expand Down Expand Up @@ -78,6 +81,39 @@ func ping(w http.ResponseWriter, _ *http.Request) {
respond(w, "ping")
}

// testProxy calls the plugin manager's internal proxy endpoint using the injected
// PROXY_URL and PLUGIN_SECRET env vars, and forwards the response back to the caller.
func testProxy(w http.ResponseWriter, r *http.Request) {
proxyURL := os.Getenv("PROXY_URL")
if proxyURL == "" {
http.Error(w, "PROXY_URL not set", http.StatusServiceUnavailable)
return
}

targetURL := proxyURL
if secret := os.Getenv("PLUGIN_SECRET"); secret != "" {
targetURL += "?secret=" + url.QueryEscape(secret)
}

req, err := http.NewRequestWithContext(r.Context(), http.MethodGet, targetURL, nil)
if err != nil {
http.Error(w, fmt.Sprintf("build request: %v", err), http.StatusInternalServerError)
return
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
http.Error(w, fmt.Sprintf("proxy call failed: %v", err), http.StatusBadGateway)
return
}
defer resp.Body.Close()

body, _ := io.ReadAll(resp.Body)
w.Header().Set("Content-Type", resp.Header.Get("Content-Type"))
w.WriteHeader(resp.StatusCode)
w.Write(body)
}

func events(w http.ResponseWriter, _ *http.Request) {
respond(w, "events")
}
Expand Down
7 changes: 7 additions & 0 deletions manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ images:
scope:
- organization:project:*
- organization:credential:*
setup:
can_replicate: true
readiness_path: /_cy/ping
min_cpu: "50m"
min_memory: "64Mi"
max_cpu: "200m"
max_memory: "256Mi"
configuration:
- name: "Message"
description: "Message to display in the job"
Expand Down