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
18 changes: 9 additions & 9 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
license-and-audit:
runs-on: ubuntu-latest
steps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
run: |
rustup update stable
rustup default stable
rustup component add clippy rustfmt

- name: Cache cargo registry
uses: actions/cache@v4
with:
Expand All @@ -292,29 +292,29 @@ jobs:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-

- name: Cache cargo tools
uses: actions/cache@v4
with:
path: ~/.cargo/bin
key: ${{ runner.os }}-cargo-tools-deny-${{ env.CARGO_DENY_VERSION }}-audit-${{ env.CARGO_AUDIT_VERSION }}
restore-keys: |
${{ runner.os }}-cargo-tools-

- name: Install cargo-deny
run: |
if ! command -v cargo-deny &> /dev/null; then
cargo install --locked --version ${{ env.CARGO_DENY_VERSION }} cargo-deny
fi

- name: Install cargo-audit
run: |
if ! command -v cargo-audit &> /dev/null; then
cargo install --locked --version ${{ env.CARGO_AUDIT_VERSION }} cargo-audit
fi

- name: Run cargo deny
run: cargo deny check

- name: Run cargo audit
run: cargo audit
run: cargo audit
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ version = "0.0.0-preview.0"
crate-type = ["cdylib"]

[dependencies]
atlas-local = { git = "https://github.com/mongodb/atlas-local-lib.git" }
napi = "3.0.0"
anyhow = "1.0.99"
atlas-local = { git = "https://github.com/mongodb/atlas-local-lib.git", rev = "36f56065e891bbe045beeb46489dd7d4142dbd41" }
bollard = "0.19.2"
napi = { version = "3.0.0", features = ["async", "anyhow"] }
napi-derive = "3.0.0"

[build-dependencies]
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ Before using this library, make sure you have:
Here's a simple example to get you started:

```typescript
// TODO
const client = await Client.connect();
const deployments = await client.listDeployments();
console.log(deployments);
```

## Development
Expand Down
27 changes: 23 additions & 4 deletions __test__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
import test from 'ava'

import { plus100 } from '../index'
import { Client } from '../index'

test('sync function from native code', (t) => {
const fixture = 42
t.is(plus100(fixture), fixture + 100)
test('smoke test: list deployments', async (t) => {
let client: Client | null = null

try {
// Create client
client = await Client.connect()
} catch (e: any) {
// If docker is not running we get this error
// any other error means failure
t.is(e?.message, 'connect to docker')
return
}

if (client == null) {
t.fail('Client not created')
return
}

// List deployments
// We don't care about the number, we're just testing that the method doesn't fail
await client.listDeployments()
t.pass()
})
63 changes: 62 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
/* auto-generated by NAPI-RS */
/* eslint-disable */
export declare function plus100(input: number): number
export declare class Client {
static connect(): Client
listDeployments(): Promise<Array<Deployment>>
}

export declare const enum BindingType {
Loopback = 'Loopback',
AnyInterface = 'AnyInterface',
Specific = 'Specific',
}

export interface CreationSource {
type: CreationSourceType
source: string
}

export declare const enum CreationSourceType {
AtlasCLI = 'AtlasCLI',
Container = 'Container',
Other = 'Other',
}

export interface Deployment {
containerId: string
name?: string
state: State
portBindings?: MongoDBPortBinding
mongodbType: MongodbType
mongodbVersion: string
creationSource?: CreationSource
localSeedLocation?: string
mongodbInitdbDatabase?: string
mongodbInitdbRootPasswordFile?: string
mongodbInitdbRootPassword?: string
mongodbInitdbRootUsernameFile?: string
mongodbInitdbRootUsername?: string
mongotLogFile?: string
runnerLogFile?: string
doNotTrack?: string
telemetryBaseUrl?: string
}

export interface MongoDbPortBinding {
type: BindingType
ip: string
port: number
}

export declare const enum MongodbType {
Community = 'Community',
Enterprise = 'Enterprise',
}

export declare const enum State {
Created = 'Created',
Dead = 'Dead',
Exited = 'Exited',
Paused = 'Paused',
Removing = 'Removing',
Restarting = 'Restarting',
Running = 'Running',
}
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,8 @@ if (!nativeBinding) {
}

module.exports = nativeBinding
module.exports.plus100 = nativeBinding.plus100
module.exports.Client = nativeBinding.Client
module.exports.BindingType = nativeBinding.BindingType
module.exports.CreationSourceType = nativeBinding.CreationSourceType
module.exports.MongodbType = nativeBinding.MongodbType
module.exports.State = nativeBinding.State
35 changes: 33 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
#![deny(clippy::all)]

use anyhow::{Context, Result};
use atlas_local::Client as AtlasLocalClient;
use bollard::Docker;
use napi_derive::napi;

use crate::models::list_deployments::Deployment;

pub mod models;

#[napi]
pub struct Client {
client: AtlasLocalClient,
}

#[napi]
pub fn plus_100(input: u32) -> u32 {
input + 100
impl Client {
#[napi(factory)]
pub fn connect() -> Result<Client> {
let docker = Docker::connect_with_defaults().context("connect to docker")?;

let atlas_local_client = AtlasLocalClient::new(docker);

Ok(Client {
client: atlas_local_client,
})
}

#[napi]
pub async fn list_deployments(&self) -> Result<Vec<Deployment>> {
self
.client
.list_deployments()
.await
.context("list deployments")
.map(|deployments| deployments.into_iter().map(|d| d.into()).collect())
}
}
Loading
Loading