Skip to content

Commit 9f8c89f

Browse files
MCC-764738: switched from http-kit to clj-http for tracing auto-instrumentation support from motel-java (#2)
1 parent 440d375 commit 9f8c89f

File tree

5 files changed

+70
-55
lines changed

5 files changed

+70
-55
lines changed

project.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[digest "1.4.8"]
99
[org.clojure/data.codec "0.1.1"]
1010
[http-kit "2.4.0-alpha2"]
11+
[clj-http "3.9.1"]
1112
[org.clojure/data.json "0.2.6"]
1213
[javax.xml.bind/jaxb-api "2.2.11"]]
1314
:jvm-opts ~(concat

src/clojure_mauth_client/header.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656
{"X-MWS-Authentication" (-> x-mws-authentication
5757
msg->sha512
5858
(sign-mauth app-uuid private-key))
59-
"X-MWS-Time" x-mws-time}))
59+
"X-MWS-Time" (str x-mws-time)}))
6060
([status body app-uuid private-key]
6161
(let [x-mws-time (epoch-seconds)
6262
x-mws-authentication (make-mws-auth-string-for-response status body app-uuid x-mws-time)]
6363
{"X-MWS-Authentication" (-> x-mws-authentication
6464
msg->sha512
6565
(sign-mauth app-uuid private-key))
66-
"X-MWS-Time" x-mws-time}))
66+
"X-MWS-Time" (str x-mws-time)}))
6767
)
6868

src/clojure_mauth_client/request.clj

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
(ns clojure-mauth-client.request
2-
(:require [org.httpkit.client :as http])
2+
(:require [org.httpkit.client :as http]
3+
[clj-http.client :as client]
4+
[clojure.data.json :as json])
35
(:use clojure-mauth-client.header
46
clojure-mauth-client.credentials)
57
(:import (javax.net.ssl SSLEngine SNIHostName SSLParameters)
@@ -13,21 +15,28 @@
1315

1416

1517

16-
(defn make-request [type base-url uri body & {:keys [additional-headers with-sni?]
18+
(defn make-request [type base-url uri body & {:keys [additional-headers with-sni? throw-exceptions?]
1719
:or {additional-headers {}
18-
with-sni? nil}}]
20+
with-sni? nil
21+
throw-exceptions? false}}]
1922
(let [cred (get-credentials)
23+
; Tech debt: test with-sni?=true and modify this code if needed
24+
; (https://jira.mdsol.com/browse/MCC-767309)
2025
options (if with-sni? {:client (http/make-client {:ssl-configurer sni-configure})} {})
2126
response (-> [(.toUpperCase type) (str base-url uri) (str body) (:app-uuid cred) (:private-key cred)]
2227
(#(apply build-mauth-headers %))
2328
(merge additional-headers)
24-
(#(http/request (-> {:headers %
29+
; We use clj-http instead of http-kit because it is supported by the motel-java tracing agent
30+
(#(client/request (-> {:headers %
2531
:url (str base-url uri)
2632
:method (keyword (.toLowerCase type))
2733
:body body
34+
:throw-exceptions throw-exceptions?
2835
:as :auto}
2936
(merge options)))))]
30-
@response
37+
; The following line is here because existing clients expect a String instead of a LazySeq.
38+
; When we're ready to make a breaking change, we should return "response" directly with no modification.
39+
(update response :body json/write-str)
3140
)
3241
)
3342

test/clojure_mauth_client/header_test.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@
4646
(let [creds (get-credentials)]
4747
(-> (build-mauth-headers "GET" "https://www.mdsol.com/api/v2/testing" "" (:app-uuid creds) (:private-key creds))
4848
(= {"X-MWS-Authentication" "MWS abcd7d78-c874-47d9-a829-ccaa51ae75c9:gI/yUeSTbiOWggLvCv2IJP19GFvmlE8RoaUrIpyLE8DY/mCQd8CUPgT9xNHGNqgPGe9f4CZdiFCC79Xvp6seZAq8/CnqA1dsJW6f46scqqTs+4N1TJml6GNCT9xU4tjUyHWFWpCBQlSvpoTFsLSq2d2zas9M9q1sgwPBS/oPGEN1agCQLHZS/Ime4ub8MuXh0Q8aWodqCpVi4GPiap/KLIQEzbvhsdayxmAcs2XDjpt+CReRf3tBCzB1RucVEfBehxtDQGgvrs/UCUbkpq7gY7f2k0RkrH+IopfhYfdNpmCHW12OEQoZ74TVbh61Uo+xcD1der46+tWk0mdnlyXKow=="
49-
"X-MWS-Time" 1532825948})
49+
"X-MWS-Time" "1532825948"})
5050
is
5151
)
5252
))
5353
(testing "It should generate a valid mauth X-MWS header for response"
5454
(let [creds (get-credentials)]
5555
(-> (build-mauth-headers 200 "{\"test\":\"testing\"}" (:app-uuid creds) (:private-key creds))
5656
(= {"X-MWS-Authentication" "MWS abcd7d78-c874-47d9-a829-ccaa51ae75c9:i0rLrgEN8Jy/M4kA1PNNckUxeGU2pL3PGCOjdhRrC6egHVTvNfJLXveVG/7wAU9H4hpLYsThyV1/LRc/OupBZmKYRDzqD6OneZVLkysehk6/OHKb8j8uJQnBSLB72ooIPPIUxJqtasHCi6cdzkBEZf3omp7qzkinhuX2Wi/t70xfC5YmeTydBoe2d+zcIDJZb6+zON4V5CwGMPlCLK6iFD8+hk9ddhszQZ+siHK8SWxrhrMGRDN9xyp3ljw+f62tlpTZi0KEHAr0M/aq49aP3Iv/XrN88Cl5Tt1nGIWslarfJrAxFNfzofO0KULqFB9nRV1NkBbrSMyjGvea7nGNBw=="
57-
"X-MWS-Time" 1532825948})
57+
"X-MWS-Time" "1532825948"})
5858
is
5959
)
6060
)

test/clojure_mauth_client/request_test.clj

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,68 +38,73 @@
3838
-----END RSA PRIVATE KEY-----"
3939
"https://mauth-sandbox.imedidata.net")
4040
(with-redefs [clojure-mauth-client.header/epoch-seconds (fn [] 1532825948)
41-
org.httpkit.client/request (fn [{:keys [client timeout filter worker-pool keepalive as follow-redirects max-redirects response
42-
trace-redirects allow-unsafe-redirect-methods proxy-host proxy-port tunnel?]
43-
:as opts
44-
:or {client nil
45-
timeout 60000
46-
follow-redirects true
47-
max-redirects 10
48-
filter nil
49-
worker-pool nil
50-
response (promise)
51-
keepalive 120000
52-
as :auto
53-
tunnel? false
54-
proxy-host nil
55-
proxy-port 3128}}
56-
& [callback]] (future opts))]
41+
clj-http.client/request (fn [{:keys [client timeout filter worker-pool keepalive as follow-redirects max-redirects response
42+
trace-redirects allow-unsafe-redirect-methods proxy-host proxy-port tunnel?]
43+
:as opts
44+
:or {client nil
45+
timeout 60000
46+
follow-redirects true
47+
max-redirects 10
48+
filter nil
49+
worker-pool nil
50+
response (promise)
51+
keepalive 120000
52+
as :auto
53+
tunnel? false
54+
proxy-host nil
55+
proxy-port 3128}}
56+
& [callback]] opts)]
5757
(f)
5858
)
5959
))
6060

6161
(def mock-get
62-
{:headers {"X-MWS-Authentication" "MWS abcd7d78-c874-47d9-a829-ccaa51ae75c9:gI/yUeSTbiOWggLvCv2IJP19GFvmlE8RoaUrIpyLE8DY/mCQd8CUPgT9xNHGNqgPGe9f4CZdiFCC79Xvp6seZAq8/CnqA1dsJW6f46scqqTs+4N1TJml6GNCT9xU4tjUyHWFWpCBQlSvpoTFsLSq2d2zas9M9q1sgwPBS/oPGEN1agCQLHZS/Ime4ub8MuXh0Q8aWodqCpVi4GPiap/KLIQEzbvhsdayxmAcs2XDjpt+CReRf3tBCzB1RucVEfBehxtDQGgvrs/UCUbkpq7gY7f2k0RkrH+IopfhYfdNpmCHW12OEQoZ74TVbh61Uo+xcD1der46+tWk0mdnlyXKow=="
63-
"X-MWS-Time" 1532825948}
64-
:url "https://www.mdsol.com/api/v2/testing"
65-
:method :get,
66-
:body "",
67-
:as :auto}
62+
{:headers {"X-MWS-Authentication" "MWS abcd7d78-c874-47d9-a829-ccaa51ae75c9:gI/yUeSTbiOWggLvCv2IJP19GFvmlE8RoaUrIpyLE8DY/mCQd8CUPgT9xNHGNqgPGe9f4CZdiFCC79Xvp6seZAq8/CnqA1dsJW6f46scqqTs+4N1TJml6GNCT9xU4tjUyHWFWpCBQlSvpoTFsLSq2d2zas9M9q1sgwPBS/oPGEN1agCQLHZS/Ime4ub8MuXh0Q8aWodqCpVi4GPiap/KLIQEzbvhsdayxmAcs2XDjpt+CReRf3tBCzB1RucVEfBehxtDQGgvrs/UCUbkpq7gY7f2k0RkrH+IopfhYfdNpmCHW12OEQoZ74TVbh61Uo+xcD1der46+tWk0mdnlyXKow=="
63+
"X-MWS-Time" "1532825948"}
64+
:url "https://www.mdsol.com/api/v2/testing"
65+
:method :get,
66+
:body "\"\"",
67+
:throw-exceptions false
68+
:as :auto}
6869
)
6970

7071
(def mock-get-with-qs
71-
{:headers {"X-MWS-Authentication" "MWS abcd7d78-c874-47d9-a829-ccaa51ae75c9:gI/yUeSTbiOWggLvCv2IJP19GFvmlE8RoaUrIpyLE8DY/mCQd8CUPgT9xNHGNqgPGe9f4CZdiFCC79Xvp6seZAq8/CnqA1dsJW6f46scqqTs+4N1TJml6GNCT9xU4tjUyHWFWpCBQlSvpoTFsLSq2d2zas9M9q1sgwPBS/oPGEN1agCQLHZS/Ime4ub8MuXh0Q8aWodqCpVi4GPiap/KLIQEzbvhsdayxmAcs2XDjpt+CReRf3tBCzB1RucVEfBehxtDQGgvrs/UCUbkpq7gY7f2k0RkrH+IopfhYfdNpmCHW12OEQoZ74TVbh61Uo+xcD1der46+tWk0mdnlyXKow=="
72-
"X-MWS-Time" 1532825948}
73-
:url "https://www.mdsol.com/api/v2/testing?testABCD=1234"
74-
:method :get,
75-
:body "",
76-
:as :auto}
72+
{:headers {"X-MWS-Authentication" "MWS abcd7d78-c874-47d9-a829-ccaa51ae75c9:gI/yUeSTbiOWggLvCv2IJP19GFvmlE8RoaUrIpyLE8DY/mCQd8CUPgT9xNHGNqgPGe9f4CZdiFCC79Xvp6seZAq8/CnqA1dsJW6f46scqqTs+4N1TJml6GNCT9xU4tjUyHWFWpCBQlSvpoTFsLSq2d2zas9M9q1sgwPBS/oPGEN1agCQLHZS/Ime4ub8MuXh0Q8aWodqCpVi4GPiap/KLIQEzbvhsdayxmAcs2XDjpt+CReRf3tBCzB1RucVEfBehxtDQGgvrs/UCUbkpq7gY7f2k0RkrH+IopfhYfdNpmCHW12OEQoZ74TVbh61Uo+xcD1der46+tWk0mdnlyXKow=="
73+
"X-MWS-Time" "1532825948"}
74+
:url "https://www.mdsol.com/api/v2/testing?testABCD=1234"
75+
:method :get,
76+
:body "\"\"",
77+
:throw-exceptions false
78+
:as :auto}
7779
)
7880

7981
(def mock-post
80-
{:headers {"X-MWS-Authentication" "MWS abcd7d78-c874-47d9-a829-ccaa51ae75c9:kYZR1udBwE02ct55cSWq5MZuGsC6xgVmK6TWYQ/+2IAbhqG7jZWhP95bPxTqo1f12XUWsX/oeUAp8jhvdUcsXsjVMeBwvQNgnC/HP1TNQasC2LMGfOs76WnsfKoV5zWDh+SNqMqn4pIXce3DALG9d/FB2Uu4mIg9kgQIUnfJJDljfLMjR7aMgDINPU7ToM51TqTJh+ReG7LAVwsEzSwFfj4zZFFpx8XrWn3inx5ZUvT7YcFhW4vOZaeI48HSnj80bCf1LDtWXzU7yk9gon+AlIYBTtrPQTSqyofBGZUtZCBexnoEp6NUhk5XkwqK56jizT7PZCN094kh1eofr3hSTg=="
81-
"X-MWS-Time" 1532825948},
82-
:url "https://www.mdsol.com/api/v2/testing1"
83-
:method :post
84-
:body "{\"a\":{\"b\":123}}"
85-
:as :auto}
82+
{:headers {"X-MWS-Authentication" "MWS abcd7d78-c874-47d9-a829-ccaa51ae75c9:kYZR1udBwE02ct55cSWq5MZuGsC6xgVmK6TWYQ/+2IAbhqG7jZWhP95bPxTqo1f12XUWsX/oeUAp8jhvdUcsXsjVMeBwvQNgnC/HP1TNQasC2LMGfOs76WnsfKoV5zWDh+SNqMqn4pIXce3DALG9d/FB2Uu4mIg9kgQIUnfJJDljfLMjR7aMgDINPU7ToM51TqTJh+ReG7LAVwsEzSwFfj4zZFFpx8XrWn3inx5ZUvT7YcFhW4vOZaeI48HSnj80bCf1LDtWXzU7yk9gon+AlIYBTtrPQTSqyofBGZUtZCBexnoEp6NUhk5XkwqK56jizT7PZCN094kh1eofr3hSTg=="
83+
"X-MWS-Time" "1532825948"},
84+
:url "https://www.mdsol.com/api/v2/testing1"
85+
:method :post
86+
:body "\"{\\\"a\\\":{\\\"b\\\":123}}\""
87+
:throw-exceptions false
88+
:as :auto}
8689
)
8790

8891
(def mock-delete
89-
{:headers {"X-MWS-Authentication" "MWS abcd7d78-c874-47d9-a829-ccaa51ae75c9:IzAzkGyzDtxbMlCbbWViYen/9o54B9Ijlnp1UoSIysGr/axJWwph8KRYukS+3DhYFJIBLbS1PfWI74kRTkWJl3Vmb0XgxiRfNCqresqh687ELlhNDt66p2mu/6LaVwbDKUBsIAwkQFomVfAOy3jckWZjHRySD+VABfDf4BAf5hfjTUgil63oOnH6xII51e6M160SFRz1/HpsMU/rnReniPJs22MwiqS6dhe3oU/DAzteawxujSdFA3i6Fol6kdJQN19w+0TTdOSbccjds1Wljqu/+E1ju1rXVAgcL0GuVg4dsCwrjSPY9VWfQOttpA4aHavGWNcPMh1p1kSmqlNa1g=="
90-
"X-MWS-Time" 1532825948}
91-
:url "https://www.mdsol.com/api/v2/testing2"
92-
:method :delete
93-
:body ""
94-
:as :auto})
92+
{:headers {"X-MWS-Authentication" "MWS abcd7d78-c874-47d9-a829-ccaa51ae75c9:IzAzkGyzDtxbMlCbbWViYen/9o54B9Ijlnp1UoSIysGr/axJWwph8KRYukS+3DhYFJIBLbS1PfWI74kRTkWJl3Vmb0XgxiRfNCqresqh687ELlhNDt66p2mu/6LaVwbDKUBsIAwkQFomVfAOy3jckWZjHRySD+VABfDf4BAf5hfjTUgil63oOnH6xII51e6M160SFRz1/HpsMU/rnReniPJs22MwiqS6dhe3oU/DAzteawxujSdFA3i6Fol6kdJQN19w+0TTdOSbccjds1Wljqu/+E1ju1rXVAgcL0GuVg4dsCwrjSPY9VWfQOttpA4aHavGWNcPMh1p1kSmqlNa1g=="
93+
"X-MWS-Time" "1532825948"}
94+
:url "https://www.mdsol.com/api/v2/testing2"
95+
:method :delete
96+
:body "\"\"",
97+
:throw-exceptions false
98+
:as :auto})
9599

96100
(def mock-put
97-
{:headers {"X-MWS-Authentication" "MWS abcd7d78-c874-47d9-a829-ccaa51ae75c9:W+hIOQKAp0aEwDthAVaMa5ysJB8ddQdJdTWNonQoDuPEBVAY7F6GUXNoAZCYcosxgbm2rfpwyfLrS7U5b77GMFpnvvUwUSCgRziZNvfhuZfWUuW9po7OkWQUXCDvd/NtJdLOu6o1bKCGHYKjdaw/8AVH876afGyPF7+Ce2vD+YFRfY+zXF0MVWiS2WfwUwLSdOXb+Csnb21XT59zDs8qBg0gUj6WagZiJ+hYTbAt1zcNCdqs/mVt5hKA7ASxB9VY7GI4QM/n0EoyC/ruUm8DYS7kkxuxKeZuNkvpexFR4IPXQax1q7EtCIgw4yekegK210uxxYoOf+EBV2wMIVpKvw=="
98-
"X-MWS-Time" 1532825948}
99-
:url "https://www.mdsol.com/api/v2/testing3"
100-
:method :put
101-
:body "{\"a\":{\"b\":123}}"
102-
:as :auto})
101+
{:headers {"X-MWS-Authentication" "MWS abcd7d78-c874-47d9-a829-ccaa51ae75c9:W+hIOQKAp0aEwDthAVaMa5ysJB8ddQdJdTWNonQoDuPEBVAY7F6GUXNoAZCYcosxgbm2rfpwyfLrS7U5b77GMFpnvvUwUSCgRziZNvfhuZfWUuW9po7OkWQUXCDvd/NtJdLOu6o1bKCGHYKjdaw/8AVH876afGyPF7+Ce2vD+YFRfY+zXF0MVWiS2WfwUwLSdOXb+Csnb21XT59zDs8qBg0gUj6WagZiJ+hYTbAt1zcNCdqs/mVt5hKA7ASxB9VY7GI4QM/n0EoyC/ruUm8DYS7kkxuxKeZuNkvpexFR4IPXQax1q7EtCIgw4yekegK210uxxYoOf+EBV2wMIVpKvw=="
102+
"X-MWS-Time" "1532825948"}
103+
:url "https://www.mdsol.com/api/v2/testing3"
104+
:method :put
105+
:body "\"{\\\"a\\\":{\\\"b\\\":123}}\""
106+
:throw-exceptions false
107+
:as :auto})
103108

104109
(def mock-payload (-> {:a {:b 123}}
105110
json/write-str))

0 commit comments

Comments
 (0)