mirror of https://github.com/helm/helm
parent
37d9bfa79c
commit
a8a85edd5c
@ -0,0 +1,15 @@
|
||||
package list
|
||||
|
||||
type ListRequest struct {
|
||||
RequestID string
|
||||
}
|
||||
|
||||
type ListRespose struct {
|
||||
Status bool
|
||||
Data []HelmRelease
|
||||
}
|
||||
|
||||
type HelmRelease struct {
|
||||
Release string `json:"release"`
|
||||
Namespace string `json:"namespace"`
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package list
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"helm.sh/helm/v3/pkg/action"
|
||||
"helm.sh/helm/v3/pkg/servercontext"
|
||||
)
|
||||
|
||||
func Handler() http.Handler {
|
||||
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
|
||||
res.Header().Set("Content-Type", "application/json")
|
||||
defer req.Body.Close()
|
||||
|
||||
var request ListRequest
|
||||
decoder := json.NewDecoder(req.Body)
|
||||
decoder.UseNumber()
|
||||
|
||||
if err := decoder.Decode(&request); err != nil {
|
||||
fmt.Println("error in request")
|
||||
return
|
||||
}
|
||||
|
||||
request.RequestID = req.Header.Get("Request-Id")
|
||||
|
||||
list := action.NewList(servercontext.App().ActionConfig)
|
||||
|
||||
list.SetStateMask()
|
||||
results, err := list.Run()
|
||||
if err != nil {
|
||||
fmt.Print("error while running helm list")
|
||||
}
|
||||
|
||||
var helmReleases []HelmRelease
|
||||
for _, res := range results {
|
||||
r := HelmRelease{Release: res.Name, Namespace: res.Namespace}
|
||||
helmReleases = append(helmReleases, r)
|
||||
}
|
||||
|
||||
response := ListRespose{Status: true, Data: helmReleases}
|
||||
payload, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
fmt.Println("error parsing response")
|
||||
return
|
||||
}
|
||||
|
||||
res.Write(payload)
|
||||
})
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package ping
|
||||
|
||||
type PingReq struct {
|
||||
RequestID string
|
||||
}
|
||||
|
||||
type PingResponse struct {
|
||||
Status bool
|
||||
Data string
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package ping
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Handler() http.Handler {
|
||||
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
|
||||
res.Header().Set("Content-Type", "application/json")
|
||||
defer req.Body.Close()
|
||||
|
||||
var request PingReq
|
||||
decoder := json.NewDecoder(req.Body)
|
||||
decoder.UseNumber()
|
||||
|
||||
if err := decoder.Decode(&request); err != nil {
|
||||
fmt.Println("error in request")
|
||||
return
|
||||
}
|
||||
|
||||
request.RequestID = req.Header.Get("Request-Id")
|
||||
|
||||
response := PingResponse{Status: true, Data: "pong"}
|
||||
payload, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
fmt.Println("error parsing response")
|
||||
return
|
||||
}
|
||||
|
||||
res.Write(payload)
|
||||
})
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package servercontext
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"helm.sh/helm/v3/pkg/action"
|
||||
"helm.sh/helm/v3/pkg/cli"
|
||||
)
|
||||
|
||||
var app Application
|
||||
|
||||
type Application struct {
|
||||
Config *cli.EnvSettings
|
||||
ActionConfig *action.Configuration
|
||||
}
|
||||
|
||||
func App() *Application {
|
||||
return &app
|
||||
}
|
||||
|
||||
func NewApp() *Application {
|
||||
app.Config = envSettings()
|
||||
app.ActionConfig = boostrapActionConfig()
|
||||
return &app
|
||||
}
|
||||
|
||||
func envSettings() *cli.EnvSettings {
|
||||
envSettings := cli.New()
|
||||
for k, v := range envSettings.EnvVars() {
|
||||
fmt.Println(k, v)
|
||||
}
|
||||
return envSettings
|
||||
}
|
||||
|
||||
func debug(format string, v ...interface{}) {
|
||||
format = fmt.Sprintf("[debug] %s\n", format)
|
||||
log.Output(2, fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
||||
func boostrapActionConfig() *action.Configuration {
|
||||
actionConfig := new(action.Configuration)
|
||||
if err := actionConfig.Init(app.Config.RESTClientGetter(), app.Config.Namespace(), os.Getenv("HELM_DRIVER"), debug); err != nil {
|
||||
log.Fatalf("error getting configuration: %v", err)
|
||||
return nil
|
||||
}
|
||||
return actionConfig
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
startServer()
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
router := http.NewServeMux()
|
||||
router.HandleFunc("/ping", pingFunc)
|
||||
|
||||
err := http.ListenAndServe(fmt.Sprintf(":%d", 8080), router)
|
||||
if err != nil {
|
||||
fmt.Println("error starting server", err)
|
||||
}
|
||||
}
|
||||
|
||||
func pingFunc(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("pong")
|
||||
}
|
Loading…
Reference in new issue