|
4 | 4 | (:require [clojure.string :as string] |
5 | 5 | [clojure.tools.cli :refer [parse-opts]] |
6 | 6 | [slingshot.slingshot :refer [throw+ try+]] |
7 | | - [temporal.client.core :as c])) |
| 7 | + [temporal.client.core :as c] |
| 8 | + [temporal.tls :as tls])) |
8 | 9 |
|
9 | 10 | (def tool-name "temporal-benchmark") |
10 | 11 |
|
|
35 | 36 | (defn error-exit [error-msg summary] |
36 | 37 | (exit -1 (str "Error: " error-msg "\n\n") summary)) |
37 | 38 |
|
38 | | -(defn global-option-error [field usage-summary] |
39 | | - (error-exit (str "global option '" field "' required") usage-summary)) |
40 | | - |
41 | 39 | (defn round2 |
42 | 40 | "Round a double to the given precision (number of significant digits)" |
43 | 41 | [precision ^double d] |
44 | 42 | (let [factor (Math/pow 10 precision)] |
45 | 43 | (/ (Math/round (* d factor)) factor))) |
46 | 44 |
|
| 45 | +(defn new-ssl-context [{:keys [temporal-ca] :as global-options}] |
| 46 | + (-> {} |
| 47 | + (cond-> temporal-ca (assoc :ca-path temporal-ca)) |
| 48 | + (tls/new-ssl-context))) |
| 49 | + |
| 50 | +(defn create-client [{:keys [temporal-target temporal-namespace temporal-tls] :as global-options}] |
| 51 | + (c/create-client (-> {:target temporal-target |
| 52 | + :namespace temporal-namespace} |
| 53 | + (cond-> temporal-tls (assoc :ssl-context (new-ssl-context global-options)))))) |
| 54 | + |
47 | 55 | (defn exec-command |
48 | | - [{:keys [command description options-spec fn]} global-summary |
49 | | - {:keys [temporal-target] :as global-options} args] |
| 56 | + [{:keys [command description options-spec fn]} global-summary global-options args] |
50 | 57 | (let [{{:keys [help] :as local-options} :options |
51 | 58 | :keys [errors summary]} (parse-opts args (cons ["-h" "--help"] options-spec)) |
52 | 59 | summary (subcommand-usage command description global-summary summary)] |
|
60 | 67 |
|
61 | 68 | :else |
62 | 69 | (let [options (merge global-options local-options) |
63 | | - client (c/create-client {:target temporal-target})] |
| 70 | + client (create-client global-options)] |
64 | 71 | (fn options client))))) |
0 commit comments