mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-21 00:29:03 +01:00
- Introduced ContainerRuntime field in AgentConfig and AgentEnvConfig. - Added IterAgents and NumAgents functions for agent pool management. - Updated agent creation and verification endpoints to handle container runtime. - Enhanced Docker Compose template to support different container runtimes. - Added runtime endpoint to retrieve agent runtime information.
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"github.com/yusing/go-proxy/agent/pkg/agent"
|
|
"github.com/yusing/go-proxy/internal/gperr"
|
|
"github.com/yusing/go-proxy/internal/route/provider"
|
|
)
|
|
|
|
func (cfg *Config) VerifyNewAgent(host string, ca agent.PEMPair, client agent.PEMPair, containerRuntime agent.ContainerRuntime) (int, gperr.Error) {
|
|
for _, a := range cfg.value.Providers.Agents {
|
|
if a.Addr == host {
|
|
return 0, gperr.New("agent already exists")
|
|
}
|
|
}
|
|
|
|
agentCfg := agent.AgentConfig{
|
|
Addr: host,
|
|
Runtime: containerRuntime,
|
|
}
|
|
err := agentCfg.StartWithCerts(cfg.Task().Context(), ca.Cert, client.Cert, client.Key)
|
|
if err != nil {
|
|
return 0, gperr.Wrap(err, "failed to start agent")
|
|
}
|
|
|
|
provider := provider.NewAgentProvider(&agentCfg)
|
|
if _, loaded := cfg.providers.LoadOrStore(provider.String(), provider); loaded {
|
|
return 0, gperr.Errorf("provider %s already exists", provider.String())
|
|
}
|
|
|
|
// agent must be added before loading routes
|
|
agent.AddAgent(&agentCfg)
|
|
err = provider.LoadRoutes()
|
|
if err != nil {
|
|
cfg.providers.Delete(provider.String())
|
|
agent.RemoveAgent(&agentCfg)
|
|
return 0, gperr.Wrap(err, "failed to load routes")
|
|
}
|
|
|
|
return provider.NumRoutes(), nil
|
|
}
|