remove add_agent command

This commit is contained in:
yusing 2025-02-14 21:56:12 +08:00
parent 964e94b3ba
commit 9cd5237bb8
3 changed files with 0 additions and 74 deletions

View file

@ -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()
}

View file

@ -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)

View file

@ -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,