mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 20:52:33 +02:00
remove add_agent command
This commit is contained in:
parent
964e94b3ba
commit
9cd5237bb8
3 changed files with 0 additions and 74 deletions
|
@ -1,69 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/yusing/go-proxy/agent/pkg/certs"
|
|
||||||
"github.com/yusing/go-proxy/internal/logging"
|
|
||||||
)
|
|
||||||
|
|
||||||
func AddAgent(args []string) {
|
|
||||||
if len(args) != 1 {
|
|
||||||
logging.Fatal().Msgf("invalid arguments: %v, expect host", args)
|
|
||||||
}
|
|
||||||
host := args[0]
|
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, "GET", "http://"+host, nil)
|
|
||||||
if err != nil {
|
|
||||||
logging.Fatal().Err(err).Msg("failed to create request")
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
logging.Fatal().Err(err).Msg("failed to send request")
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
msg, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
msg = []byte("unknown error")
|
|
||||||
}
|
|
||||||
logging.Fatal().Int("status", resp.StatusCode).Str("msg", string(msg)).Msg("failed to add agent")
|
|
||||||
}
|
|
||||||
|
|
||||||
zip, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
logging.Fatal().Err(err).Msg("failed to read response body")
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := os.OpenFile(certs.AgentCertsFilename(host), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)
|
|
||||||
if err != nil {
|
|
||||||
logging.Fatal().Err(err).Msg("failed to create client certs file")
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
if _, err := f.Write(zip); err != nil {
|
|
||||||
logging.Fatal().Err(err).Msg("failed to save client certs")
|
|
||||||
}
|
|
||||||
|
|
||||||
logging.Info().Msgf("agent %s added, certs saved to %s", host, certs.AgentCertsFilename(host))
|
|
||||||
|
|
||||||
req, err = http.NewRequestWithContext(ctx, "GET", "http://"+host+"/done", nil)
|
|
||||||
if err != nil {
|
|
||||||
logging.Fatal().Err(err).Msg("failed to create done request")
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err = http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
logging.Fatal().Err(err).Msg("failed to send done request")
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
}
|
|
|
@ -30,9 +30,6 @@ func main() {
|
||||||
case common.CommandSetup:
|
case common.CommandSetup:
|
||||||
Setup()
|
Setup()
|
||||||
return
|
return
|
||||||
case common.CommandAddAgent:
|
|
||||||
AddAgent(args.Args)
|
|
||||||
return
|
|
||||||
case common.CommandReload:
|
case common.CommandReload:
|
||||||
if err := query.ReloadServer(); err != nil {
|
if err := query.ReloadServer(); err != nil {
|
||||||
E.LogFatal("server reload error", err)
|
E.LogFatal("server reload error", err)
|
||||||
|
|
|
@ -3,7 +3,6 @@ package common
|
||||||
const (
|
const (
|
||||||
CommandStart = ""
|
CommandStart = ""
|
||||||
CommandSetup = "setup"
|
CommandSetup = "setup"
|
||||||
CommandAddAgent = "add-agent"
|
|
||||||
CommandValidate = "validate"
|
CommandValidate = "validate"
|
||||||
CommandListConfigs = "ls-config"
|
CommandListConfigs = "ls-config"
|
||||||
CommandListRoutes = "ls-routes"
|
CommandListRoutes = "ls-routes"
|
||||||
|
@ -20,7 +19,6 @@ func (v MainServerCommandValidator) IsCommandValid(cmd string) bool {
|
||||||
switch cmd {
|
switch cmd {
|
||||||
case CommandStart,
|
case CommandStart,
|
||||||
CommandSetup,
|
CommandSetup,
|
||||||
CommandAddAgent,
|
|
||||||
CommandValidate,
|
CommandValidate,
|
||||||
CommandListConfigs,
|
CommandListConfigs,
|
||||||
CommandListRoutes,
|
CommandListRoutes,
|
||||||
|
|
Loading…
Add table
Reference in a new issue