diff options
Diffstat (limited to 'ipfs-api/src')
-rw-r--r-- | ipfs-api/src/client/internal.rs | 150 | ||||
-rw-r--r-- | ipfs-api/src/request/config.rs | 20 | ||||
-rw-r--r-- | ipfs-api/src/response/config.rs | 10 |
3 files changed, 180 insertions, 0 deletions
diff --git a/ipfs-api/src/client/internal.rs b/ipfs-api/src/client/internal.rs index 17059fd..974d3c0 100644 --- a/ipfs-api/src/client/internal.rs +++ b/ipfs-api/src/client/internal.rs @@ -789,6 +789,156 @@ impl IpfsClient { self.request(request::Commands, None).await } + /// Get ipfs config strings. + /// + /// ```no_run + /// use ipfs_api::IpfsClient; + /// + /// let client = IpfsClient::default(); + /// let res = client.config_get_string("Identity.PeerID"); + /// ``` + /// + #[inline] + pub async fn config_get_string(&self, key: &str) -> Result<response::ConfigResponse, Error> { + self.request( + request::Config { + key, + value: None, + boolean: None, + stringified_json: None, + }, + None, + ) + .await + } + + /// Get ipfs config booleans. + /// + /// ```no_run + /// use ipfs_api::IpfsClient; + /// + /// let client = IpfsClient::default(); + /// let res = client.config_get_bool("Datastore.HashOnRead"); + /// ``` + /// + #[inline] + pub async fn config_get_bool(&self, key: &str) -> Result<response::ConfigResponse, Error> { + self.request( + request::Config { + key, + value: None, + boolean: None, + stringified_json: None, + }, + None, + ) + .await + } + + /// Get ipfs config json. + /// + /// ```no_run + /// use ipfs_api::IpfsClient; + /// + /// let client = IpfsClient::default(); + /// let res = client.config_get_json("Mounts"); + /// ``` + /// + #[inline] + pub async fn config_get_json(&self, key: &str) -> Result<response::ConfigResponse, Error> { + self.request( + request::Config { + key, + value: None, + boolean: None, + stringified_json: None, + }, + None, + ) + .await + } + + /// Set ipfs config string. + /// + /// ```no_run + /// use ipfs_api::IpfsClient; + /// + /// let client = IpfsClient::default(); + /// let res = client.config_set_string("Routing.Type", "dht"); + /// ``` + /// + #[inline] + pub async fn config_set_string( + &self, + key: &str, + value: &str, + ) -> Result<response::ConfigResponse, Error> { + self.request( + request::Config { + key, + value: Some(value), + boolean: None, + stringified_json: None, + }, + None, + ) + .await + } + + /// Set ipfs config boolean. + /// + /// ```no_run + /// use ipfs_api::IpfsClient; + /// + /// let client = IpfsClient::default(); + /// let res = client.config_set_bool("Pubsub.DisableSigning", "false"); + /// ``` + /// + #[inline] + pub async fn config_set_bool( + &self, + key: &str, + value: bool, + ) -> Result<response::ConfigResponse, Error> { + self.request( + request::Config { + key, + value: Some(&value.to_string()), + boolean: Some(true), + stringified_json: None, + }, + None, + ) + .await + } + + /// Set ipfs config json. + /// + /// ```no_run + /// use ipfs_api::IpfsClient; + /// + /// let client = IpfsClient::default(); + /// let res = config_set_json("Discovery", r#"{"MDNS":{"Enabled":true,"Interval":10}}"#); + /// ``` + /// + #[inline] + pub async fn config_set_json( + &self, + key: &str, + value: &str, + ) -> Result<response::ConfigResponse, Error> { + self.request( + request::Config { + key, + value: Some(value), + boolean: None, + stringified_json: Some(true), + }, + None, + ) + .await + } + /// Opens the config file for editing (on the server). /// /// ```no_run diff --git a/ipfs-api/src/request/config.rs b/ipfs-api/src/request/config.rs index a6d5c58..9ea5250 100644 --- a/ipfs-api/src/request/config.rs +++ b/ipfs-api/src/request/config.rs @@ -7,6 +7,26 @@ // use crate::request::ApiRequest; +use crate::serde::Serialize; + +#[derive(Serialize)] +pub struct Config<'a> { + #[serde(rename = "arg")] + pub key: &'a str, + + #[serde(rename = "arg")] + pub value: Option<&'a str>, + + #[serde(rename = "bool")] + pub boolean: Option<bool>, + + #[serde(rename = "json")] + pub stringified_json: Option<bool>, +} + +impl<'a> ApiRequest for Config<'a> { + const PATH: &'static str = "/config"; +} pub struct ConfigEdit; diff --git a/ipfs-api/src/response/config.rs b/ipfs-api/src/response/config.rs index 81e8caf..0bacf98 100644 --- a/ipfs-api/src/response/config.rs +++ b/ipfs-api/src/response/config.rs @@ -6,6 +6,16 @@ // copied, modified, or distributed except according to those terms. // +use crate::serde::Deserialize; + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct ConfigResponse { + pub key: String, + + pub value: serde_json::value::Value, +} + pub type ConfigEditResponse = (); pub type ConfigReplaceResponse = (); |