Skip to content

Commit

Permalink
refactor!: Remove config
Browse files Browse the repository at this point in the history
  • Loading branch information
sirewix committed Jul 23, 2024
1 parent 8b88836 commit ec9cff9
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,6 @@ struct Token {
expiry: time::OffsetDateTime,
}

pub struct Config {
url: Url,
service_account_file: PathBuf,
}

impl Config {
/// Create a Zitadel client config
///
/// - `url` should point to the Zitadel instance the client is for
/// - `service_account_file` should be the Zitadel-generated
/// private key file as documented here:
/// https://zitadel.com/docs/guides/integrate/service-users/private-key-jwt#2-generate-a-private-key-file
pub fn new(url: Url, service_account_file: PathBuf) -> Self {
Self { url, service_account_file }
}
}

/// Create a new tonic channel with specified endpoint. Uses http proxy if
/// able.
async fn get_channel(api_endpoint: &str) -> Result<Channel> {
Expand Down Expand Up @@ -224,11 +207,15 @@ fn wrap_intercept_with_no_proxy(

impl Zitadel {
/// Builds a new Zitadel instance.
/// - `url` should point to the Zitadel instance the client is for
/// - `service_account_file` should be the Zitadel-generated
/// private key file as documented here:
/// https://zitadel.com/docs/guides/integrate/service-users/private-key-jwt#2-generate-a-private-key-file
#[tracing::instrument(level = "debug", skip_all)]
pub async fn new(config: &Config) -> Result<Self> {
pub async fn new(url: Url, service_account_file: PathBuf) -> Result<Self> {
// Zitadel matches this against the OIDC issuer, which is set
// to not have a trailing slash
let audience = config.url.as_str().trim_end_matches('/');
let audience = url.as_str().trim_end_matches('/');

// Wait for Zitadel instance to become ready.
/*
Expand All @@ -238,7 +225,7 @@ impl Zitadel {
.change_context(Error::Zitadel)?;
*/
let service_account = ServiceAccount::load_from_json(
std::fs::read_to_string(&config.service_account_file)?.as_ref(),
std::fs::read_to_string(&service_account_file)?.as_ref(),
)?;
let auth_options = AuthenticationOptions { api_access: true, ..Default::default() };

Expand All @@ -247,13 +234,13 @@ impl Zitadel {
expiry: time::OffsetDateTime::now_utc() + time::Duration::minutes(59),
}));

let channel = get_channel(config.url.as_str()).await?;
let channel = get_channel(url.as_str()).await?;
let admin_client = AdminServiceClient::new(channel);

let channel = get_channel(config.url.as_str()).await?;
let channel = get_channel(url.as_str()).await?;
let management_client = ManagementServiceClient::new(channel);

let channel = get_channel(config.url.as_str()).await?;
let channel = get_channel(url.as_str()).await?;
let auth_client = AuthServiceClient::new(channel);

Ok(Zitadel {
Expand Down

0 comments on commit ec9cff9

Please sign in to comment.