-
Notifications
You must be signed in to change notification settings - Fork 22
Environment configuration #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
dd91bde
envconfig impl
THardy98 3504fad
linting
THardy98 4d79036
fix steep type checks
THardy98 e89c4ab
Merge branch 'main' into env_config
THardy98 a79438c
formatting
THardy98 6dfaca3
Refactor envconfig classes to use Data.define for immutability
THardy98 3fb3b51
Rename hash methods to use idiomatic Ruby naming
THardy98 12d3824
Replace TLS config hash with Connection::TLSOptions object
THardy98 a3696a0
Refactor to use inline pattern instead of temporary variables
THardy98 027a1ba
Refactor to_client_connect_options to return tuple for one-liner usage
THardy98 902dbfe
Make hash methods private
THardy98 4979a3d
Remove File.exist? check by using type system for path vs data distin…
THardy98 33eccab
Use symbol keys instead of string keys in Rust FFI bridge
THardy98 1ded95f
Bump golang.org/x/net in /temporalio/test/golangworker (#303)
dependabot[bot] 0d16b46
Bump tracing-subscriber from 0.3.19 to 0.3.20 in /temporalio (#331)
dependabot[bot] 5c49d24
Reduce the scope of the illegal call tracer and other tracing fixes (…
cretz b0b337e
Remove unnecessary fully qualified import names
THardy98 928070c
Remove envconfig import in temporalio.rb
THardy98 fae411e
_source_to_path_and_data prefixed with underscore and private doc vis…
THardy98 35c2f47
TLS disabled field now optional
THardy98 5af7ceb
Rubocop fixes
THardy98 7f2f777
Steep fixes
THardy98 4a276af
Renamed envconfig.rb -> env_config.rb
THardy98 6fe479e
Pass data string as RString, Rust bridge converts to Vec
THardy98 20f28ff
Rename load_client_connect_config -> load_client_connect_options
THardy98 dee3b0a
Format envconfig.rs
THardy98 f3b478f
Merge branch 'main' into env_config
THardy98 656a511
Nits
THardy98 cde7c6f
Update core submodule
THardy98 89e03de
Revert irrelevant cancellation changes
THardy98 aeaf17a
Update Cargo.lock
THardy98 6db2dcc
Propagate set_headers failure in client bridge
THardy98 edfed08
Add experimental warning
THardy98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,241 @@ | ||
| use std::collections::HashMap; | ||
|
|
||
| use magnus::{Error, RHash, RString, Ruby, class, function, prelude::*, scan_args}; | ||
| use temporal_sdk_core_api::envconfig::{ | ||
| ClientConfig as CoreClientConfig, ClientConfigCodec, | ||
| ClientConfigProfile as CoreClientConfigProfile, ClientConfigTLS as CoreClientConfigTLS, | ||
| DataSource, LoadClientConfigOptions, LoadClientConfigProfileOptions, | ||
| load_client_config as core_load_client_config, | ||
| load_client_config_profile as core_load_client_config_profile, | ||
| }; | ||
|
|
||
| use crate::{ROOT_MOD, error}; | ||
|
|
||
| pub fn init(ruby: &Ruby) -> Result<(), Error> { | ||
| let root_mod = ruby.get_inner(&ROOT_MOD); | ||
|
|
||
| let class = root_mod.define_class("EnvConfig", class::object())?; | ||
| class.define_singleton_method("load_client_config", function!(load_client_config, -1))?; | ||
| class.define_singleton_method( | ||
| "load_client_connect_config", | ||
| function!(load_client_connect_config, -1), | ||
| )?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn data_source_to_hash(ruby: &Ruby, ds: &DataSource) -> Result<RHash, Error> { | ||
| let hash = RHash::new(); | ||
| match ds { | ||
| DataSource::Path(p) => { | ||
| hash.aset(ruby.sym_new("path"), ruby.str_new(p))?; | ||
| } | ||
| DataSource::Data(d) => { | ||
| hash.aset(ruby.sym_new("data"), ruby.str_from_slice(d))?; | ||
| } | ||
| } | ||
| Ok(hash) | ||
| } | ||
|
|
||
| fn tls_to_hash(ruby: &Ruby, tls: &CoreClientConfigTLS) -> Result<RHash, Error> { | ||
| let hash = RHash::new(); | ||
| hash.aset(ruby.sym_new("disabled"), tls.disabled)?; | ||
|
|
||
| if let Some(v) = &tls.client_cert { | ||
| hash.aset(ruby.sym_new("client_cert"), data_source_to_hash(ruby, v)?)?; | ||
| } | ||
| if let Some(v) = &tls.client_key { | ||
| hash.aset(ruby.sym_new("client_key"), data_source_to_hash(ruby, v)?)?; | ||
| } | ||
| if let Some(v) = &tls.server_ca_cert { | ||
| hash.aset( | ||
| ruby.sym_new("server_ca_cert"), | ||
| data_source_to_hash(ruby, v)?, | ||
| )?; | ||
| } | ||
| if let Some(v) = &tls.server_name { | ||
| hash.aset(ruby.sym_new("server_name"), ruby.str_new(v))?; | ||
| } | ||
| hash.aset( | ||
| ruby.sym_new("disable_host_verification"), | ||
| tls.disable_host_verification, | ||
| )?; | ||
|
|
||
| Ok(hash) | ||
| } | ||
|
|
||
| fn codec_to_hash(ruby: &Ruby, codec: &ClientConfigCodec) -> Result<RHash, Error> { | ||
| let hash = RHash::new(); | ||
| if let Some(v) = &codec.endpoint { | ||
| hash.aset(ruby.sym_new("endpoint"), ruby.str_new(v))?; | ||
| } | ||
| if let Some(v) = &codec.auth { | ||
| hash.aset(ruby.sym_new("auth"), ruby.str_new(v))?; | ||
| } | ||
| Ok(hash) | ||
| } | ||
|
|
||
| fn profile_to_hash(ruby: &Ruby, profile: &CoreClientConfigProfile) -> Result<RHash, Error> { | ||
| let hash = RHash::new(); | ||
|
|
||
| if let Some(v) = &profile.address { | ||
| hash.aset(ruby.sym_new("address"), ruby.str_new(v))?; | ||
| } | ||
| if let Some(v) = &profile.namespace { | ||
| hash.aset(ruby.sym_new("namespace"), ruby.str_new(v))?; | ||
| } | ||
| if let Some(v) = &profile.api_key { | ||
| hash.aset(ruby.sym_new("api_key"), ruby.str_new(v))?; | ||
| } | ||
| if let Some(tls) = &profile.tls { | ||
| hash.aset(ruby.sym_new("tls"), tls_to_hash(ruby, tls)?)?; | ||
| } | ||
| if let Some(codec) = &profile.codec { | ||
| hash.aset(ruby.sym_new("codec"), codec_to_hash(ruby, codec)?)?; | ||
| } | ||
| if !profile.grpc_meta.is_empty() { | ||
| let grpc_meta_hash = RHash::new(); | ||
| for (k, v) in &profile.grpc_meta { | ||
| grpc_meta_hash.aset(ruby.str_new(k), ruby.str_new(v))?; | ||
| } | ||
| hash.aset(ruby.sym_new("grpc_meta"), grpc_meta_hash)?; | ||
| } | ||
|
|
||
| Ok(hash) | ||
| } | ||
|
|
||
| fn core_config_to_hash(ruby: &Ruby, core_config: &CoreClientConfig) -> Result<RHash, Error> { | ||
| let profiles_hash = RHash::new(); | ||
| for (name, profile) in &core_config.profiles { | ||
| let profile_hash = profile_to_hash(ruby, profile)?; | ||
| profiles_hash.aset(ruby.str_new(name), profile_hash)?; | ||
| } | ||
| Ok(profiles_hash) | ||
| } | ||
|
|
||
| fn load_client_config_inner( | ||
| ruby: &Ruby, | ||
| config_source: Option<DataSource>, | ||
| config_file_strict: bool, | ||
| disable_file: bool, | ||
| env_vars: Option<HashMap<String, String>>, | ||
| ) -> Result<RHash, Error> { | ||
| let core_config = if disable_file { | ||
| CoreClientConfig::default() | ||
| } else { | ||
| let options = LoadClientConfigOptions { | ||
| config_source, | ||
| config_file_strict, | ||
| }; | ||
| core_load_client_config(options, env_vars.as_ref()) | ||
| .map_err(|e| error!("EnvConfig error: {}", e))? | ||
| }; | ||
|
|
||
| core_config_to_hash(ruby, &core_config) | ||
| } | ||
|
|
||
| fn load_client_connect_config_inner( | ||
| ruby: &Ruby, | ||
| config_source: Option<DataSource>, | ||
| profile: Option<String>, | ||
| disable_file: bool, | ||
| disable_env: bool, | ||
| config_file_strict: bool, | ||
| env_vars: Option<HashMap<String, String>>, | ||
| ) -> Result<RHash, Error> { | ||
| let options = LoadClientConfigProfileOptions { | ||
| config_source, | ||
| config_file_profile: profile, | ||
| config_file_strict, | ||
| disable_file, | ||
| disable_env, | ||
| }; | ||
|
|
||
| let profile = core_load_client_config_profile(options, env_vars.as_ref()) | ||
| .map_err(|e| error!("EnvConfig error: {}", e))?; | ||
|
|
||
| profile_to_hash(ruby, &profile) | ||
| } | ||
|
|
||
| // load_client_config(path: String|nil, data: String|nil, disable_file: bool, config_file_strict: bool, env_vars: Hash|nil) | ||
| fn load_client_config(args: &[magnus::Value]) -> Result<RHash, Error> { | ||
| let ruby = Ruby::get().expect("Not in Ruby thread"); | ||
| let args = scan_args::scan_args::< | ||
| (Option<String>, Option<RString>, bool, bool), | ||
| (Option<HashMap<String, String>>,), | ||
| (), | ||
| (), | ||
| (), | ||
| (), | ||
| >(args)?; | ||
| let (path, data, disable_file, config_file_strict) = args.required; | ||
| let (env_vars,) = args.optional; | ||
|
|
||
| let config_source = match (path, data) { | ||
| (Some(p), None) => Some(DataSource::Path(p)), | ||
| (None, Some(d)) => { | ||
| let bytes = unsafe { d.as_slice().to_vec() }; | ||
| Some(DataSource::Data(bytes)) | ||
| } | ||
| (None, None) => None, | ||
| (Some(_), Some(_)) => { | ||
| return Err(error!( | ||
| "Cannot specify both path and data for config source" | ||
| )); | ||
| } | ||
| }; | ||
|
|
||
| load_client_config_inner( | ||
| &ruby, | ||
| config_source, | ||
| config_file_strict, | ||
| disable_file, | ||
| env_vars, | ||
| ) | ||
| } | ||
|
|
||
| // load_client_connect_config(profile: String|nil, path: String|nil, data: String|nil, disable_file: bool, disable_env: bool, config_file_strict: bool, env_vars: Hash|nil) | ||
| fn load_client_connect_config(args: &[magnus::Value]) -> Result<RHash, Error> { | ||
| let ruby = Ruby::get().expect("Not in Ruby thread"); | ||
| let args = scan_args::scan_args::< | ||
| ( | ||
| Option<String>, | ||
| Option<String>, | ||
| Option<RString>, | ||
| bool, | ||
| bool, | ||
| bool, | ||
| ), | ||
| (Option<HashMap<String, String>>,), | ||
| (), | ||
| (), | ||
| (), | ||
| (), | ||
| >(args)?; | ||
| let (profile, path, data, disable_file, disable_env, config_file_strict) = args.required; | ||
| let (env_vars,) = args.optional; | ||
|
|
||
| let config_source = match (path, data) { | ||
| (Some(p), None) => Some(DataSource::Path(p)), | ||
| (None, Some(d)) => { | ||
| let bytes = unsafe { d.as_slice().to_vec() }; | ||
| Some(DataSource::Data(bytes)) | ||
| } | ||
| (None, None) => None, | ||
| (Some(_), Some(_)) => { | ||
| return Err(error!( | ||
| "Cannot specify both path and data for config source" | ||
| )); | ||
| } | ||
| }; | ||
|
|
||
| load_client_connect_config_inner( | ||
| &ruby, | ||
| config_source, | ||
| profile, | ||
| disable_file, | ||
| disable_env, | ||
| config_file_strict, | ||
| env_vars, | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to just accept a defined-in-Ruby struct options set as we do in other Rust-from-Ruby calls if that makes it cleaner once it gets to this many parameters