Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add imdsclient library for querying IMDS #1372

Merged
merged 4 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/os/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ source-groups = [
"webpki-roots-shim",
"logdog",
"models",
"imdsclient"
]

[lib]
Expand Down
71 changes: 68 additions & 3 deletions sources/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sources/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ members = [

"bottlerocket-release",

"imdsclient",

"ghostdog",

"growpart",
Expand Down
3 changes: 2 additions & 1 deletion sources/api/early-boot-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ exclude = ["README.md"]

[dependencies]
apiclient = { path = "../apiclient" }
async-trait = "0.1.36"
base64 = "0.13"
flate2 = { version = "1.0", default-features = false, features = ["rust_backend"] }
http = "0.2"
imdsclient = { path = "../../imdsclient" }
log = "0.4"
reqwest = { version = "0.11", default-features = false, features = ["blocking"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
serde_plain = "0.3"
Expand Down
1 change: 1 addition & 0 deletions sources/api/early-boot-config/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ async fn run() -> Result<()> {
let method = "PATCH";
for settings_json in data_provider
.platform_data()
.await
.context(error::ProviderError)?
{
// Don't send an empty request to the API
Expand Down
6 changes: 5 additions & 1 deletion sources/api/early-boot-config/src/provider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! The provider module owns the `PlatformDataProvider` trait

use crate::settings::SettingsJson;
use async_trait::async_trait;

#[cfg(any(bottlerocket_platform = "aws", bottlerocket_platform = "aws-dev"))]
pub(crate) mod aws;
Expand All @@ -12,11 +13,14 @@ pub(crate) mod local_file;
pub(crate) mod vmware;

/// Support for new platforms can be added by implementing this trait.
#[async_trait]
pub(crate) trait PlatformDataProvider {
/// You should return a list of SettingsJson, representing the settings changes you want to
/// send to the API.
///
/// This is a list so that handling multiple data sources within a platform can feel more
/// natural; you can also send all changes in one entry if you like.
fn platform_data(&self) -> std::result::Result<Vec<SettingsJson>, Box<dyn std::error::Error>>;
async fn platform_data(
&self,
) -> std::result::Result<Vec<SettingsJson>, Box<dyn std::error::Error>>;
}
Loading