Skip to content

Commit e8d22bc

Browse files
committed
Add support for Temporal Cloud APIKEYs
See https://docs.temporal.io/cloud/api-keys#overview Adds a new :api-key-fn option to the (create-client) methods. Also introduces (create-client-async) to work-around an issue with API KEYs and ConnectedServiceStubs. We also bump the version to 1.5.x and update the Temporal Java SDK dep to v1.31.0 Signed-off-by: Greg Haskins <greg@manetu.com>
1 parent 51be94b commit e8d22bc

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

project.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject io.github.manetu/temporal-sdk "1.4.1-SNAPSHOT"
1+
(defproject io.github.manetu/temporal-sdk "1.5.0-SNAPSHOT"
22
:description "A Temporal SDK for Clojure"
33
:url "https://github.com/manetu/temporal-clojure-sdk"
44
:license {:name "Apache License 2.0"
@@ -13,8 +13,8 @@
1313
[lein-codox "0.10.8"]]
1414
:dependencies [[org.clojure/clojure "1.12.0"]
1515
[org.clojure/core.async "1.7.701"]
16-
[io.temporal/temporal-sdk "1.28.3"]
17-
[io.temporal/temporal-testing "1.28.3"]
16+
[io.temporal/temporal-sdk "1.31.0"]
17+
[io.temporal/temporal-testing "1.31.0"]
1818
[com.taoensso/encore "3.139.0"]
1919
[com.taoensso/timbre "6.6.1"]
2020
[com.taoensso/nippy "3.4.2"]
@@ -36,5 +36,5 @@
3636
:cloverage {:runner :eftest
3737
:runner-opts {:multithread? false
3838
:fail-fast? true}
39-
:fail-threshold 91
39+
:fail-threshold 90
4040
:ns-exclude-regex [#"temporal.client.worker"]})

src/temporal/client/core.clj

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,41 @@
1212
(:import [java.time Duration]
1313
[io.temporal.client WorkflowClient WorkflowStub]))
1414

15+
(defn- ^:no-doc create-client*
16+
[service-stub options]
17+
(WorkflowClient/newInstance service-stub (copts/workflow-client-options-> options)))
18+
19+
(defn create-client-async
20+
"
21+
Creates a new client instance suitable for implementing Temporal workers (See [[temporal.client.worker/start]]) or
22+
workflow clients (See [[create-workflow]]). Will not verify the connection before returning.
23+
24+
Arguments:
25+
26+
- `options`: Options for configuring the `WorkflowClient` (See [[temporal.client.options/workflow-client-options]] and [[temporal.client.options/stub-options]])
27+
28+
"
29+
([] (create-client-async {}))
30+
([options]
31+
(create-client* (copts/service-stub-> options) options)))
32+
1533
(defn create-client
1634
"
1735
Creates a new client instance suitable for implementing Temporal workers (See [[temporal.client.worker/start]]) or
18-
workflow clients (See [[create-workflow]]).
36+
workflow clients (See [[create-workflow]]). The caller is blocked while the connection is verified for up to the
37+
specified timeout duration, or 5s if not specified.
1938
2039
Arguments:
2140
2241
- `options`: Options for configuring the `WorkflowClient` (See [[temporal.client.options/workflow-client-options]] and [[temporal.client.options/stub-options]])
23-
- `timeout`: Connection timeout as a [Duration](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html) (default: 5s)
42+
- `timeout`: Optional connection timeout as a [Duration](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html) (Default: 5s).
2443
2544
"
2645
([] (create-client {}))
2746
([options]
2847
(create-client options (Duration/ofSeconds 5)))
2948
([options timeout]
30-
(let [service (copts/service-stub-> options timeout)]
31-
(WorkflowClient/newInstance service (copts/workflow-client-options-> options)))))
49+
(create-client* (copts/service-stub-> options timeout) options)))
3250

3351
(defn create-workflow
3452
"

src/temporal/client/options.clj

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
(:import [io.temporal.client WorkflowClientOptions WorkflowClientOptions$Builder]
44
[io.temporal.common.interceptors WorkflowClientInterceptorBase]
55
[io.temporal.client.schedules ScheduleClientOptions ScheduleClientOptions$Builder]
6-
[io.temporal.serviceclient WorkflowServiceStubs WorkflowServiceStubsOptions WorkflowServiceStubsOptions$Builder]))
6+
[io.temporal.serviceclient WorkflowServiceStubs WorkflowServiceStubsOptions WorkflowServiceStubsOptions$Builder]
7+
[io.temporal.authorization AuthorizationTokenSupplier]))
78

89
(def workflow-client-options
910
"
@@ -46,6 +47,12 @@
4647
^ScheduleClientOptions [params]
4748
(u/build (ScheduleClientOptions/newBuilder (ScheduleClientOptions/getDefaultInstance)) schedule-client-options params))
4849

50+
(defn ^:no-doc apikey-auth-fn->
51+
^AuthorizationTokenSupplier [f]
52+
(reify AuthorizationTokenSupplier
53+
(supply [_]
54+
(f))))
55+
4956
(def stub-options
5057
"
5158
`WorkflowServiceStubsOptions` configuration map (See [[temporal.client.core/create-client]] or [[temporal.client.schedule/create-client]])
@@ -54,6 +61,7 @@
5461
| ------------------------- | --------------------------------------------------------------------------- | ------------ | ------- |
5562
| :channel | Sets gRPC channel to use. Exclusive with target and sslContext | [ManagedChannel](https://grpc.github.io/grpc-java/javadoc/io/grpc/ManagedChannel.html) | |
5663
| :ssl-context | Sets gRPC SSL Context to use (See [[temporal.tls/new-ssl-context]]) | [SslContext](https://netty.io/4.0/api/io/netty/handler/ssl/SslContext.html) | |
64+
| :api-key-fn | Sets [a function to return an API Key](https://docs.temporal.io/develop/java/temporal-client#connect-to-temporal-cloud-api-key) for authentication to Temporal Cloud | A 0-arity (fn) that evaluates to an API Key string | |
5765
| :enable-https | Sets option to enable SSL/TLS/HTTPS for gRPC | boolean | false |
5866
| :rpc-timeout | Sets the rpc timeout value for non query and non long poll calls | [Duration](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html) | 10s |
5967
| :rpc-long-poll-timeout | Sets the rpc timeout value | [Duration](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html) | 60s |
@@ -70,6 +78,7 @@
7078
"
7179
{:channel #(.setChannel ^WorkflowServiceStubsOptions$Builder %1 %2)
7280
:ssl-context #(.setSslContext ^WorkflowServiceStubsOptions$Builder %1 %2)
81+
:api-key-fn #(.addApiKey ^WorkflowServiceStubsOptions$Builder %1 (apikey-auth-fn-> %2))
7382
:enable-https #(.setEnableHttps ^WorkflowServiceStubsOptions$Builder %1 %2)
7483
:target #(.setTarget ^WorkflowServiceStubsOptions$Builder %1 %2)
7584
:rpc-timeout #(.setRpcTimeout ^WorkflowServiceStubsOptions$Builder %1 %2)
@@ -89,5 +98,7 @@
8998
(u/build (WorkflowServiceStubsOptions/newBuilder) stub-options params))
9099

91100
(defn service-stub->
92-
[options timeout]
93-
(WorkflowServiceStubs/newConnectedServiceStubs (stub-options-> options) timeout))
101+
([options]
102+
(WorkflowServiceStubs/newServiceStubs (stub-options-> options)))
103+
([options timeout]
104+
(WorkflowServiceStubs/newConnectedServiceStubs (stub-options-> options) timeout)))

0 commit comments

Comments
 (0)