Skip to content

Commit

Permalink
feat: scratch method retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
J0sueTM committed Aug 7, 2024
1 parent 1bfd4d8 commit 47ff1dc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
8 changes: 5 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{:paths ["src"]
{:paths ["src" "resources"]
:deps
{redis.clients/jedis {:mvn/version "5.1.2"}
{redis.clients/jedis {#_#_:mvn/version "5.1.2"
:local/root "vendor/jedis/target/jedis-5.2.0-SNAPSHOT.jar"}
org.clojure/tools.logging {:mvn/version "1.3.0"}
ch.qos.logback/logback-classic {:mvn/version "1.5.6"}}
ch.qos.logback/logback-classic {:mvn/version "1.5.6"}
camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"}}

:aliases
{;; clj -A:dev -m com.moclojer.rq
Expand Down
4 changes: 4 additions & 0 deletions resources/command-allowlist.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#{"lpush" "rpush" "lpop" "rpop" "brpop"
"blpop" "lrange" "lindex" "lset" "lrem"
"llen" "linsert" "ltrim" "rpoplpush"
"brpoplpush" "lmove"}
38 changes: 38 additions & 0 deletions src/com/moclojer/rq.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,41 @@
"Disconnect and close redis client"
([] (close-client *redis-pool*))
([client] (.close @client)))

(comment
;; (import [java.util Arrays])
(require '[clojure.string :as str]
'[clojure.java.io :as io]
'[clojure.edn :as edn]
'[camel-snake-kebab.core :as csk])
(import [redis.clients.jedis JedisPooled])

(def allowlist
(-> (io/resource "command-allowlist.edn")
(slurp)
(edn/read-string)))

(->> (.getMethods JedisPooled)
(map
(fn [class]
{:name (csk/->kebab-case (.getName class))
:parameters (map
#(identity
{:type (-> (.. % getType getName)
(str/split #"\.")
(last)
(csk/->kebab-case))
:name (csk/->kebab-case (.getName %))})
(.getParameters class))}))
(filter #(contains? allowlist (:name %)))
(reduce
(fn [methods {:keys [name parameters]}]
(let [overload-count (count
(filter
#(str/starts-with? (key %) name)
methods))
cur-overload-id (when (> overload-count 0) overload-count)]
(assoc methods (str name cur-overload-id) parameters)))
{}))
;;
)

0 comments on commit 47ff1dc

Please sign in to comment.