-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add host-container user-data setting
You can set settings.host-containers.NAME.user-data to a valid base64-encoded string to have the (decoded) data placed in a file accessible to the host container at /.bottlerocket/host-containers/NAME/user-data.
- Loading branch information
Showing
10 changed files
with
121 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
12 changes: 12 additions & 0 deletions
12
sources/api/migration/migrations/v1.0.5/add-user-data/Cargo.toml
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,12 @@ | ||
[package] | ||
name = "add-user-data" | ||
version = "0.1.0" | ||
authors = ["Tom Kirchner <[email protected]>"] | ||
license = "Apache-2.0 OR MIT" | ||
edition = "2018" | ||
publish = false | ||
# Don't rebuild crate just because of changes to README. | ||
exclude = ["README.md"] | ||
|
||
[dependencies] | ||
migration-helpers = { path = "../../../migration-helpers" } |
45 changes: 45 additions & 0 deletions
45
sources/api/migration/migrations/v1.0.5/add-user-data/src/main.rs
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,45 @@ | ||
#![deny(rust_2018_idioms)] | ||
|
||
use migration_helpers::{migrate, Migration, MigrationData, Result}; | ||
use std::process; | ||
|
||
/// This migration removes host-container user data settings when downgrading to versions that | ||
/// don't understand them. | ||
pub struct AddUserDataMigration; | ||
|
||
impl Migration for AddUserDataMigration { | ||
/// There's no user data by default, it's just left empty on upgrade. | ||
fn forward(&mut self, input: MigrationData) -> Result<MigrationData> { | ||
println!("AddUserDataMigration has no work to do on upgrade."); | ||
Ok(input) | ||
} | ||
|
||
/// Older versions don't know about the user-data settings; we remove them so that old versions | ||
/// don't see them and fail deserialization. | ||
fn backward(&mut self, mut input: MigrationData) -> Result<MigrationData> { | ||
for setting in input.data.clone().keys() { | ||
// We don't currently have structured data available to migrations, and we don't want | ||
// to re-parse keys. We know no other keys could match these basic patterns. | ||
if setting.starts_with("settings.host-containers.") && setting.ends_with(".user-data") { | ||
if let Some(data) = input.data.remove(setting) { | ||
println!("Removed {}, which was set to '{}'", setting, data); | ||
} | ||
} | ||
} | ||
Ok(input) | ||
} | ||
} | ||
|
||
fn run() -> Result<()> { | ||
migrate(AddUserDataMigration) | ||
} | ||
|
||
// Returning a Result from main makes it print a Debug representation of the error, but with Snafu | ||
// we have nice Display representations of the error, so we wrap "main" (run) and print any error. | ||
// https://github.com/shepmaster/snafu/issues/110 | ||
fn main() { | ||
if let Err(e) = run() { | ||
eprintln!("{}", e); | ||
process::exit(1); | ||
} | ||
} |
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