Skip to content

Commit

Permalink
Allow directly passing SecretString (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep authored Mar 15, 2024
1 parent 71a45f7 commit 388c185
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/api/checks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use chrono::{DateTime, Utc};
use hyper::body::Body;

use crate::models::checks::{AutoTriggerCheck, CheckSuite, CheckSuitePreferences};
use crate::models::{AppId, CheckRunId, CheckSuiteId};
Expand Down
13 changes: 6 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,8 @@ impl OctocrabBuilder<NoSvc, DefaultOctocrabBuilderConfig, NoAuth, NotLayerReady>
}

/// Add a personal token to use for authentication.
pub fn personal_token(mut self, token: String) -> Self {
self.config.auth = Auth::PersonalToken(SecretString::new(token));
pub fn personal_token<S: Into<SecretString>>(mut self, token: S) -> Self {
self.config.auth = Auth::PersonalToken(token.into());
self
}

Expand All @@ -547,8 +547,8 @@ impl OctocrabBuilder<NoSvc, DefaultOctocrabBuilderConfig, NoAuth, NotLayerReady>
}

/// Authenticate with a user access token.
pub fn user_access_token(mut self, token: String) -> Self {
self.config.auth = Auth::UserAccessToken(SecretString::new(token));
pub fn user_access_token<S: Into<SecretString>>(mut self, token: S) -> Self {
self.config.auth = Auth::UserAccessToken(token.into());
self
}

Expand Down Expand Up @@ -834,9 +834,8 @@ impl CachedToken {
self.valid_token_with_buffer(chrono::Duration::seconds(30))
}

fn set(&self, token: String, expiration: Option<DateTime<Utc>>) {
*self.0.write().unwrap() =
Some(CachedTokenInner::new(SecretString::new(token), expiration));
fn set<S: Into<SecretString>>(&self, token: S, expiration: Option<DateTime<Utc>>) {
*self.0.write().unwrap() = Some(CachedTokenInner::new(token.into(), expiration));
}
}

Expand Down

0 comments on commit 388c185

Please sign in to comment.