Error Handling for NewAgentConfig
This commit is contained in:
parent
89d7ec8242
commit
87c035cd39
3 changed files with 10 additions and 7 deletions
|
|
@ -97,7 +97,10 @@ func New(logger *logrus.Logger, version string) *Agent {
|
||||||
pybin = filepath.Join(pd, "py38-x32", "python.exe")
|
pybin = filepath.Join(pd, "py38-x32", "python.exe")
|
||||||
}
|
}
|
||||||
|
|
||||||
ac := NewAgentConfig()
|
ac, err := NewAgentConfig()
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
headers := make(map[string]string)
|
headers := make(map[string]string)
|
||||||
if len(ac.Token) > 0 {
|
if len(ac.Token) > 0 {
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ func (a *Agent) osString() string {
|
||||||
return fmt.Sprintf("%s %s %s %s", strings.Title(h.Platform), h.PlatformVersion, h.KernelArch, h.KernelVersion)
|
return fmt.Sprintf("%s %s %s %s", strings.Title(h.Platform), h.PlatformVersion, h.KernelArch, h.KernelVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAgentConfig() *rmm.AgentConfig {
|
func NewAgentConfig() (*rmm.AgentConfig, error) {
|
||||||
viper.SetConfigName("tacticalagent")
|
viper.SetConfigName("tacticalagent")
|
||||||
viper.SetConfigType("json")
|
viper.SetConfigType("json")
|
||||||
viper.AddConfigPath("/etc/")
|
viper.AddConfigPath("/etc/")
|
||||||
|
|
@ -139,7 +139,7 @@ func NewAgentConfig() *rmm.AgentConfig {
|
||||||
err := viper.ReadInConfig()
|
err := viper.ReadInConfig()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &rmm.AgentConfig{}
|
return &rmm.AgentConfig{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
agentpk := viper.GetString("agentpk")
|
agentpk := viper.GetString("agentpk")
|
||||||
|
|
@ -159,7 +159,7 @@ func NewAgentConfig() *rmm.AgentConfig {
|
||||||
NatsProxyPort: viper.GetString("natsproxyport"),
|
NatsProxyPort: viper.GetString("natsproxyport"),
|
||||||
NatsStandardPort: viper.GetString("natsstandardport"),
|
NatsStandardPort: viper.GetString("natsstandardport"),
|
||||||
}
|
}
|
||||||
return ret
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) RunScript(code string, shell string, args []string, timeout int, runasuser bool) (stdout, stderr string, exitcode int, e error) {
|
func (a *Agent) RunScript(code string, shell string, args []string, timeout int, runasuser bool) (stdout, stderr string, exitcode int, e error) {
|
||||||
|
|
|
||||||
|
|
@ -47,10 +47,10 @@ var (
|
||||||
getDriveType = windows.NewLazySystemDLL("kernel32.dll").NewProc("GetDriveTypeW")
|
getDriveType = windows.NewLazySystemDLL("kernel32.dll").NewProc("GetDriveTypeW")
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewAgentConfig() *rmm.AgentConfig {
|
func NewAgentConfig() (*rmm.AgentConfig, error) {
|
||||||
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\TacticalRMM`, registry.ALL_ACCESS)
|
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\TacticalRMM`, registry.ALL_ACCESS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &rmm.AgentConfig{}
|
return &rmm.AgentConfig{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
baseurl, _, _ := k.GetStringValue("BaseURL")
|
baseurl, _, _ := k.GetStringValue("BaseURL")
|
||||||
|
|
@ -79,7 +79,7 @@ func NewAgentConfig() *rmm.AgentConfig {
|
||||||
NatsProxyPath: natsProxyPath,
|
NatsProxyPath: natsProxyPath,
|
||||||
NatsProxyPort: natsProxyPort,
|
NatsProxyPort: natsProxyPort,
|
||||||
NatsStandardPort: natsStandardPort,
|
NatsStandardPort: natsStandardPort,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) RunScript(code string, shell string, args []string, timeout int, runasuser bool) (stdout, stderr string, exitcode int, e error) {
|
func (a *Agent) RunScript(code string, shell string, args []string, timeout int, runasuser bool) (stdout, stderr string, exitcode int, e error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue