z_osmf/files/
extra_attributes.rs1pub mod reset;
2pub mod set;
3
4use std::marker::PhantomData;
5use std::sync::Arc;
6
7use serde::{Deserialize, Serialize};
8use z_osmf_macros::{Endpoint, Getters};
9
10use crate::convert::TryFromResponse;
11use crate::restfiles::get_transaction_id;
12use crate::{ClientCore, Error, Result};
13
14#[derive(Clone, Debug, Deserialize, Eq, Getters, Hash, Ord, PartialEq, PartialOrd, Serialize)]
15pub struct FileExtraAttributeList {
16 name: Arc<str>,
17 apf_authorized: bool,
18 program_controlled: bool,
19 shared_address_space: bool,
20 shared_library: bool,
21 transaction_id: Arc<str>,
22}
23
24impl TryFromResponse for FileExtraAttributeList {
25 async fn try_from_response(value: reqwest::Response) -> Result<Self> {
26 let transaction_id = get_transaction_id(&value)?;
27
28 let json: ResponseJson = value.json().await?;
29
30 if let [name, a, p, s, l] = &json.stdout[..] {
31 let apf_authorized = a.ends_with("YES");
32 let program_controlled = p.ends_with("YES");
33 let shared_address_space = s.ends_with("YES");
34 let shared_library = l.ends_with("YES");
35
36 Ok(FileExtraAttributeList {
37 name: name.clone(),
38 apf_authorized,
39 program_controlled,
40 shared_address_space,
41 shared_library,
42 transaction_id,
43 })
44 } else {
45 Err(Error::InvalidFormat(json.stdout))
46 }
47 }
48}
49
50#[derive(Clone, Debug, Endpoint)]
51#[endpoint(method = put, path = "/zosmf/restfiles/fs{path}")]
52pub(crate) struct FileExtraAttributeListBuilder<T>
53where
54 T: TryFromResponse,
55{
56 core: Arc<ClientCore>,
57
58 #[endpoint(path)]
59 path: Arc<str>,
60
61 #[endpoint(builder_fn = build_body)]
62 target_type: PhantomData<T>,
63}
64
65fn build_body<T>(
66 request_builder: reqwest::RequestBuilder,
67 _: &FileExtraAttributeListBuilder<T>,
68) -> reqwest::RequestBuilder
69where
70 T: TryFromResponse,
71{
72 request_builder.json(&RequestJson {
73 request: "extattr",
74 set: None,
75 reset: None,
76 })
77}
78
79#[derive(Serialize)]
80struct RequestJson {
81 request: &'static str,
82 #[serde(skip_serializing_if = "Option::is_none")]
83 set: Option<Arc<str>>,
84 #[serde(skip_serializing_if = "Option::is_none")]
85 reset: Option<Arc<str>>,
86}
87
88#[derive(Deserialize)]
89struct ResponseJson {
90 stdout: Arc<[Arc<str>]>,
91}