Skip to content

Commit

Permalink
Mask client secret in debug
Browse files Browse the repository at this point in the history
  • Loading branch information
c12i committed Nov 9, 2023
1 parent 624511a commit e590cb2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
13 changes: 2 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ license = "MIT"
chrono = {version = "0.4", optional = true, default-features = false, features = ["clock", "serde"] }
openssl = {version = "0.10", optional = true}
reqwest = {version = "0.11", features = ["json"]}
secrecy = "0.8.0"
serde = {version="1.0", features= ["derive"]}
serde_json = "1.0"
serde_repr = "0.1"
Expand All @@ -25,17 +26,7 @@ tokio = {version = "1", features = ["rt", "rt-multi-thread", "macros"]}
wiremock = "0.5"

[features]
default = [
"account_balance",
"b2b",
"b2c",
"bill_manager",
"c2b_register",
"c2b_simulate",
"express_request",
"transaction_reversal",
"transaction_status"
]
default = ["account_balance", "b2b", "b2c", "bill_manager", "c2b_register", "c2b_simulate", "express_request", "transaction_reversal", "transaction_status"]
account_balance = ["dep:openssl"]
b2b = ["dep:openssl"]
b2c = ["dep:openssl"]
Expand Down
7 changes: 4 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use openssl::base64;
use openssl::rsa::Padding;
use openssl::x509::X509;
use reqwest::Client as HttpClient;
use secrecy::{ExposeSecret, Secret};
use std::cell::RefCell;

/// Source: [test credentials](https://developer.safaricom.co.ke/test_credentials)
Expand All @@ -24,7 +25,7 @@ pub type MpesaResult<T> = Result<T, MpesaError>;
#[derive(Clone, Debug)]
pub struct Mpesa<Env: ApiEnvironment> {
client_key: String,
client_secret: String,
client_secret: Secret<String>,
initiator_password: RefCell<Option<String>>,
pub(crate) environment: Env,
pub(crate) http_client: HttpClient,
Expand All @@ -51,7 +52,7 @@ impl<'mpesa, Env: ApiEnvironment> Mpesa<Env> {
.expect("Error building http client");
Self {
client_key: client_key.into(),
client_secret: client_secret.into(),
client_secret: Secret::new(client_secret.into()),
initiator_password: RefCell::new(None),
environment,
http_client,
Expand Down Expand Up @@ -109,7 +110,7 @@ impl<'mpesa, Env: ApiEnvironment> Mpesa<Env> {
let response = self
.http_client
.get(&url)
.basic_auth(&self.client_key, Some(&self.client_secret))
.basic_auth(&self.client_key, Some(&self.client_secret.expose_secret()))
.send()
.await?
.error_for_status()?
Expand Down

0 comments on commit e590cb2

Please sign in to comment.