From a2f74e048858d0d43749e5d7a4c93d60bbe12c28 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Tue, 12 Jan 2021 21:14:43 +0000 Subject: [PATCH] add natsapi flags --- main.go | 8 +++++++- natsapi/api.go | 23 +++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 1d849191..23986c53 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,15 @@ package main import ( + "flag" + "github.com/wh1te909/tacticalrmm/natsapi" ) func main() { - api.Listen() + apiHost := flag.String("api-host", "", "django api base url") + debug := flag.Bool("debug", false, "Debug") + flag.Parse() + + api.Listen(*apiHost, *debug) } diff --git a/natsapi/api.go b/natsapi/api.go index aae299e8..f4fa1636 100644 --- a/natsapi/api.go +++ b/natsapi/api.go @@ -18,7 +18,11 @@ import ( var rClient = resty.New() -func getAPI() (string, error) { +func getAPI(apihost string) (string, error) { + if apihost != "" { + return apihost, nil + } + f, err := os.Open(`/etc/nginx/sites-available/rmm.conf`) if err != nil { return "", err @@ -35,14 +39,21 @@ func getAPI() (string, error) { return "", errors.New("unable to parse api from nginx conf") } -func Listen() { - api, err := getAPI() +func Listen(apihost string, debug bool) { + var baseURL string + api, err := getAPI(apihost) if err != nil { log.Fatalln(err) } - //rClient.SetHostURL(fmt.Sprintf("https://%s/natsapi", api)) - rClient.SetHostURL(fmt.Sprintf("http://%s:8000/natsapi", api)) - rClient.SetTimeout(5 * time.Second) + + if debug { + baseURL = fmt.Sprintf("http://%s:8000/natsapi", api) + } else { + baseURL = fmt.Sprintf("https://%s/natsapi", api) + } + + rClient.SetHostURL(baseURL) + rClient.SetTimeout(30 * time.Second) natsinfo, err := rClient.R().SetResult(&NatsInfo{}).Get("/natsinfo/") if err != nil { log.Fatalln(err)