spin_http/
app_info.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use serde::{Deserialize, Serialize};
#[cfg(feature = "runtime")]
use spin_app::{App, APP_NAME_KEY, APP_VERSION_KEY, OCI_IMAGE_DIGEST_KEY};

#[derive(Debug, Serialize, Deserialize)]
pub struct AppInfo {
    pub name: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub version: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub oci_image_digest: Option<String>,
}

impl AppInfo {
    #[cfg(feature = "runtime")]
    pub fn new(app: &App) -> Self {
        let name = app
            .get_metadata(APP_NAME_KEY)
            .unwrap_or_default()
            .unwrap_or_default();
        let version = app.get_metadata(APP_VERSION_KEY).unwrap_or_default();
        let oci_image_digest = app.get_metadata(OCI_IMAGE_DIGEST_KEY).unwrap_or_default();
        Self {
            name,
            version,
            oci_image_digest,
        }
    }
}