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}; |
| 19 | use std::fs::File; |
| 20 | use std::io; |
| 21 | |
| 22 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 23 | pub struct VmPayloadConfig { |
| 24 | #[serde(default)] |
| 25 | pub task: Option<Task>, |
| 26 | } |
| 27 | |
| 28 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 29 | pub struct Task { |
| 30 | pub command: String, |
| 31 | #[serde(default)] |
| 32 | pub args: Vec<String>, |
| 33 | } |
| 34 | |
| 35 | impl VmPayloadConfig { |
| 36 | pub fn load_from(path: &str) -> io::Result<VmPayloadConfig> { |
| 37 | info!("loading config from {}...", path); |
| 38 | let file = File::open(path)?; |
| 39 | Ok(serde_json::from_reader(file)?) |
| 40 | } |
| 41 | } |