Skip to content

Commit

Permalink
Removing cloudsmith dependencies and improving server response
Browse files Browse the repository at this point in the history
  • Loading branch information
sagojez committed Apr 14, 2024
1 parent fccd811 commit 2015a08
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 124 deletions.
3 changes: 0 additions & 3 deletions .cargo/config

This file was deleted.

92 changes: 53 additions & 39 deletions Cargo.lock

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

6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@ actix = "0.13.1"
actix-cors = "0.7.0"
actix-governor = "0.5.0"
actix-web = "4.5.1"
actix-web-actors = "4.2.0"
actix-web-lab = "0.20.2"
anyhow = "1.0.79"
chrono = { version = "0.4.33", features = ["serde"] }
dotenvy = "0.15.7"
envconfig = "0.10.0"
futures = "0.3.30"
handlebars = "5.1.1"
integrationos-domain = { version = "0.1.3", features = ["dummy", "actix-error"] }
integrationos-domain = { version = "1.3.0", features = ["dummy", "actix-error"] }
jsonwebtoken = "9.2.0"
moka = { version = "0.12.5", features = ["future"] }
mongodb = "2.8.0"
reqwest = "0.11.24"
serde = { version = "1.0.196", features = ["derive"] }
serde_json = "1.0.113"
thiserror = "1.0.56"
tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.40", features = ["log"] }
tracing-actix-web = "0.7.9"
Expand All @@ -42,9 +40,7 @@ name = "oauth-api"
path = "src/main.rs"

[dev-dependencies]
derive = "1.0.0"
fake = { version = "=2.9.1", features = ["dummy"] }
features = "0.10.0"
mark-flaky-tests = { version = "1.0.2", features = ["tokio"] }
once_cell = "1.19.0"
rand = "0.8.5"
Expand Down
12 changes: 6 additions & 6 deletions src/algebra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ pub use trigger::*;

use chrono::{DateTime, Utc};
use integrationos_domain::{
algebra::adapter::StoreAdapter, error::IntegrationOSError as Error, mongo::MongoDbStore,
Connection, Id,
algebra::{MongoStore, StoreExt},
Connection, Id, IntegrationOSError,
};
use mongodb::bson::doc;

pub async fn get_connections_to_refresh(
collection: &MongoDbStore<Connection>,
collection: &MongoStore<Connection>,
refresh_before: &DateTime<Utc>,
refresh_after: &DateTime<Utc>,
) -> Result<Vec<Connection>, Error> {
) -> Result<Vec<Connection>, IntegrationOSError> {
collection
.get_many(
Some(doc! {
Expand All @@ -37,9 +37,9 @@ pub async fn get_connections_to_refresh(
}

pub async fn get_connection_to_trigger(
collection: &MongoDbStore<Connection>,
collection: &MongoStore<Connection>,
id: Id,
) -> Result<Option<Connection>, Error> {
) -> Result<Option<Connection>, IntegrationOSError> {
collection
.get_one(doc! {
"_id": id.to_string(),
Expand Down
13 changes: 7 additions & 6 deletions src/algebra/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ use actix::prelude::*;
use chrono::{Duration, Utc};
use futures::lock::Mutex;
use integrationos_domain::{
connection_oauth_definition::ConnectionOAuthDefinition, error::IntegrationOSError as Error,
mongo::MongoDbStore, service::secrets_client::SecretsClient, Connection, InternalError,
algebra::MongoStore, connection_oauth_definition::ConnectionOAuthDefinition,
error::IntegrationOSError as Error, service::secrets_client::SecretsClient, Connection,
InternalError,
};
use reqwest::Client;
use std::sync::Arc;

pub struct RefreshActor {
connections: Arc<MongoDbStore<Connection>>,
oauths: Arc<MongoDbStore<ConnectionOAuthDefinition>>,
connections: Arc<MongoStore<Connection>>,
oauths: Arc<MongoStore<ConnectionOAuthDefinition>>,
secrets: Arc<SecretsClient>,
client: Client,
state: Arc<Mutex<StatefulActor>>,
}

impl RefreshActor {
pub fn new(
oauths: Arc<MongoDbStore<ConnectionOAuthDefinition>>,
connections: Arc<MongoDbStore<Connection>>,
oauths: Arc<MongoStore<ConnectionOAuthDefinition>>,
connections: Arc<MongoStore<Connection>>,
secrets: Arc<SecretsClient>,
client: Client,
) -> Self {
Expand Down
11 changes: 5 additions & 6 deletions src/algebra/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ use crate::prelude::{Outcome, Trigger};
use actix::prelude::*;
use chrono::Duration;
use integrationos_domain::{
algebra::adapter::StoreAdapter,
algebra::{MongoStore, StoreExt},
api_model_config::ContentType,
connection_oauth_definition::{Computation, ConnectionOAuthDefinition, OAuthResponse},
error::IntegrationOSError as Error,
get_secret_request::GetSecretRequest,
mongo::MongoDbStore,
oauth_secret::OAuthSecret,
service::secrets_client::SecretsClient,
ApplicationError, Connection, Id, InternalError, OAuth,
Expand All @@ -21,17 +20,17 @@ use tracing::warn;
use tracing_actix_web::RequestId;

pub struct TriggerActor {
connections: Arc<MongoDbStore<Connection>>,
oauths: Arc<MongoDbStore<ConnectionOAuthDefinition>>,
connections: Arc<MongoStore<Connection>>,
oauths: Arc<MongoStore<ConnectionOAuthDefinition>>,
secrets_client: Arc<SecretsClient>,
request_id: Option<RequestId>,
client: Client,
}

impl TriggerActor {
pub fn new(
connections: Arc<MongoDbStore<Connection>>,
oauths: Arc<MongoDbStore<ConnectionOAuthDefinition>>,
connections: Arc<MongoStore<Connection>>,
oauths: Arc<MongoStore<ConnectionOAuthDefinition>>,
secrets_client: Arc<SecretsClient>,
client: Client,
request_id: Option<RequestId>,
Expand Down
2 changes: 1 addition & 1 deletion src/service/http/admin/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ pub async fn get_state(state: Data<AppState>) -> Result<HttpResponse, Error> {
.await
.map_err(|e| InternalError::io_err(e.to_string().as_str(), None))?;

Ok(HttpResponse::Ok().json(ServerResponse::new(ResponseType::Query, response)))
Ok(ServerResponse::from(ResponseType::Query, response, 200))
}
2 changes: 1 addition & 1 deletion src/service/http/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use actix_web::{
Error as ActixWebError, HttpMessage,
};
use actix_web_lab::middleware::Next;
use integrationos_domain::{algebra::adapter::StoreAdapter, event_access::EventAccess, Claims};
use integrationos_domain::{algebra::StoreExt, event_access::EventAccess, Claims};
use jsonwebtoken::{decode, DecodingKey, Validation};
use mongodb::bson::doc;
use std::sync::Arc;
Expand Down
43 changes: 7 additions & 36 deletions src/service/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ mod application;
mod middleware;
mod public;

use actix_web::{HttpResponse, HttpResponseBuilder};
pub use admin::*;
pub use application::*;
pub use middleware::*;
pub use public::*;
use reqwest::StatusCode;

#[derive(serde::Serialize, serde::Deserialize, Debug, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
Expand All @@ -24,48 +26,17 @@ where
T: serde::Serialize,
{
#[serde(rename = "type")]
pub response_type: ResponseType,
pub r#type: ResponseType,
pub args: T,
pub code: u16,
}

impl<T> ServerResponse<T>
where
T: serde::Serialize,
{
pub fn new(response_type: ResponseType, args: T) -> Self {
Self {
response_type,
args,
}
}
}

#[derive(serde::Serialize, serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ServerError {
pub message: Vec<String>,
}

impl ServerError {
pub fn new(message: Vec<String>) -> Self {
Self { message }
}
}

impl From<Vec<String>> for ServerResponse<ServerError> {
fn from(message: Vec<String>) -> Self {
Self {
response_type: ResponseType::Error,
args: ServerError::new(message.iter().map(|s| s.to_string()).collect()),
}
}
}

impl<'a> From<Vec<&'a str>> for ServerResponse<ServerError> {
fn from(message: Vec<&'a str>) -> Self {
Self {
response_type: ResponseType::Error,
args: ServerError::new(message.iter().map(|s| s.to_string()).collect()),
}
pub fn from(r#type: ResponseType, args: T, code: u16) -> HttpResponse {
HttpResponseBuilder::new(StatusCode::from_u16(code).unwrap_or(StatusCode::OK))
.json(ServerResponse { r#type, args, code })
}
}
Loading

0 comments on commit 2015a08

Please sign in to comment.