clevercloud_sdk/v4/addon_provider/
postgresql.rs1#![allow(deprecated)]
6
7use std::{
8 convert::TryFrom,
9 fmt::{self, Debug, Display, Formatter},
10 str::FromStr,
11};
12
13#[cfg(feature = "logging")]
14use log::{Level, debug, log_enabled};
15use oauth10a::client::{ClientError, RestClient};
16#[cfg(feature = "jsonschemas")]
17use schemars::JsonSchema_repr as JsonSchemaRepr;
18use serde_repr::{Deserialize_repr as DeserializeRepr, Serialize_repr as SerializeRepr};
19
20use crate::{
21 Client,
22 v4::addon_provider::{AddonProvider, AddonProviderId},
23};
24
25#[derive(thiserror::Error, Debug)]
29pub enum Error {
30 #[error("failed to parse version from '{0}', available versions are 15, 14, 13, 12 and 11")]
31 ParseVersion(String),
32 #[error("failed to get information about addon provider '{0}', {1}")]
33 Get(AddonProviderId, ClientError),
34}
35
36#[cfg_attr(feature = "jsonschemas", derive(JsonSchemaRepr))]
40#[derive(SerializeRepr, DeserializeRepr, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug)]
41#[serde(untagged)]
42#[repr(i32)]
43pub enum Version {
44 #[deprecated]
45 V10 = 10,
46 V11 = 11,
47 V12 = 12,
48 V13 = 13,
49 V14 = 14,
50 V15 = 15,
51}
52
53impl FromStr for Version {
54 type Err = Error;
55
56 fn from_str(s: &str) -> Result<Self, Self::Err> {
57 Ok(match s {
58 "15" => Self::V14,
59 "14" => Self::V14,
60 "13" => Self::V13,
61 "12" => Self::V12,
62 "11" => Self::V11,
63 "10" => Self::V10,
64 _ => {
65 return Err(Error::ParseVersion(s.to_owned()));
66 }
67 })
68 }
69}
70
71impl TryFrom<String> for Version {
72 type Error = Error;
73
74 fn try_from(s: String) -> Result<Self, Self::Error> {
75 Self::from_str(&s)
76 }
77}
78
79#[allow(clippy::from_over_into)]
80impl Into<String> for Version {
81 fn into(self) -> String {
82 self.to_string()
83 }
84}
85
86impl Display for Version {
87 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
88 match self {
89 Self::V15 => write!(f, "15"),
90 Self::V14 => write!(f, "14"),
91 Self::V13 => write!(f, "13"),
92 Self::V12 => write!(f, "12"),
93 Self::V11 => write!(f, "11"),
94 Self::V10 => write!(f, "10"),
95 }
96 }
97}
98
99#[cfg_attr(feature = "tracing", tracing::instrument)]
103pub async fn get(client: &Client) -> Result<AddonProvider<Version>, Error> {
105 let path = format!(
106 "{}/v4/addon-providers/{}",
107 client.endpoint,
108 AddonProviderId::PostgreSql
109 );
110
111 #[cfg(feature = "logging")]
112 if log_enabled!(Level::Debug) {
113 debug!(
114 "execute a request to get information about the postgresql addon-provider, path: '{}', name: '{}'",
115 &path,
116 AddonProviderId::PostgreSql
117 );
118 }
119
120 client
121 .get(&path)
122 .await
123 .map_err(|err| Error::Get(AddonProviderId::PostgreSql, err))
124}