Skip to content

Commit d9f3b92

Browse files
authored
Merge pull request #703 from Gor027/move-ssl-from-cloud
Allow ssl-context only for non-cloud session builder
2 parents 58e0d53 + 3276af0 commit d9f3b92

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

scylla/src/transport/session_builder.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,38 @@ impl SessionBuilder {
328328
self.config.enable_write_coalescing = enable;
329329
self
330330
}
331+
332+
/// ssl feature
333+
/// Provide SessionBuilder with SslContext from openssl crate that will be
334+
/// used to create an ssl connection to the database.
335+
/// If set to None SSL connection won't be used.
336+
/// Default is None.
337+
///
338+
/// # Example
339+
/// ```
340+
/// # use std::fs;
341+
/// # use std::path::PathBuf;
342+
/// # use scylla::{Session, SessionBuilder};
343+
/// # use openssl::ssl::{SslContextBuilder, SslVerifyMode, SslMethod, SslFiletype};
344+
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
345+
/// let certdir = fs::canonicalize(PathBuf::from("./examples/certs/scylla.crt"))?;
346+
/// let mut context_builder = SslContextBuilder::new(SslMethod::tls())?;
347+
/// context_builder.set_certificate_file(certdir.as_path(), SslFiletype::PEM)?;
348+
/// context_builder.set_verify(SslVerifyMode::NONE);
349+
///
350+
/// let session: Session = SessionBuilder::new()
351+
/// .known_node("127.0.0.1:9042")
352+
/// .ssl_context(Some(context_builder.build()))
353+
/// .build()
354+
/// .await?;
355+
/// # Ok(())
356+
/// # }
357+
/// ```
358+
#[cfg(feature = "ssl")]
359+
pub fn ssl_context(mut self, ssl_context: Option<SslContext>) -> Self {
360+
self.config.ssl_context = ssl_context;
361+
self
362+
}
331363
}
332364
#[cfg(feature = "cloud")]
333365
impl CloudSessionBuilder {
@@ -497,38 +529,6 @@ impl<K: SessionBuilderKind> GenericSessionBuilder<K> {
497529
self
498530
}
499531

500-
/// ssl feature
501-
/// Provide SessionBuilder with SslContext from openssl crate that will be
502-
/// used to create an ssl connection to the database.
503-
/// If set to None SSL connection won't be used.
504-
/// Default is None.
505-
///
506-
/// # Example
507-
/// ```
508-
/// # use std::fs;
509-
/// # use std::path::PathBuf;
510-
/// # use scylla::{Session, SessionBuilder};
511-
/// # use openssl::ssl::{SslContextBuilder, SslVerifyMode, SslMethod, SslFiletype};
512-
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
513-
/// let certdir = fs::canonicalize(PathBuf::from("./examples/certs/scylla.crt"))?;
514-
/// let mut context_builder = SslContextBuilder::new(SslMethod::tls())?;
515-
/// context_builder.set_certificate_file(certdir.as_path(), SslFiletype::PEM)?;
516-
/// context_builder.set_verify(SslVerifyMode::NONE);
517-
///
518-
/// let session: Session = SessionBuilder::new()
519-
/// .known_node("127.0.0.1:9042")
520-
/// .ssl_context(Some(context_builder.build()))
521-
/// .build()
522-
/// .await?;
523-
/// # Ok(())
524-
/// # }
525-
/// ```
526-
#[cfg(feature = "ssl")]
527-
pub fn ssl_context(mut self, ssl_context: Option<SslContext>) -> Self {
528-
self.config.ssl_context = ssl_context;
529-
self
530-
}
531-
532532
/// Builds the Session after setting all the options
533533
///
534534
/// # Example

0 commit comments

Comments
 (0)