Skip to content

Commit

Permalink
Add CloudSessionBuilder construction from existing CloudConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHargrave authored and RomanHargraveRC committed Jan 29, 2025
1 parent 8e65567 commit 6b4bb35
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions scylla/src/client/session_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,10 @@ impl GenericSessionBuilder<DefaultMode> {
// here, but rather in `impl<K> GenericSessionBuilder<K>` block.
#[cfg(feature = "cloud")]
impl CloudSessionBuilder {
/// Creates a new SessionBuilder with default configuration,
/// based on provided path to Scylla Cloud Config yaml.
pub fn new(cloud_config: impl AsRef<Path>) -> Result<Self, CloudConfigError> {
/// Creates a new SessionBuilder with default configuration, based
/// on the provided [`CloudConfig`].
pub fn from_config(cloud_config: CloudConfig) -> Self {
let mut config = SessionConfig::new();
let cloud_config = CloudConfig::read_from_yaml(cloud_config)?;
let mut exec_profile_builder = ExecutionProfile::builder();
if let Some(default_consistency) = cloud_config.get_default_consistency() {
exec_profile_builder = exec_profile_builder.consistency(default_consistency);
Expand All @@ -380,10 +379,17 @@ impl CloudSessionBuilder {
}
config.default_execution_profile_handle = exec_profile_builder.build().into_handle();
config.cloud_config = Some(Arc::new(cloud_config));
Ok(CloudSessionBuilder {
CloudSessionBuilder {
config,
kind: PhantomData,
})
}
}

/// Creates a new SessionBuilder with default configuration,
/// based on provided path to Scylla Cloud Config yaml.
pub fn new(cloud_config: impl AsRef<Path>) -> Result<Self, CloudConfigError> {
let cloud_config = CloudConfig::read_from_yaml(cloud_config)?;
Ok(Self::from_config(cloud_config))
}
}

Expand Down

0 comments on commit 6b4bb35

Please sign in to comment.