Skip to content

Commit

Permalink
Merge pull request #1372 from jpculp/imdsclient-lib
Browse files Browse the repository at this point in the history
Add imdsclient library for querying IMDS
  • Loading branch information
jpculp authored May 21, 2021
2 parents 51f95a9 + 2770773 commit b25435d
Show file tree
Hide file tree
Showing 18 changed files with 1,036 additions and 424 deletions.
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

0 comments on commit b25435d

Please sign in to comment.