Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
feat!: Removed generic lifetime parameter from DapsClient to make the…
Browse files Browse the repository at this point in the history
… usage easier

BREAKING CHANGE: DapsClient lost its lifetime parameter
  • Loading branch information
schoenenberg committed Sep 30, 2024
1 parent 41ccaa4 commit 2c0f51c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.1] - 2024-09-30

### Changed

- Removed generic lifetime parameter from DapsClient to make the usage easier

## [0.2.0] - 2024-09-30

### Changed
Expand All @@ -14,5 +20,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Moved the CertificatesCache to its own module and added a test for it
- Bump dependencies

[0.2.1]: https://github.com///compare/v0.2.0..0.2.1

<!-- generated by git-cliff -->
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ edition = "2021"

name = "ids-daps-client"
description = "A client to connect with the IDS DAPS."
version = "0.2.0"
version = "0.2.1"
license = "Apache-2.0"
repository = "https://github.com/truzzt/ids-daps-client-rs"
readme = "README.md"
Expand Down
3 changes: 2 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::borrow::Cow;
/// Configuration for the DAPS client.
#[derive(Debug, derive_builder::Builder)]
#[builder(setter(into), build_fn(validate = "Self::validate"))]
#[allow(clippy::module_name_repetitions)]
pub struct DapsConfig<'a> {
/// The URL for the request of a DAPS token.
pub(super) token_url: Cow<'a, str>,
Expand Down Expand Up @@ -46,4 +47,4 @@ impl DapsConfigBuilder<'_> {
}
Ok(())
}
}
}
22 changes: 10 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
//! .expect("Failed to build DAPS-Config");
//!
//! // Create DAPS client
//! let client: ReqwestDapsClient<'_> = DapsClient::new(config);
//! let client: ReqwestDapsClient = DapsClient::new(&config);
//!
//! // Request a DAT token
//! let dat = client.request_dat().await?;
Expand All @@ -68,8 +68,6 @@ pub mod cert;
pub mod config;
mod http_client;

use std::borrow::Cow;

/// The type of the audience field in the DAT token. It can be a single string or a list of strings.
#[derive(Debug, serde::Deserialize, Clone)]
#[serde(untagged)]
Expand Down Expand Up @@ -142,15 +140,15 @@ pub enum DapsError {
}

/// An alias for the DAPS client using the Reqwest HTTP client.
pub type ReqwestDapsClient<'a> = DapsClient<'a, http_client::reqwest_client::ReqwestDapsClient>;
pub type ReqwestDapsClient = DapsClient<http_client::reqwest_client::ReqwestDapsClient>;

/// The main struct of this crate. It provides the functionality to request and validate DAT tokens
/// from a DAPS.
pub struct DapsClient<'a, C> {
pub struct DapsClient<C> {
/// The HTTP client to use for requests. It is generic over the actual implementation.
client: C,
/// The subject of the client.
sub: Cow<'a, str>,
sub: String,
/// The URL for the request of the certificates for validation.
certs_url: String,
/// The URL for the request of a DAPS token.
Expand All @@ -165,13 +163,13 @@ pub struct DapsClient<'a, C> {
certs_cache: cache::CertificatesCache,
}

impl<C> DapsClient<'_, C>
impl<C> DapsClient<C>
where
C: http_client::DapsClientRequest,
{
/// Creates a new DAPS client based on the given configuration.
#[must_use]
pub fn new(config: config::DapsConfig<'_>) -> Self {
pub fn new(config: &config::DapsConfig<'_>) -> Self {
// Read sub and private key from file
let (ski_aki, private_key) = cert::ski_aki_and_private_key_from_file(
config.private_key.as_ref(),
Expand All @@ -184,7 +182,7 @@ where

Self {
client: C::default(),
sub: ski_aki,
sub: ski_aki.to_string(),
scope: config.scope.to_string(),
certs_url: config.certs_url.to_string(),
token_url: config.token_url.to_string(),
Expand Down Expand Up @@ -356,14 +354,14 @@ mod test {
.certs_url(certs_url)
.token_url(token_url)
.private_key(std::path::Path::new("./testdata/connector-certificate.p12"))
.private_key_password(Some(Cow::from("Password1")))
.scope(Cow::from("idsc:IDS_CONNECTORS_ALL"))
.private_key_password(Some(std::borrow::Cow::from("Password1")))
.scope(std::borrow::Cow::from("idsc:IDS_CONNECTORS_ALL"))
.certs_cache_ttl(1_u64)
.build()
.expect("Failed to build DAPS-Config");

// Create DAPS client
let client: ReqwestDapsClient<'_> = DapsClient::new(config);
let client: ReqwestDapsClient = DapsClient::new(&config);

// Now the test really starts...
// Request a DAT token
Expand Down

0 comments on commit 2c0f51c

Please sign in to comment.