big refactor

This commit is contained in:
redanthrax 2022-06-17 16:45:28 -07:00
parent 6abf716844
commit 7fbb0fe7e1
25 changed files with 2761 additions and 822 deletions

View file

@ -8,6 +8,25 @@ import (
"github.com/go-resty/resty/v2"
)
func PostRequest(url string, body interface{}, timeout time.Duration) (resty.Response, error) {
agentConfig := NewAgentConfig()
client := resty.New()
client.SetBaseURL(agentConfig.BaseURL)
client.SetTimeout(timeout * time.Second)
client.SetCloseConnection(true)
if len(agentConfig.Proxy) > 0 {
}
if shared.DEBUG {
client.SetDebug(true)
}
response, err := client.R().SetBody(body).Post(url)
return *response, err
}
func SyncMeshNodeID() bool {
id, err := GetMeshNodeID()
if err != nil {
@ -16,21 +35,12 @@ func SyncMeshNodeID() bool {
}
agentConfig := NewAgentConfig()
payload := shared.MeshNodeID{
Func: "syncmesh",
Agentid: agentConfig.AgentID,
NodeID: utils.StripAll(id),
}
client := resty.New()
client.SetBaseURL(agentConfig.BaseURL)
client.SetTimeout(15 * time.Second)
client.SetCloseConnection(true)
if shared.DEBUG {
client.SetDebug(true)
}
_, err = client.R().SetBody(payload).Post("/api/v3/syncmesh/")
_, err = PostRequest("/api/v3/syncmesh/", payload, 15)
return err == nil
}
}