Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ jobs:
build: yarn build --target aarch64-apple-darwin
- host: ubuntu-latest
target: aarch64-unknown-linux-gnu
build: yarn build --target aarch64-unknown-linux-gnu --use-napi-cross
build: |
export CFLAGS_aarch64_unknown_linux_gnu="-D__ARM_ARCH=8"
yarn build --target aarch64-unknown-linux-gnu --use-napi-cross
name: stable - ${{ matrix.settings.target }} - node@22
runs-on: ${{ matrix.settings.host }}
steps:
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ crate-type = ["cdylib"]

[dependencies]
anyhow = "1.0.99"
atlas-local = { git = "https://github.com/mongodb/atlas-local-lib.git", rev = "7d8de1e2b9b865fafeb4120c765b1223d500bbc1" }
atlas-local = { git = "https://github.com/mongodb/atlas-local-lib.git", rev = "df190245295e6675949fb5c63a164fadc0007dab" }
bollard = "0.19.2"
napi = { version = "3.0.0", features = ["async", "anyhow"] }
napi-derive = "3.0.0"
napi = { version = "^3.3.0", features = ["async", "anyhow"] }
napi-derive = "^3.2.5"
semver = "1.0.26"

[build-dependencies]
Expand Down
6 changes: 6 additions & 0 deletions __test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ test('smoke test', async (t) => {
let getDeployment = await client.getDeployment(createDeploymentOptions.name)
t.is(getDeployment.name,createDeploymentOptions.name)

let getConnectionStringOptions = {
containerIdOrName: createDeploymentOptions.name,
}
let connString = await client.getConnectionString(getConnectionStringOptions)
t.assert(connString === `mongodb://127.0.0.1:${getDeployment.portBindings.port}/?directConnection=true`)

// Count deployments after creation
let after_create_deployment_count = (await client.listDeployments()).length
t.assert(after_create_deployment_count - start_deployments_count === 1)
Expand Down
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ targets = [
# they are connected to another crate in the graph that hasn't been pruned,
# so it should be used with care. The identifiers are [Package ID Specifications]
# (https://doc.rust-lang.org/cargo/reference/pkgid-spec.html)
#exclude = []
exclude = ["mongodb"]
# If true, metadata will be collected with `--all-features`. Note that this can't
# be toggled off if true, if you want to conditionally enable `--all-features` it
# is recommended to pass `--all-features` on the cmd line instead
Expand Down
7 changes: 7 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export declare class Client {
listDeployments(): Promise<Array<Deployment>>
deleteDeployment(deploymentName: string): Promise<void>
getDeployment(deploymentName: string): Promise<Deployment>
getConnectionString(options: GetConnectionStringOptions): Promise<string>
}

export declare const enum BindingType {
Expand Down Expand Up @@ -66,6 +67,12 @@ export interface Deployment {
telemetryBaseUrl?: string
}

export interface GetConnectionStringOptions {
containerIdOrName: string
dbUsername?: string
dbPassword?: string
}

export interface MongoDbPortBinding {
type: BindingType
ip: string
Expand Down
226 changes: 195 additions & 31 deletions index.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,17 @@ impl Client {
.context("get deployment")
.map(|d| d.into())
}

#[napi]
pub async fn get_connection_string(
&self,
options: crate::models::get_connection_string::GetConnectionStringOptions,
) -> Result<String> {
let options: atlas_local::models::GetConnectionStringOptions = options.into();
self
.client
.get_connection_string(options)
.await
.context("get connection string")
}
}
49 changes: 49 additions & 0 deletions src/models/get_connection_string.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use napi_derive::napi;

#[napi(object)]
pub struct GetConnectionStringOptions {
pub container_id_or_name: String,
pub db_username: Option<String>,
pub db_password: Option<String>,
}

impl From<GetConnectionStringOptions> for atlas_local::models::GetConnectionStringOptions {
fn from(source: GetConnectionStringOptions) -> Self {
Self {
container_id_or_name: source.container_id_or_name,
db_username: source.db_username,
db_password: source.db_password,
}
}
}

// test
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_get_connection_string_options() {
let options = GetConnectionStringOptions {
container_id_or_name: "test_container".into(),
db_username: Some("test_user".into()),
db_password: Some("test_pass".into()),
};

let get_connection_string_options: atlas_local::models::GetConnectionStringOptions =
options.into();

assert_eq!(
get_connection_string_options.container_id_or_name,
"test_container"
);
assert_eq!(
get_connection_string_options.db_username,
Some("test_user".into())
);
assert_eq!(
get_connection_string_options.db_password,
Some("test_pass".into())
);
}
}
1 change: 1 addition & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod create_deployment;
pub mod get_connection_string;
pub mod list_deployments;