mirror of
https://github.com/dragonheim/gagent.git
synced 2025-04-26 01:08:59 -07:00
minor cleanup and standardization of package names.
This commit is contained in:
parent
3bb7096625
commit
d13a309593
9 changed files with 38 additions and 38 deletions
|
@ -50,6 +50,7 @@ import (
|
||||||
|
|
||||||
var environment struct {
|
var environment struct {
|
||||||
ConfigFile string `env:"GAGENT_CONFIG" envDefault:"/etc/gagent/gagent.hcl"`
|
ConfigFile string `env:"GAGENT_CONFIG" envDefault:"/etc/gagent/gagent.hcl"`
|
||||||
|
LogLevel string `env:"GAGENT_LOGLEVEL" envDefault:"WARN"`
|
||||||
Mode string `env:"GAGENT_MODE" envDefault:"setup"`
|
Mode string `env:"GAGENT_MODE" envDefault:"setup"`
|
||||||
MonitorPort int `env:"MONITOR_PORT" envDefault:"0"`
|
MonitorPort int `env:"MONITOR_PORT" envDefault:"0"`
|
||||||
}
|
}
|
||||||
|
@ -134,15 +135,11 @@ func main() {
|
||||||
*/
|
*/
|
||||||
func init() {
|
func init() {
|
||||||
cfg := environment
|
cfg := environment
|
||||||
if err := env.Parse(&cfg); err != nil {
|
env.Parse(&cfg)
|
||||||
log.Printf("%+v\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("%+v\n", cfg)
|
|
||||||
|
|
||||||
filter := &logutils.LevelFilter{
|
filter := &logutils.LevelFilter{
|
||||||
Levels: []logutils.LogLevel{"DEBUG", "INFO", "WARN", "ERROR"},
|
Levels: []logutils.LogLevel{"DEBUG", "INFO", "WARN", "ERROR"},
|
||||||
MinLevel: logutils.LogLevel("DEBUG"),
|
MinLevel: logutils.LogLevel(cfg.LogLevel),
|
||||||
Writer: os.Stderr,
|
Writer: os.Stderr,
|
||||||
}
|
}
|
||||||
log.SetOutput(filter)
|
log.SetOutput(filter)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package main_test
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
main "github.com/dragonheim/gagent/cmd/gagent"
|
// main "github.com/dragonheim/gagent/cmd/gagent"
|
||||||
gstructs "github.com/dragonheim/gagent/internal/gstructs"
|
gstructs "github.com/dragonheim/gagent/internal/gstructs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ func TestMain(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the main function with the temporary config
|
// Run the main function with the temporary config
|
||||||
main.Run(config)
|
t.Run(config)
|
||||||
|
|
||||||
// Check if the config has been set up correctly
|
// Check if the config has been set up correctly
|
||||||
expectedConfig := gstructs.GagentConfig{
|
expectedConfig := gstructs.GagentConfig{
|
||||||
|
|
|
@ -7,7 +7,8 @@ import (
|
||||||
log "log"
|
log "log"
|
||||||
time "time"
|
time "time"
|
||||||
|
|
||||||
gstructs "github.com/dragonheim/gagent/internal/gstructs"
|
gs "github.com/dragonheim/gagent/internal/gstructs"
|
||||||
|
|
||||||
cty "github.com/zclconf/go-cty/cty"
|
cty "github.com/zclconf/go-cty/cty"
|
||||||
|
|
||||||
hclsimple "github.com/hashicorp/hcl/v2/hclsimple"
|
hclsimple "github.com/hashicorp/hcl/v2/hclsimple"
|
||||||
|
@ -21,7 +22,7 @@ type GagentDb struct {
|
||||||
type GagentDbRow struct {
|
type GagentDbRow struct {
|
||||||
Timestamp time.Time `hcl:"timestamp"`
|
Timestamp time.Time `hcl:"timestamp"`
|
||||||
DBName string `hcl:"chainid,optional"`
|
DBName string `hcl:"chainid,optional"`
|
||||||
Agent gstructs.AgentDetails `hcl:"agent,block"`
|
Agent gs.AgentDetails `hcl:"agent,block"`
|
||||||
DbCurrHash [32]byte `hcl:"currhash"`
|
DbCurrHash [32]byte `hcl:"currhash"`
|
||||||
DbPrevHash [32]byte `hcl:"prevhash"`
|
DbPrevHash [32]byte `hcl:"prevhash"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
gstructs "github.com/dragonheim/gagent/internal/gstructs"
|
gs "github.com/dragonheim/gagent/internal/gstructs"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testChainDBPath = "/tmp/test_chaindb.hcl"
|
const testChainDBPath = "/tmp/test_chaindb.hcl"
|
||||||
|
@ -18,7 +18,7 @@ func TestGagentDb(t *testing.T) {
|
||||||
// Add a row to the database
|
// Add a row to the database
|
||||||
row := &GagentDbRow{
|
row := &GagentDbRow{
|
||||||
DBName: "testDB",
|
DBName: "testDB",
|
||||||
Agent: gstructs.AgentDetails{
|
Agent: gs.AgentDetails{
|
||||||
Client: "testAgent",
|
Client: "testAgent",
|
||||||
Shasum: "v1.0.0",
|
Shasum: "v1.0.0",
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
sync "sync"
|
sync "sync"
|
||||||
time "time"
|
time "time"
|
||||||
|
|
||||||
gstructs "github.com/dragonheim/gagent/internal/gstructs"
|
gs "github.com/dragonheim/gagent/internal/gstructs"
|
||||||
|
|
||||||
zmq "github.com/pebbe/zmq4"
|
zmq "github.com/pebbe/zmq4"
|
||||||
)
|
)
|
||||||
|
@ -26,11 +26,11 @@ import (
|
||||||
* of it's most recent request.
|
* of it's most recent request.
|
||||||
* Main is the entrypoint for the client process
|
* Main is the entrypoint for the client process
|
||||||
*/
|
*/
|
||||||
func Main(wg *sync.WaitGroup, config gstructs.GagentConfig) {
|
func Main(wg *sync.WaitGroup, config gs.GagentConfig) {
|
||||||
log.Printf("[INFO] Starting client\n")
|
log.Printf("[INFO] Starting client\n")
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
var agent gstructs.AgentDetails
|
var agent gs.AgentDetails
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if config.CMode {
|
if config.CMode {
|
||||||
|
@ -67,7 +67,7 @@ func Main(wg *sync.WaitGroup, config gstructs.GagentConfig) {
|
||||||
/*
|
/*
|
||||||
* Parse Agent file for GHINT data to populate the G'Agent hints
|
* Parse Agent file for GHINT data to populate the G'Agent hints
|
||||||
*/
|
*/
|
||||||
func getTagsFromHints(agent gstructs.AgentDetails) []string {
|
func getTagsFromHints(agent gs.AgentDetails) []string {
|
||||||
var tags []string
|
var tags []string
|
||||||
|
|
||||||
// Use named capture groups to extract the hints
|
// Use named capture groups to extract the hints
|
||||||
|
@ -89,7 +89,7 @@ func getTagsFromHints(agent gstructs.AgentDetails) []string {
|
||||||
return tags
|
return tags
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendAgent(wg *sync.WaitGroup, uuid string, connectString string, agent gstructs.AgentDetails) {
|
func sendAgent(wg *sync.WaitGroup, uuid string, connectString string, agent gs.AgentDetails) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
|
|
|
@ -9,7 +9,8 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
gstructs "github.com/dragonheim/gagent/internal/gstructs"
|
gs "github.com/dragonheim/gagent/internal/gstructs"
|
||||||
|
|
||||||
zmq "github.com/pebbe/zmq4"
|
zmq "github.com/pebbe/zmq4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ func (m *mockSocket) Events() zmq.State
|
||||||
func (m *mockSocket) String() string { return "" }
|
func (m *mockSocket) String() string { return "" }
|
||||||
|
|
||||||
func TestGetTagsFromHints(t *testing.T) {
|
func TestGetTagsFromHints(t *testing.T) {
|
||||||
agent := gstructs.AgentDetails{
|
agent := gs.AgentDetails{
|
||||||
Script: []byte(`*set GHINT[split "tag1,tag2,tag3",]`),
|
Script: []byte(`*set GHINT[split "tag1,tag2,tag3",]`),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,10 +56,10 @@ func TestGetTagsFromHints(t *testing.T) {
|
||||||
|
|
||||||
func TestSendAgent(t *testing.T) {
|
func TestSendAgent(t *testing.T) {
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
config := gstructs.GagentConfig{
|
config := gs.GagentConfig{
|
||||||
UUID: "test-uuid",
|
UUID: "test-uuid",
|
||||||
ClientPort: 1234,
|
ClientPort: 1234,
|
||||||
Routers: map[string]gstructs.Router{
|
Routers: map[string]gs.Router{
|
||||||
"test-router": {
|
"test-router": {
|
||||||
RouterAddr: "127.0.0.1",
|
RouterAddr: "127.0.0.1",
|
||||||
ClientPort: 1234,
|
ClientPort: 1234,
|
||||||
|
@ -66,7 +67,7 @@ func TestSendAgent(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
agent := gstructs.AgentDetails{
|
agent := gs.AgentDetails{
|
||||||
Client: "test-client",
|
Client: "test-client",
|
||||||
Script: []byte(`*set GHINT[split "tag1,tag2,tag3",]`),
|
Script: []byte(`*set GHINT[split "tag1,tag2,tag3",]`),
|
||||||
}
|
}
|
||||||
|
@ -120,12 +121,12 @@ func TestMain(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
config := gstructs.GagentConfig{
|
config := gs.GagentConfig{
|
||||||
CMode: true,
|
CMode: true,
|
||||||
UUID: "test-uuid",
|
UUID: "test-uuid",
|
||||||
ClientPort: 1234,
|
ClientPort: 1234,
|
||||||
Agent: tmpAgentFile.Name(),
|
Agent: tmpAgentFile.Name(),
|
||||||
Routers: map[string]gstructs.Router{
|
Routers: map[string]gs.Router{
|
||||||
"test-router": {
|
"test-router": {
|
||||||
RouterAddr: "127.0.0.1",
|
RouterAddr: "127.0.0.1",
|
||||||
ClientPort: 1234,
|
ClientPort: 1234,
|
||||||
|
|
|
@ -3,12 +3,12 @@ package gstructs_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/dragonheim/gagent/internal/gstructs"
|
gs "github.com/dragonheim/gagent/internal/gstructs"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetByIndex(t *testing.T) {
|
func TestGetByIndex(t *testing.T) {
|
||||||
agentStatuses := gstructs.AgentStatuses
|
agentStatuses := gs.AgentStatuses
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
index int
|
index int
|
||||||
|
@ -34,7 +34,7 @@ func TestGetByIndex(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetByName(t *testing.T) {
|
func TestGetByName(t *testing.T) {
|
||||||
agentStatuses := gstructs.AgentStatuses
|
agentStatuses := gs.AgentStatuses
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
|
@ -3,11 +3,11 @@ package gstructs_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/dragonheim/gagent/internal/gstructs"
|
gs "github.com/dragonheim/gagent/internal/gstructs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGagentConfig(t *testing.T) {
|
func TestGagentConfig(t *testing.T) {
|
||||||
config := gstructs.GagentConfig{
|
config := gs.GagentConfig{
|
||||||
Name: "test-config",
|
Name: "test-config",
|
||||||
Mode: "client",
|
Mode: "client",
|
||||||
UUID: "test-uuid",
|
UUID: "test-uuid",
|
||||||
|
@ -17,13 +17,13 @@ func TestGagentConfig(t *testing.T) {
|
||||||
ClientPort: 1234,
|
ClientPort: 1234,
|
||||||
RouterPort: 5678,
|
RouterPort: 5678,
|
||||||
WorkerPort: 9012,
|
WorkerPort: 9012,
|
||||||
Clients: []*gstructs.ClientDetails{
|
Clients: []*gs.ClientDetails{
|
||||||
{
|
{
|
||||||
ClientName: "test-client",
|
ClientName: "test-client",
|
||||||
ClientID: "client-id",
|
ClientID: "client-id",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Routers: []*gstructs.RouterDetails{
|
Routers: []*gs.RouterDetails{
|
||||||
{
|
{
|
||||||
RouterName: "test-router",
|
RouterName: "test-router",
|
||||||
RouterID: "router-id",
|
RouterID: "router-id",
|
||||||
|
@ -34,7 +34,7 @@ func TestGagentConfig(t *testing.T) {
|
||||||
WorkerPort: 9012,
|
WorkerPort: 9012,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Workers: []*gstructs.WorkerDetails{
|
Workers: []*gs.WorkerDetails{
|
||||||
{
|
{
|
||||||
WorkerName: "test-worker",
|
WorkerName: "test-worker",
|
||||||
WorkerID: "worker-id",
|
WorkerID: "worker-id",
|
||||||
|
@ -57,7 +57,7 @@ func TestGagentConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAgentDetails(t *testing.T) {
|
func TestAgentDetails(t *testing.T) {
|
||||||
agent := gstructs.AgentDetails{
|
agent := gs.AgentDetails{
|
||||||
Status: 1,
|
Status: 1,
|
||||||
Client: "test-client",
|
Client: "test-client",
|
||||||
Shasum: "123456789abcdef",
|
Shasum: "123456789abcdef",
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
gs "github.com/dragonheim/gagent/internal/gstructs"
|
gs "github.com/dragonheim/gagent/internal/gstructs"
|
||||||
|
|
||||||
"github.com/dragonheim/gagent/internal/worker"
|
"github.com/dragonheim/gagent/internal/worker"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue