Skip to content

Commit

Permalink
fix: .env file typo on integrationos-api README and wrong instantia…
Browse files Browse the repository at this point in the history
…tion of SecretsService (picahq#165)
  • Loading branch information
sagojez authored Sep 25, 2024
1 parent 9ae3ee6 commit 48e5597
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
4 changes: 2 additions & 2 deletions integrationos-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ cargo watch -x run -q | bunyan

Create a .env file in the root of the project with the following environment:

bash
```bash
RUST_LOG=info
ENVIRONMENT=development
EVENT_DATABASE_URL=mongodb://localhost:27017/?directConnection=true
Expand All @@ -29,7 +29,7 @@ EVENT_DATABASE_NAME=events-service
CONTEXT_DATABASE_NAME=events-service
CONTROL_DATABASE_NAME=events-service
UDM_DATABASE_NAME=events-service

```

Then run the following command:

Expand Down
20 changes: 1 addition & 19 deletions integrationos-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ use anyhow::Result;
use dotenvy::dotenv;
use envconfig::Envconfig;
use integrationos_api::{config::ConnectionsConfig, server::Server};
use integrationos_domain::secret::Secret;
use integrationos_domain::secrets::SecretServiceProvider;
use integrationos_domain::telemetry::{get_subscriber, init_subscriber};
use integrationos_domain::{GoogleKms, IOSKms, MongoStore, SecretExt, Store};
use mongodb::Client;
use std::sync::Arc;
use tracing::info;

fn main() -> Result<()> {
Expand All @@ -24,20 +19,7 @@ fn main() -> Result<()> {
.enable_all()
.build()?
.block_on(async move {
let client = Client::with_uri_str(&config.db_config.event_db_url).await?;
let database = client.database(&config.db_config.event_db_name);
let secrets_store = MongoStore::<Secret>::new(&database, &Store::Secrets).await?;
let secrets_client: Arc<dyn SecretExt + Sync + Send> =
match config.secrets_config.provider {
SecretServiceProvider::GoogleKms => {
Arc::new(GoogleKms::new(&config.secrets_config, secrets_store).await?)
}
SecretServiceProvider::IosKms => {
Arc::new(IOSKms::new(&config.secrets_config, secrets_store).await?)
}
};

let server: Server = Server::init(config, secrets_client).await?;
let server: Server = Server::init(config).await?;

server.run().await
})
Expand Down
19 changes: 14 additions & 5 deletions integrationos-api/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ use integrationos_domain::{
event_access::EventAccess,
page::PlatformPage,
secret::Secret,
secrets::SecretServiceProvider,
stage::Stage,
user::UserClient,
Connection, Event, Pipeline, PlatformData, SecretExt, Store, Transaction,
Connection, Event, GoogleKms, IOSKms, Pipeline, PlatformData, SecretExt, Store, Transaction,
};
use integrationos_unified::unified::{UnifiedCacheTTLs, UnifiedDestination};
use mongodb::{options::UpdateOptions, Client, Database};
Expand Down Expand Up @@ -83,10 +84,7 @@ pub struct Server {
}

impl Server {
pub async fn init(
config: ConnectionsConfig,
secrets_client: Arc<dyn SecretExt + Sync + Send + 'static>,
) -> Result<Self> {
pub async fn init(config: ConnectionsConfig) -> Result<Self> {
let client = Client::with_uri_str(&config.db_config.control_db_url).await?;
let db = client.database(&config.db_config.control_db_name);

Expand Down Expand Up @@ -117,6 +115,17 @@ impl Server {
let cursors = MongoStore::new(&db, &Store::Cursors).await?;
let stages = MongoStore::new(&db, &Store::Stages).await?;
let clients = MongoStore::new(&db, &Store::Clients).await?;
let secrets_store = MongoStore::<Secret>::new(&db, &Store::Secrets).await?;

let secrets_client: Arc<dyn SecretExt + Sync + Send> = match config.secrets_config.provider
{
SecretServiceProvider::GoogleKms => {
Arc::new(GoogleKms::new(&config.secrets_config, secrets_store).await?)
}
SecretServiceProvider::IosKms => {
Arc::new(IOSKms::new(&config.secrets_config, secrets_store).await?)
}
};

let extractor_caller = UnifiedDestination::new(
config.db_config.clone(),
Expand Down
8 changes: 5 additions & 3 deletions integrationos-api/tests/api_tests/test_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ impl TestServer {
("CACHE_SIZE".to_string(), "0".to_string()),
("REDIS_URL".to_string(), redis),
("JWT_SECRET".to_string(), token_secret.clone()),
(
"SECRETS_SERVICE_PROVIDER".to_string(),
"ios-kms".to_string(),
),
]))
.unwrap();

Expand Down Expand Up @@ -226,9 +230,7 @@ impl TestServer {
.await
.unwrap();

let server = Server::init(config.clone(), secrets_client.clone())
.await
.unwrap();
let server = Server::init(config.clone()).await.unwrap();

tokio::task::spawn(async move { server.run().await });

Expand Down

0 comments on commit 48e5597

Please sign in to comment.