|
| 1 | +use crate::models::list_deployments::{CreationSource, MongoDBPortBinding}; |
| 2 | +use napi_derive::napi; |
| 3 | +use semver::Version; |
| 4 | + |
| 5 | +#[napi(object)] |
| 6 | +pub struct CreateDeploymentOptions { |
| 7 | + // Identifiers |
| 8 | + pub name: Option<String>, |
| 9 | + |
| 10 | + // Image details |
| 11 | + pub image: Option<String>, |
| 12 | + pub mongodb_version: Option<String>, |
| 13 | + |
| 14 | + // Creation source |
| 15 | + pub creation_source: Option<CreationSource>, |
| 16 | + |
| 17 | + // Initial database configuration |
| 18 | + pub local_seed_location: Option<String>, |
| 19 | + pub mongodb_initdb_database: Option<String>, |
| 20 | + pub mongodb_initdb_root_password_file: Option<String>, |
| 21 | + pub mongodb_initdb_root_password: Option<String>, |
| 22 | + pub mongodb_initdb_root_username_file: Option<String>, |
| 23 | + pub mongodb_initdb_root_username: Option<String>, |
| 24 | + |
| 25 | + // Logging |
| 26 | + pub mongot_log_file: Option<String>, |
| 27 | + pub runner_log_file: Option<String>, |
| 28 | + |
| 29 | + // Telemetry |
| 30 | + pub do_not_track: Option<bool>, |
| 31 | + pub telemetry_base_url: Option<String>, |
| 32 | + |
| 33 | + // Port configuration |
| 34 | + pub mongodb_port_binding: Option<MongoDBPortBinding>, |
| 35 | +} |
| 36 | + |
| 37 | +impl From<CreateDeploymentOptions> for atlas_local::models::CreateDeploymentOptions { |
| 38 | + fn from(source: CreateDeploymentOptions) -> Self { |
| 39 | + let version: Option<Version> = match source.mongodb_version.as_deref() { |
| 40 | + Some("latest") => None, |
| 41 | + None => None, |
| 42 | + Some(ver_string) => { |
| 43 | + // If malformed Version if given, it will panic here |
| 44 | + Some(Version::parse(ver_string).expect("Parse version string")) |
| 45 | + } |
| 46 | + }; |
| 47 | + |
| 48 | + Self { |
| 49 | + name: source.name, |
| 50 | + image: source.image, |
| 51 | + mongodb_version: version, |
| 52 | + creation_source: source |
| 53 | + .creation_source |
| 54 | + .map(atlas_local::models::CreationSource::from), |
| 55 | + local_seed_location: source.local_seed_location, |
| 56 | + mongodb_initdb_database: source.mongodb_initdb_database, |
| 57 | + mongodb_initdb_root_password_file: source.mongodb_initdb_root_password_file, |
| 58 | + mongodb_initdb_root_password: source.mongodb_initdb_root_password, |
| 59 | + mongodb_initdb_root_username_file: source.mongodb_initdb_root_username_file, |
| 60 | + mongodb_initdb_root_username: source.mongodb_initdb_root_username, |
| 61 | + mongot_log_file: source.mongot_log_file, |
| 62 | + runner_log_file: source.runner_log_file, |
| 63 | + do_not_track: source.do_not_track, |
| 64 | + telemetry_base_url: source.telemetry_base_url, |
| 65 | + mongodb_port_binding: source |
| 66 | + .mongodb_port_binding |
| 67 | + .map(atlas_local::models::MongoDBPortBinding::from), |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments