-
Notifications
You must be signed in to change notification settings - Fork 0
chore: delte constants" #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
prestwich
wants to merge
4
commits into
main
Choose a base branch
from
prestwich/delete-constants
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use crate::{signer::LocalOrAws, tasks::oauth::SharedToken}; | ||
use alloy::signers::Signer; | ||
use eyre::bail; | ||
use init4_bin_base::deps::tracing::{self, debug, info, instrument, trace}; | ||
use oauth2::TokenResponse; | ||
use reqwest::Client; | ||
use signet_types::{SignRequest, SignResponse}; | ||
|
||
/// A quincey client for making requests to the Quincey API. | ||
#[derive(Debug, Clone)] | ||
pub enum Quincey { | ||
/// A remote quincey, this is used for production environments. | ||
/// The client will access the Quincey API over HTTP(S) via OAuth. | ||
Remote { | ||
/// The remote client. | ||
client: Client, | ||
/// The base URL for the remote API. | ||
url: reqwest::Url, | ||
/// OAuth shared token. | ||
token: SharedToken, | ||
}, | ||
/// An owned quincey, either local or AWS. This is used primarily for | ||
/// testing and development environments. The client will simulate the | ||
/// Quincey API using a local or AWS KMS key. | ||
Owned(LocalOrAws), | ||
} | ||
|
||
impl Quincey { | ||
/// Creates a new Quincey client from the provided URL and token. | ||
pub const fn new_remote(client: Client, url: reqwest::Url, token: SharedToken) -> Self { | ||
Self::Remote { client, url, token } | ||
} | ||
|
||
/// Creates a new Quincey client for making requests to the Quincey API. | ||
pub const fn new_owned(client: LocalOrAws) -> Self { | ||
Self::Owned(client) | ||
} | ||
|
||
async fn sup_owned(&self, sig_request: &SignRequest) -> eyre::Result<SignResponse> { | ||
let Self::Owned(signer) = &self else { eyre::bail!("not an owned client") }; | ||
|
||
info!("signing with owned quincey"); | ||
signer | ||
.sign_hash(&sig_request.signing_hash()) | ||
.await | ||
.map_err(Into::into) | ||
.map(|sig| SignResponse { sig, req: *sig_request }) | ||
} | ||
|
||
async fn sup_remote(&self, sig_request: &SignRequest) -> eyre::Result<SignResponse> { | ||
let Self::Remote { client, url, token } = &self else { bail!("not a remote client") }; | ||
|
||
let Some(token) = token.read() else { bail!("no token available") }; | ||
|
||
let resp: reqwest::Response = client | ||
.post(url.clone()) | ||
.json(sig_request) | ||
.bearer_auth(token.access_token().secret()) | ||
.send() | ||
.await? | ||
.error_for_status()?; | ||
|
||
let body = resp.bytes().await?; | ||
|
||
debug!(bytes = body.len(), "retrieved response body"); | ||
trace!(body = %String::from_utf8_lossy(&body), "response body"); | ||
|
||
serde_json::from_slice(&body).map_err(Into::into) | ||
} | ||
|
||
/// Get a signature for the provided request, by either using the owned | ||
/// or remote client. | ||
#[instrument(skip(self))] | ||
pub async fn get_signature(&self, sig_request: &SignRequest) -> eyre::Result<SignResponse> { | ||
match self { | ||
Self::Owned(_) => self.sup_owned(sig_request).await, | ||
Self::Remote { .. } => self.sup_remote(sig_request).await, | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intended in this commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes and explicitly flagged in the pr description. i would rather have a crash than faulty behavior