Skip to content

Commit

Permalink
google-apis-rs#36 use the "PUBSUB_EMULATOR_HOST" environment variable…
Browse files Browse the repository at this point in the history
… if present
  • Loading branch information
Tarkin25 committed Feb 8, 2022
1 parent e356904 commit 9be4b31
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions google-cloud/src/pubsub/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,24 @@ impl Client {
project_name: impl Into<String>,
creds: ApplicationCredentials,
) -> Result<Client, Error> {
let tls_config = ClientTlsConfig::new()
.ca_certificate(Certificate::from_pem(TLS_CERTS))
.domain_name(Client::DOMAIN_NAME);

let channel = Channel::from_static(Client::ENDPOINT)
.tls_config(tls_config)?
.connect()
.await?;
let endpoint_str = env::var("PUBSUB_EMULATOR_HOST")
.map(|s| format!("http://{}", s))
.map(|s| &*Box::leak(s.into_boxed_str()))
.unwrap_or(Client::ENDPOINT);

let endpoint = Channel::from_static(endpoint_str);

let endpoint = if endpoint_str.starts_with("https") {
let tls_config = ClientTlsConfig::new()
.ca_certificate(Certificate::from_pem(TLS_CERTS))
.domain_name(Client::DOMAIN_NAME);

endpoint.tls_config(tls_config)?
} else {
endpoint
};

let channel = endpoint.connect().await?;

Ok(Client {
project_name: project_name.into(),
Expand Down

0 comments on commit 9be4b31

Please sign in to comment.