Skip to content

Commit

Permalink
feat: basic Permit client with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chesedo committed Mar 19, 2024
1 parent 4ab5f08 commit 3a01180
Show file tree
Hide file tree
Showing 5 changed files with 481 additions and 7 deletions.
113 changes: 112 additions & 1 deletion Cargo.lock

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

4 changes: 3 additions & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ headers = { workspace = true, optional = true }
http = { workspace = true, optional = true }
http-body = { workspace = true, optional = true }
hyper = { workspace = true, optional = true }
hyper-tls = { version = "0.5.0", optional = true, features = ["vendored"] }
jsonwebtoken = { workspace = true, optional = true }
once_cell = { workspace = true, optional = true }
opentelemetry = { workspace = true, optional = true }
opentelemetry_sdk = { workspace = true, optional = true }
opentelemetry-http = { workspace = true, optional = true }
Expand Down Expand Up @@ -58,6 +58,7 @@ backend = [
"axum/json",
"claims",
"hyper/client",
"hyper-tls",
"opentelemetry_sdk",
"opentelemetry-appender-tracing",
"opentelemetry-otlp",
Expand Down Expand Up @@ -103,6 +104,7 @@ test-utils = ["wiremock"]
tracing = ["dep:tracing"]

[dev-dependencies]
async-once-cell = "0.5.0"
axum = { workspace = true }
base64 = { workspace = true }
hyper = { workspace = true }
Expand Down
26 changes: 22 additions & 4 deletions common/src/backends/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use bytes::Bytes;
use headers::{ContentType, Header, HeaderMapExt};
use http::{Method, Request, StatusCode, Uri};
use hyper::{body, client::HttpConnector, Body, Client};
use hyper::{
body,
client::{connect::Connect, HttpConnector},
Body, Client,
};
use opentelemetry::global;
use opentelemetry_http::HeaderInjector;
use serde::{de::DeserializeOwned, Serialize};
Expand All @@ -10,9 +14,11 @@ use tracing::{trace, Span};
use tracing_opentelemetry::OpenTelemetrySpanExt;

pub mod gateway;
pub mod permit;
mod resource_recorder;

pub use gateway::ProjectsDal;
pub use permit::PermissionsDal;
pub use resource_recorder::ResourceDal;

#[derive(Error, Debug)]
Expand All @@ -31,18 +37,30 @@ pub enum Error {

/// `Hyper` wrapper to make request to RESTful Shuttle services easy
#[derive(Clone)]
pub struct ServicesApiClient {
client: Client<HttpConnector>,
pub struct ServicesApiClient<C: Clone = HttpConnector> {
client: Client<C>,
base: Uri,
}

impl ServicesApiClient {
impl ServicesApiClient<HttpConnector> {
fn new(base: Uri) -> Self {
Self {
client: Client::new(),
base,
}
}
}

impl<C> ServicesApiClient<C>
where
C: Connect + Clone + Send + Sync + 'static,
{
fn builder(base: Uri, connector: C) -> Self {
Self {
client: Client::builder().build(connector),
base,
}
}

pub async fn request<B: Serialize, T: DeserializeOwned, H: Header>(
&self,
Expand Down
Loading

0 comments on commit 3a01180

Please sign in to comment.