add config file
This commit is contained in:
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"main/argohandler"
|
||||
"main/db"
|
||||
@@ -22,6 +23,7 @@ type Cluster struct {
|
||||
Memory string `json:"memory"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UserID primitive.ObjectID `json:"userId"`
|
||||
Cluster_config string `json:"clusterconfig"`
|
||||
}
|
||||
|
||||
type Header struct {
|
||||
@@ -51,12 +53,15 @@ func CreateClusterHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
_, err := db.Vclusters_details.InsertOne(context.TODO(), cluster)
|
||||
res, err := db.Vclusters_details.InsertOne(context.TODO(), cluster)
|
||||
if err != nil {
|
||||
http.Error(w, `{"message": "Could not create cluster"}`, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
argohandler.CreateApp(cluster.Name, cluster.ControlPlane, cluster.PlatformVersion, cluster.Cpu, cluster.Memory, "userid")
|
||||
objectID := res.InsertedID.(primitive.ObjectID)
|
||||
idStr := objectID.Hex()
|
||||
|
||||
argohandler.CreateApp(idStr, cluster.Name, cluster.ControlPlane, cluster.PlatformVersion, cluster.Cpu, cluster.Memory, "userid")
|
||||
|
||||
response := map[string]string{"message": "Cluster created"}
|
||||
|
||||
@@ -74,6 +79,28 @@ func ListUserClusters(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
func Connect(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
clusterName := r.URL.Query().Get("Name")
|
||||
if clusterName == "" {
|
||||
http.Error(w, "Missing 'Name' parameter", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
var existsCluster Cluster
|
||||
_ = db.Vclusters_details.FindOne(context.TODO(), bson.M{"name": clusterName}).Decode(&existsCluster)
|
||||
|
||||
decoded, err := base64.StdEncoding.DecodeString(existsCluster.Cluster_config)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to decode cluster config", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/x-yaml")
|
||||
w.Write(decoded)
|
||||
|
||||
}
|
||||
|
||||
// func RegsiterClusterRoute(r *mux.Router) {
|
||||
// r.HandleFunc("/createcluster", createClusterHandler).Methods("POST", "OPTIONS")
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user