From a8176741f647dc0142f437a8141ac9152c1b1df2 Mon Sep 17 00:00:00 2001
From: Sergey Yakubov <sergey.yakubov@desy.de>
Date: Tue, 28 Sep 2021 14:02:20 +0200
Subject: [PATCH] token to db

---
 .../src/asapo_authorizer/cli/list_tokens.go   | 55 +++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 authorizer/src/asapo_authorizer/cli/list_tokens.go

diff --git a/authorizer/src/asapo_authorizer/cli/list_tokens.go b/authorizer/src/asapo_authorizer/cli/list_tokens.go
new file mode 100644
index 000000000..0c8397eba
--- /dev/null
+++ b/authorizer/src/asapo_authorizer/cli/list_tokens.go
@@ -0,0 +1,55 @@
+package cli
+
+import (
+	"asapo_authorizer/authorization"
+	"asapo_authorizer/database"
+	"asapo_authorizer/server"
+	"fmt"
+	"os"
+)
+
+type listTokenFlags struct {
+	Beamtime   string
+	Beamline   string
+}
+
+func (cmd *command) CommandList_tokens() (err error) {
+	message_string := "List tokens"
+	if cmd.description(message_string) {
+		return nil
+	}
+
+	_, err = cmd.parseTokenFlags(message_string)
+	if err != nil {
+		return err
+	}
+
+	var res map[string]interface{}
+	_, err = db.ProcessRequest(database.Request{
+		DbName:     database.KAdminDb,
+		Collection: database.KTokens,
+		Op:         "list_records",
+	}, &res)
+	if err != nil {
+		return err
+	}
+
+	answer := authorization.UserTokenResponce(request, token)
+	fmt.Fprintf(outBuf, "%s\n", string(answer))
+	return nil
+}
+
+func (cmd *command) parseListTokenFlags(message_string string) (tokenFlags, error) {
+
+	var flags tokenFlags
+	flagset := cmd.createDefaultFlagset(message_string, "")
+	flagset.StringVar(&flags.Beamtime, "beamtime", "", "beamtime for user token")
+	flagset.StringVar(&flags.Beamline, "beamline", "", "beamline for user token")
+
+	flagset.Parse(cmd.args)
+
+	if printHelp(flagset) {
+		os.Exit(0)
+	}
+	return flags, nil
+}
-- 
GitLab