Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@

[Consul](https://www.consul.io) is an awesome service discovery and configuration provider.

```clojure
[consul-clojure "0.7.4"]
```


## Changelog

### 0.7.4

> This is a **minor update** that **is BREAKING** for the `catalog-services` function.

Fixed `catalog-services` query to return a hashmap with service names as keys. Previously the service names were kebab-cased and sometimes that would lead to service names that would not exist.
Added test for the `catalog-services` operation.
Fixed the prepared queries parameters handling.
Updated dependencies.

### 0.7.3

Prepared queries support.

### 0.7.2

> This is a **minor update**
Expand All @@ -13,7 +30,7 @@
[consul-clojure "0.7.1"]
```

* [wkoelewijn] Fixes issue with TTL check
* [jwkoelewijn] Fixes issue with TTL check

### 0.7.1

Expand Down
10 changes: 5 additions & 5 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject com.nedap.staffing-solutions/consul-clojure "0.7.3"
(defproject com.nedap.staffing-solutions/consul-clojure "0.7.4"
:description "A Consul client for Clojure applications."
:url "http://github.com/bpoweski/consul-clojure"
:license {:name "Eclipse Public License"
Expand All @@ -9,8 +9,8 @@
"releases" {:url "https://nedap.jfrog.io/nedap/staffing-solutions/"
:username :env/artifactory_user
:password :env/artifactory_pass}}
:dependencies [[camel-snake-kebab "0.3.1" :exclusions [org.clojure/clojure com.keminglabs/cljx]]
[cheshire "5.5.0"]
:dependencies [[camel-snake-kebab "0.4.1" :exclusions [org.clojure/clojure com.keminglabs/cljx]]
[cheshire "5.10.0"]
[clj-http-lite "0.3.0" :exclusions [org.clojure/clojure]]]
:profiles {:dev {:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/core.async "0.1.346.0-17112a-alpha"]]}})
:profiles {:dev {:dependencies [[org.clojure/clojure "1.10.0"]
[org.clojure/core.async "1.1.587"]]}})
18 changes: 8 additions & 10 deletions src/consul/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,13 @@
([conn service-id {:as params}]
(consul-200 conn :put [:agent :service :deregister service-id] {:query-params params})))


(defn agent-maintenance-service
"Put a service into maintenance"
([conn service-id enable reason]
(agent-maintenance-service conn service-id {:enable enable :reason reason}))
([conn service-id {:keys [enable reason] :as params}]
(consul-200 conn :get [:agent :service :maintenance service-id] {:query-params params})))


;; Catalog endpoints - https://www.consul.io/docs/agent/http/catalog.html

;; These are low level endpoints, so it is preferrable to use the other functions instead
Expand Down Expand Up @@ -448,8 +446,8 @@
(defn catalog-services
([conn]
(catalog-services conn {}))
([conn {:keys [dc] :as params}]
(:body (consul-index conn :get [:catalog :services] {:query-params params}))))
([conn {:as params}]
(shallow-nameify-keys (:body (consul conn :get [:catalog :services] {:query-params params})))))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe introduce threading here


(defn catalog-service
([conn service]
Expand Down Expand Up @@ -642,18 +640,18 @@
(consul-200 conn :delete [:query (.toString query-id)] params)))

(defn execute-prepared-query
"Execute a prepared query by either its ID (a UUID) or
its name"
"Execute a prepared query by either its ID (a UUID) or its name"
([conn query-id]
(execute-prepared-query conn query-id {}))
([conn query-id params]
(->> (consul conn :get [:query (.toString query-id) :execute] :query-params params)
:body
(cske/transform-keys csk/->kebab-case-keyword))))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toString instead of str

(-> (consul-index conn :get [:query (.toString query-id) :execute] {:query-params params})
:body)))

(defn explain-prepared-query
"This generates a fully-rendered query for a given, post interpolation"
([conn query-id]
(explain-prepared-query conn query-id {}))
([conn query-id params]
(:body (consul conn :get [:query (.toString query-id) :explain] :query-params params))))
(-> (consul conn :get [:query (.toString query-id) :explain] {:query-params params})
:body)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline police🚨

12 changes: 12 additions & 0 deletions test/consul/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@
(is (map? (get-in (agent-services :local) [service-id])))
(is (= 2 (count (filter (comp #{service-id} :service-id) (vals (agent-checks :local)))))))))

(deftest ^{:integration true} catalog-test
(testing "registering and deregistering a service using the agent but checking the catalog"
(let [service-id (str "consul-clojure.service." (UUID/randomUUID))
service-name "service-test-name-api-v1-production"]
(is (nil? (get (catalog-services :local) service-name)))
(is (true? (agent-register-service :local {:id service-id
:name service-name})))
(is (true? (contains? (catalog-services :local)
service-name)))
(is (true? (agent-deregister-service :local service-id)))
(is (nil? (get (catalog-services :local) service-name))))))

(deftest ^{:integration true} prepared-query-test
(testing "registering and removing prepared queries"
(let [pq-name (str "consul-clojure.prepared-query." (UUID/randomUUID))]
Expand Down