From 56e97663dc1ebbf2c00aa3b6485d02b89d034bc0 Mon Sep 17 00:00:00 2001 From: Arnaldo Garcia Rincon Date: Wed, 11 Aug 2021 21:58:43 +0000 Subject: [PATCH 1/3] sources: remove unused struct from apiserver mod This commit removes the `BaseHttpResponse` struct from the apiserver's mod.rs file Signed-off-by: Arnaldo Garcia Rincon --- sources/api/apiserver/src/server/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/api/apiserver/src/server/mod.rs b/sources/api/apiserver/src/server/mod.rs index 697554cb8e8..71077b0ebac 100644 --- a/sources/api/apiserver/src/server/mod.rs +++ b/sources/api/apiserver/src/server/mod.rs @@ -6,7 +6,7 @@ mod error; pub use error::Error; use actix_web::{ - body::Body, error::ResponseError, web, App, BaseHttpResponse, FromRequest, HttpRequest, + body::Body, error::ResponseError, web, App, FromRequest, HttpRequest, HttpResponse, HttpServer, Responder, }; use bottlerocket_release::BottlerocketRelease; From 6c3c28a9eed34170e4276e1d0ddde41ae36047c2 Mon Sep 17 00:00:00 2001 From: Arnaldo Garcia Rincon Date: Tue, 10 Aug 2021 21:43:21 +0000 Subject: [PATCH 2/3] sources: add constants crate This commit adds the constants crate, which is shared accross different crates Signed-off-by: Arnaldo Garcia Rincon --- sources/Cargo.lock | 7 +++++++ sources/Cargo.toml | 2 ++ sources/constants/Cargo.toml | 14 ++++++++++++++ sources/constants/README.md | 9 +++++++++ sources/constants/README.tpl | 9 +++++++++ sources/constants/build.rs | 32 ++++++++++++++++++++++++++++++++ sources/constants/src/lib.rs | 15 +++++++++++++++ 7 files changed, 88 insertions(+) create mode 100644 sources/constants/Cargo.toml create mode 100644 sources/constants/README.md create mode 100644 sources/constants/README.tpl create mode 100644 sources/constants/build.rs create mode 100644 sources/constants/src/lib.rs diff --git a/sources/Cargo.lock b/sources/Cargo.lock index aba175bc79a..b65f041a67e 100644 --- a/sources/Cargo.lock +++ b/sources/Cargo.lock @@ -508,6 +508,13 @@ dependencies = [ "serde_json", ] +[[package]] +name = "bottlerocket-constants" +version = "0.1.0" +dependencies = [ + "cargo-readme", +] + [[package]] name = "bottlerocket-release" version = "0.1.0" diff --git a/sources/Cargo.toml b/sources/Cargo.toml index ddda7392445..cb32159abc6 100644 --- a/sources/Cargo.toml +++ b/sources/Cargo.toml @@ -51,6 +51,8 @@ members = [ "updater/updog", "webpki-roots-shim", + + "constants" ] [profile.release] diff --git a/sources/constants/Cargo.toml b/sources/constants/Cargo.toml new file mode 100644 index 00000000000..7cccaf3e6ba --- /dev/null +++ b/sources/constants/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "constants" +version = "0.1.0" +authors = ["Arnaldo Garcia Rincon "] +license = "Apache-2.0 OR MIT" +edition = "2018" +publish = false +# Don't rebuild crate just because of changes to README. +exclude = ["README.md"] + +[dependencies] + +[build-dependencies] +cargo-readme = "3.1" diff --git a/sources/constants/README.md b/sources/constants/README.md new file mode 100644 index 00000000000..5658066c757 --- /dev/null +++ b/sources/constants/README.md @@ -0,0 +1,9 @@ +# constants + +Current version: 0.1.0 + + This crate contains constants shared across multiple Bottlerocket crates + +## Colophon + +This text was generated from `README.tpl` using [cargo-readme](https://crates.io/crates/cargo-readme), and includes the rustdoc from `src/main.rs`. \ No newline at end of file diff --git a/sources/constants/README.tpl b/sources/constants/README.tpl new file mode 100644 index 00000000000..7b992c507f5 --- /dev/null +++ b/sources/constants/README.tpl @@ -0,0 +1,9 @@ +# {{crate}} + +Current version: {{version}} + +{{readme}} + +## Colophon + +This text was generated from `README.tpl` using [cargo-readme](https://crates.io/crates/cargo-readme), and includes the rustdoc from `src/main.rs`. diff --git a/sources/constants/build.rs b/sources/constants/build.rs new file mode 100644 index 00000000000..86c7bbc026e --- /dev/null +++ b/sources/constants/build.rs @@ -0,0 +1,32 @@ +// Automatically generate README.md from rustdoc. + +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Check for environment variable "SKIP_README". If it is set, + // skip README generation + if env::var_os("SKIP_README").is_some() { + return; + } + + let mut source = File::open("src/lib.rs").unwrap(); + let mut template = File::open("README.tpl").unwrap(); + + let content = cargo_readme::generate_readme( + &PathBuf::from("."), // root + &mut source, // source + Some(&mut template), // template + // The "add x" arguments don't apply when using a template. + true, // add title + false, // add badges + false, // add license + true, // indent headings + ) + .unwrap(); + + let mut readme = File::create("README.md").unwrap(); + readme.write_all(content.as_bytes()).unwrap(); +} diff --git a/sources/constants/src/lib.rs b/sources/constants/src/lib.rs new file mode 100644 index 00000000000..979c3e85e22 --- /dev/null +++ b/sources/constants/src/lib.rs @@ -0,0 +1,15 @@ +/*! + This crate contains constants shared across multiple Bottlerocket crates +*/ + +// Shared API settings +pub const API_SOCKET: &str = "/run/api.sock"; +pub const API_SETTINGS_URI: &str = "/settings"; +pub const API_SETTINGS_GENERATORS_URI: &str = "/metadata/setting-generators"; + +// Shared transaction used by boot time services +pub const LAUNCH_TRANSACTION: &str = "bottlerocket-launch"; + +// Shared binaries' locations +pub const SYSTEMCTL_BIN: &str = "/bin/systemctl"; +pub const HOST_CTR_BIN: &str = "/bin/host-ctr"; From 4e698fef36170bbb46cf853438aa02f1fe789479 Mon Sep 17 00:00:00 2001 From: Arnaldo Garcia Rincon Date: Tue, 10 Aug 2021 21:43:59 +0000 Subject: [PATCH 3/3] sources: use shared constants crate in crates This commit updates the following crates to use the shared constants crate: - apiclient - bootstrap-containers - certdog - corndog - early-boot-config - ecs-settings-applier - host-containers - pluto - schnauzer - service-dog - settings-commiter - static-pods - storewolf - sundog - thar-be-settings - thar-be-updates Signed-off-by: Arnaldo Garcia Rincon --- sources/Cargo.lock | 30 +++++++++++++++----- sources/api/apiclient/Cargo.toml | 1 + sources/api/apiclient/src/main.rs | 6 ++-- sources/api/bootstrap-containers/Cargo.toml | 1 + sources/api/bootstrap-containers/src/main.rs | 26 +++++++---------- sources/api/certdog/Cargo.toml | 1 + sources/api/certdog/src/main.rs | 8 ++---- sources/api/corndog/Cargo.toml | 1 + sources/api/corndog/src/main.rs | 6 ++-- sources/api/early-boot-config/Cargo.toml | 1 + sources/api/early-boot-config/src/main.rs | 13 +++------ sources/api/ecs-settings-applier/Cargo.toml | 1 + sources/api/ecs-settings-applier/src/ecs.rs | 6 ++-- sources/api/host-containers/Cargo.toml | 1 + sources/api/host-containers/src/main.rs | 29 ++++++++----------- sources/api/pluto/Cargo.toml | 1 + sources/api/pluto/src/api.rs | 10 +++---- sources/api/schnauzer/Cargo.toml | 1 + sources/api/schnauzer/src/main.rs | 6 ++-- sources/api/servicedog/Cargo.toml | 1 + sources/api/servicedog/src/main.rs | 13 +++------ sources/api/settings-committer/Cargo.toml | 1 + sources/api/settings-committer/src/main.rs | 10 +++---- sources/api/static-pods/Cargo.toml | 1 + sources/api/static-pods/src/static_pods.rs | 7 ++--- sources/api/storewolf/Cargo.toml | 1 + sources/api/storewolf/src/main.rs | 8 ++---- sources/api/sundog/Cargo.toml | 1 + sources/api/sundog/src/main.rs | 17 ++++------- sources/api/thar-be-settings/Cargo.toml | 1 + sources/api/thar-be-settings/src/main.rs | 8 ++---- sources/api/thar-be-updates/Cargo.toml | 1 + sources/api/thar-be-updates/src/main.rs | 12 ++++---- 33 files changed, 111 insertions(+), 120 deletions(-) diff --git a/sources/Cargo.lock b/sources/Cargo.lock index b65f041a67e..73d32523baf 100644 --- a/sources/Cargo.lock +++ b/sources/Cargo.lock @@ -254,6 +254,7 @@ name = "apiclient" version = "0.1.0" dependencies = [ "cargo-readme", + "constants", "datastore", "futures", "http", @@ -489,6 +490,7 @@ dependencies = [ "apiclient", "base64", "cargo-readme", + "constants", "datastore", "http", "log", @@ -508,13 +510,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "bottlerocket-constants" -version = "0.1.0" -dependencies = [ - "cargo-readme", -] - [[package]] name = "bottlerocket-release" version = "0.1.0" @@ -606,6 +601,7 @@ dependencies = [ "argh", "base64", "cargo-readme", + "constants", "der-parser", "http", "log", @@ -666,6 +662,13 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f92cfa0fd5690b3cf8c1ef2cabbd9b7ef22fa53cf5e1f92b05103f6d5d1cf6e7" +[[package]] +name = "constants" +version = "0.1.0" +dependencies = [ + "cargo-readme", +] + [[package]] name = "convert_case" version = "0.4.0" @@ -694,6 +697,7 @@ version = "0.1.0" dependencies = [ "apiclient", "cargo-readme", + "constants", "http", "log", "models", @@ -942,6 +946,7 @@ dependencies = [ "async-trait", "base64", "cargo-readme", + "constants", "flate2", "hex-literal", "http", @@ -964,6 +969,7 @@ name = "ecs-settings-applier" version = "0.1.0" dependencies = [ "cargo-readme", + "constants", "log", "schnauzer", "serde", @@ -1373,6 +1379,7 @@ dependencies = [ "apiclient", "base64", "cargo-readme", + "constants", "http", "log", "models", @@ -2255,6 +2262,7 @@ version = "0.1.0" dependencies = [ "apiclient", "cargo-readme", + "constants", "imdsclient", "models", "rusoto_core", @@ -2680,6 +2688,7 @@ dependencies = [ "base64", "bottlerocket-release", "cargo-readme", + "constants", "handlebars", "http", "lazy_static", @@ -2845,6 +2854,7 @@ version = "0.1.0" dependencies = [ "apiclient", "cargo-readme", + "constants", "datastore", "http", "log", @@ -2862,6 +2872,7 @@ version = "0.1.0" dependencies = [ "apiclient", "cargo-readme", + "constants", "http", "log", "serde", @@ -3063,6 +3074,7 @@ version = "0.1.0" dependencies = [ "base64", "cargo-readme", + "constants", "log", "models", "schnauzer", @@ -3135,6 +3147,7 @@ version = "0.1.0" dependencies = [ "bottlerocket-release", "cargo-readme", + "constants", "datastore", "log", "merge-toml", @@ -3195,6 +3208,7 @@ version = "0.1.0" dependencies = [ "apiclient", "cargo-readme", + "constants", "datastore", "http", "log", @@ -3283,6 +3297,7 @@ version = "0.1.0" dependencies = [ "apiclient", "cargo-readme", + "constants", "handlebars", "http", "itertools", @@ -3305,6 +3320,7 @@ dependencies = [ "bottlerocket-release", "cargo-readme", "chrono", + "constants", "fs2", "http", "log", diff --git a/sources/api/apiclient/Cargo.toml b/sources/api/apiclient/Cargo.toml index dbc0c99be55..40597008ca2 100644 --- a/sources/api/apiclient/Cargo.toml +++ b/sources/api/apiclient/Cargo.toml @@ -10,6 +10,7 @@ build = "build.rs" exclude = ["README.md"] [dependencies] +constants = { path = "../../constants" } datastore = { path = "../datastore" } futures = { version = "0.3", default-features = false } http = "0.2" diff --git a/sources/api/apiclient/src/main.rs b/sources/api/apiclient/src/main.rs index 070d708ac77..400eb8409c3 100644 --- a/sources/api/apiclient/src/main.rs +++ b/sources/api/apiclient/src/main.rs @@ -18,8 +18,8 @@ use std::env; use std::process; use std::str::FromStr; use unindent::unindent; +use constants; -const DEFAULT_API_SOCKET: &str = "/run/api.sock"; const DEFAULT_METHOD: &str = "GET"; /// Stores user-supplied global arguments. @@ -33,7 +33,7 @@ impl Default for Args { fn default() -> Self { Self { log_level: LevelFilter::Info, - socket_path: DEFAULT_API_SOCKET.to_string(), + socket_path: constants::API_SOCKET.to_string(), } } } @@ -151,7 +151,7 @@ fn usage() -> ! { update cancel options: None."#, - socket = DEFAULT_API_SOCKET, + socket = constants::API_SOCKET, method = DEFAULT_METHOD, ); eprintln!("{}", unindent(msg)); diff --git a/sources/api/bootstrap-containers/Cargo.toml b/sources/api/bootstrap-containers/Cargo.toml index 9aadb07e505..e394fcebe9b 100644 --- a/sources/api/bootstrap-containers/Cargo.toml +++ b/sources/api/bootstrap-containers/Cargo.toml @@ -11,6 +11,7 @@ exclude = ["README.md"] [dependencies] apiclient = { path = "../apiclient" } +constants = { path = "../../constants" } datastore = { path = "../datastore" } base64 = "0.13" http = "0.2" diff --git a/sources/api/bootstrap-containers/src/main.rs b/sources/api/bootstrap-containers/src/main.rs index 1b2a7805975..1ed55bb7a12 100644 --- a/sources/api/bootstrap-containers/src/main.rs +++ b/sources/api/bootstrap-containers/src/main.rs @@ -87,21 +87,15 @@ use std::fs; use std::path::Path; use std::process::{self, Command}; use std::str::FromStr; +use constants; use model::modeled_types::{BootstrapContainerMode, Identifier}; -// FIXME Get from configuration in the future -const DEFAULT_API_SOCKET: &str = "/run/api.sock"; -const API_SETTINGS_URI: &str = "/settings"; - const ENV_FILE_DIR: &str = "/etc/bootstrap-containers"; const DROPIN_FILE_DIR: &str = "/etc/systemd/system"; const PERSISTENT_STORAGE_DIR: &str = "/local/bootstrap-containers"; const DROP_IN_FILENAME: &str = "overrides.conf"; -const SYSTEMCTL_BIN: &str = "/bin/systemctl"; -const HOST_CTR_BIN: &str = "/bin/host-ctr"; - /// Stores user-supplied global arguments #[derive(Debug)] struct Args { @@ -113,7 +107,7 @@ impl Default for Args { fn default() -> Self { Self { log_level: LevelFilter::Info, - socket_path: DEFAULT_API_SOCKET.to_string(), + socket_path: constants::API_SOCKET.to_string(), } } } @@ -150,7 +144,7 @@ fn usage() { --mode MODE Socket path defaults to {}", - program_name, DEFAULT_API_SOCKET, + program_name, constants::API_SOCKET, ); } @@ -313,7 +307,7 @@ where if host_containerd_unit.is_active()? { debug!("Cleaning up container '{}'", name); command( - HOST_CTR_BIN, + constants::HOST_CTR_BIN, &[ "clean-up", "--container-id", @@ -327,7 +321,7 @@ where // Clean up any left over tasks, before the container is enabled if host_containerd_unit.is_active()? && !systemd_unit.is_enabled()? { command( - HOST_CTR_BIN, + constants::HOST_CTR_BIN, &[ "clean-up", "--container-id", @@ -397,7 +391,7 @@ where debug!("Querying the API for settings"); let method = "GET"; - let uri = API_SETTINGS_URI; + let uri = constants::API_SETTINGS_URI; let (_code, response_body) = apiclient::raw_request(&socket_path, uri, method, None) .await .context(error::APIRequest { method, uri })?; @@ -422,7 +416,7 @@ impl<'a> SystemdUnit<'a> { } fn is_enabled(&self) -> Result { - match command(SYSTEMCTL_BIN, &["is-enabled", &self.unit]) { + match command(constants::SYSTEMCTL_BIN, &["is-enabled", &self.unit]) { Ok(()) => Ok(true), Err(e) => { // If the systemd unit is not enabled, then `systemctl is-enabled` will return a @@ -439,7 +433,7 @@ impl<'a> SystemdUnit<'a> { } fn is_active(&self) -> Result { - match command(SYSTEMCTL_BIN, &["is-active", &self.unit]) { + match command(constants::SYSTEMCTL_BIN, &["is-active", &self.unit]) { Ok(()) => Ok(true), Err(e) => { // If the systemd unit is not active(running), then `systemctl is-active` will @@ -458,13 +452,13 @@ impl<'a> SystemdUnit<'a> { fn enable(&self) -> Result<()> { // Only enable the unit, since it will be started once systemd reaches the `preconfigured` // target - command(SYSTEMCTL_BIN, &["enable", &self.unit]) + command(constants::SYSTEMCTL_BIN, &["enable", &self.unit]) } fn disable(&self) -> Result<()> { // Bootstrap containers won't be up by the time the user sends configurations through // `apiclient`, so there is no need to add `--now` to stop them - command(SYSTEMCTL_BIN, &["disable", &self.unit]) + command(constants::SYSTEMCTL_BIN, &["disable", &self.unit]) } } diff --git a/sources/api/certdog/Cargo.toml b/sources/api/certdog/Cargo.toml index 1f563254ec2..627231e9d4d 100644 --- a/sources/api/certdog/Cargo.toml +++ b/sources/api/certdog/Cargo.toml @@ -13,6 +13,7 @@ exclude = ["README.md"] apiclient = { path = "../apiclient" } argh = "0.1.3" base64 = "0.13" +constants = { path = "../../constants" } # x509-parser depends on der-parser ^5.0. 5.1.1 contains breaking changes. # The 5.1.1 release isn't in the master branch; those changes are instead in a # 6.0.0 release, more clearly implying breaking changes. Lock to 5.1.0. diff --git a/sources/api/certdog/src/main.rs b/sources/api/certdog/src/main.rs index 9e44683e962..6dfa7336eeb 100644 --- a/sources/api/certdog/src/main.rs +++ b/sources/api/certdog/src/main.rs @@ -20,12 +20,10 @@ use std::io::{BufRead, Seek}; use std::path::Path; use std::process; use x509_parser; +use constants; use model::modeled_types::Identifier; -// FIXME Get from configuration in the future -const DEFAULT_API_SOCKET: &str = "/run/api.sock"; -const API_SETTINGS_URI: &str = "/settings"; // Read from the source in `/usr/share/factory` not the copy in `/etc` const DEFAULT_SOURCE_BUNDLE: &str = "/usr/share/factory/etc/pki/tls/certs/ca-bundle.crt"; // This file is first created with tmpfilesd configurations @@ -42,7 +40,7 @@ struct Args { #[argh(option, default = "LevelFilter::Info", short = 'l')] /// log-level trace|debug|info|warn|error log_level: LevelFilter, - #[argh(option, default = "DEFAULT_API_SOCKET.to_string()", short = 's')] + #[argh(option, default = "constants::API_SOCKET.to_string()", short = 's')] /// socket-path path to apiserver socket socket_path: String, #[argh(option, default = "DEFAULT_TRUSTED_STORE.to_string()", short = 't')] @@ -67,7 +65,7 @@ where debug!("Querying the API for settings"); let method = "GET"; - let uri = API_SETTINGS_URI; + let uri = constants::API_SETTINGS_URI; let (_code, response_body) = apiclient::raw_request(&socket_path, uri, method, None) .await .context(error::APIRequest { method, uri })?; diff --git a/sources/api/corndog/Cargo.toml b/sources/api/corndog/Cargo.toml index 9482e7f536b..27318c26512 100644 --- a/sources/api/corndog/Cargo.toml +++ b/sources/api/corndog/Cargo.toml @@ -11,6 +11,7 @@ exclude = ["README.md"] [dependencies] apiclient = { path = "../apiclient" } +constants = { path = "../../constants" } http = "0.2" log = "0.4" models = { path = "../../models" } diff --git a/sources/api/corndog/src/main.rs b/sources/api/corndog/src/main.rs index c4450aa5321..00bf0953653 100644 --- a/sources/api/corndog/src/main.rs +++ b/sources/api/corndog/src/main.rs @@ -16,8 +16,8 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use std::string::String; use std::{env, process}; +use constants; -const DEFAULT_API_SOCKET: &str = "/run/api.sock"; const SYSCTL_PATH_PREFIX: &str = "/proc/sys"; const LOCKDOWN_PATH: &str = "/sys/kernel/security/lockdown"; @@ -183,7 +183,7 @@ fn usage() -> ! { --log-level trace|debug|info|warn|error Socket path defaults to {}", - program_name, DEFAULT_API_SOCKET, + program_name, constants::API_SOCKET, ); process::exit(2); } @@ -228,7 +228,7 @@ fn parse_args(args: env::Args) -> Args { Args { subcommand: subcommand.unwrap_or_else(|| usage_msg("Must specify a subcommand.")), log_level: log_level.unwrap_or_else(|| LevelFilter::Info), - socket_path: socket_path.unwrap_or_else(|| DEFAULT_API_SOCKET.to_string()), + socket_path: socket_path.unwrap_or_else(|| constants::API_SOCKET.to_string()), } } diff --git a/sources/api/early-boot-config/Cargo.toml b/sources/api/early-boot-config/Cargo.toml index ebeaead6214..ff89dfc7948 100644 --- a/sources/api/early-boot-config/Cargo.toml +++ b/sources/api/early-boot-config/Cargo.toml @@ -13,6 +13,7 @@ exclude = ["README.md"] apiclient = { path = "../apiclient" } async-trait = "0.1.36" base64 = "0.13" +constants = { path = "../../constants" } flate2 = { version = "1.0", default-features = false, features = ["rust_backend"] } http = "0.2" imdsclient = { path = "../../imdsclient" } diff --git a/sources/api/early-boot-config/src/main.rs b/sources/api/early-boot-config/src/main.rs index 6064d7bf215..0d62aeb07b3 100644 --- a/sources/api/early-boot-config/src/main.rs +++ b/sources/api/early-boot-config/src/main.rs @@ -20,6 +20,7 @@ use snafu::{ensure, ResultExt}; use std::fs; use std::str::FromStr; use std::{env, process}; +use constants; mod compression; mod provider; @@ -29,12 +30,6 @@ use crate::provider::{Platform, PlatformDataProvider}; // TODO // Tests! -// FIXME Get these from configuration in the future -const DEFAULT_API_SOCKET: &str = "/run/api.sock"; -const API_SETTINGS_URI: &str = "/settings"; -// We change settings in the shared transaction used by boot-time services. -const TRANSACTION: &str = "bottlerocket-launch"; - // We only want to run early-boot-config once, at first boot. Our systemd unit file has a // ConditionPathExists that will prevent it from running again if this file exists. // We create it after running successfully. @@ -56,7 +51,7 @@ fn usage() -> ! { [ --log-level trace|debug|info|warn|error ] Socket path defaults to {}", - program_name, DEFAULT_API_SOCKET, + program_name, constants::API_SOCKET, ); process::exit(2); } @@ -97,7 +92,7 @@ fn parse_args(args: env::Args) -> Args { Args { log_level: log_level.unwrap_or_else(|| LevelFilter::Info), - socket_path: socket_path.unwrap_or_else(|| DEFAULT_API_SOCKET.to_string()), + socket_path: socket_path.unwrap_or_else(|| constants::API_SOCKET.to_string()), } } @@ -111,7 +106,7 @@ async fn run() -> Result<()> { info!("early-boot-config started"); info!("Retrieving platform-specific data"); - let uri = &format!("{}?tx={}", API_SETTINGS_URI, TRANSACTION); + let uri = &format!("{}?tx={}", constants::API_SETTINGS_URI, constants::LAUNCH_TRANSACTION); let method = "PATCH"; for settings_json in Platform .platform_data() diff --git a/sources/api/ecs-settings-applier/Cargo.toml b/sources/api/ecs-settings-applier/Cargo.toml index 3e75b638db6..5713ce67080 100644 --- a/sources/api/ecs-settings-applier/Cargo.toml +++ b/sources/api/ecs-settings-applier/Cargo.toml @@ -10,6 +10,7 @@ build = "build.rs" exclude = ["README.md"] [dependencies] +constants = { path = "../../constants" } serde = {version = "1.0", features = ["derive"]} serde_json = "1" schnauzer = { path = "../schnauzer" } diff --git a/sources/api/ecs-settings-applier/src/ecs.rs b/sources/api/ecs-settings-applier/src/ecs.rs index 85b1eadde3d..d7e88a8ab76 100644 --- a/sources/api/ecs-settings-applier/src/ecs.rs +++ b/sources/api/ecs-settings-applier/src/ecs.rs @@ -13,8 +13,8 @@ use snafu::{OptionExt, ResultExt}; use std::fs; use std::path::Path; use std::{env, process}; +use constants; -const DEFAULT_API_SOCKET: &str = "/run/api.sock"; const DEFAULT_ECS_CONFIG_PATH: &str = "/etc/ecs/ecs.config.json"; const VARIANT_ATTRIBUTE_NAME: &str = "bottlerocket.variant"; @@ -153,7 +153,7 @@ fn parse_args(args: env::Args) -> Args { } } Args { - socket_path: socket_path.unwrap_or_else(|| DEFAULT_API_SOCKET.to_string()), + socket_path: socket_path.unwrap_or_else(|| constants::API_SOCKET.to_string()), } } @@ -171,7 +171,7 @@ fn usage() -> ! { [ (-s | --socket-path) PATH ] Socket path defaults to {}", - program_name, DEFAULT_API_SOCKET + program_name, constants::API_SOCKET ); process::exit(2); } diff --git a/sources/api/host-containers/Cargo.toml b/sources/api/host-containers/Cargo.toml index 400e3d532aa..707b373f819 100644 --- a/sources/api/host-containers/Cargo.toml +++ b/sources/api/host-containers/Cargo.toml @@ -12,6 +12,7 @@ exclude = ["README.md"] [dependencies] apiclient = { path = "../apiclient" } base64 = "0.13" +constants = { path = "../../constants" } http = "0.2" log = "0.4" models = { path = "../../models" } diff --git a/sources/api/host-containers/src/main.rs b/sources/api/host-containers/src/main.rs index c1abbe33cf1..077db522578 100644 --- a/sources/api/host-containers/src/main.rs +++ b/sources/api/host-containers/src/main.rs @@ -27,18 +27,13 @@ use std::os::unix::fs::PermissionsExt; use std::path::{Path, PathBuf}; use std::process::{self, Command}; use std::str::FromStr; +use constants; use model::modeled_types::Identifier; -// FIXME Get from configuration in the future -const DEFAULT_API_SOCKET: &str = "/run/api.sock"; -const API_SETTINGS_URI: &str = "/settings"; const ENV_FILE_DIR: &str = "/etc/host-containers"; const PERSISTENT_STORAGE_BASE_DIR: &str = "/local/host-containers"; -const SYSTEMCTL_BIN: &str = "/bin/systemctl"; -const HOST_CTR_BIN: &str = "/bin/host-ctr"; - mod error { use http::StatusCode; use snafu::Snafu; @@ -149,7 +144,7 @@ where debug!("Querying the API for settings"); let method = "GET"; - let uri = API_SETTINGS_URI; + let uri = constants::API_SETTINGS_URI; let (code, response_body) = apiclient::raw_request(&socket_path, uri, method, None) .await .context(error::APIRequest { method, uri })?; @@ -182,7 +177,7 @@ impl<'a> SystemdUnit<'a> { } fn is_enabled(&self) -> Result { - match command(SYSTEMCTL_BIN, &["is-enabled", &self.unit]) { + match command(constants::SYSTEMCTL_BIN, &["is-enabled", &self.unit]) { Ok(_) => Ok(true), Err(e) => { // If the systemd unit is not enabled, then `systemctl is-enabled` will return a @@ -199,7 +194,7 @@ impl<'a> SystemdUnit<'a> { } fn is_active(&self) -> Result { - match command(SYSTEMCTL_BIN, &["is-active", &self.unit]) { + match command(constants::SYSTEMCTL_BIN, &["is-active", &self.unit]) { Ok(_) => Ok(true), Err(e) => { // If the systemd unit is not active(running), then `systemctl is-active` will @@ -216,14 +211,14 @@ impl<'a> SystemdUnit<'a> { } fn enable(&self) -> Result<()> { - command(SYSTEMCTL_BIN, &["enable", &self.unit])?; + command(constants::SYSTEMCTL_BIN, &["enable", &self.unit])?; Ok(()) } fn enable_and_start(&self) -> Result<()> { command( - SYSTEMCTL_BIN, + constants::SYSTEMCTL_BIN, &["enable", &self.unit, "--now", "--no-block"], )?; @@ -232,7 +227,7 @@ impl<'a> SystemdUnit<'a> { fn disable_and_stop(&self) -> Result<()> { command( - SYSTEMCTL_BIN, + constants::SYSTEMCTL_BIN, &["disable", &self.unit, "--now", "--no-block"], )?; @@ -307,7 +302,7 @@ fn usage() -> ! { [ --log-level trace|debug|info|warn|error ] Socket path defaults to {}", - program_name, DEFAULT_API_SOCKET, + program_name, constants::API_SOCKET, ); process::exit(2); } @@ -349,7 +344,7 @@ fn parse_args(args: env::Args) -> Args { Args { log_level: log_level.unwrap_or_else(|| LevelFilter::Info), - socket_path: socket_path.unwrap_or_else(|| DEFAULT_API_SOCKET.into()), + socket_path: socket_path.unwrap_or_else(|| constants::API_SOCKET.into()), } } @@ -400,12 +395,12 @@ where // // We only attempt to do this only if host-containerd is active and running if host_containerd_unit.is_active()? && !systemd_unit.is_enabled()? { - command(HOST_CTR_BIN, &["clean-up", "--container-id", name])?; + command(constants::HOST_CTR_BIN, &["clean-up", "--container-id", name])?; } // Only start the host container if the systemd target is 'multi-user', otherwise // it will start before the system is fully configured - match command(SYSTEMCTL_BIN, &["get-default"])?.trim().as_ref() { + match command(constants::SYSTEMCTL_BIN, &["get-default"])?.trim().as_ref() { "multi-user.target" => { debug!("Enabling and starting container: '{}'", unit_name); systemd_unit.enable_and_start()? @@ -422,7 +417,7 @@ where // // We only attempt to do this only if host-containerd is active and running if host_containerd_unit.is_active()? { - command(HOST_CTR_BIN, &["clean-up", "--container-id", name])?; + command(constants::HOST_CTR_BIN, &["clean-up", "--container-id", name])?; } } diff --git a/sources/api/pluto/Cargo.toml b/sources/api/pluto/Cargo.toml index dea733b8158..75174065163 100644 --- a/sources/api/pluto/Cargo.toml +++ b/sources/api/pluto/Cargo.toml @@ -11,6 +11,7 @@ exclude = ["README.md"] [dependencies] apiclient = { path = "../apiclient" } +constants = { path = "../../constants" } imdsclient = { path = "../../imdsclient" } models = { path = "../../models" } rusoto_core = { version = "0.47", default-features = false, features = ["rustls"] } diff --git a/sources/api/pluto/src/api.rs b/sources/api/pluto/src/api.rs index e3b0641d2cf..81faff13fc7 100644 --- a/sources/api/pluto/src/api.rs +++ b/sources/api/pluto/src/api.rs @@ -16,10 +16,7 @@ pub(crate) struct AwsK8sInfo { mod inner { use super::*; use snafu::{OptionExt, ResultExt, Snafu}; - - // FIXME Get these from configuration in the future - const DEFAULT_API_SOCKET: &str = "/run/api.sock"; - const SETTINGS_URI: &str = "/settings"; + use constants; #[derive(Debug, Snafu)] pub(crate) enum Error { @@ -38,10 +35,11 @@ mod inner { /// Gets the Bottlerocket settings from the API and deserializes them into a struct. async fn get_settings() -> Result { + let uri = constants::API_SETTINGS_URI; let (_status, response_body) = - apiclient::raw_request(DEFAULT_API_SOCKET, SETTINGS_URI, "GET", None) + apiclient::raw_request(constants::API_SOCKET, uri, "GET", None) .await - .context(ApiClient { uri: SETTINGS_URI })?; + .context(ApiClient { uri })?; serde_json::from_str(&response_body).context(SettingsJson) } diff --git a/sources/api/schnauzer/Cargo.toml b/sources/api/schnauzer/Cargo.toml index 4121d7c8a4b..760450497a2 100644 --- a/sources/api/schnauzer/Cargo.toml +++ b/sources/api/schnauzer/Cargo.toml @@ -12,6 +12,7 @@ exclude = ["README.md"] [dependencies] apiclient = { path = "../apiclient" } base64 = "0.13" +constants = { path = "../../constants" } bottlerocket-release = { path = "../../bottlerocket-release" } handlebars = "4.1" http = "0.2" diff --git a/sources/api/schnauzer/src/main.rs b/sources/api/schnauzer/src/main.rs index 4e9949e65cb..27dc220d918 100644 --- a/sources/api/schnauzer/src/main.rs +++ b/sources/api/schnauzer/src/main.rs @@ -19,9 +19,9 @@ use snafu::{ensure, OptionExt, ResultExt}; use std::collections::HashMap; use std::string::String; use std::{env, process}; +use constants; // Setting generators do not require dynamic socket paths at this moment. -const DEFAULT_API_SOCKET: &str = "/run/api.sock"; const API_METADATA_URI_BASE: &str = "/metadata/"; mod error { @@ -91,7 +91,7 @@ type Result = std::result::Result; async fn get_metadata(key: &str, meta: &str) -> Result { let uri = &format!("{}{}?keys={}", API_METADATA_URI_BASE, meta, key); let method = "GET"; - let (code, response_body) = apiclient::raw_request(DEFAULT_API_SOCKET, &uri, method, None) + let (code, response_body) = apiclient::raw_request(constants::API_SOCKET, &uri, method, None) .await .context(error::APIRequest { method, uri })?; ensure!( @@ -147,7 +147,7 @@ async fn run() -> Result<()> { let registry = schnauzer::build_template_registry().context(error::BuildTemplateRegistry)?; let template = get_metadata(&setting_name, "templates").await?; - let settings = schnauzer::get_settings(DEFAULT_API_SOCKET) + let settings = schnauzer::get_settings(constants::API_SOCKET) .await .context(error::GetSettings)?; diff --git a/sources/api/servicedog/Cargo.toml b/sources/api/servicedog/Cargo.toml index b3b2757f11e..e9fe7da211c 100644 --- a/sources/api/servicedog/Cargo.toml +++ b/sources/api/servicedog/Cargo.toml @@ -11,6 +11,7 @@ exclude = ["README.md"] [dependencies] apiclient = { path = "../apiclient" } +constants = { path = "../../constants" } datastore = { path = "../datastore" } http = "0.2" log = "0.4" diff --git a/sources/api/servicedog/src/main.rs b/sources/api/servicedog/src/main.rs index 3d32771c6e3..7dd4717f10f 100644 --- a/sources/api/servicedog/src/main.rs +++ b/sources/api/servicedog/src/main.rs @@ -24,16 +24,11 @@ use std::env; use std::ffi::OsStr; use std::process::{self, Command}; use std::str::FromStr; +use constants; use datastore::serialization::to_pairs_with_prefix; use datastore::{Key, KeyType}; -// FIXME Get from configuration in the future -const DEFAULT_API_SOCKET: &str = "/run/api.sock"; -const API_SETTINGS_URI: &str = "/settings"; - -const SYSTEMCTL_BIN: &str = "/bin/systemctl"; - mod error { use http::StatusCode; use snafu::Snafu; @@ -148,8 +143,8 @@ where let key = Key::new(KeyType::Data, key_str).context(error::InvalidKey { key: key_str })?; debug!("Querying the API for setting: {}", key_str); - let uri = format!("{}?keys={}", API_SETTINGS_URI, key_str); - let (code, response_body) = apiclient::raw_request(DEFAULT_API_SOCKET, &uri, "GET", None) + let uri = format!("{}?keys={}", constants::API_SETTINGS_URI, key_str); + let (code, response_body) = apiclient::raw_request(constants::API_SOCKET, &uri, "GET", None) .await .context(error::APIRequest { method: "GET", @@ -238,7 +233,7 @@ where // a `Command` whereas `.args()` returns a `&mut Command`. We use // `Command` in our error reporting, which does not play nice with // mutable references. - let mut command = Command::new(SYSTEMCTL_BIN); + let mut command = Command::new(constants::SYSTEMCTL_BIN); command.args(args); let output = command .output() diff --git a/sources/api/settings-committer/Cargo.toml b/sources/api/settings-committer/Cargo.toml index 043237ee033..1a4c61696c7 100644 --- a/sources/api/settings-committer/Cargo.toml +++ b/sources/api/settings-committer/Cargo.toml @@ -11,6 +11,7 @@ exclude = ["README.md"] [dependencies] apiclient = { path = "../apiclient" } +constants = { path = "../../constants" } snafu = "0.6" http = "0.2" log = "0.4" diff --git a/sources/api/settings-committer/src/main.rs b/sources/api/settings-committer/src/main.rs index 0d6b04e5f7e..d9b4a553c5e 100644 --- a/sources/api/settings-committer/src/main.rs +++ b/sources/api/settings-committer/src/main.rs @@ -17,12 +17,10 @@ use simplelog::{Config as LogConfig, LevelFilter, SimpleLogger}; use snafu::ResultExt; use std::str::FromStr; use std::{collections::HashMap, env, process}; +use constants; -const DEFAULT_API_SOCKET: &str = "/run/api.sock"; const API_PENDING_URI_BASE: &str = "/tx"; const API_COMMIT_URI_BASE: &str = "/tx/commit"; -// By default we commit settings from a shared transaction used by boot-time services. -const DEFAULT_TRANSACTION: &str = "bottlerocket-launch"; type Result = std::result::Result; @@ -144,7 +142,7 @@ fn usage() -> ! { Transaction defaults to {} Socket path defaults to {}", - program_name, DEFAULT_TRANSACTION, DEFAULT_API_SOCKET + program_name, constants::LAUNCH_TRANSACTION, constants::API_SOCKET ); process::exit(2); } @@ -192,9 +190,9 @@ fn parse_args(args: env::Args) -> Args { } Args { - transaction: transaction.unwrap_or_else(|| DEFAULT_TRANSACTION.to_string()), + transaction: transaction.unwrap_or_else(|| constants::LAUNCH_TRANSACTION.to_string()), log_level: log_level.unwrap_or_else(|| LevelFilter::Info), - socket_path: socket_path.unwrap_or_else(|| DEFAULT_API_SOCKET.to_string()), + socket_path: socket_path.unwrap_or_else(|| constants::API_SOCKET.to_string()), } } diff --git a/sources/api/static-pods/Cargo.toml b/sources/api/static-pods/Cargo.toml index f78ce692032..ae2a5c28c39 100644 --- a/sources/api/static-pods/Cargo.toml +++ b/sources/api/static-pods/Cargo.toml @@ -10,6 +10,7 @@ build = "build.rs" exclude = ["README.md"] [dependencies] +constants = { path = "../../constants" } base64 = "0.13" log = "0.4" models = { path = "../../models" } diff --git a/sources/api/static-pods/src/static_pods.rs b/sources/api/static-pods/src/static_pods.rs index 433a0534b82..e2ec21d2b46 100644 --- a/sources/api/static-pods/src/static_pods.rs +++ b/sources/api/static-pods/src/static_pods.rs @@ -23,9 +23,6 @@ use std::process; use std::str::FromStr; use tempfile::{NamedTempFile, TempDir}; -// FIXME Get from configuration in the future -const DEFAULT_API_SOCKET: &str = "/run/api.sock"; - const STATIC_POD_DIR: &str = "/etc/kubernetes/static-pods"; const ETC_KUBE_DIR: &str = "/etc/kubernetes"; @@ -178,7 +175,7 @@ fn usage() { [ --log-level trace|debug|info|warn|error ] Socket path defaults to {}", - program_name, DEFAULT_API_SOCKET, + program_name, constants::API_SOCKET, ); } @@ -221,7 +218,7 @@ fn parse_args(args: env::Args) -> Result { Ok(Args { log_level: log_level.unwrap_or_else(|| LevelFilter::Info), - socket_path: socket_path.unwrap_or_else(|| DEFAULT_API_SOCKET.into()), + socket_path: socket_path.unwrap_or_else(|| constants::API_SOCKET.into()), }) } diff --git a/sources/api/storewolf/Cargo.toml b/sources/api/storewolf/Cargo.toml index eff901c745c..dba5deded1f 100644 --- a/sources/api/storewolf/Cargo.toml +++ b/sources/api/storewolf/Cargo.toml @@ -10,6 +10,7 @@ build = "build.rs" exclude = ["README.md"] [dependencies] +constants = { path = "../../constants" } bottlerocket-release = { path = "../../bottlerocket-release" } datastore = { path = "../datastore" } log = "0.4" diff --git a/sources/api/storewolf/src/main.rs b/sources/api/storewolf/src/main.rs index d1c150c8c59..f2ca00f2403 100644 --- a/sources/api/storewolf/src/main.rs +++ b/sources/api/storewolf/src/main.rs @@ -26,8 +26,7 @@ use datastore::serialization::{to_pairs, to_pairs_with_prefix}; use datastore::{self, DataStore, FilesystemDataStore, ScalarError}; use model::modeled_types::SingleLineString; -// Shared transaction used by boot-time services. -const TRANSACTION: &str = "bottlerocket-launch"; +use constants; mod error { use std::io; @@ -285,7 +284,7 @@ fn populate_default_datastore>( &settings_to_write ); let pending = datastore::Committed::Pending { - tx: TRANSACTION.to_string(), + tx: constants::LAUNCH_TRANSACTION.to_string(), }; datastore .set_keys(&settings_to_write, &pending) @@ -456,8 +455,7 @@ fn run() -> Result<()> { let args = parse_args(env::args()); // SimpleLogger will send errors to stderr and anything less to stdout. - SimpleLogger::init(args.log_level, LogConfig::default()) - .context(error::Logger)?; + SimpleLogger::init(args.log_level, LogConfig::default()).context(error::Logger)?; info!("Storewolf started"); diff --git a/sources/api/sundog/Cargo.toml b/sources/api/sundog/Cargo.toml index 1eab8d8e71c..b839fc83955 100644 --- a/sources/api/sundog/Cargo.toml +++ b/sources/api/sundog/Cargo.toml @@ -11,6 +11,7 @@ exclude = ["README.md"] [dependencies] apiclient = { path = "../apiclient" } +constants = { path = "../../constants" } datastore = { path = "../datastore" } http = "0.2" log = "0.4" diff --git a/sources/api/sundog/src/main.rs b/sources/api/sundog/src/main.rs index c069c5b75ca..e80078131f3 100644 --- a/sources/api/sundog/src/main.rs +++ b/sources/api/sundog/src/main.rs @@ -19,16 +19,11 @@ use std::env; use std::path::Path; use std::process; use std::str::{self, FromStr}; +use constants; use datastore::serialization::to_pairs_with_prefix; use datastore::{self, deserialization, Key, KeyType}; -// FIXME Get from configuration in the future -const DEFAULT_API_SOCKET: &str = "/run/api.sock"; -const API_SETTINGS_URI: &str = "/settings"; -const API_SETTING_GENERATORS_URI: &str = "/metadata/setting-generators"; -// We change settings in the shared transaction used by boot-time services. -const TRANSACTION: &str = "bottlerocket-launch"; /// Potential errors during Sundog execution mod error { @@ -161,7 +156,7 @@ async fn get_setting_generators(socket_path: S) -> Result, { - let uri = API_SETTING_GENERATORS_URI; + let uri = constants::API_SETTINGS_GENERATORS_URI; debug!("Requesting setting generators from API"); let (code, response_body) = apiclient::raw_request(socket_path.as_ref(), uri, "GET", None) @@ -195,7 +190,7 @@ where // Build the query string and the URI containing that query. let query = to_query.join(","); - let uri = &format!("{}?keys={}", API_SETTINGS_URI, query); + let uri = &format!("{}?keys={}", constants::API_SETTINGS_URI, query); let (code, response_body) = apiclient::raw_request(socket_path.as_ref(), uri, "GET", None) .await @@ -362,7 +357,7 @@ where // Serialize our Settings struct to the JSON wire format let request_body = serde_json::to_string(&settings).context(error::SerializeRequest)?; - let uri = &format!("{}?tx={}", API_SETTINGS_URI, TRANSACTION); + let uri = &format!("{}?tx={}", constants::API_SETTINGS_URI, constants::LAUNCH_TRANSACTION); let method = "PATCH"; trace!("Settings to {} to {}: {}", method, uri, &request_body); let (code, response_body) = @@ -397,7 +392,7 @@ fn usage() -> ! { [ --log-level trace|debug|info|warn|error ] Socket path defaults to {}", - program_name, DEFAULT_API_SOCKET, + program_name, constants::API_SOCKET, ); process::exit(2); } @@ -438,7 +433,7 @@ fn parse_args(args: env::Args) -> Args { Args { log_level: log_level.unwrap_or_else(|| LevelFilter::Info), - socket_path: socket_path.unwrap_or_else(|| DEFAULT_API_SOCKET.to_string()), + socket_path: socket_path.unwrap_or_else(|| constants::API_SOCKET.to_string()), } } diff --git a/sources/api/thar-be-settings/Cargo.toml b/sources/api/thar-be-settings/Cargo.toml index e4b935c7a51..be945ef9921 100644 --- a/sources/api/thar-be-settings/Cargo.toml +++ b/sources/api/thar-be-settings/Cargo.toml @@ -11,6 +11,7 @@ exclude = ["README.md"] [dependencies] apiclient = { path = "../apiclient" } +constants = { path = "../../constants" } handlebars = "4.1" http = "0.2" itertools = "0.10" diff --git a/sources/api/thar-be-settings/src/main.rs b/sources/api/thar-be-settings/src/main.rs index 0b383e4af3c..09f274b29fd 100644 --- a/sources/api/thar-be-settings/src/main.rs +++ b/sources/api/thar-be-settings/src/main.rs @@ -9,12 +9,10 @@ use std::env; use std::process; use std::str::FromStr; use tokio::runtime::Runtime; +use constants; use thar_be_settings::{config, get_changed_settings, service}; -// FIXME Get from configuration in the future -const DEFAULT_API_SOCKET: &str = "/run/api.sock"; - mod error { use snafu::Snafu; use std::path::PathBuf; @@ -70,7 +68,7 @@ fn usage() -> ! { process; this is useful to prevent blocking an API call. Socket path defaults to {}", - program_name, DEFAULT_API_SOCKET, + program_name, constants::API_SOCKET, ); process::exit(2); } @@ -119,7 +117,7 @@ fn parse_args(args: env::Args) -> Args { daemon, mode, log_level: log_level.unwrap_or_else(|| LevelFilter::Info), - socket_path: socket_path.unwrap_or_else(|| DEFAULT_API_SOCKET.to_string()), + socket_path: socket_path.unwrap_or_else(|| constants::API_SOCKET.to_string()), } } diff --git a/sources/api/thar-be-updates/Cargo.toml b/sources/api/thar-be-updates/Cargo.toml index 305772369e3..6e35fdebb37 100644 --- a/sources/api/thar-be-updates/Cargo.toml +++ b/sources/api/thar-be-updates/Cargo.toml @@ -11,6 +11,7 @@ exclude = ["README.md"] [dependencies] apiclient = { path = "../apiclient" } +constants = { path = "../../constants" } bottlerocket-release = { path = "../../bottlerocket-release" } chrono = { version = "0.4.11", features = [ "serde" ] } fs2 = "0.4.3" diff --git a/sources/api/thar-be-updates/src/main.rs b/sources/api/thar-be-updates/src/main.rs index 4b8119aa5cf..1d9a1ee4046 100644 --- a/sources/api/thar-be-updates/src/main.rs +++ b/sources/api/thar-be-updates/src/main.rs @@ -16,6 +16,7 @@ thar-be-updates uses a lockfile to control read/write access to the disks and th */ +use constants; use fs2::FileExt; use log::{debug, warn}; use nix::unistd::{fork, ForkResult}; @@ -36,9 +37,6 @@ use thar_be_updates::status::{ UPDATE_STATUS_FILE, }; -// FIXME Get this from configuration in the future -const DEFAULT_API_SOCKET: &str = "/run/api.sock"; - const UPDATE_STATUS_DIR: &str = "/run/cache/thar-be-updates"; /// Stores the command line arguments @@ -64,7 +62,8 @@ fn usage() -> ! { Global options: [ --socket-path PATH ] Bottlerocket API socket path (default {}) [ --log-level trace|debug|info|warn|error ] (default info)", - program_name, DEFAULT_API_SOCKET, + program_name, + constants::API_SOCKET, ); process::exit(2); } @@ -114,7 +113,7 @@ fn parse_args(args: std::env::Args) -> Args { Args { subcommand: subcommand.unwrap_or_else(|| usage()), log_level: log_level.unwrap_or_else(|| LevelFilter::Info), - socket_path: socket_path.unwrap_or_else(|| DEFAULT_API_SOCKET.to_string()), + socket_path: socket_path.unwrap_or_else(|| constants::API_SOCKET.to_string()), } } @@ -331,8 +330,7 @@ fn run() -> Result<()> { let args = parse_args(env::args()); // SimpleLogger will send errors to stderr and anything less to stdout. - SimpleLogger::init(args.log_level, LogConfig::default()) - .context(error::Logger)?; + SimpleLogger::init(args.log_level, LogConfig::default()).context(error::Logger)?; // Open the lockfile for concurrency control, create it if it doesn't exist let lockfile = File::create(UPDATE_LOCKFILE).context(error::UpdateLockFile {