-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1539 from golemfactory/prekucki/id-auto-provisioning
Prekucki/id auto provisioning
- Loading branch information
Showing
9 changed files
with
201 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::env; | ||
|
||
use ethsign::*; | ||
use rustc_hex::FromHex; | ||
|
||
use ya_core_model::NodeId; | ||
|
||
use crate::id_key::IdentityKey; | ||
use anyhow::Context; | ||
|
||
// autoconfiguration | ||
const ENV_AUTOCONF_PK: &str = "YAGNA_AUTOCONF_ID_SECRET"; | ||
const ENV_AUTOCONF_APP_KEY: &str = "YAGNA_AUTOCONF_APPKEY"; | ||
|
||
pub fn preconfigured_identity(password: Protected) -> anyhow::Result<Option<IdentityKey>> { | ||
let secret_hex: Vec<u8> = match env::var(ENV_AUTOCONF_PK) { | ||
Ok(v) => v | ||
.from_hex() | ||
.with_context(|| format!("Failed to parse identity from {}", ENV_AUTOCONF_PK))?, | ||
Err(_) => return Ok(None), | ||
}; | ||
let secret = SecretKey::from_raw(&secret_hex)?; | ||
Ok(Some(IdentityKey::from_secret(None, secret, password))) | ||
} | ||
|
||
pub fn preconfigured_node_id() -> anyhow::Result<Option<NodeId>> { | ||
let secret_hex: Vec<u8> = match env::var(ENV_AUTOCONF_PK) { | ||
Ok(v) => v.from_hex()?, | ||
Err(_) => return Ok(None), | ||
}; | ||
let secret = SecretKey::from_raw(&secret_hex)?; | ||
Ok(Some(NodeId::from(secret.public().address().as_ref()))) | ||
} | ||
|
||
pub fn preconfigured_appkey() -> anyhow::Result<Option<String>> { | ||
Ok(env::var(ENV_AUTOCONF_APP_KEY).ok()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ extern crate diesel; | |
pub mod cli; | ||
pub mod service; | ||
|
||
mod autoconf; | ||
pub mod dao; | ||
mod db; | ||
mod id_key; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters