Skip to content

Commit

Permalink
Merge pull request #3 from lightningrodlabs/feat/in-proc-lair
Browse files Browse the repository at this point in the history
Add option to run in-process lair
  • Loading branch information
matthme committed Sep 24, 2024
2 parents 5b9ea13 + 151a5e6 commit 404f51e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

/* auto-generated by NAPI-RS */

export function overwriteConfig(adminPort: number, configPath: string, keystoreConnectionUrl: string, bootstrapServerUrl: string, signalingServerUrl: string, allowedOrigin: string, useDpki: boolean, iceServerUrls?: Array<string> | undefined | null): string
export function defaultConductorConfig(adminPort: number, conductorEnvironmentPath: string, keystoreConnectionUrl: string, bootstrapServerUrl: string, signalingServerUrl: string, allowedOrigin: string, useDpki: boolean, iceServerUrls?: Array<string> | undefined | null): string
export function overwriteConfig(adminPort: number, configPath: string, keystoreConnectionUrl: string, bootstrapServerUrl: string, signalingServerUrl: string, allowedOrigin: string, useDpki: boolean, iceServerUrls?: Array<string> | undefined | null, keystoreInProcEnvironmentDir?: string | undefined | null): string
export function defaultConductorConfig(adminPort: number, conductorEnvironmentPath: string, keystoreConnectionUrl: string, bootstrapServerUrl: string, signalingServerUrl: string, allowedOrigin: string, useDpki: boolean, iceServerUrls?: Array<string> | undefined | null, keystoreInProcEnvironmentDir?: string | undefined | null): string
export function happBytesWithCustomProperties(happPath: string, properties: Record<string, string | undefined | null>): Promise<Array<number>>
export function saveHappOrWebhapp(happOrWebHappPath: string, uisDir: string, happsDir: string): Promise<string>
/** Checks that the happ or webhapp is of the correct format */
Expand Down
43 changes: 32 additions & 11 deletions src/conductor_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub fn overwrite_config(
allowed_origin: String,
use_dpki: bool,
ice_server_urls: Option<Vec<String>>,
keystore_in_proc_environment_dir: Option<String>,
) -> Result<String> {
let mut config = std::fs::read_to_string(&PathBuf::from(config_path))
.map_err(|_| create_error("Failed to read file"))
Expand Down Expand Up @@ -85,14 +86,24 @@ pub fn overwrite_config(
Value::Sequence(vec![Value::Mapping(admin_interface)]),
);

insert_mapping(
&mut config,
"keystore",
Value::Mapping(create_mapping_with_entries(vec![
("type", Value::String(String::from("lair_server"))),
("connection_url", Value::String(keystore_connection_url)),
])),
);
match keystore_in_proc_environment_dir {
Some(path) => insert_mapping(
&mut config,
"keystore",
Value::Mapping(create_mapping_with_entries(vec![
("type", Value::String(String::from("lair_server_in_proc"))),
("lair_root", Value::String(path)),
])),
),
None => insert_mapping(
&mut config,
"keystore",
Value::Mapping(create_mapping_with_entries(vec![
("type", Value::String(String::from("lair_server"))),
("connection_url", Value::String(keystore_connection_url)),
])),
),
};

let dpki_config = match use_dpki {
true => DpkiConfig::default(),
Expand Down Expand Up @@ -166,6 +177,7 @@ pub fn default_conductor_config(
allowed_origin: String,
use_dpki: bool,
ice_server_urls: Option<Vec<String>>,
keystore_in_proc_environment_dir: Option<String>,
) -> Result<String> {
let mut network_config = KitsuneP2pConfig::default();
network_config.bootstrap_service = Some(url2::url2!("{}", bootstrap_server_url));
Expand All @@ -191,14 +203,23 @@ pub fn default_conductor_config(
false => DpkiConfig::disabled(),
};

// If a keystore environment directory for in-process lair is provided, ignore
// the value passed with keystore_connection_url
let keystore_config = match keystore_in_proc_environment_dir {
Some(path) => KeystoreConfig::LairServerInProc {
lair_root: Some(PathBuf::from(path).into()),
},
None => KeystoreConfig::LairServer {
connection_url: url2::url2!("{}", keystore_connection_url),
},
};

let config = ConductorConfig {
data_root_path: Some(DataRootPath::from(PathBuf::from(
conductor_environment_path,
))),
dpki: dpki_config,
keystore: KeystoreConfig::LairServer {
connection_url: url2::url2!("{}", keystore_connection_url),
},
keystore: keystore_config,
admin_interfaces: Some(vec![AdminInterfaceConfig {
driver: InterfaceDriver::Websocket {
port: admin_port,
Expand Down

0 comments on commit 404f51e

Please sign in to comment.