Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Sep 26, 2024
1 parent c5eea51 commit 312b980
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
5 changes: 4 additions & 1 deletion core/identity/src/autoconf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use anyhow::Context;

const ENV_AUTOCONF_APP_KEY: &str = "YAGNA_AUTOCONF_APPKEY";

pub fn identity_from_env(password: Protected, env_name: &str) -> anyhow::Result<Option<IdentityKey>> {
pub fn identity_from_env(
password: Protected,
env_name: &str,
) -> anyhow::Result<Option<IdentityKey>> {
let secret_hex: Vec<u8> = match env::var(env_name) {
Ok(v) => v
.from_hex()
Expand Down
50 changes: 26 additions & 24 deletions core/identity/src/service/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::convert::{TryFrom, TryInto};
use std::rc::Rc;
use std::sync::Arc;

use anyhow::{bail};
use anyhow::bail;
use chrono::Utc;
use ethsign::{KeyFile, Protected, PublicKey};
use futures::lock::Mutex;
Expand All @@ -14,16 +14,17 @@ use ya_client_model::NodeId;
use ya_core_model::bus::GsbBindPoints;
use ya_service_bus::{typed as bus, RpcEndpoint, RpcMessage};

use ya_core_model::identity as model;
use ya_core_model::identity::event::IdentityEvent;
use ya_persistence::executor::DbExecutor;
use crate::dao::identity::Identity;
use crate::dao::{Error as DaoError, Error, IdentityDao};
use crate::id_key::{default_password, generate_identity_key, IdentityKey};
use ya_core_model::identity as model;
use ya_core_model::identity::event::IdentityEvent;
use ya_persistence::executor::DbExecutor;

lazy_static! (
static ref DEFAULT_IDENTITY_INIT_PRIVATE_KEY: Arc<Mutex<Option<String>>> = Arc::new(Mutex::new(None));
);
lazy_static! {
static ref DEFAULT_IDENTITY_INIT_PRIVATE_KEY: Arc<Mutex<Option<String>>> =
Arc::new(Mutex::new(None));
};

Check failure on line 27 in core/identity/src/service/identity.rs

View workflow job for this annotation

GitHub Actions / Check formatting

expected item, found `;`

Check failure on line 27 in core/identity/src/service/identity.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest)

expected item, found `;`

Check failure on line 27 in core/identity/src/service/identity.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (macos-latest)

expected item, found `;`

Check failure on line 27 in core/identity/src/service/identity.rs

View workflow job for this annotation

GitHub Actions / System Tests (ubuntu-latest)

expected item, found `;`

Check failure on line 27 in core/identity/src/service/identity.rs

View workflow job for this annotation

GitHub Actions / Market Test Suite (macos-latest)

expected item, found `;`

Check failure on line 27 in core/identity/src/service/identity.rs

View workflow job for this annotation

GitHub Actions / Market Test Suite (ubuntu-latest)

expected item, found `;`

Check failure on line 27 in core/identity/src/service/identity.rs

View workflow job for this annotation

GitHub Actions / Build binaries (aarch64)

expected item, found `;`

Check failure on line 27 in core/identity/src/service/identity.rs

View workflow job for this annotation

GitHub Actions / build-aarch64

expected item, found `;`

Check failure on line 27 in core/identity/src/service/identity.rs

View workflow job for this annotation

GitHub Actions / Unit Tests (windows-latest)

expected item, found `;`

Check failure on line 27 in core/identity/src/service/identity.rs

View workflow job for this annotation

GitHub Actions / Market Test Suite (windows-latest)

expected item, found `;`

#[derive(Default)]
struct Subscription {
Expand Down Expand Up @@ -95,22 +96,23 @@ impl IdentityService {
});
}

let default_key =
if let Some(key) = crate::autoconf::identity_from_env(default_password(), "YAGNA_AUTOCONF_ID_SECRET")? {
db.as_dao::<IdentityDao>()
.init_preconfigured(Identity {
identity_id: key.id(),
key_file_json: key.to_key_file()?,
is_default: true,
is_deleted: false,
alias: None,
note: None,
created_date: Utc::now().naive_utc(),
})
.await?
.identity_id
} else {
db.as_dao::<IdentityDao>()
let default_key = if let Some(key) =
crate::autoconf::identity_from_env(default_password(), "YAGNA_AUTOCONF_ID_SECRET")?
{
db.as_dao::<IdentityDao>()
.init_preconfigured(Identity {
identity_id: key.id(),
key_file_json: key.to_key_file()?,
is_default: true,
is_deleted: false,
alias: None,
note: None,
created_date: Utc::now().naive_utc(),
})
.await?
.identity_id
} else {
db.as_dao::<IdentityDao>()
.init_default_key(|| {
match crate::autoconf::identity_from_env(default_password(), "YAGNA_DEFAULT_SECRET_KEY") {
Ok(Some(key)) => {
Expand Down Expand Up @@ -146,7 +148,7 @@ impl IdentityService {
})
.await?
.identity_id
};
};

log::info!("using default identity: {:?}", default_key);

Expand Down

0 comments on commit 312b980

Please sign in to comment.