Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate paths #15

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
58 changes: 51 additions & 7 deletions generator/src/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl Generator {
let client_name = Ident::new(&client_name, quote!().span());

let mut module_defs = ModuleDefs::default();
let proxmox_client = proxmox_api(quote!(ProxmoxClient));

let methods: Vec<_> = node
.value
Expand Down Expand Up @@ -128,15 +129,24 @@ impl Generator {
let fn_name_str = method.to_ascii_lowercase();
let fn_name = Ident::new(&fn_name_str, quote!().span());

let (signature, defer_signature) = if let Some(TypeDef::Struct(strt)) = &parameters
{
let params = if let Some(TypeDef::Struct(strt)) = &parameters {
let name = Ident::new(&strt.name(), quote! {}.span());
(quote!(&self, params: #name), quote!(&path, &params))
quote!(#name)
} else if parameters.is_none() {
quote!(())
} else {
panic!("Cannot handle non-struct, non-empty parameters!");
};

let base_signature = quote!(&self, params: #params);

let (signature, defer_signature) = if parameters.is_some() {
(base_signature.clone(), quote!(&path, &params))
} else {
(quote!(&self), quote!(&path, &()))
};

let (returns, call) = if let Some(ret) = info.returns.as_ref() {
let (output_ty, returns, call) = if let Some(ret) = info.returns.as_ref() {
let output = ret.type_def("", &format!("{method}Output"));

if let Some(output) = output {
Expand All @@ -149,15 +159,24 @@ impl Generator {

let call = Self::to_call(def.primitive(), &fn_name, defer_signature);

(quote! { -> Result<#name, T::Error> }, call)
(
Some(name.clone()),
quote! { -> Result<#name, T::Error> },
call,
)
} else {
(
None,
quote!( -> Result<(), T::Error> ),
quote!(self.client.#fn_name(#defer_signature)),
)
}
} else {
(quote!(), quote!(self.client.#fn_name(#defer_signature)))
(
None,
quote!(),
quote!(self.client.#fn_name(#defer_signature)),
)
};

let doc = if let Some(doc) = &info.description {
Expand All @@ -171,17 +190,34 @@ impl Generator {
let fn_definition = quote! {
#doc
pub fn #fn_name(#signature) #returns {
let path = self.path.to_string();
let path = #proxmox_client::path(self).as_ref();
#call
}
};

let client = proxmox_api(quote!(client::Client));
let action = proxmox_api(quote!(proxmox_client::ProxmoxClientAction));

let params_ty = params.clone();
let params = parameters.as_ref().map(|_| quote!(params)).into_iter();
let output_ty = output_ty.unwrap_or_else(|| quote!(()));
let method = Ident::new(&method, quote!().span());
let method = proxmox_api(quote!(client::Method::#method));
let method_ty = proxmox_api(quote!(client::Method));

let block = quote! {
impl<T> #client_name<T> where T: #client {
#fn_definition
}

impl<T> #action<#params_ty, #output_ty, T::Error>
for &#client_name<T> where T: #client {
const METHOD: #method_ty = #method;

fn exec(#base_signature) -> Result<#output_ty, T::Error> {
self.#fn_name(#(#params)*)
}
}
};

block
Expand Down Expand Up @@ -257,6 +293,14 @@ impl Generator {
#new
}

impl<'a, T> #proxmox_client for &'a #client_name<T> where T: #client {
type Path = &'a str;

fn path(self) -> Self::Path {
&self.path
}
}

#(#methods)*

#module_defs
Expand Down
21 changes: 20 additions & 1 deletion proxmox-api/src/generated/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,36 @@ where
}
}
}
impl<'a, T> crate::ProxmoxClient for &'a AccessClient<T>
where
T: crate::client::Client,
{
type Path = &'a str;
fn path(self) -> Self::Path {
&self.path
}
}
impl<T> AccessClient<T>
where
T: crate::client::Client,
{
#[doc = "Directory index."]
#[doc = ""]
pub fn get(&self) -> Result<Vec<GetOutputItems>, T::Error> {
let path = self.path.to_string();
let path = crate::ProxmoxClient::path(self).as_ref();
self.client.get(&path, &())
}
}
impl<T> crate::proxmox_client::ProxmoxClientAction<(), Vec<GetOutputItems>, T::Error>
for &AccessClient<T>
where
T: crate::client::Client,
{
const METHOD: crate::client::Method = crate::client::Method::Get;
fn exec(&self, params: ()) -> Result<Vec<GetOutputItems>, T::Error> {
self.get()
}
}
impl GetOutputItems {
pub fn new(subdir: String) -> Self {
Self {
Expand Down
32 changes: 30 additions & 2 deletions proxmox-api/src/generated/access/acl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,56 @@ where
}
}
}
impl<'a, T> crate::ProxmoxClient for &'a AclClient<T>
where
T: crate::client::Client,
{
type Path = &'a str;
fn path(self) -> Self::Path {
&self.path
}
}
impl<T> AclClient<T>
where
T: crate::client::Client,
{
#[doc = "Get Access Control List (ACLs)."]
#[doc = ""]
pub fn get(&self) -> Result<Vec<GetOutputItems>, T::Error> {
let path = self.path.to_string();
let path = crate::ProxmoxClient::path(self).as_ref();
self.client.get(&path, &())
}
}
impl<T> crate::proxmox_client::ProxmoxClientAction<(), Vec<GetOutputItems>, T::Error>
for &AclClient<T>
where
T: crate::client::Client,
{
const METHOD: crate::client::Method = crate::client::Method::Get;
fn exec(&self, params: ()) -> Result<Vec<GetOutputItems>, T::Error> {
self.get()
}
}
impl<T> AclClient<T>
where
T: crate::client::Client,
{
#[doc = "Update Access Control List (add or remove permissions)."]
#[doc = ""]
pub fn put(&self, params: PutParams) -> Result<(), T::Error> {
let path = self.path.to_string();
let path = crate::ProxmoxClient::path(self).as_ref();
self.client.put(&path, &params)
}
}
impl<T> crate::proxmox_client::ProxmoxClientAction<PutParams, (), T::Error> for &AclClient<T>
where
T: crate::client::Client,
{
const METHOD: crate::client::Method = crate::client::Method::Put;
fn exec(&self, params: PutParams) -> Result<(), T::Error> {
self.put(params)
}
}
impl GetOutputItems {
pub fn new(path: String, roleid: String, ty: Type, ugid: String) -> Self {
Self {
Expand Down
32 changes: 30 additions & 2 deletions proxmox-api/src/generated/access/domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,56 @@ where
}
}
}
impl<'a, T> crate::ProxmoxClient for &'a DomainsClient<T>
where
T: crate::client::Client,
{
type Path = &'a str;
fn path(self) -> Self::Path {
&self.path
}
}
impl<T> DomainsClient<T>
where
T: crate::client::Client,
{
#[doc = "Authentication domain index."]
#[doc = ""]
pub fn get(&self) -> Result<Vec<GetOutputItems>, T::Error> {
let path = self.path.to_string();
let path = crate::ProxmoxClient::path(self).as_ref();
self.client.get(&path, &())
}
}
impl<T> crate::proxmox_client::ProxmoxClientAction<(), Vec<GetOutputItems>, T::Error>
for &DomainsClient<T>
where
T: crate::client::Client,
{
const METHOD: crate::client::Method = crate::client::Method::Get;
fn exec(&self, params: ()) -> Result<Vec<GetOutputItems>, T::Error> {
self.get()
}
}
impl<T> DomainsClient<T>
where
T: crate::client::Client,
{
#[doc = "Add an authentication server."]
#[doc = ""]
pub fn post(&self, params: PostParams) -> Result<(), T::Error> {
let path = self.path.to_string();
let path = crate::ProxmoxClient::path(self).as_ref();
self.client.post(&path, &params)
}
}
impl<T> crate::proxmox_client::ProxmoxClientAction<PostParams, (), T::Error> for &DomainsClient<T>
where
T: crate::client::Client,
{
const METHOD: crate::client::Method = crate::client::Method::Post;
fn exec(&self, params: PostParams) -> Result<(), T::Error> {
self.post(params)
}
}
impl GetOutputItems {
pub fn new(realm: String, ty: String) -> Self {
Self {
Expand Down
42 changes: 39 additions & 3 deletions proxmox-api/src/generated/access/domains/realm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,75 @@ where
}
}
}
impl<'a, T> crate::ProxmoxClient for &'a RealmClient<T>
where
T: crate::client::Client,
{
type Path = &'a str;
fn path(self) -> Self::Path {
&self.path
}
}
impl<T> RealmClient<T>
where
T: crate::client::Client,
{
#[doc = "Delete an authentication server."]
#[doc = ""]
pub fn delete(&self) -> Result<(), T::Error> {
let path = self.path.to_string();
let path = crate::ProxmoxClient::path(self).as_ref();
self.client.delete(&path, &())
}
}
impl<T> crate::proxmox_client::ProxmoxClientAction<(), (), T::Error> for &RealmClient<T>
where
T: crate::client::Client,
{
const METHOD: crate::client::Method = crate::client::Method::Delete;
fn exec(&self, params: ()) -> Result<(), T::Error> {
self.delete()
}
}
impl<T> RealmClient<T>
where
T: crate::client::Client,
{
#[doc = "Get auth server configuration."]
#[doc = ""]
pub fn get(&self) -> Result<(), T::Error> {
let path = self.path.to_string();
let path = crate::ProxmoxClient::path(self).as_ref();
self.client.get(&path, &())
}
}
impl<T> crate::proxmox_client::ProxmoxClientAction<(), (), T::Error> for &RealmClient<T>
where
T: crate::client::Client,
{
const METHOD: crate::client::Method = crate::client::Method::Get;
fn exec(&self, params: ()) -> Result<(), T::Error> {
self.get()
}
}
impl<T> RealmClient<T>
where
T: crate::client::Client,
{
#[doc = "Update authentication server settings."]
#[doc = ""]
pub fn put(&self, params: PutParams) -> Result<(), T::Error> {
let path = self.path.to_string();
let path = crate::ProxmoxClient::path(self).as_ref();
self.client.put(&path, &params)
}
}
impl<T> crate::proxmox_client::ProxmoxClientAction<PutParams, (), T::Error> for &RealmClient<T>
where
T: crate::client::Client,
{
const METHOD: crate::client::Method = crate::client::Method::Put;
fn exec(&self, params: PutParams) -> Result<(), T::Error> {
self.put(params)
}
}
#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, Default)]
pub struct PutParams {
#[serde(rename = "acr-values")]
Expand Down
20 changes: 19 additions & 1 deletion proxmox-api/src/generated/access/domains/realm/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,35 @@ where
}
}
}
impl<'a, T> crate::ProxmoxClient for &'a SyncClient<T>
where
T: crate::client::Client,
{
type Path = &'a str;
fn path(self) -> Self::Path {
&self.path
}
}
impl<T> SyncClient<T>
where
T: crate::client::Client,
{
#[doc = "Syncs users and/or groups from the configured LDAP to user.cfg. NOTE: Synced groups will have the name 'name-$realm', so make sure those groups do not exist to prevent overwriting."]
#[doc = ""]
pub fn post(&self, params: PostParams) -> Result<String, T::Error> {
let path = self.path.to_string();
let path = crate::ProxmoxClient::path(self).as_ref();
self.client.post(&path, &params)
}
}
impl<T> crate::proxmox_client::ProxmoxClientAction<PostParams, String, T::Error> for &SyncClient<T>
where
T: crate::client::Client,
{
const METHOD: crate::client::Method = crate::client::Method::Post;
fn exec(&self, params: PostParams) -> Result<String, T::Error> {
self.post(params)
}
}
#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, Default)]
pub struct PostParams {
#[serde(rename = "dry-run")]
Expand Down
Loading
Loading