Author: Paolo Lulli <paolo@lulli.net>
Show client permissions
client/main.go | 34 ++++++++++++++++++++++++++++------ client/metric-client-rest.go | 8 +++++--- client/perms-client.go | 15 +++++++++++++++
diff --git a/client/main.go b/client/main.go index 39763d4ca372f687c540a9d98df40195a901806d..01b05d80ce2dd8015317d166c9e54ee362571ade 100644 --- a/client/main.go +++ b/client/main.go @@ -37,8 +37,10 @@ sourceOption := flag.StringP("source", "s", "", "Source Application") isMetricOption := flag.BoolP("metric", "m", false, "Metric Mode") - isEventOption := flag.BoolP("event", "e", true, "Event Mode") - isPositionOption := flag.BoolP("metric", "p", false, "Position Mode") + //isEventOption := flag.BoolP("event", "e", false, "Event Mode") + isPositionOption := flag.BoolP("position", "p", false, "Position Mode") + + isShowPermsOption := flag.BoolP("show-permissions", "S", false, "Show User Permissions") writeModeOption := flag.BoolP("write", "w", false, "Write Mode") @@ -48,10 +50,25 @@ metricNameOption := flag.StringP("metricName", "n", "", "Metric name") flag.Parse() + if *isShowPermsOption { + listResponse, err := yatsClient.PermissionsList() + if err == nil { + fmt.Printf("%s", listResponse) + } else { + fmt.Println(err) + } + os.Exit(0) + } + if !*writeModeOption { if *isMetricOption { - listResponse := yatsClient.MetricList(*sourceOption, *metricNameOption, *fromOption, *toOption) - fmt.Printf("%s", listResponse) + //fmt.Printf("metricNameOption: %s", *metricNameOption) + listResponse, err := yatsClient.MetricList(*sourceOption, *metricNameOption, *fromOption, *toOption) + if err == nil { + fmt.Printf("%s", listResponse) + } else { + fmt.Println(err) + } } else if *isPositionOption { listResponse := yatsClient.PositionList(*sourceOption, *fromOption, *toOption) fmt.Printf("%s", listResponse) @@ -62,8 +79,13 @@ } } else { // Write Mode if *isMetricOption { - listResponse := yatsClient.MetricList(*sourceOption, *metricNameOption, *fromOption, *toOption) - fmt.Printf("%s", listResponse) + fmt.Printf("metricNameOption: %s", *metricNameOption) + listResponse, err := yatsClient.MetricList(*sourceOption, *metricNameOption, *fromOption, *toOption) + if err == nil { + fmt.Printf("%s", listResponse) + } else { + fmt.Println(err) + } } else if *isPositionOption { listResponse := yatsClient.PositionList(*sourceOption, *fromOption, *toOption) fmt.Printf("%s", listResponse) diff --git a/client/metric-client-rest.go b/client/metric-client-rest.go index 71eaa028082ce56c8548a522b243a7ec1c2747ad..be4140886fbb0c326ca64086d8e4d2ceb07dd958 100644 --- a/client/metric-client-rest.go +++ b/client/metric-client-rest.go @@ -10,12 +10,14 @@ */ package main import ( + "errors" "strconv" ) -func (c *YatsClient) MetricList(source string, metricName string, from int64, to int64) string { +func (c *YatsClient) MetricList(source string, metricName string, from int64, to int64) (string, error) { if metricName == "" { - panic("Metric Name is empty") + //fmt.Println("Metric Name is empty") + return "", errors.New("Metric Name is empty") } var body string if to == 0 { @@ -23,5 +25,5 @@ body = "{\"source\": \"" + source + "\", \"name\":\"" + metricName + "\", \"from\":" + strconv.FormatInt(from, 10) + " }" } else { body = "{\"source\": \"" + source + "\",\"name\":\"" + metricName + "\", \"from\":" + strconv.FormatInt(from, 10) + ",\"to\":" + strconv.FormatInt(to, 10) + " }" } - return c.ApiPost(c.config.Endpoint+"/metric/search", body) + return c.ApiPost(c.config.Endpoint+"/metric/search", body), nil } diff --git a/client/perms-client.go b/client/perms-client.go new file mode 100644 index 0000000000000000000000000000000000000000..004316401fb1b133f95384895e68f7202fa26368 --- /dev/null +++ b/client/perms-client.go @@ -0,0 +1,15 @@ +/** + * Yats - yats + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Paolo Lulli <kevwe.com> + * @copyright Paolo Lulli 2024 + */ +package main + +func (c *YatsClient) PermissionsList() (string, error) { + + return c.ApiGet(c.config.Endpoint + "/perms"), nil +}