Compare commits
2 Commits
v1.0
...
6dc9100b45
| Author | SHA1 | Date | |
|---|---|---|---|
| 6dc9100b45 | |||
| 1863e82595 |
@@ -2,7 +2,7 @@
|
||||
(:require [clojure.tools.build.api :as b]))
|
||||
|
||||
(def lib 'es.rcorral/clj-topt)
|
||||
(def version (format "1.0.%s" (b/git-count-revs nil)))
|
||||
(def version (format "1.1.%s" (b/git-count-revs nil)))
|
||||
(def class-dir "target/classes")
|
||||
(def uber-file (format "target/%s-%s-standalone.jar" (name lib) version))
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
NATIVE=~/.sdkman/candidates/java/21.0.2-graalce/bin/native-image
|
||||
UBERJAR=clj-topt-1.0.32-standalone.jar
|
||||
UBERJAR=clj-topt-1.0.38-standalone.jar
|
||||
BIN_FILE=totp
|
||||
|
||||
echo "Creating uberjar"
|
||||
|
||||
131
src/totp/app.clj
131
src/totp/app.clj
@@ -29,34 +29,141 @@
|
||||
)
|
||||
|
||||
(defn cmd-generate
|
||||
[& {:keys [secret continuous] :as otps}]
|
||||
;(pp/pprint otps)
|
||||
[& {:keys [secret continuous] :as opts}]
|
||||
;(pp/pprint opts)
|
||||
(if continuous
|
||||
(print-confinuous secret)
|
||||
(println (get-otp secret))
|
||||
))
|
||||
|
||||
|
||||
(defn cmd-config
|
||||
[& {:keys [command] :as opts}]
|
||||
(pp/pprint opts)
|
||||
(case command
|
||||
"info" (println "Configuration file: "
|
||||
(if exists-config
|
||||
cfg-file
|
||||
(str "<not found. default:" cfg-file ">")))
|
||||
"init" (if exists-config
|
||||
(do
|
||||
(println "Configuration already exists, this will delete it. Are you sure? [N/y]")
|
||||
(case (read-line)
|
||||
"y" (create-cfg-file)
|
||||
"Y" (create-cfg-file)
|
||||
(println "Cancelling operation.")))
|
||||
(create-cfg-file))
|
||||
"show" (do
|
||||
(println "Config file:\n")
|
||||
(println (slurp cfg-file)))))
|
||||
|
||||
|
||||
(defn cmd-list
|
||||
[])
|
||||
|
||||
|
||||
(defn cmd-add
|
||||
[& {:keys [name secret user issuer algorithm digits period update] :as opts}]
|
||||
(pp/pprint opts))
|
||||
|
||||
|
||||
(defn cmd-delete
|
||||
[& {:keys [name force] :as opts}]
|
||||
(pp/pprint opts))
|
||||
|
||||
|
||||
(def cli-options
|
||||
{:app {:command "totp"
|
||||
:version "1.0.0"
|
||||
:version "1.1"
|
||||
:description ["Generate a TOTP"]}
|
||||
|
||||
:commands [{:command "generate" :short "g"
|
||||
:description "Generate one TOTP with a given secret in BASE32"
|
||||
:examples ["totp generate \"MJXW42LBORXQ====\""
|
||||
"totp g \"MJXW42LBORXQ====\""]
|
||||
:opts [{:option "secret"
|
||||
:short 0
|
||||
:as "Secret codified in BASE32"
|
||||
:examples ["Generate one TOTP and exits:"
|
||||
" totp generate \"MJXW42LBORXQ====\""
|
||||
"Generate one TOTP and refresh it continuosly:"
|
||||
" totp g \"MJXW42LBORXQ====\""]
|
||||
:opts [{:option "secret" :short 0
|
||||
:as "Secret encoded in BASE32"
|
||||
:type :string
|
||||
:default :present}
|
||||
{:option "continuous"
|
||||
:short "c"
|
||||
:type :with-flag
|
||||
{:option "continuous" :short "c"
|
||||
:as "Contiuous mode"
|
||||
:type :with-flag
|
||||
:default false}]
|
||||
:runs cmd-generate}]})
|
||||
:runs cmd-generate}
|
||||
|
||||
{:command "config" :short "c"
|
||||
:description "Manage configuration"
|
||||
:examples ["Show location for the configuration file:"
|
||||
" totp config info"
|
||||
"Recreate config (warning: it will delete the existing config file):"
|
||||
" totp config init"
|
||||
"Show configuration:"
|
||||
" totp config show"]
|
||||
:opts [{:option "command" :short 0
|
||||
:as "Command to execute. See examples"
|
||||
:type #{"info" "init" "show"}
|
||||
:default :present}]
|
||||
:runs cmd-config}
|
||||
|
||||
{:command "list" :short "l"
|
||||
:description "List existing apps"
|
||||
:examples ["List apps:"
|
||||
" totp list"]
|
||||
:runs cmd-list}
|
||||
|
||||
{:command "add" :short "a"
|
||||
:description "Add a new application with an unique name"
|
||||
:examples ["Add a new application named 'app1' with a BASE32 secred, with defaults:"
|
||||
" totp add app1 \"MJXW42LBORXQ====\""
|
||||
"Add an application, with all posible configuration params:"
|
||||
" topt add app2 \"MJXW42LBORXQ====\" -u \"user1@server\" -i my_provider -a sha1 -d 6 -p 30 --update"]
|
||||
:opts [{:option "name" :short 0
|
||||
:as "Unique name (alias) for the application"
|
||||
:type :string
|
||||
:default :present}
|
||||
{:option "secret" :short 1
|
||||
:as "Secret encoded in BASE32"
|
||||
:type :string
|
||||
:default :present}
|
||||
{:option "user" :short "u"
|
||||
:as "Username in the format <user>@<server>"
|
||||
:type :string}
|
||||
{:option "issuer" :short "i"
|
||||
:as "The issuer (provider) of the service"
|
||||
:type :string}
|
||||
{:option "algorithm" :short "a"
|
||||
:as "Algorithm used for the key generation"
|
||||
:type #{"sha1" "sha256" "sha512"}
|
||||
:default "sha1"}
|
||||
{:option "digits" :short "d"
|
||||
:as "Number of digits for OTP. Usually 6 or 8"
|
||||
:type :int
|
||||
:default 6}
|
||||
{:option "period" :short "p"
|
||||
:as "Validity time in seconds"
|
||||
:type :int
|
||||
:default 30}
|
||||
{:option "update"
|
||||
:as "Update an app with the same name if exists"
|
||||
:type :flag
|
||||
:default false}]
|
||||
:runs cmd-add}
|
||||
|
||||
{:command "delete" :short "d"
|
||||
:description "Removes an existing application by it's unique name"
|
||||
:examples ["Remove the application name app1"
|
||||
" totp remove app1"]
|
||||
:opts [{:option "name" :short 0
|
||||
:as "Unique name of the application"
|
||||
:type :string
|
||||
:default :present}
|
||||
{:option "force" :short "f"
|
||||
:as "Don't ask, just remove"
|
||||
:type :flag
|
||||
:default false}]
|
||||
:runs cmd-delete}]})
|
||||
|
||||
|
||||
(defn -main [& args]
|
||||
|
||||
Reference in New Issue
Block a user