Skip to content

Commit

Permalink
Merge pull request #187 Use iam url for get token at service account …
Browse files Browse the repository at this point in the history
…cred
  • Loading branch information
rekby authored Apr 3, 2024
2 parents 6a8d37f + c63fe52 commit 60096be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions ydb/src/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl ServiceAccountCredentials {
private_key: impl Into<String>,
) -> Self {
Self {
audience_url: Self::DEFAULT_AUDIENCE.to_string(),
audience_url: Self::IAM_TOKEN_DEFAULT.to_string(),
private_key: SecretString::new(private_key.into()),
service_account_id: service_account_id.into(),
key_id: key_id.into(),
Expand Down Expand Up @@ -227,14 +227,14 @@ impl ServiceAccountCredentials {
let key: JsonKey = serde_json::from_str(json_key)?;

Ok(Self {
audience_url: Self::DEFAULT_AUDIENCE.to_string(),
audience_url: Self::IAM_TOKEN_DEFAULT.to_string(),
key_id: key.id,
service_account_id: key.service_account_id,
private_key: SecretString::new(key.private_key),
})
}

const DEFAULT_AUDIENCE: &'static str = "https://iam.api.cloud.yandex.net/iam/v1/tokens";
const IAM_TOKEN_DEFAULT: &'static str = "https://iam.api.cloud.yandex.net/iam/v1/tokens";
const JWT_TOKEN_LIFE_TIME: usize = 720; // max 3600

fn build_jwt(&self) -> YdbResult<String> {
Expand Down Expand Up @@ -286,7 +286,6 @@ impl ServiceAccountCredentials {

impl Credentials for ServiceAccountCredentials {
fn create_token(&self) -> YdbResult<TokenInfo> {
const API_URL: &'static str = "https://iam.api.cloud.yandex.net/iam/v1/tokens";
use chrono::Utc;
#[derive(Deserialize)]
struct TokenResponse {
Expand All @@ -306,7 +305,7 @@ impl Credentials for ServiceAccountCredentials {
let req = TokenRequest { jwt };
let client = reqwest::blocking::Client::new();
let res: TokenResponse = client
.request(reqwest::Method::POST, API_URL)
.request(reqwest::Method::POST, self.audience_url.clone())
.json(&req)
.send()?
.json()?;
Expand Down

0 comments on commit 60096be

Please sign in to comment.