Skip to content

Commit

Permalink
Clippy and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
korvyashka committed Aug 30, 2024
1 parent 03e3aeb commit 4d33fc2
Show file tree
Hide file tree
Showing 20 changed files with 178 additions and 153 deletions.
9 changes: 5 additions & 4 deletions src/api/asset.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::api::Api;
use crate::commands::CommandError;
use crate::commands;
use crate::commands::CommandError;

use serde::{Deserialize, Serialize};
use serde_json::Value;

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct AssetSignature {
Expand Down Expand Up @@ -44,6 +43,8 @@ impl Api {
),
)?;

Ok(serde_json::from_value::<Vec<AssetProcessingStatus>>(response)?)
Ok(serde_json::from_value::<Vec<AssetProcessingStatus>>(
response,
)?)
}
}
}
5 changes: 2 additions & 3 deletions src/api/edge_app/app.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use log::debug;

use crate::api::Api;
use crate::commands::CommandError;
use crate::commands;
use crate::commands::CommandError;

use serde_json::{json, Value};
use serde::{Deserialize, Serialize};

use serde_json::{json, Value};

#[derive(Debug)]
pub struct EdgeApps {
Expand Down
11 changes: 8 additions & 3 deletions src/api/edge_app/channel.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
use crate::api::Api;
use crate::commands::CommandError;
use crate::commands;
use crate::commands::CommandError;

use serde_json::json;

use serde::Deserialize;

impl Api {
pub fn update_channel(&self, channel: &str, app_id: &str, revision: u32) -> Result<(), CommandError> {
pub fn update_channel(
&self,
channel: &str,
app_id: &str,
revision: u32,
) -> Result<(), CommandError> {
let response = commands::patch(
&self.authentication,
&format!(
Expand Down Expand Up @@ -36,4 +41,4 @@ impl Api {

Ok(())
}
}
}
19 changes: 6 additions & 13 deletions src/api/edge_app/installation.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
use crate::api::Api;
use crate::commands::CommandError;
use crate::commands;
use crate::commands::CommandError;

use std::collections::HashMap;
use std::ops::Not;
use std::str::FromStr;
use serde_json::Value;
use log::debug;

use serde::Deserializer;
use strum::IntoEnumIterator;
use strum_macros::{Display, EnumIter, EnumString};

use crate::commands::serde_utils::{deserialize_string_field, serialize_non_empty_string_field};
use serde::{Deserialize, Serialize};
use serde_json::json;

Expand Down Expand Up @@ -72,7 +61,11 @@ impl Api {
Ok(())
}

pub fn update_installation_name(&self, installation_id: &str, name: &str) -> Result<(), CommandError> {
pub fn update_installation_name(
&self,
installation_id: &str,
name: &str,
) -> Result<(), CommandError> {
let payload = json!({
"name": name,
});
Expand Down
4 changes: 2 additions & 2 deletions src/api/edge_app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod app;
pub mod channel;
pub mod installation;
pub mod setting;
pub mod version;
pub mod channel;
pub mod installation;
90 changes: 67 additions & 23 deletions src/api/edge_app/setting.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{api::Api, commands::EdgeAppSettings};
use crate::commands::CommandError;
use crate::commands;
use crate::commands::CommandError;
use crate::{api::Api, commands::EdgeAppSettings};

use log::debug;
use serde_json::{json, Value};
use std::collections::HashMap;
use std::ops::Not;
use std::str::FromStr;
use log::debug;
use serde_json::{json, Value};

use serde::Deserializer;
use strum::IntoEnumIterator;
Expand Down Expand Up @@ -207,7 +207,6 @@ impl Setting {
}
}


impl Api {
pub fn get_settings(&self, app_id: &str) -> Result<Vec<Setting>, CommandError> {
Ok(deserialize_settings_from_array(commands::get(
Expand Down Expand Up @@ -255,7 +254,11 @@ impl Api {
Ok(EdgeAppSettings::new(serde_json::to_value(app_settings)?))
}

pub fn get_global_setting(&self, app_id: &str, setting_key: &str) -> Result<Option<SettingValue>, CommandError> {
pub fn get_global_setting(
&self,
app_id: &str,
setting_key: &str,
) -> Result<Option<SettingValue>, CommandError> {
let response = commands::get(
&self.authentication,
&format!(
Expand All @@ -270,7 +273,12 @@ impl Api {
Ok(Some(settings[0].clone()))
}

pub fn get_local_setting(&self, app_id: &str, installation_id: &str, setting_key: &str) -> Result<Option<SettingValue>, CommandError> {
pub fn get_local_setting(
&self,
app_id: &str,
installation_id: &str,
setting_key: &str,
) -> Result<Option<SettingValue>, CommandError> {
let response = commands::get(
&self.authentication,
&format!(
Expand All @@ -294,7 +302,7 @@ impl Api {
payload.insert("name".to_owned(), json!(setting.name));

debug!("Creating setting: {:?}", &payload);
Ok(commands::post(&self.authentication, "v4.1/edge-apps/settings", &payload)?)
commands::post(&self.authentication, "v4.1/edge-apps/settings", &payload)
}

pub fn update_setting(&self, app_id: &str, setting: &Setting) -> Result<Value, CommandError> {
Expand All @@ -304,15 +312,15 @@ impl Api {

debug!("Updating setting: {:?}", &payload);

Ok(commands::patch(
commands::patch(
&self.authentication,
&format!(
"v4.1/edge-apps/settings?app_id=eq.{id}&name=eq.{name}",
id = app_id,
name = setting.name
),
&payload,
)?)
)
}

pub fn delete_setting(&self, app_id: &str, setting: &Setting) -> Result<(), CommandError> {
Expand All @@ -327,7 +335,12 @@ impl Api {
Ok(())
}

pub fn create_global_setting_value(&self, app_id: &str, setting_key: &str, setting_value: &str) -> Result<(), CommandError> {
pub fn create_global_setting_value(
&self,
app_id: &str,
setting_key: &str,
setting_value: &str,
) -> Result<(), CommandError> {
let settings_values_payload = json!(
{
"app_id": app_id,
Expand All @@ -337,14 +350,19 @@ impl Api {
);
commands::post(
&self.authentication,
&format!("v4.1/edge-apps/settings/values"),
"v4.1/edge-apps/settings/values",
&settings_values_payload,
)?;

Ok(())
}

pub fn create_local_setting_value(&self, app_id: &str, installation_id: &str, setting_key: &str, setting_value: &str) -> Result<(), CommandError> {
pub fn create_local_setting_value(
&self,
installation_id: &str,
setting_key: &str,
setting_value: &str,
) -> Result<(), CommandError> {
let settings_values_payload = json!(
{
"installation_id": installation_id,
Expand All @@ -354,17 +372,25 @@ impl Api {
);
commands::post(
&self.authentication,
&format!("v4.1/edge-apps/settings/values"),
"v4.1/edge-apps/settings/values",
&settings_values_payload,
)?;

Ok(())
}

pub fn update_global_setting_value(&self, app_id: &str, setting_key: &str, setting_value: &str) -> Result<(), CommandError> {
pub fn update_global_setting_value(
&self,
app_id: &str,
setting_key: &str,
setting_value: &str,
) -> Result<(), CommandError> {
commands::patch(
&self.authentication,
&format!("v4.1/edge-apps/settings/values?app_id=eq.{}&name=eq.{}&installation_id=is.null", app_id, setting_key),
&format!(
"v4.1/edge-apps/settings/values?app_id=eq.{}&name=eq.{}&installation_id=is.null",
app_id, setting_key
),
&json!({
"value": setting_value,
}),
Expand All @@ -373,10 +399,18 @@ impl Api {
Ok(())
}

pub fn update_local_setting_value(&self, installation_id: &str, setting_key: &str, setting_value: &str) -> Result<(), CommandError> {
pub fn update_local_setting_value(
&self,
installation_id: &str,
setting_key: &str,
setting_value: &str,
) -> Result<(), CommandError> {
commands::patch(
&self.authentication,
&format!("v4.1/edge-apps/settings/values?installation_id=eq.{}&name=eq.{}", installation_id, setting_key),
&format!(
"v4.1/edge-apps/settings/values?installation_id=eq.{}&name=eq.{}",
installation_id, setting_key
),
&json!({
"value": setting_value,
}),
Expand All @@ -385,7 +419,12 @@ impl Api {
Ok(())
}

pub fn create_global_secret_value(&self, app_id: &str, setting_key: &str, setting_value: &str) -> Result<(), CommandError> {
pub fn create_global_secret_value(
&self,
app_id: &str,
setting_key: &str,
setting_value: &str,
) -> Result<(), CommandError> {
let payload = json!(
{
"app_id": app_id,
Expand All @@ -395,14 +434,19 @@ impl Api {
);
commands::post(
&self.authentication,
&format!("v4.1/edge-apps/secrets/values"),
"v4.1/edge-apps/secrets/values",
&payload,
)?;

Ok(())
}

pub fn create_local_secret_value(&self, installation_id: &str, setting_key: &str, setting_value: &str) -> Result<(), CommandError> {
pub fn create_local_secret_value(
&self,
installation_id: &str,
setting_key: &str,
setting_value: &str,
) -> Result<(), CommandError> {
let payload = json!(
{
"installation_id": installation_id,
Expand All @@ -412,10 +456,10 @@ impl Api {
);
commands::post(
&self.authentication,
&format!("v4.1/edge-apps/secrets/values"),
"v4.1/edge-apps/secrets/values",
&payload,
)?;

Ok(())
}
}
}
24 changes: 10 additions & 14 deletions src/api/edge_app/version.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
use crate::api::Api;
use crate::commands::CommandError;
use crate::commands;
use crate::commands::CommandError;

use std::collections::HashMap;
use std::ops::Not;
use std::str::FromStr;
use serde_json::Value;
use log::debug;
use serde_json::Value;
use std::collections::HashMap;

use serde::Deserializer;
use strum::IntoEnumIterator;
use strum_macros::{Display, EnumIter, EnumString};

use crate::commands::serde_utils::{deserialize_string_field, serialize_non_empty_string_field};
use serde::{Deserialize, Serialize};
use serde::Deserialize;
use serde_json::json;


impl Api {
pub fn version_exists(&self, app_id: &str, revision: u32) -> Result<bool, CommandError> {
let get_response = commands::get(
Expand Down Expand Up @@ -54,7 +46,11 @@ impl Api {
Err(CommandError::MissingField)
}

pub fn get_file_tree(&self, app_id: &str, revision: u32) -> Result<HashMap<String, String>, CommandError> {
pub fn get_file_tree(
&self,
app_id: &str,
revision: u32,
) -> Result<HashMap<String, String>, CommandError> {
let response = commands::get(
&self.authentication,
&format!(
Expand Down Expand Up @@ -86,4 +82,4 @@ impl Api {
)?;
Ok(())
}
}
}
4 changes: 2 additions & 2 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::authentication::Authentication;

pub mod asset;
pub mod edge_app;
pub mod version;
pub mod asset;

pub struct Api {
pub authentication: Authentication
pub authentication: Authentication,
}
Loading

0 comments on commit 4d33fc2

Please sign in to comment.