Skip to content

Commit

Permalink
chore: use const for default user or owner
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed May 13, 2024
1 parent 63bb510 commit d5f5810
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
5 changes: 3 additions & 2 deletions sn_node_manager/src/bin/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use sn_node_manager::{
cmd, VerbosityLevel,
};
use sn_peers_acquisition::PeersArgs;
use sn_transfers::DEFAULT_NODE_OWNER;
use std::{net::Ipv4Addr, path::PathBuf};

const DEFAULT_NODE_COUNT: u16 = 25;
Expand Down Expand Up @@ -733,7 +734,7 @@ async fn main() -> Result<()> {
skip_validation: _,
owner,
} => {
let owner = owner.unwrap_or("maidsafe_test".to_string());
let owner = owner.unwrap_or(DEFAULT_NODE_OWNER.to_string());
cmd::local::join(
build,
count,
Expand Down Expand Up @@ -762,7 +763,7 @@ async fn main() -> Result<()> {
skip_validation: _,
owner,
} => {
let owner = owner.unwrap_or("maidsafe_test".to_string());
let owner = owner.unwrap_or(DEFAULT_NODE_OWNER.to_string());
cmd::local::run(
build,
clean,
Expand Down
3 changes: 3 additions & 0 deletions sn_node_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ use tracing::debug;

pub const DAEMON_DEFAULT_PORT: u16 = 12500;
pub const DAEMON_SERVICE_NAME: &str = "safenodemand";

pub const DEFAULT_CI_USER: &str = "runner";

const RPC_START_UP_DELAY_MS: u64 = 3000;

pub struct ServiceManager<T: ServiceStateActions + Send> {
Expand Down
11 changes: 7 additions & 4 deletions sn_node_manager/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

use crate::helpers::{get_bin_version, get_username};
use crate::{
helpers::{get_bin_version, get_username},
DEFAULT_CI_USER,
};
use color_eyre::eyre::OptionExt;
use color_eyre::{eyre::eyre, Result};
use colored::Colorize;
Expand All @@ -18,7 +21,7 @@ use sn_service_management::{
rpc::{RpcActions, RpcClient},
FaucetServiceData, NodeRegistry, NodeServiceData, ServiceStatus,
};
use sn_transfers::get_faucet_data_dir;
use sn_transfers::{get_faucet_data_dir, DEFAULT_NODE_OWNER};
use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
path::PathBuf,
Expand Down Expand Up @@ -299,8 +302,8 @@ pub async fn run_node(
// We shall use the input or env parsed username,
// as long as they are not default ones for tests.
// Input user_name is prioritized than parsed env.
let user = match (get_username(), run_options.owner == *"maidsafe_test") {
(Ok(user), true) if user == *"runner" => {
let user = match (get_username(), run_options.owner == *DEFAULT_NODE_OWNER) {
(Ok(user), true) if user == *DEFAULT_CI_USER => {
format!("node_{}", run_options.number)
}
(_, false) | (Err(_), true) => run_options.owner.clone(),
Expand Down
6 changes: 2 additions & 4 deletions sn_node_manager/tests/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod utils;

use assert_cmd::Command;
use color_eyre::eyre::{bail, eyre, OptionExt, Result};
use sn_node_manager::DAEMON_DEFAULT_PORT;
use sn_node_manager::{DAEMON_DEFAULT_PORT, DEFAULT_CI_USER};
use sn_service_management::safenode_manager_proto::{
safe_node_manager_client::SafeNodeManagerClient, NodeServiceRestartRequest,
};
Expand All @@ -24,8 +24,6 @@ use std::{
use tonic::Request;
use utils::get_service_status;

const CI_USER: &str = "runner";

/// These tests need to execute as the root user.
///
/// They are intended to run on a CI-based environment with a fresh build agent because they will
Expand Down Expand Up @@ -66,7 +64,7 @@ async fn restart_node() -> Result<()> {
let mut cmd = Command::cargo_bin("safenode-manager")?;
cmd.arg("add")
.arg("--user")
.arg(CI_USER)
.arg(DEFAULT_CI_USER)
.arg("--count")
.arg("3")
.arg("--peer")
Expand Down
5 changes: 2 additions & 3 deletions sn_node_manager/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use assert_cmd::Command;
use libp2p_identity::PeerId;
use sn_node_manager::DEFAULT_CI_USER;
use sn_service_management::{ServiceStatus, StatusSummary};

/// These tests need to execute as the root user.
Expand All @@ -17,8 +18,6 @@ use sn_service_management::{ServiceStatus, StatusSummary};
///
/// If you run them on your own dev machine, do so at your own risk!
const CI_USER: &str = "runner";

/// The default behaviour is for the service to run as the `safe` user, which gets created during
/// the process. However, there seems to be some sort of issue with adding user accounts on the GHA
/// build agent, so we will just tell it to use the `runner` user, which is the account for the
Expand All @@ -30,7 +29,7 @@ fn cross_platform_service_install_and_control() {
let mut cmd = Command::cargo_bin("safenode-manager").unwrap();
cmd.arg("add")
.arg("--user")
.arg(CI_USER)
.arg(DEFAULT_CI_USER)
.arg("--count")
.arg("3")
.arg("--peer")
Expand Down
11 changes: 5 additions & 6 deletions sn_node_manager/tests/upgrades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ mod utils;

use assert_cmd::Command;
use color_eyre::Result;
use sn_node_manager::DEFAULT_CI_USER;
use sn_releases::{ReleaseType, SafeReleaseRepoActions};
use utils::get_service_status;

const CI_USER: &str = "runner";

/// These tests need to execute as the root user.
///
/// They are intended to run on a CI-based environment with a fresh build agent because they will
Expand All @@ -29,7 +28,7 @@ async fn upgrade_to_latest_version() -> Result<()> {
let mut cmd = Command::cargo_bin("safenode-manager")?;
cmd.arg("add")
.arg("--user")
.arg(CI_USER)
.arg(DEFAULT_CI_USER)
.arg("--count")
.arg("3")
.arg("--peer")
Expand Down Expand Up @@ -85,7 +84,7 @@ async fn force_upgrade_when_two_binaries_have_the_same_version() -> Result<()> {
let mut cmd = Command::cargo_bin("safenode-manager")?;
cmd.arg("add")
.arg("--user")
.arg(CI_USER)
.arg(DEFAULT_CI_USER)
.arg("--count")
.arg("3")
.arg("--peer")
Expand Down Expand Up @@ -145,7 +144,7 @@ async fn force_downgrade_to_a_previous_version() -> Result<()> {
let mut cmd = Command::cargo_bin("safenode-manager")?;
cmd.arg("add")
.arg("--user")
.arg(CI_USER)
.arg(DEFAULT_CI_USER)
.arg("--count")
.arg("3")
.arg("--peer")
Expand Down Expand Up @@ -205,7 +204,7 @@ async fn upgrade_from_older_version_to_specific_version() -> Result<()> {
let mut cmd = Command::cargo_bin("safenode-manager")?;
cmd.arg("add")
.arg("--user")
.arg(CI_USER)
.arg(DEFAULT_CI_USER)
.arg("--count")
.arg("3")
.arg("--peer")
Expand Down
3 changes: 3 additions & 0 deletions sn_transfers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ mod wallet;

pub(crate) use cashnotes::{Input, TransactionBuilder};

/// Default value as a node owner
pub const DEFAULT_NODE_OWNER: &str = "maidsafe_test";

/// Types used in the public API
pub use cashnotes::{
CashNote, DerivationIndex, DerivedSecretKey, Hash, MainPubkey, MainSecretKey, NanoTokens,
Expand Down

0 comments on commit d5f5810

Please sign in to comment.