Skip to content

Commit

Permalink
Remove -types & add task management
Browse files Browse the repository at this point in the history
  • Loading branch information
tarkah committed Nov 25, 2024
1 parent 7578c34 commit 88bb2aa
Show file tree
Hide file tree
Showing 35 changed files with 281 additions and 140 deletions.
13 changes: 1 addition & 12 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ serde_json = "1.0"
sha2 = "0.10.8"
thiserror = "1.0.56"
tokio-stream = "0.1.14"
tokio-util = "0.7"
toml = "0.8.8"
tracing = "0.1.40"
url = "2.5.2"
Expand Down
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ COPY --from=rust-builder /summit .
VOLUME /app/state
VOLUME /app/config.toml
EXPOSE 5000
CMD ["/app/summit", "0.0.0.0", "--port", "5000", "--root", "/app"]
ENTRYPOINT ["/app/summit"]
CMD ["0.0.0.0", "--port", "5000", "--root", "/app"]

FROM alpine:3.20 AS vessel
WORKDIR /app
Expand All @@ -37,7 +38,8 @@ VOLUME /app/state
VOLUME /app/config.toml
VOLUME /import
EXPOSE 5001
CMD ["/app/vessel", "0.0.0.0", "--port", "5001", "--root", "/app", "--import", "/import"]
ENTRYPOINT ["/app/vessel"]
CMD ["0.0.0.0", "--port", "5001", "--root", "/app", "--import", "/import"]

FROM alpine:3.20 AS avalanche
WORKDIR /app
Expand All @@ -48,4 +50,5 @@ COPY --from=rust-builder /tools/boulder/data/macros /usr/share/boulder/macros
VOLUME /app/state
VOLUME /app/config.toml
EXPOSE 5002
CMD ["/app/avalanche", "0.0.0.0", "--port", "5002", "--root", "/app"]
ENTRYPOINT ["/app/avalanche"]
CMD ["0.0.0.0", "--port", "5002", "--root", "/app"]
1 change: 0 additions & 1 deletion crates/avalanche/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition.workspace = true

[dependencies]
service = { path = "../service" }
service-types = { path = "../service-types" }

clap.workspace = true
color-eyre.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/avalanche/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use service::{
api::{self, v1::avalanche::PackageBuild},
error, Endpoint, State,
};
use service_types::{collectable, Collectable, Remote};
use service::{collectable, Collectable, Remote};
use sha2::{Digest, Sha256};
use tokio::{
fs::{self, File},
Expand Down
17 changes: 3 additions & 14 deletions crates/avalanche/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::{net::IpAddr, path::PathBuf};

use clap::Parser;
use futures::{select, FutureExt};
use service::{signal, Role, Server, State};
use service::{Role, Server, State};
use tracing::info;

pub type Result<T, E = color_eyre::eyre::Error> = std::result::Result<T, E>;
Expand Down Expand Up @@ -30,21 +29,11 @@ async fn main() -> Result<()> {

info!("avalanche listening on {host}:{port}");

let mut http = Server::new(Role::Builder, &config, &state)
Server::new(Role::Builder, &config, &state)
.merge_api(api::service(state.clone(), config.clone()))
.serve_directory("/assets", "assets")
.start((host, port))
.boxed()
.fuse();

let mut stop = signal::capture([signal::Kind::terminate(), signal::Kind::interrupt()])
.boxed()
.fuse();

select! {
res = http => res?,
res = stop => res?,
}
.await?;

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions crates/service-core/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pub use self::operation::Operation;

pub mod operation;
pub mod v1;

/// API version
#[derive(Debug, Clone, strum::Display)]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use serde::{Deserialize, Serialize};
use service_core::operation;

use crate::Remote;
use crate::{operation, Remote};

operation!(Build, POST, "avalanche/build", ACCESS_TOKEN | SERVICE_ACCOUNT | NOT_EXPIRED, req: BuildRequestBody);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use service_core::operation;

use crate::endpoint::enrollment;
use crate::operation;

operation!(
Enroll,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use serde::{Deserialize, Serialize};
use service_core::operation;

use crate::Collectable;
use crate::{operation, Collectable};

operation!(BuildSucceeded, POST, "summit/buildSucceeded", ACCESS_TOKEN | SERVICE_ACCOUNT | NOT_EXPIRED, req: BuildBody);
operation!(BuildFailed, POST, "summit/buildFailed", ACCESS_TOKEN | SERVICE_ACCOUNT | NOT_EXPIRED, req: BuildBody);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use serde::{Deserialize, Serialize};
use service_core::operation;

use crate::Collectable;
use crate::{operation, Collectable};

operation!(Build, POST, "vessel/build", ACCESS_TOKEN | SERVICE_ACCOUNT | NOT_EXPIRED, req: BuildRequestBody);

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use serde::{Deserialize, Serialize};
use service_core::Role;

/// Core tenant in the Enrollment API
use crate::Role;

/// An endpoint enrollment request
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Request {
Expand Down
7 changes: 6 additions & 1 deletion crates/service-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
//! Primitive service types

#![warn(missing_docs)]
// #![warn(missing_docs)]

pub use self::collectable::Collectable;
pub use self::remote::Remote;
pub use self::role::Role;

pub mod api;
pub mod auth;
pub mod collectable;
pub mod endpoint;
pub mod remote;
pub mod role;
File renamed without changes.
10 changes: 0 additions & 10 deletions crates/service-types/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion crates/service-types/src/api.rs

This file was deleted.

7 changes: 0 additions & 7 deletions crates/service-types/src/lib.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition.workspace = true

[dependencies]
service-core = { path = "../service-core" }
service-types = { path = "../service-types" }

axum.workspace = true
base64.workspace = true
Expand All @@ -32,6 +31,7 @@ strum.workspace = true
thiserror.workspace = true
tokio.workspace = true
tokio-stream.workspace = true
tokio-util.workspace = true
toml.workspace = true
tower.workspace = true
tower-http.workspace = true
Expand Down
13 changes: 6 additions & 7 deletions crates/service/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@ use axum::{
};
use futures::{future::BoxFuture, FutureExt};

pub use http::Method;

use serde::Serialize;
pub use service_core::api::{
operation::{self, Operation},
Version,
};
use service_core::auth;
pub use service_types::api::v1;
use tracing::warn;

use crate::{middleware, token::VerifiedToken};

pub use service_core::api::{
operation::{self, Operation},
Version,
};

pub use self::handler::Handler;

pub mod handler;
pub mod v1;

type RawRequest = axum::extract::Request;
type RawResponse = axum::response::Response;
Expand Down
6 changes: 6 additions & 0 deletions crates/service/src/api/v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! V1 API
pub use service_core::api::v1::{avalanche, summit, vessel};

pub(crate) use services::services;

pub mod services;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use http::Uri;
use thiserror::Error;
use tracing::{debug, error, info};

pub use service_core::api::v1::services::*;

use crate::{
account, api,
crypto::{EncodedPublicKey, PublicKey},
Expand All @@ -18,14 +20,17 @@ use crate::{
token, Config, Database, Role, Token,
};

/// An implementation of the endpoint service operations
pub fn service(role: Role, config: &Config, state: &crate::State) -> api::Service {
/// An implementation of the shared service operations
//
// Provided by shared [`Server`](crate::Server)
// so doesn't need to be public
pub(crate) fn services(role: Role, config: &Config, state: &crate::State) -> api::Service {
api::Service::new()
.register::<api::v1::services::Enroll, Error, _>(enroll)
.register::<api::v1::services::Accept, Error, _>(accept)
.register::<api::v1::services::Decline, Error, _>(decline)
.register::<api::v1::services::RefreshToken, Error, _>(refresh_token)
.register::<api::v1::services::RefreshIssueToken, Error, _>(refresh_issue_token)
.register::<Enroll, Error, _>(enroll)
.register::<Accept, Error, _>(accept)
.register::<Decline, Error, _>(decline)
.register::<RefreshToken, Error, _>(refresh_token)
.register::<RefreshIssueToken, Error, _>(refresh_issue_token)
.with_state(State {
issuer: config.issuer(role, state.key_pair.clone()),
db: state.db.clone(),
Expand All @@ -36,7 +41,7 @@ pub fn service(role: Role, config: &Config, state: &crate::State) -> api::Servic

/// State for endpoint handlers
#[derive(Debug, Clone)]
pub struct State {
struct State {
/// Issuer details of this service
issuer: Issuer,
/// Shared database of this service
Expand All @@ -57,7 +62,7 @@ impl State {
}
}

async fn enroll(request: api::Request<api::v1::services::Enroll>, state: State) -> Result<(), Error> {
async fn enroll(request: api::Request<Enroll>, state: State) -> Result<(), Error> {
let upstream = *state.upstream.as_ref().ok_or(Error::UpstreamNotSet)?;

let request = request.body.request;
Expand Down Expand Up @@ -124,7 +129,7 @@ async fn enroll(request: api::Request<api::v1::services::Enroll>, state: State)
Ok(())
}

async fn accept(request: api::Request<api::v1::services::Accept>, state: State) -> Result<(), Error> {
async fn accept(request: api::Request<Accept>, state: State) -> Result<(), Error> {
let token = request.token.clone().ok_or(Error::MissingRequestToken)?;

let request = request.body.request;
Expand Down Expand Up @@ -178,7 +183,7 @@ async fn accept(request: api::Request<api::v1::services::Accept>, state: State)
Ok(())
}

async fn decline(request: api::Request<api::v1::services::Decline>, state: State) -> Result<(), Error> {
async fn decline(request: api::Request<Decline>, state: State) -> Result<(), Error> {
let token = request.token.clone().ok_or(Error::MissingRequestToken)?;

let endpoint = token
Expand All @@ -202,7 +207,7 @@ async fn decline(request: api::Request<api::v1::services::Decline>, state: State
}

// Middleware already validates this token is valid for this endpoint
async fn refresh_token(request: api::Request<api::v1::services::RefreshToken>, state: State) -> Result<String, Error> {
async fn refresh_token(request: api::Request<RefreshToken>, state: State) -> Result<String, Error> {
request
.token
.ok_or(Error::MissingRequestToken)?
Expand All @@ -216,10 +221,7 @@ async fn refresh_token(request: api::Request<api::v1::services::RefreshToken>, s
}

// Middleware already validates this token is valid for this endpoint
async fn refresh_issue_token(
request: api::Request<api::v1::services::RefreshIssueToken>,
state: State,
) -> Result<String, Error> {
async fn refresh_issue_token(request: api::Request<RefreshIssueToken>, state: State) -> Result<String, Error> {
request
.token
.ok_or(Error::MissingRequestToken)?
Expand Down
3 changes: 0 additions & 3 deletions crates/service/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ use crate::{
Database, Role, Token,
};

pub(crate) use self::service::service;

pub mod enrollment;
pub(crate) mod service;

/// Unique identifier of an [`Endpoint`]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, From)]
Expand Down
Loading

0 comments on commit 88bb2aa

Please sign in to comment.