aboutsummaryrefslogtreecommitdiff
path: root/cli.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-10-06 16:35:12 +0700
committerShulhan <ms@kilabit.info>2023-10-06 16:35:12 +0700
commitaedc3c206dd997c6dd96ce53a807b0b6ae635b3c (patch)
treebc152d29ee0c864437cd8204e8bdfb0cd474b7a6 /cli.go
parent3ca05089eccb6c2e738c0a86725bd22695f5b7a7 (diff)
downloadgotp-aedc3c206dd997c6dd96ce53a807b0b6ae635b3c.tar.xz
all: implement command "get"
The "get" command get and print the issuer by its LABEL. This will print the issuer secret, unencrypted.
Diffstat (limited to 'cli.go')
-rw-r--r--cli.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/cli.go b/cli.go
index 491db69..8f97a30 100644
--- a/cli.go
+++ b/cli.go
@@ -198,6 +198,25 @@ func (cli *Cli) Generate(label string, n int) (listOtp []string, err error) {
return listOtp, nil
}
+// Get the stored Issuer by its label.
+func (cli *Cli) Get(label string) (issuer *Issuer, err error) {
+ var logp = `Get`
+
+ if cli.cfg.privateKey == nil {
+ cli.cfg.privateKey, err = loadPrivateKey(cli.cfg.PrivateKey, nil)
+ if err != nil {
+ return nil, fmt.Errorf(`%s: %w`, logp, err)
+ }
+ }
+
+ issuer, err = cli.cfg.get(label)
+ if err != nil {
+ return nil, fmt.Errorf(`%s: %w`, logp, err)
+ }
+
+ return issuer, nil
+}
+
// Import the TOTP configuration from file format based on provider.
func (cli *Cli) Import(providerName, file string) (n int, err error) {
var (