From 3faaf2bccfb29af3e3db6617dbaa6001d6bcd309 Mon Sep 17 00:00:00 2001 From: Chad Retz Date: Tue, 12 Mar 2024 13:39:32 -0500 Subject: [PATCH] Client API key (#203) Fixes #191 --- src/Temporalio/Bridge/Cargo.lock | 452 +++++++++++------- src/Temporalio/Bridge/Cargo.toml | 7 +- src/Temporalio/Bridge/Client.cs | 15 + src/Temporalio/Bridge/Interop/Interop.cs | 6 + src/Temporalio/Bridge/OptionsExtensions.cs | 1 + .../Bridge/include/temporal-sdk-bridge.h | 3 + src/Temporalio/Bridge/sdk-core | 2 +- src/Temporalio/Bridge/src/client.rs | 29 +- src/Temporalio/Client/ITemporalConnection.cs | 24 +- src/Temporalio/Client/TemporalConnection.cs | 34 +- .../Client/TemporalConnectionOptions.cs | 11 + .../Client/TemporalClientTests.cs | 1 + 12 files changed, 394 insertions(+), 191 deletions(-) diff --git a/src/Temporalio/Bridge/Cargo.lock b/src/Temporalio/Bridge/Cargo.lock index 4ea4c618..459f1632 100644 --- a/src/Temporalio/Bridge/Cargo.lock +++ b/src/Temporalio/Bridge/Cargo.lock @@ -56,16 +56,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] -name = "anyhow" -version = "1.0.79" +name = "anstyle" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" [[package]] -name = "arc-swap" -version = "1.6.0" +name = "anyhow" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" [[package]] name = "async-stream" @@ -128,9 +128,9 @@ dependencies = [ "bitflags 1.3.2", "bytes", "futures-util", - "http", - "http-body", - "hyper", + "http 0.2.11", + "http-body 0.4.6", + "hyper 0.14.28", "itoa", "matchit", "memchr", @@ -154,8 +154,8 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 0.2.11", + "http-body 0.4.6", "mime", "rustversion", "tower-layer", @@ -295,6 +295,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "chrono" version = "0.4.31" @@ -421,9 +427,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.14.4" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" +checksum = "54e36fcd13ed84ffdfda6f5be89b31287cbb80c439841fe69e04841435464391" dependencies = [ "darling_core", "darling_macro", @@ -431,27 +437,27 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.14.4" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" +checksum = "9c2cf1c23a687a1feeb728783b993c4e1ad83d99f351801977dd809b48d0a70f" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", "strsim", - "syn 1.0.109", + "syn 2.0.48", ] [[package]] name = "darling_macro" -version = "0.14.4" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" +checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core", "quote", - "syn 1.0.109", + "syn 2.0.48", ] [[package]] @@ -478,33 +484,33 @@ dependencies = [ [[package]] name = "derive_builder" -version = "0.12.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8" +checksum = "0350b5cb0331628a5916d6c5c0b72e97393b8b6b03b47a9284f4e7f5a405ffd7" dependencies = [ "derive_builder_macro", ] [[package]] name = "derive_builder_core" -version = "0.12.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f" +checksum = "d48cda787f839151732d396ac69e3473923d54312c070ee21e9effcaa8ca0b1d" dependencies = [ "darling", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.48", ] [[package]] name = "derive_builder_macro" -version = "0.12.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e" +checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b" dependencies = [ "derive_builder_core", - "syn 1.0.109", + "syn 2.0.48", ] [[package]] @@ -520,12 +526,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "difflib" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" - [[package]] name = "digest" version = "0.10.7" @@ -560,18 +560,18 @@ dependencies = [ [[package]] name = "enum-iterator" -version = "1.4.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7add3873b5dd076766ee79c8e406ad1a472c385476b9e38849f8eec24f1be689" +checksum = "600536cfe9e2da0820aa498e570f6b2b9223eec3ce2f835c8ae4861304fa4794" dependencies = [ "enum-iterator-derive", ] [[package]] name = "enum-iterator-derive" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eecf8589574ce9b895052fa12d69af7a233f99e6107f5cb8dd1044f2a17bfdcb" +checksum = "03cdc46ec28bd728e67540c528013c6a10eb69a02eb31078a1bda695438cbfb8" dependencies = [ "proc-macro2", "quote", @@ -649,15 +649,6 @@ dependencies = [ "miniz_oxide", ] -[[package]] -name = "float-cmp" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" -dependencies = [ - "num-traits", -] - [[package]] name = "fnv" version = "1.0.7" @@ -838,16 +829,35 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.22" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.11", + "indexmap 2.1.0", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "h2" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" +checksum = "31d030e59af851932b72ceebadf4a2b5986dba4c3b99dd2493f8273a0f151943" dependencies = [ "bytes", "fnv", "futures-core", "futures-sink", "futures-util", - "http", + "http 1.1.0", "indexmap 2.1.0", "slab", "tokio", @@ -921,6 +931,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.6" @@ -928,7 +949,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.11", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" +dependencies = [ + "bytes", + "futures-core", + "http 1.1.0", + "http-body 1.0.0", "pin-project-lite", ] @@ -954,9 +998,9 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", - "http", - "http-body", + "h2 0.3.24", + "http 0.2.11", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -968,6 +1012,26 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186548d73ac615b32a73aafe38fb4f56c0d340e110e5a200bcadbaf2e199263a" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.2", + "http 1.1.0", + "http-body 1.0.0", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", +] + [[package]] name = "hyper-rustls" version = "0.24.2" @@ -975,11 +1039,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", - "http", - "hyper", - "rustls", + "http 0.2.11", + "hyper 0.14.28", + "rustls 0.21.10", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", ] [[package]] @@ -988,12 +1052,28 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" dependencies = [ - "hyper", + "hyper 0.14.28", "pin-project-lite", "tokio", "tokio-io-timeout", ] +[[package]] +name = "hyper-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +dependencies = [ + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "hyper 1.2.0", + "pin-project-lite", + "socket2", + "tokio", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -1062,18 +1142,18 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "itertools" -version = "0.10.5" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" dependencies = [ "either", ] [[package]] name = "itertools" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ "either", ] @@ -1110,9 +1190,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.152" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "linux-raw-sys" @@ -1138,9 +1218,9 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "lru" -version = "0.11.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a83fb7698b3643a0e34f9ae6f2e8f0178c0fd42f8b59d493aa271ff3a5bf21" +checksum = "d3262e75e648fce39813cb56ac41f3c3e3f65217ebf3844d818d1f9398cfb0dc" dependencies = [ "hashbrown 0.14.3", ] @@ -1203,9 +1283,9 @@ dependencies = [ [[package]] name = "mockall" -version = "0.11.4" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c84490118f2ee2d74570d114f3d0493cbf02790df303d2707606c3e14e07c96" +checksum = "43766c2b5203b10de348ffe19f7e54564b64f3d6018ff7648d1e2d6d3a0f0a48" dependencies = [ "cfg-if", "downcast", @@ -1218,14 +1298,14 @@ dependencies = [ [[package]] name = "mockall_derive" -version = "0.11.4" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ce75669015c4f47b289fd4d4f56e894e4c96003ffdf3ac51313126f94c6cbb" +checksum = "af7cbce79ec385a1d4f54baa90a76401eb15d9cab93685f62e7e9f942aa00ae2" dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.48", ] [[package]] @@ -1236,12 +1316,13 @@ checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" [[package]] name = "nix" -version = "0.27.1" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" +checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ "bitflags 2.4.1", "cfg-if", + "cfg_aliases", "libc", ] @@ -1257,12 +1338,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" -[[package]] -name = "normalize-line-endings" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" - [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -1315,13 +1390,12 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "opentelemetry" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e32339a5dc40459130b3bd269e9892439f55b33e772d2a9d402a789baaf4e8a" +checksum = "900d57987be3f2aeb70d385fff9b27fb74c5723cc9a52d904d4f9c807a0667bf" dependencies = [ "futures-core", "futures-sink", - "indexmap 2.1.0", "js-sys", "once_cell", "pin-project-lite", @@ -1331,13 +1405,13 @@ dependencies = [ [[package]] name = "opentelemetry-otlp" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f24cda83b20ed2433c68241f918d0f6fdec8b1d43b7a9590ab4420c5095ca930" +checksum = "1a016b8d9495c639af2145ac22387dcb88e44118e45320d9238fbf4e7889abcb" dependencies = [ "async-trait", "futures-core", - "http", + "http 0.2.11", "opentelemetry", "opentelemetry-proto", "opentelemetry-semantic-conventions", @@ -1350,9 +1424,9 @@ dependencies = [ [[package]] name = "opentelemetry-prometheus" -version = "0.14.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f8f082da115b0dcb250829e3ed0b8792b8f963a1ad42466e48422fbe6a079bd" +checksum = "30bbcf6341cab7e2193e5843f0ac36c446a5b3fccb28747afaeda17996dcd02e" dependencies = [ "once_cell", "opentelemetry", @@ -1363,9 +1437,9 @@ dependencies = [ [[package]] name = "opentelemetry-proto" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2e155ce5cc812ea3d1dffbd1539aed653de4bf4882d60e6e04dcf0901d674e1" +checksum = "3a8fddc9b68f5b80dae9d6f510b88e02396f006ad48cac349411fbecc80caae4" dependencies = [ "opentelemetry", "opentelemetry_sdk", @@ -1375,18 +1449,15 @@ dependencies = [ [[package]] name = "opentelemetry-semantic-conventions" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5774f1ef1f982ef2a447f6ee04ec383981a3ab99c8e77a1a7b30182e65bbc84" -dependencies = [ - "opentelemetry", -] +checksum = "f9ab5bd6c42fb9349dcf28af2ba9a0667f697f9bdcca045d39f2cec5543e2910" [[package]] name = "opentelemetry_sdk" -version = "0.21.2" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f16aec8a98a457a52664d69e0091bac3a0abd18ead9b641cb00202ba4e0efe4" +checksum = "9e90c7113be649e31e9a0f8b5ee24ed7a16923b322c3c5ab6367469c049d6b7e" dependencies = [ "async-trait", "crossbeam-channel", @@ -1539,16 +1610,12 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "predicates" -version = "2.1.5" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59230a63c37f3e18569bdb90e4a89cbf5bf8b06fea0b84e65ea10cc4df47addd" +checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8" dependencies = [ - "difflib", - "float-cmp", - "itertools 0.10.5", - "normalize-line-endings", + "anstyle", "predicates-core", - "regex", ] [[package]] @@ -1569,12 +1636,12 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.1.25" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" +checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" dependencies = [ "proc-macro2", - "syn 1.0.109", + "syn 2.0.48", ] [[package]] @@ -1603,9 +1670,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.11.9" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" +checksum = "146c289cda302b98a28d40c8b3b90498d6e526dd24ac2ecea73e4e491685b94a" dependencies = [ "bytes", "prost-derive", @@ -1613,53 +1680,53 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.11.9" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" +checksum = "c55e02e35260070b6f716a2423c2ff1c3bb1642ddca6f99e1f26d06268a0e2d2" dependencies = [ "bytes", "heck", - "itertools 0.10.5", - "lazy_static", + "itertools 0.11.0", "log", "multimap", + "once_cell", "petgraph", "prettyplease", "prost", "prost-types", "regex", - "syn 1.0.109", + "syn 2.0.48", "tempfile", "which", ] [[package]] name = "prost-derive" -version = "0.11.9" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" +checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e" dependencies = [ "anyhow", - "itertools 0.10.5", + "itertools 0.11.0", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.48", ] [[package]] name = "prost-types" -version = "0.11.9" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" +checksum = "193898f59edcf43c26227dcd4c8427f00d99d61e95dcde58dabd49fa291d470e" dependencies = [ "prost", ] [[package]] name = "prost-wkt" -version = "0.4.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "562788060bcf2bfabe055194bd991ed2442457661744c88e0a0828ff9a08c08b" +checksum = "4d8ef9c3f0f1dab910d2b7e2c24a8e4322e122eba6d7a1921eeebcebbc046c40" dependencies = [ "chrono", "inventory", @@ -1672,9 +1739,9 @@ dependencies = [ [[package]] name = "prost-wkt-build" -version = "0.4.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4dca8bcead3b728a6a7da017cc95e7f4cb2320ec4f6896bc593a1c4700f7328" +checksum = "5b31cae9a54ca84fee1504740a82eebf2479532905e106f63ca0c3bc8d780321" dependencies = [ "heck", "prost", @@ -1685,9 +1752,9 @@ dependencies = [ [[package]] name = "prost-wkt-types" -version = "0.4.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2377c5680f2342871823045052e791b4487f7c90aae17e0feaee24cf59578a34" +checksum = "435be4a8704091b4c5fb1d79799de7f2dbff53af05edf29385237f8cf7ab37ee" dependencies = [ "chrono", "prost", @@ -1844,10 +1911,10 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2", - "http", - "http-body", - "hyper", + "h2 0.3.24", + "http 0.2.11", + "http-body 0.4.6", + "hyper 0.14.28", "hyper-rustls", "ipnet", "js-sys", @@ -1856,14 +1923,14 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls", - "rustls-pemfile", + "rustls 0.21.10", + "rustls-pemfile 1.0.4", "serde", "serde_json", "serde_urlencoded", "system-configuration", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tokio-util", "tower-service", "url", @@ -1957,18 +2024,33 @@ checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" dependencies = [ "log", "ring", - "rustls-webpki", + "rustls-webpki 0.101.7", "sct", ] +[[package]] +name = "rustls" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e87c9956bd9807afa1f77e0f7594af32566e830e088a5576d27c5b6f30f49d41" +dependencies = [ + "log", + "ring", + "rustls-pki-types", + "rustls-webpki 0.102.2", + "subtle", + "zeroize", +] + [[package]] name = "rustls-native-certs" -version = "0.6.3" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792" dependencies = [ "openssl-probe", - "rustls-pemfile", + "rustls-pemfile 2.1.1", + "rustls-pki-types", "schannel", "security-framework", ] @@ -1982,6 +2064,22 @@ dependencies = [ "base64", ] +[[package]] +name = "rustls-pemfile" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f48172685e6ff52a556baa527774f61fcaa884f59daf3375c62a3f1cd2549dab" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ede67b28608b4c60685c7d54122d4400d90f62b40caee7700e700380a390fa8" + [[package]] name = "rustls-webpki" version = "0.101.7" @@ -1992,6 +2090,17 @@ dependencies = [ "untrusted", ] +[[package]] +name = "rustls-webpki" +version = "0.102.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -2167,9 +2276,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "socket2" @@ -2283,9 +2392,8 @@ dependencies = [ "derive_more", "futures", "futures-retry", - "http", + "http 0.2.11", "once_cell", - "opentelemetry", "parking_lot", "prost-types", "slotmap", @@ -2309,7 +2417,6 @@ dependencies = [ "futures", "libc", "log", - "parking_lot", "prost", "prost-types", "rand", @@ -2332,7 +2439,6 @@ name = "temporal-sdk-core" version = "0.1.0" dependencies = [ "anyhow", - "arc-swap", "async-trait", "base64", "crossbeam-channel", @@ -2346,9 +2452,10 @@ dependencies = [ "futures", "futures-util", "governor", - "http", - "hyper", - "itertools 0.11.0", + "http-body-util", + "hyper 1.2.0", + "hyper-util", + "itertools 0.12.1", "log", "lru", "mockall", @@ -2382,7 +2489,6 @@ dependencies = [ "tonic", "tonic-build", "tracing", - "tracing-futures", "tracing-subscriber", "url", "uuid", @@ -2558,7 +2664,18 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls", + "rustls 0.21.10", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" +dependencies = [ + "rustls 0.22.2", + "rustls-pki-types", "tokio", ] @@ -2598,29 +2715,28 @@ dependencies = [ [[package]] name = "tonic" -version = "0.9.2" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3082666a3a6433f7f511c7192923fa1fe07c69332d3c6a2e6bb040b569199d5a" +checksum = "76c4eb7a4e9ef9d4763600161f12f5070b92a578e1b634db88a6887844c91a13" dependencies = [ "async-stream", "async-trait", "axum", "base64", "bytes", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", + "h2 0.3.24", + "http 0.2.11", + "http-body 0.4.6", + "hyper 0.14.28", "hyper-timeout", "percent-encoding", "pin-project", "prost", "rustls-native-certs", - "rustls-pemfile", + "rustls-pemfile 2.1.1", + "rustls-pki-types", "tokio", - "tokio-rustls", + "tokio-rustls 0.25.0", "tokio-stream", "tower", "tower-layer", @@ -2630,15 +2746,15 @@ dependencies = [ [[package]] name = "tonic-build" -version = "0.9.2" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6fdaae4c2c638bb70fe42803a26fbd6fc6ac8c72f5c59f67ecc2a2dcabf4b07" +checksum = "be4ef6dd70a610078cb4e338a0f79d06bc759ff1b22d2120c2ff02ae264ba9c2" dependencies = [ "prettyplease", "proc-macro2", "prost-build", "quote", - "syn 1.0.109", + "syn 2.0.48", ] [[package]] @@ -2706,16 +2822,6 @@ dependencies = [ "valuable", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project", - "tracing", -] - [[package]] name = "tracing-log" version = "0.2.0" @@ -3173,6 +3279,12 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "zeroize" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" + [[package]] name = "zip" version = "0.6.6" diff --git a/src/Temporalio/Bridge/Cargo.toml b/src/Temporalio/Bridge/Cargo.toml index 41973044..bf2910a3 100644 --- a/src/Temporalio/Bridge/Cargo.toml +++ b/src/Temporalio/Bridge/Cargo.toml @@ -12,9 +12,8 @@ anyhow = "1.0" futures = "0.3" libc = "0.2" log = "0.4" -parking_lot = "0.12" -prost = "0.11" -prost-types = "0.11" +prost = "0.12" +prost-types = "0.12" # We rely on Cargo semver rules not updating a 0.x to 0.y. Per the rand # documentation, before 1.0, minor 0.x updates _can_ break portability which can # cause non-determinism. @@ -28,7 +27,7 @@ temporal-sdk-core-protos = { version = "0.1.0", path = "./sdk-core/sdk-core-prot tokio = "1.26" tokio-stream = "0.1" tokio-util = "0.7" -tonic = "0.9" +tonic = "0.11" tracing = "0.1" url = "2.2" diff --git a/src/Temporalio/Bridge/Client.cs b/src/Temporalio/Bridge/Client.cs index 4954e497..57514c9a 100644 --- a/src/Temporalio/Bridge/Client.cs +++ b/src/Temporalio/Bridge/Client.cs @@ -84,6 +84,21 @@ public void UpdateMetadata(IEnumerable> metadata) } } + /// + /// Update client API key. + /// + /// API key to set. + public void UpdateApiKey(string? apiKey) + { + using (var scope = new Scope()) + { + unsafe + { + Interop.Methods.client_update_api_key(Ptr, scope.ByteArray(apiKey)); + } + } + } + /// /// Make RPC call to Temporal. /// diff --git a/src/Temporalio/Bridge/Interop/Interop.cs b/src/Temporalio/Bridge/Interop/Interop.cs index 7a5d7957..716c3e39 100644 --- a/src/Temporalio/Bridge/Interop/Interop.cs +++ b/src/Temporalio/Bridge/Interop/Interop.cs @@ -151,6 +151,9 @@ internal unsafe partial struct ClientOptions [NativeTypeName("MetadataRef")] public ByteArrayRef metadata; + [NativeTypeName("struct ByteArrayRef")] + public ByteArrayRef api_key; + [NativeTypeName("struct ByteArrayRef")] public ByteArrayRef identity; @@ -585,6 +588,9 @@ internal static unsafe partial class Methods [DllImport("temporal_sdk_bridge", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] public static extern void client_update_metadata([NativeTypeName("struct Client *")] Client* client, [NativeTypeName("struct ByteArrayRef")] ByteArrayRef metadata); + [DllImport("temporal_sdk_bridge", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void client_update_api_key([NativeTypeName("struct Client *")] Client* client, [NativeTypeName("struct ByteArrayRef")] ByteArrayRef api_key); + [DllImport("temporal_sdk_bridge", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] public static extern void client_rpc_call([NativeTypeName("struct Client *")] Client* client, [NativeTypeName("const struct RpcCallOptions *")] RpcCallOptions* options, void* user_data, [NativeTypeName("ClientRpcCallCallback")] IntPtr callback); diff --git a/src/Temporalio/Bridge/OptionsExtensions.cs b/src/Temporalio/Bridge/OptionsExtensions.cs index 4872e021..9825defe 100644 --- a/src/Temporalio/Bridge/OptionsExtensions.cs +++ b/src/Temporalio/Bridge/OptionsExtensions.cs @@ -227,6 +227,7 @@ public static unsafe Interop.ClientOptions ToInteropOptions( client_name = ClientName.Ref, client_version = ClientVersion.Ref, metadata = scope.Metadata(options.RpcMetadata), + api_key = scope.ByteArray(options.ApiKey), identity = scope.ByteArray(options.Identity), tls_options = options.Tls == null ? null : scope.Pointer(options.Tls.ToInteropOptions(scope)), diff --git a/src/Temporalio/Bridge/include/temporal-sdk-bridge.h b/src/Temporalio/Bridge/include/temporal-sdk-bridge.h index 0ae6b9d6..3a4035fd 100644 --- a/src/Temporalio/Bridge/include/temporal-sdk-bridge.h +++ b/src/Temporalio/Bridge/include/temporal-sdk-bridge.h @@ -97,6 +97,7 @@ typedef struct ClientOptions { struct ByteArrayRef client_name; struct ByteArrayRef client_version; MetadataRef metadata; + struct ByteArrayRef api_key; struct ByteArrayRef identity; const struct ClientTlsOptions *tls_options; const struct ClientRetryOptions *retry_options; @@ -405,6 +406,8 @@ void client_free(struct Client *client); void client_update_metadata(struct Client *client, struct ByteArrayRef metadata); +void client_update_api_key(struct Client *client, struct ByteArrayRef api_key); + /** * Client, options, and user data must live through callback. */ diff --git a/src/Temporalio/Bridge/sdk-core b/src/Temporalio/Bridge/sdk-core index 6ad5da2c..bcda5d9f 160000 --- a/src/Temporalio/Bridge/sdk-core +++ b/src/Temporalio/Bridge/sdk-core @@ -1 +1 @@ -Subproject commit 6ad5da2c5f8608b58e8a8cf464efd97048552ea7 +Subproject commit bcda5d9f73b082ddf6816921e15db5e68a8ce47e diff --git a/src/Temporalio/Bridge/src/client.rs b/src/Temporalio/Bridge/src/client.rs index 9ed133c2..f047abdc 100644 --- a/src/Temporalio/Bridge/src/client.rs +++ b/src/Temporalio/Bridge/src/client.rs @@ -5,9 +5,7 @@ use crate::CancellationToken; use crate::MetadataRef; use crate::UserDataHandle; -use parking_lot::RwLock; use std::str::FromStr; -use std::sync::Arc; use std::time::Duration; use temporal_client::{ ClientKeepAliveConfig, ClientOptions as CoreClientOptions, ClientOptionsBuilder, @@ -23,6 +21,7 @@ pub struct ClientOptions { client_name: ByteArrayRef, client_version: ByteArrayRef, metadata: MetadataRef, + api_key: ByteArrayRef, identity: ByteArrayRef, tls_options: *const ClientTlsOptions, retry_options: *const ClientRetryOptions, @@ -83,13 +82,6 @@ pub extern "C" fn client_connect( let runtime = unsafe { &mut *runtime }; // Convert opts let options = unsafe { &*options }; - let headers = if options.metadata.size == 0 { - None - } else { - Some(Arc::new(RwLock::new( - options.metadata.to_string_map_on_newlines(), - ))) - }; let core_options: CoreClientOptions = match options.try_into() { Ok(v) => v, Err(err) => { @@ -110,7 +102,7 @@ pub extern "C" fn client_connect( let core = runtime.core.clone(); runtime.core.tokio_handle().spawn(async move { match core_options - .connect_no_namespace(core.telemetry().get_temporal_metric_meter(), headers) + .connect_no_namespace(core.telemetry().get_temporal_metric_meter()) .await { Ok(core) => { @@ -151,6 +143,15 @@ pub extern "C" fn client_update_metadata(client: *mut Client, metadata: ByteArra .set_headers(metadata.to_string_map_on_newlines()); } +#[no_mangle] +pub extern "C" fn client_update_api_key(client: *mut Client, api_key: ByteArrayRef) { + let client = unsafe { &*client }; + client + .core + .get_client() + .set_api_key(api_key.to_option_string()); +} + #[repr(C)] pub struct RpcCallOptions { service: RpcService, @@ -441,7 +442,13 @@ impl TryFrom<&ClientOptions> for CoreClientOptions { .retry_config( unsafe { opts.retry_options.as_ref() }.map_or(RetryConfig::default(), |c| c.into()), ) - .keep_alive(unsafe { opts.keep_alive_options.as_ref() }.map(Into::into)); + .keep_alive(unsafe { opts.keep_alive_options.as_ref() }.map(Into::into)) + .headers(if opts.metadata.size == 0 { + None + } else { + Some(opts.metadata.to_string_map_on_newlines()) + }) + .api_key(opts.api_key.to_option_string()); if let Some(tls_config) = unsafe { opts.tls_options.as_ref() } { opts_builder.tls_cfg(tls_config.try_into()?); } diff --git a/src/Temporalio/Client/ITemporalConnection.cs b/src/Temporalio/Client/ITemporalConnection.cs index 51eeaff7..8b6cbda3 100644 --- a/src/Temporalio/Client/ITemporalConnection.cs +++ b/src/Temporalio/Client/ITemporalConnection.cs @@ -13,15 +13,31 @@ namespace Temporalio.Client public interface ITemporalConnection : IBridgeClientProvider { /// - /// Gets or sets the current RPC metadata (i.e. the headers). This can be updated which will - /// apply to all future calls the client makes including inside a worker. Setting this value - /// is thread safe. When setting, this will error if the client is not already connected - /// (e.g. a lazy client has not made a call). + /// Gets or sets the current RPC metadata (i.e. the headers). /// + /// + /// This can be updated which will apply to all future calls the client makes including + /// inside a worker. Setting this value is thread safe. When setting, this will error if the + /// client is not already connected (e.g. a lazy client has not made a call). + /// /// Client is not already /// connected. IReadOnlyCollection> RpcMetadata { get; set; } + /// + /// Gets or sets the current API key. + /// + /// + /// This is the "Authorization" HTTP header for every call, with "Bearer " prepended. This + /// is only set if the RPC metadata doesn't already have an "Authorization" key. This can be + /// updated which will apply to all future calls the client makes including inside a worker. + /// Setting this value is thread safe. When setting, this will error if the client is not + /// already connected (e.g. a lazy client has not made a call). + /// + /// Client is not already + /// connected. + string? ApiKey { get; set; } + /// /// Gets the raw workflow service. /// diff --git a/src/Temporalio/Client/TemporalConnection.cs b/src/Temporalio/Client/TemporalConnection.cs index e7ad3fdc..84547e5d 100644 --- a/src/Temporalio/Client/TemporalConnection.cs +++ b/src/Temporalio/Client/TemporalConnection.cs @@ -23,8 +23,10 @@ public sealed class TemporalConnection : ITemporalConnection // Not set if not lazy private readonly SemaphoreSlim? semaphoreForLazyClient; private readonly object rpcMetadataLock = new(); + private readonly object apiKeyLock = new(); private Bridge.Client? client; private IReadOnlyCollection> rpcMetadata; + private string? apiKey; private TemporalConnection(TemporalConnectionOptions options, bool lazy) { @@ -40,6 +42,7 @@ private TemporalConnection(TemporalConnectionOptions options, bool lazy) { rpcMetadata = new List>(options.RpcMetadata); } + apiKey = options.ApiKey; // Set default identity if unset options.Identity ??= System.Diagnostics.Process.GetCurrentProcess().Id + "@" @@ -78,7 +81,7 @@ public IReadOnlyCollection> RpcMetadata { throw new InvalidOperationException("Cannot set RPC metadata if client never connected"); } - lock (rpcMetadata) + lock (rpcMetadataLock) { // Set on Rust side first to prevent errors from affecting field #pragma warning disable VSTHRD002 // We know it's completed @@ -90,6 +93,35 @@ public IReadOnlyCollection> RpcMetadata } } + /// + public string? ApiKey + { + get + { + lock (apiKeyLock) + { + return apiKey; + } + } + + set + { + var client = this.client; + if (client == null) + { + throw new InvalidOperationException("Cannot set API key if client never connected"); + } + lock (apiKeyLock) + { + // Set on Rust side first to prevent errors from affecting field +#pragma warning disable VSTHRD002 // We know it's completed + client.UpdateApiKey(value); +#pragma warning restore VSTHRD002 + apiKey = value; + } + } + } + /// public WorkflowService WorkflowService { get; private init; } diff --git a/src/Temporalio/Client/TemporalConnectionOptions.cs b/src/Temporalio/Client/TemporalConnectionOptions.cs index e479056f..7a725195 100644 --- a/src/Temporalio/Client/TemporalConnectionOptions.cs +++ b/src/Temporalio/Client/TemporalConnectionOptions.cs @@ -69,6 +69,17 @@ public TemporalConnectionOptions() /// public IReadOnlyCollection>? RpcMetadata { get; set; } + /// + /// Gets or sets the API key for all calls. + /// + /// + /// This is the "Authorization" HTTP header for every call, with "Bearer " prepended. This + /// is only set if the RPC metadata doesn't already have an "Authorization" key. Note, this + /// is only the initial value, updates will not be applied. Use + /// property setter to update. + /// + public string? ApiKey { get; set; } + /// /// Gets or sets the identity for this connection. /// diff --git a/tests/Temporalio.Tests/Client/TemporalClientTests.cs b/tests/Temporalio.Tests/Client/TemporalClientTests.cs index 6728d38f..baba23ce 100644 --- a/tests/Temporalio.Tests/Client/TemporalClientTests.cs +++ b/tests/Temporalio.Tests/Client/TemporalClientTests.cs @@ -28,6 +28,7 @@ public async Task ConnectAsync_Connection_Succeeds() // Update some headers and call again // TODO(cretz): Find way to confirm this works without running our own gRPC server Client.Connection.RpcMetadata = new Dictionary { ["header"] = "value" }; + Client.Connection.ApiKey = "my-api-key"; resp = await Client.Connection.WorkflowService.GetSystemInfoAsync( new Api.WorkflowService.V1.GetSystemInfoRequest()); Assert.NotEmpty(resp.ServerVersion);