Skip to content

Instantly share code, notes, and snippets.

@alexeldeib
Created December 17, 2019 08:01
Show Gist options
  • Save alexeldeib/3b77fe2d54ebc37c904bd26ac7777271 to your computer and use it in GitHub Desktop.
Save alexeldeib/3b77fe2d54ebc37c904bd26ac7777271 to your computer and use it in GitHub Desktop.
imds sced
# ------------------------------------------------------------------------------
# Cargo Build Stage
# ------------------------------------------------------------------------------
FROM rust:latest as cargo-build
ARG APP=blah
ENV APP=$APP
ENV USER=root
WORKDIR /usr/src/blah
COPY . .
RUN cargo vendor
RUN cargo build --release
RUN cargo install --path .
# ------------------------------------------------------------------------------
# Final Stage
# ------------------------------------------------------------------------------
FROM gcr.io/distroless/cc
COPY --from=cargo-build /usr/src/blah/target/release/blah /usr/local/bin/blah
CMD ["/usr/local/bin/blah"]
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
struct Metadata {
compute: Compute,
}
#[derive(Serialize, Deserialize, Debug)]
struct Compute {
name: String,
#[serde(rename = "azEnvironment")]
environment: String,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct ScheduledEventResponse {
document_incarnation: String,
events: Vec<Event>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct Event {
event_id: String,
event_type: String,
resource_type: String,
resources: Vec<String>,
event_status: String,
not_before: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let res = reqwest::Client::new()
.get("http://169.254.169.254/metadata/scheduledevents?api-version=2017-11-01")
.header("Metadata", "true")
.send()
.await?
.text()
.await?;
let data: ScheduledEventResponse = serde_json::from_str(&res[..]).unwrap();
println!("{:#?}", data);
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment