Compare commits
4 Commits
c0d4a62d60
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59bd105247 | ||
|
|
a23a1e28f4 | ||
|
|
2482e37e8c | ||
|
|
eb42739472 |
Submodule application updated: 282c3e52d0...84e5df6078
@@ -13,6 +13,8 @@ import (
|
|||||||
|
|
||||||
"github.com/argoproj/argo-cd/v2/pkg/apiclient"
|
"github.com/argoproj/argo-cd/v2/pkg/apiclient"
|
||||||
"github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
|
"github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
|
||||||
|
clusterapi "github.com/argoproj/argo-cd/v2/pkg/apiclient/cluster"
|
||||||
|
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
|
||||||
argoprojv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
|
argoprojv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
@@ -61,8 +63,8 @@ var (
|
|||||||
|
|
||||||
func InitializeClient() {
|
func InitializeClient() {
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
argocdServer := "130.185.77.247:30966"
|
argocdServer := "argocd.bugx.ir"
|
||||||
argocdToken := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhcmdvY2QiLCJzdWIiOiJhZG1pbjphcGlLZXkiLCJuYmYiOjE3NjAwMjE1NjAsImlhdCI6MTc2MDAyMTU2MCwianRpIjoiZTdjMzMyNWQtZDU0Yy00M2Q0LWIzOGYtYjc3NGQ4OTcxZGZmIn0.35lU-UOwl3XxjvqEfnEXIhaVoug90-J2WWj5x0OihC0"
|
argocdToken := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhcmdvY2QiLCJzdWIiOiJhZG1pbjphcGlLZXkiLCJuYmYiOjE3NjMxMzQ3NzEsImlhdCI6MTc2MzEzNDc3MSwianRpIjoiNDVkMmViYmYtMDYzNC00MTFlLTk4ODctMjMzMmJjMGFjNDkxIn0.UgQ7oIWzrsP7mCaN8Tfd7wrcFQ7Ew6wYFQHevMIGflw"
|
||||||
|
|
||||||
config := apiclient.ClientOptions{
|
config := apiclient.ClientOptions{
|
||||||
ServerAddr: argocdServer,
|
ServerAddr: argocdServer,
|
||||||
@@ -108,7 +110,7 @@ func CreateApp(objectID string, clustername string, ControlPlane string, Platfor
|
|||||||
Path: "vcluster-0.28.0",
|
Path: "vcluster-0.28.0",
|
||||||
Cluster: "in-cluster",
|
Cluster: "in-cluster",
|
||||||
Server: "https://kubernetes.default.svc",
|
Server: "https://kubernetes.default.svc",
|
||||||
RepoURL: "http://130.185.77.247:31300/gitea_admin/application.git",
|
RepoURL: "https://git.bugx.ir/gitea_admin/application.git",
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,11 +278,84 @@ func updateConfig(objectID string, configStrings string, namespace string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = db.Vclusters_details.UpdateOne(context.TODO(), filter, update)
|
_, err = db.Vclusters_details.UpdateOne(context.TODO(), filter, update)
|
||||||
|
RegisterToArgo(configStrings, namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("update cluster config error: ", err)
|
fmt.Println("update cluster config error: ", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RegisterToArgo(kubeConfigString string, namespace string) {
|
||||||
|
|
||||||
|
// ArgoCD server
|
||||||
|
argocdServer := "argocd.bugx.ir"
|
||||||
|
argocdToken := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhcmdvY2QiLCJzdWIiOiJhZG1pbjphcGlLZXkiLCJuYmYiOjE3NjMxMzQ3NzEsImlhdCI6MTc2MzEzNDc3MSwianRpIjoiNDVkMmViYmYtMDYzNC00MTFlLTk4ODctMjMzMmJjMGFjNDkxIn0.UgQ7oIWzrsP7mCaN8Tfd7wrcFQ7Ew6wYFQHevMIGflw"
|
||||||
|
|
||||||
|
// Context name that must exist in kubeconfig
|
||||||
|
clusterContext := "kubernetes-super-admin@kubernetes"
|
||||||
|
|
||||||
|
decoded, err := base64.StdEncoding.DecodeString(kubeConfigString)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Load kubeconfig of the target cluster ----
|
||||||
|
cfg, err := clientcmd.Load([]byte(decoded))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := cfg.Contexts[clusterContext]
|
||||||
|
if ctx == nil {
|
||||||
|
panic("cluster context not found in kubeconfig")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Real cluster data
|
||||||
|
cluster := cfg.Clusters[ctx.Cluster]
|
||||||
|
user := cfg.AuthInfos[ctx.AuthInfo]
|
||||||
|
|
||||||
|
// ---- Create ArgoCD API client ----
|
||||||
|
clientOpts := apiclient.ClientOptions{
|
||||||
|
ServerAddr: argocdServer,
|
||||||
|
AuthToken: argocdToken,
|
||||||
|
Insecure: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
argocdClient, err := apiclient.NewClient(&clientOpts)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
closer, clusterIf, err := argocdClient.NewClusterClient()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer closer.Close()
|
||||||
|
|
||||||
|
// ---- Build the correct request type ----
|
||||||
|
req := &clusterapi.ClusterCreateRequest{
|
||||||
|
Cluster: &v1alpha1.Cluster{
|
||||||
|
Name: namespace + clusterContext,
|
||||||
|
Server: cluster.Server,
|
||||||
|
Config: v1alpha1.ClusterConfig{
|
||||||
|
BearerToken: user.Token,
|
||||||
|
TLSClientConfig: v1alpha1.TLSClientConfig{
|
||||||
|
CAData: cluster.CertificateAuthorityData,
|
||||||
|
Insecure: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Register cluster to ArgoCD ----
|
||||||
|
createdCluster, err := clusterIf.Create(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Cluster registered:", createdCluster.Name)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func SyncApp(objectID string, appName string, cluster string, namesname string) {
|
func SyncApp(objectID string, appName string, cluster string, namesname string) {
|
||||||
|
|
||||||
InitializeClient()
|
InitializeClient()
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ import (
|
|||||||
"main/argohandler"
|
"main/argohandler"
|
||||||
"main/db"
|
"main/db"
|
||||||
"main/helpers"
|
"main/helpers"
|
||||||
|
"main/jobs"
|
||||||
"main/models"
|
"main/models"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hibiken/asynq"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
batchv1 "k8s.io/api/batch/v1"
|
batchv1 "k8s.io/api/batch/v1"
|
||||||
@@ -3562,6 +3562,7 @@ func Helm_install(w http.ResponseWriter, r *http.Request) {
|
|||||||
Namespace string `json:"Namespace"`
|
Namespace string `json:"Namespace"`
|
||||||
Release string `json:"Release"`
|
Release string `json:"Release"`
|
||||||
Repo string `json:"Repo"`
|
Repo string `json:"Repo"`
|
||||||
|
Version string `json:"Version"`
|
||||||
}
|
}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||||
http.Error(w, "Invalid JSON body", http.StatusBadRequest)
|
http.Error(w, "Invalid JSON body", http.StatusBadRequest)
|
||||||
@@ -3582,46 +3583,24 @@ func Helm_install(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write kubeconfig to temp file
|
var redisClient = asynq.NewClient(asynq.RedisClientOpt{Addr: "130.185.77.247:30828", Password: "xwy8ahx46F"})
|
||||||
tmpFile, err := os.CreateTemp("", "kubeconfig-*.yaml")
|
chart := jobs.InstallChartPayload{
|
||||||
|
ChartName: req.Chart,
|
||||||
|
Release: req.Release,
|
||||||
|
Version: req.Version,
|
||||||
|
Namespace: req.Namespace,
|
||||||
|
UserID: "razzaghi",
|
||||||
|
}
|
||||||
|
if _, err := json.Marshal(chart); err != nil {
|
||||||
|
fmt.Printf("Could not json ")
|
||||||
|
}
|
||||||
|
task := jobs.NewInstallCahrtTask(chart.ChartName, chart.Version, chart.Namespace, chart.UserID, chart.Release, kubeconfig)
|
||||||
|
info, err := redisClient.Enqueue(task)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to create temp file: "+err.Error(), http.StatusInternalServerError)
|
fmt.Printf("Error in connecting redis")
|
||||||
return
|
|
||||||
}
|
|
||||||
defer os.Remove(tmpFile.Name())
|
|
||||||
|
|
||||||
if _, err := tmpFile.WriteString(kubeconfig); err != nil {
|
|
||||||
http.Error(w, "Failed to write kubeconfig: "+err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tmpFile.Close()
|
|
||||||
|
|
||||||
// Add repo if not exists
|
|
||||||
cmd := exec.Command("helm", "repo", "add", "temp-repo", req.Repo)
|
|
||||||
cmd.Env = append(os.Environ(), "KUBECONFIG="+tmpFile.Name())
|
|
||||||
output, err := cmd.CombinedOutput()
|
|
||||||
if err != nil && !strings.Contains(string(output), "already exists") {
|
|
||||||
http.Error(w, "Failed to add helm repo: "+string(output), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update repo
|
|
||||||
cmd = exec.Command("helm", "repo", "update")
|
|
||||||
cmd.Env = append(os.Environ(), "KUBECONFIG="+tmpFile.Name())
|
|
||||||
output, err = cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, "Failed to update helm repo: "+string(output), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Install chart
|
|
||||||
cmd = exec.Command("helm", "install", req.Release, req.Chart, "--namespace", req.Namespace, "--create-namespace")
|
|
||||||
cmd.Env = append(os.Environ(), "KUBECONFIG="+tmpFile.Name())
|
|
||||||
output, err = cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, "Failed to install helm chart: "+string(output), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
fmt.Printf("This is issued task %v", info.ID)
|
||||||
|
go startWorkerHelmInstaller()
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(map[string]string{
|
json.NewEncoder(w).Encode(map[string]string{
|
||||||
@@ -3629,6 +3608,6 @@ func Helm_install(w http.ResponseWriter, r *http.Request) {
|
|||||||
"release": req.Release,
|
"release": req.Release,
|
||||||
"namespace": req.Namespace,
|
"namespace": req.Namespace,
|
||||||
"chart": req.Chart,
|
"chart": req.Chart,
|
||||||
"output": string(output),
|
//"output": string(output),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
)
|
)
|
||||||
|
|
||||||
func startWorker() {
|
func startWorkerHelmInstaller() {
|
||||||
srv := asynq.NewServer(
|
srv := asynq.NewServer(
|
||||||
asynq.RedisClientOpt{Addr: "130.185.77.247:30828", Password: "xwy8ahx46F"},
|
asynq.RedisClientOpt{Addr: "130.185.77.247:30828", Password: "xwy8ahx46F"},
|
||||||
asynq.Config{Concurrency: 5},
|
asynq.Config{Concurrency: 5},
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
@@ -15,18 +16,23 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type InstallChartPayload struct {
|
type InstallChartPayload struct {
|
||||||
ChartName string
|
ChartName string
|
||||||
Version string
|
Version string
|
||||||
Namespace string
|
Namespace string
|
||||||
UserID string
|
UserID string
|
||||||
|
Release string
|
||||||
|
Repo string
|
||||||
|
KubeConfig string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInstallCahrtTask(chartname, version, ns, userID string) *asynq.Task {
|
func NewInstallCahrtTask(chartname, version, ns, userID string, release string, kubeconfig string) *asynq.Task {
|
||||||
payload, _ := json.Marshal(InstallChartPayload{
|
payload, _ := json.Marshal(InstallChartPayload{
|
||||||
ChartName: chartname,
|
ChartName: chartname,
|
||||||
Version: version,
|
Version: version,
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
|
Release: release,
|
||||||
|
KubeConfig: kubeconfig,
|
||||||
})
|
})
|
||||||
|
|
||||||
return asynq.NewTask(TypeInstallChart, payload)
|
return asynq.NewTask(TypeInstallChart, payload)
|
||||||
@@ -38,7 +44,121 @@ func HandleInstallCahrt(ctx context.Context, t *asynq.Task) error {
|
|||||||
return fmt.Errorf("Faild to parse payload: %w", err)
|
return fmt.Errorf("Faild to parse payload: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[Job] Installing chart %s in namespace %s", payload.ChartName, payload.Namespace)
|
// Write kubeconfig to temp file
|
||||||
|
tmpFile, err := os.CreateTemp("", "kubeconfig-*.yaml")
|
||||||
|
if err != nil {
|
||||||
|
//http.Error(w, "Failed to create temp file: "+err.Error(), http.StatusInternalServerError)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer os.Remove(tmpFile.Name())
|
||||||
|
|
||||||
|
if _, err := tmpFile.WriteString(payload.KubeConfig); err != nil {
|
||||||
|
//http.Error(w, "Failed to write kubeconfig: "+err.Error(), http.StatusInternalServerError)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tmpFile.Close()
|
||||||
|
|
||||||
|
// settings := cli.New()
|
||||||
|
// settings.KubeConfig = tmpFile.Name()
|
||||||
|
// repoName := payload.ChartName
|
||||||
|
// repoURL := "http://130.185.77.247:31300/gitea_admin/application/src/branch/main/backing-services"
|
||||||
|
// username := "gitea_admin"
|
||||||
|
// password := "Tips123$"
|
||||||
|
|
||||||
|
// // Add the Helm repo
|
||||||
|
// repoFile := settings.RepositoryConfig
|
||||||
|
// repoCache := settings.RepositoryCache
|
||||||
|
// entry := &repo.Entry{
|
||||||
|
// Name: repoName,
|
||||||
|
// URL: repoURL,
|
||||||
|
// Username: username,
|
||||||
|
// Password: password,
|
||||||
|
// }
|
||||||
|
// chartRepo, err := repo.NewChartRepository(entry, getter.All(settings))
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Printf("Faild to connect to repository, %s", err)
|
||||||
|
// }
|
||||||
|
// _, err = chartRepo.DownloadIndexFile()
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println("Failed to connect to repo: %v", err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fmt.Println("✅ Connected to Helm repo successfully")
|
||||||
|
|
||||||
|
// // Save to repositories.yaml
|
||||||
|
// file, err := repo.LoadFile(repoFile)
|
||||||
|
// if os.IsNotExist(err) {
|
||||||
|
// file = repo.NewFile()
|
||||||
|
// }
|
||||||
|
// file.Update(entry)
|
||||||
|
// if err := file.WriteFile(repoFile, 0644); err != nil {
|
||||||
|
// fmt.Printf("%s", err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Create Helm install client
|
||||||
|
// actionConfig := new(action.Configuration)
|
||||||
|
// if err := actionConfig.Init(settings.RESTClientGetter(), "default", os.Getenv("HELM_DRIVER"), func(format string, v ...interface{}) {}); err != nil {
|
||||||
|
// panic(err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// install := action.NewInstall(actionConfig)
|
||||||
|
// install.ReleaseName = "mysql"
|
||||||
|
// install.Namespace = "default"
|
||||||
|
// install.RepoURL = repoURL
|
||||||
|
// install.ChartPathOptions.RepoURL = repoURL
|
||||||
|
// install.ChartPathOptions.Username = username
|
||||||
|
// install.ChartPathOptions.Password = password
|
||||||
|
|
||||||
|
// // Chart name
|
||||||
|
// chartName := fmt.Sprintf("%s/mysql", repoName)
|
||||||
|
|
||||||
|
// // Load values (optional)
|
||||||
|
// valOpts := &values.Options{}
|
||||||
|
// vals, err := valOpts.MergeValues(getter.All(settings))
|
||||||
|
// if err != nil {
|
||||||
|
// panic(err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Run the install
|
||||||
|
// cp, err := install.ChartPathOptions.LocateChart(chartName, settings)
|
||||||
|
// if err != nil {
|
||||||
|
// panic(err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// rel, err := install.RunWithContext(context.Background(), cp, vals)
|
||||||
|
// if err != nil {
|
||||||
|
// panic(fmt.Sprintf("Helm install failed: %v", err))
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fmt.Printf("✅ Helm chart '%s' installed successfully: %s\n", rel.Name, rel.Info.Status)
|
||||||
|
// // Add repo if not exists
|
||||||
|
// cmd := exec.Command("helm", "repo", "add", "temp-repo", req.Repo)
|
||||||
|
// cmd.Env = append(os.Environ(), "KUBECONFIG="+tmpFile.Name())
|
||||||
|
// output, err := cmd.CombinedOutput()
|
||||||
|
// if err != nil && !strings.Contains(string(output), "already exists") {
|
||||||
|
// http.Error(w, "Failed to add helm repo: "+string(output), http.StatusInternalServerError)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Update repo
|
||||||
|
// cmd = exec.Command("helm", "repo", "update")
|
||||||
|
// cmd.Env = append(os.Environ(), "KUBECONFIG="+tmpFile.Name())
|
||||||
|
// output, err = cmd.CombinedOutput()
|
||||||
|
// if err != nil {
|
||||||
|
// http.Error(w, "Failed to update helm repo: "+string(output), http.StatusInternalServerError)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Install chart
|
||||||
|
// cmd = exec.Command("helm", "install", req.Release, req.Chart, "--namespace", req.Namespace, "--create-namespace")
|
||||||
|
// cmd.Env = append(os.Environ(), "KUBECONFIG="+tmpFile.Name())
|
||||||
|
// output, err = cmd.CombinedOutput()
|
||||||
|
// if err != nil {
|
||||||
|
// http.Error(w, "Failed to install helm chart: "+string(output), http.StatusInternalServerError)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
log.Printf("[Job] Installing chart %s Release %s in namespace %s", payload.ChartName, payload.Release, payload.Namespace)
|
||||||
log.Printf("[Job] Validating Chart ... ")
|
log.Printf("[Job] Validating Chart ... ")
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
|
|
||||||
|
|||||||
21
main.go
21
main.go
@@ -8,14 +8,12 @@ import (
|
|||||||
|
|
||||||
"main/db"
|
"main/db"
|
||||||
"main/handler"
|
"main/handler"
|
||||||
"main/jobs"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang-jwt/jwt/v4"
|
"github.com/golang-jwt/jwt/v4"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/hibiken/asynq"
|
|
||||||
"github.com/rs/cors"
|
"github.com/rs/cors"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
@@ -61,7 +59,6 @@ func registerHnadler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
var existUser User
|
var existUser User
|
||||||
_ = db.UserCollection.FindOne(context.TODO(), bson.M{"email": user.Email}).Decode(&existUser)
|
_ = db.UserCollection.FindOne(context.TODO(), bson.M{"email": user.Email}).Decode(&existUser)
|
||||||
|
|
||||||
if existUser.Email == user.Email {
|
if existUser.Email == user.Email {
|
||||||
http.Error(w, `{"message": "User already registered"}`, http.StatusUnauthorized)
|
http.Error(w, `{"message": "User already registered"}`, http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
@@ -123,24 +120,6 @@ func loginHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
db.InitDB()
|
db.InitDB()
|
||||||
var redisClient = asynq.NewClient(asynq.RedisClientOpt{Addr: "130.185.77.247:30828", Password: "xwy8ahx46F"})
|
|
||||||
chart := jobs.InstallChartPayload{
|
|
||||||
ChartName: "redis",
|
|
||||||
Version: "2.1.0",
|
|
||||||
Namespace: "default",
|
|
||||||
UserID: "razaghi",
|
|
||||||
}
|
|
||||||
if _, err := json.Marshal(chart); err != nil {
|
|
||||||
fmt.Printf("Could not json ")
|
|
||||||
}
|
|
||||||
task := jobs.NewInstallCahrtTask(chart.ChartName, chart.Namespace, chart.Namespace, chart.UserID)
|
|
||||||
info, err := redisClient.Enqueue(task)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error in connecting redis")
|
|
||||||
}
|
|
||||||
fmt.Printf("This is issued task %v", info.ID)
|
|
||||||
go startWorker()
|
|
||||||
|
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.HandleFunc("/register", registerHnadler)
|
router.HandleFunc("/register", registerHnadler)
|
||||||
router.HandleFunc("/login", loginHandler)
|
router.HandleFunc("/login", loginHandler)
|
||||||
|
|||||||
Reference in New Issue
Block a user