From 9cd5237bb8280556165a364cf36cb2f2eb281086 Mon Sep 17 00:00:00 2001 From: yusing Date: Fri, 14 Feb 2025 21:56:12 +0800 Subject: [PATCH] remove add_agent command --- cmd/add_agent.go | 69 ----------------------------------------- cmd/main.go | 3 -- internal/common/args.go | 2 -- 3 files changed, 74 deletions(-) delete mode 100644 cmd/add_agent.go diff --git a/cmd/add_agent.go b/cmd/add_agent.go deleted file mode 100644 index 68ac55a..0000000 --- a/cmd/add_agent.go +++ /dev/null @@ -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() -} diff --git a/cmd/main.go b/cmd/main.go index d8ab826..fbc704b 100755 --- a/cmd/main.go +++ b/cmd/main.go @@ -30,9 +30,6 @@ func main() { case common.CommandSetup: Setup() return - case common.CommandAddAgent: - AddAgent(args.Args) - return case common.CommandReload: if err := query.ReloadServer(); err != nil { E.LogFatal("server reload error", err) diff --git a/internal/common/args.go b/internal/common/args.go index 824118b..7c907a6 100644 --- a/internal/common/args.go +++ b/internal/common/args.go @@ -3,7 +3,6 @@ package common const ( CommandStart = "" CommandSetup = "setup" - CommandAddAgent = "add-agent" CommandValidate = "validate" CommandListConfigs = "ls-config" CommandListRoutes = "ls-routes" @@ -20,7 +19,6 @@ func (v MainServerCommandValidator) IsCommandValid(cmd string) bool { switch cmd { case CommandStart, CommandSetup, - CommandAddAgent, CommandValidate, CommandListConfigs, CommandListRoutes,