Skip to content

Commit

Permalink
Move state module to common crate to avoid cli dependency on connector
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoverton committed Mar 14, 2024
1 parent fb2adbe commit dc07744
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 11 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ path = "./src/main.rs"

[dependencies]
configuration = { path = "../configuration" }
mongodb-connector = { path = "../mongodb-connector" }
mongodb-agent-common = { path = "../mongodb-agent-common" }
mongodb = "2.8"
ndc-sdk = { git = "https://github.com/hasura/ndc-hub.git" }
Expand Down
8 changes: 5 additions & 3 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
//! The CLI can do a few things. This provides a central point where those things are routed and
//! then done, making it easier to test this crate deterministically.


use std::path::PathBuf;

use clap::Subcommand;

use configuration::Configuration;
use mongodb_agent_common::{interface_types::MongoConfig, schema::get_schema};
use mongodb_connector::api_type_conversions::v2_schema_response_to_configuration;

/// The command invoked by the user.
#[derive(Debug, Clone, Subcommand)]
Expand Down Expand Up @@ -64,9 +65,10 @@ pub async fn run(command: Command, context: &Context) -> anyhow::Result<()> {
///
/// This expects a configuration with a valid connection URI.
async fn update(context: &Context) -> anyhow::Result<()> {
let schema = get_schema(&context.mongo_config).await?;
// TODO: Get metadata directly from DB introspection instead of going via v2 get_schema()
let _schema = get_schema(&context.mongo_config).await?;

let configuration = v2_schema_response_to_configuration(schema);
let configuration = Configuration::default(); // v2_schema_response_to_configuration(schema);

configuration::write_directory(&context.path, &configuration).await?;

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::env;
use std::path::PathBuf;

use clap::Parser;
use mongodb_connector::state::{try_init_state_from_uri, DATABASE_URI_ENV_VAR};
use mongodb_agent_common::state::{try_init_state_from_uri, DATABASE_URI_ENV_VAR};
use mongodb_cli_plugin::{run, Command, Context};

/// The command-line arguments.
Expand Down
2 changes: 1 addition & 1 deletion crates/configuration/src/read_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tokio::fs;

use crate::Configuration;

pub const CONFIGURATION_FILENAME: &str = "configuration";
pub const CONFIGURATION_FILENAME: &str = "metadata";
pub const CONFIGURATION_EXTENSIONS: [(&str, FileFormat); 3] =
[("json", JSON), ("yaml", YAML), ("yml", YAML)];
pub const DEFAULT_EXTENSION: &str = "json";
Expand Down
1 change: 1 addition & 0 deletions crates/mongodb-agent-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pub mod mongodb_connection;
pub mod query;
pub mod scalar_types_capabilities;
pub mod schema;
pub mod state;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{env, error::Error};

use anyhow::anyhow;
use mongodb_agent_common::{interface_types::MongoConfig, mongodb_connection::get_mongodb_client};
use crate::{interface_types::MongoConfig, mongodb_connection::get_mongodb_client};

pub const DATABASE_URI_ENV_VAR: &str = "MONGODB_DATABASE_URI";

Expand Down
1 change: 0 additions & 1 deletion crates/mongodb-connector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ pub mod capabilities;
pub mod error_mapping;
pub mod mongo_connector;
pub mod schema;
pub mod state;
1 change: 0 additions & 1 deletion crates/mongodb-connector/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ mod capabilities;
mod error_mapping;
mod mongo_connector;
mod schema;
mod state;

use std::error::Error;

Expand Down
2 changes: 1 addition & 1 deletion crates/mongodb-connector/src/mongo_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Connector for MongoConnector {
_configuration: &Self::Configuration,
_metrics: &mut prometheus::Registry,
) -> Result<Self::State, InitializationError> {
let state = crate::state::try_init_state().await?;
let state = mongodb_agent_common::state::try_init_state().await?;
Ok(state)
}

Expand Down

0 comments on commit dc07744

Please sign in to comment.