1use serde::{Deserialize, Serialize};
2#[cfg(feature = "runtime")]
3use spin_app::{App, APP_NAME_KEY, APP_VERSION_KEY, OCI_IMAGE_DIGEST_KEY};
4
5#[derive(Debug, Serialize, Deserialize)]
6pub struct AppInfo {
7 pub name: String,
8 #[serde(default, skip_serializing_if = "Option::is_none")]
9 pub version: Option<String>,
10 #[serde(default, skip_serializing_if = "Option::is_none")]
11 pub oci_image_digest: Option<String>,
12}
13
14impl AppInfo {
15 #[cfg(feature = "runtime")]
16 pub fn new(app: &App) -> Self {
17 let name = app
18 .get_metadata(APP_NAME_KEY)
19 .unwrap_or_default()
20 .unwrap_or_default();
21 let version = app.get_metadata(APP_VERSION_KEY).unwrap_or_default();
22 let oci_image_digest = app.get_metadata(OCI_IMAGE_DIGEST_KEY).unwrap_or_default();
23 Self {
24 name,
25 version,
26 oci_image_digest,
27 }
28 }
29}