Jooyung Han | 347d9f2 | 2021-05-28 00:05:14 +0900 | [diff] [blame] | 1 | // Copyright 2021, The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | //! VM Payload Config |
| 16 | |
| 17 | use log::info; |
| 18 | use serde::{Deserialize, Serialize}; |
Jooyung Han | 347d9f2 | 2021-05-28 00:05:14 +0900 | [diff] [blame] | 19 | use std::io; |
Jooyung Han | f48ceb4 | 2021-06-01 18:00:04 +0900 | [diff] [blame] | 20 | use std::path::Path; |
| 21 | use std::time::Duration; |
| 22 | |
| 23 | use crate::ioutil; |
| 24 | |
| 25 | const WAIT_TIMEOUT: Duration = Duration::from_secs(10); |
Jooyung Han | 347d9f2 | 2021-05-28 00:05:14 +0900 | [diff] [blame] | 26 | |
| 27 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 28 | pub struct VmPayloadConfig { |
| 29 | #[serde(default)] |
| 30 | pub task: Option<Task>, |
| 31 | } |
| 32 | |
| 33 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 34 | pub struct Task { |
| 35 | pub command: String, |
| 36 | #[serde(default)] |
| 37 | pub args: Vec<String>, |
| 38 | } |
| 39 | |
| 40 | impl VmPayloadConfig { |
Jooyung Han | f48ceb4 | 2021-06-01 18:00:04 +0900 | [diff] [blame] | 41 | pub fn load_from(path: &Path) -> io::Result<VmPayloadConfig> { |
| 42 | info!("loading config from {:?}...", path); |
| 43 | let file = ioutil::wait_for_file(path, WAIT_TIMEOUT)?; |
Jooyung Han | 347d9f2 | 2021-05-28 00:05:14 +0900 | [diff] [blame] | 44 | Ok(serde_json::from_reader(file)?) |
| 45 | } |
| 46 | } |