Skip to content

Commit

Permalink
Make it possible to export definitions of a specific virtual host
Browse files Browse the repository at this point in the history
and reflect the changes in the function names,
which is a minor breaking change.
  • Loading branch information
michaelklishin committed Feb 8, 2025
1 parent 76027ca commit 3de8cc7
Show file tree
Hide file tree
Showing 7 changed files with 359 additions and 28 deletions.
26 changes: 25 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
# Rust Client for the RabbitMQ HTTP API Change Log

## v0.21.0 (in development)
## v0.22.0 (in development)

No (documented) changes yet.


## v0.21.0 (Feb 8, 2025)

### Enhancements

* `responses::VirtualHostDefinitionSet` is an equivalent of `responses::ClusterDefinitionSet` but adapted
for the specific of virtual host-specific definitions, namely the fact that they do not contain
virtual hosts, users, or permissions, and objects such as queues or bindings do not have the
virtual host field to make it possible to import them into a virtual host with any name

* `Client#export_vhost_definitions`, `Client#export_vhost_definitions_as_string` and
`Client#export_vhost_definitions_as_data` are new functions that export virtual host-specific
definitions (as opposed to cluster-wide ones)

### Breaking Changes

* `responses::ClusterDefinitionSet` was renamed to `responses::ClusterDefinitionSet` to
differentiate it from virtual host-specific definitions, which are from now on
represented by `responses::VirtualHostDefinitionSet`

* `Client#export_definitions` was renamed to `Client#export_cluster_wide_definitions`
* `Client#export_definitions_as_string` was renamed to `Client#export_cluster_wide_definitions_as_string`
* `Client#export_definitions_as_data` was renamed to `Client#export_cluster_wide_definitions_as_data`


## v0.20.0 (Feb 2, 2025)

### Enhancements
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ This library is relatively young, breaking API changes are possible.
### Blocking Client

```toml
rabbitmq_http_client = { version = "0.20.0", features = ["core", "blocking"] }
rabbitmq_http_client = { version = "0.21.0", features = ["core", "blocking"] }
```

### Async Client

```toml
rabbitmq_http_client = { version = "0.20.0", features = ["core", "async"] }
rabbitmq_http_client = { version = "0.21.0", features = ["core", "async"] }
```

### Blocking Client with Tabled Support

```toml
rabbitmq_http_client = { version = "0.20.0", features = ["core", "blocking", "tabled"] }
rabbitmq_http_client = { version = "0.21.0", features = ["core", "blocking", "tabled"] }
```

### Async Client with Tabled Support

```toml
rabbitmq_http_client = { version = "0.20.0", features = ["core", "async", "tabled"] }
rabbitmq_http_client = { version = "0.21.0", features = ["core", "async", "tabled"] }
```


Expand Down
36 changes: 30 additions & 6 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use crate::error::Error::{ClientErrorResponse, NotFound, ServerErrorResponse};
use crate::requests::{EmptyPayload, StreamParams};
use crate::responses::{
DeprecatedFeatureList, FeatureFlag, FeatureFlagList, FeatureFlagStability, FeatureFlagState,
GetMessage, OAuthConfiguration, SchemaDefinitionSyncStatus, WarmStandbyReplicationStatus,
GetMessage, OAuthConfiguration, SchemaDefinitionSyncStatus, VirtualHostDefinitionSet,
WarmStandbyReplicationStatus,
};
use crate::{
commons::{BindingDestinationType, SupportedProtocol, UserLimitTarget, VirtualHostLimitTarget},
Expand All @@ -36,7 +37,7 @@ use crate::{
self, BulkUserDelete, EnforcedLimitParams, ExchangeParams, Permissions, PolicyParams,
QueueParams, RuntimeParameterDefinition, UserParams, VirtualHostParams, XArguments,
},
responses::{self, BindingInfo, DefinitionSet},
responses::{self, BindingInfo, ClusterDefinitionSet},
};

pub type HttpClientResponse = reqwest::Response;
Expand Down Expand Up @@ -1255,22 +1256,45 @@ where
//
// Definitions

pub async fn export_definitions(&self) -> Result<String> {
self.export_definitions_as_string().await
pub async fn export_cluster_wide_definitions(&self) -> Result<String> {
self.export_cluster_wide_definitions_as_string().await
}

pub async fn export_definitions_as_string(&self) -> Result<String> {
pub async fn export_cluster_wide_definitions_as_string(&self) -> Result<String> {
let response = self.http_get("definitions", None, None).await?;
let response = response.text().await?;
Ok(response)
}

pub async fn export_definitions_as_data(&self) -> Result<DefinitionSet> {
pub async fn export_cluster_wide_definitions_as_data(&self) -> Result<ClusterDefinitionSet> {
let response = self.http_get("definitions", None, None).await?;
let response = response.json().await?;
Ok(response)
}

pub async fn export_vhost_definitions(&self, vhost: &str) -> Result<String> {
self.export_vhost_definitions_as_string(vhost).await
}

pub async fn export_vhost_definitions_as_string(&self, vhost: &str) -> Result<String> {
let response = self
.http_get(path!("definitions", vhost), None, None)
.await?;
let response = response.text().await?;
Ok(response)
}

pub async fn export_vhost_definitions_as_data(
&self,
vhost: &str,
) -> Result<VirtualHostDefinitionSet> {
let response = self
.http_get(path!("definitions", vhost), None, None)
.await?;
let response = response.json().await?;
Ok(response)
}

pub async fn import_definitions(&self, definitions: Value) -> Result<()> {
self.http_post("definitions", &definitions, None, None)
.await?;
Expand Down
31 changes: 25 additions & 6 deletions src/blocking_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::error::Error::{ClientErrorResponse, NotFound, ServerErrorResponse};
use crate::requests::{EmptyPayload, StreamParams};
use crate::responses::{
DeprecatedFeatureList, FeatureFlag, FeatureFlagList, FeatureFlagStability, FeatureFlagState,
GetMessage, OAuthConfiguration, WarmStandbyReplicationStatus,
GetMessage, OAuthConfiguration, VirtualHostDefinitionSet, WarmStandbyReplicationStatus,
};
use crate::{
commons::{BindingDestinationType, SupportedProtocol, UserLimitTarget, VirtualHostLimitTarget},
Expand All @@ -27,7 +27,7 @@ use crate::{
self, BulkUserDelete, EnforcedLimitParams, ExchangeParams, Permissions, PolicyParams,
QueueParams, RuntimeParameterDefinition, UserParams, VirtualHostParams, XArguments,
},
responses::{self, BindingInfo, DefinitionSet, SchemaDefinitionSyncStatus},
responses::{self, BindingInfo, ClusterDefinitionSet, SchemaDefinitionSyncStatus},
};
use backtrace::Backtrace;
use reqwest::{
Expand Down Expand Up @@ -1097,22 +1097,41 @@ where
//
// Definitions

pub fn export_definitions(&self) -> Result<String> {
self.export_definitions_as_string()
pub fn export_cluster_wide_definitions(&self) -> Result<String> {
self.export_cluster_wide_definitions_as_string()
}

pub fn export_definitions_as_string(&self) -> Result<String> {
pub fn export_cluster_wide_definitions_as_string(&self) -> Result<String> {
let response = self.http_get("definitions", None, None)?;
let response = response.text()?;
Ok(response)
}

pub fn export_definitions_as_data(&self) -> Result<DefinitionSet> {
pub fn export_cluster_wide_definitions_as_data(&self) -> Result<ClusterDefinitionSet> {
let response = self.http_get("definitions", None, None)?;
let response = response.json()?;
Ok(response)
}

pub fn export_vhost_definitions(&self, vhost: &str) -> Result<String> {
self.export_vhost_definitions_as_string(vhost)
}

pub fn export_vhost_definitions_as_string(&self, vhost: &str) -> Result<String> {
let response = self.http_get(path!("definitions", vhost), None, None)?;
let response = response.text()?;
Ok(response)
}

pub fn export_vhost_definitions_as_data(
&self,
vhost: &str,
) -> Result<VirtualHostDefinitionSet> {
let response = self.http_get(path!("definitions", vhost), None, None)?;
let response = response.json()?;
Ok(response)
}

pub fn import_definitions(&self, definitions: Value) -> Result<()> {
self.http_post("definitions", &definitions, None, None)?;
Ok(())
Expand Down
98 changes: 95 additions & 3 deletions src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,20 @@ pub struct QueueDefinition {
pub arguments: XArguments,
}

/// Used in virtual host-specific definitions.
/// The virtual host is omitted so that such objects can
/// be imported into an arbitrary virtual host.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
#[allow(dead_code)]
pub struct QueueDefinitionWithoutVirtualHost {
pub name: String,
pub durable: bool,
pub auto_delete: bool,
#[cfg_attr(feature = "tabled", tabled(skip))]
pub arguments: XArguments,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
#[allow(dead_code)]
Expand All @@ -748,7 +762,22 @@ pub struct ExchangeInfo {
#[cfg_attr(feature = "tabled", tabled(display_with = "display_arg_table"))]
pub arguments: XArguments,
}
type ExchangeDefinition = ExchangeInfo;

/// Used in virtual host-specific definitions.
/// The virtual host is omitted so that such objects can
/// be imported into an arbitrary virtual host.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
#[allow(dead_code)]
pub struct ExchangeInfoWithoutVirtualHost {
pub name: String,
#[serde(rename = "type")]
pub exchange_type: String,
pub durable: bool,
pub auto_delete: bool,
#[cfg_attr(feature = "tabled", tabled(display_with = "display_arg_table"))]
pub arguments: XArguments,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
Expand All @@ -765,6 +794,23 @@ pub struct BindingInfo {
pub properties_key: Option<String>,
}

/// Used in virtual host-specific definitions.
/// The virtual host is omitted so that such objects can
/// be imported into an arbitrary virtual host.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
#[allow(dead_code)]
pub struct BindingInfoWithoutVirtualHost {
pub source: String,
pub destination: String,
pub destination_type: BindingDestinationType,
pub routing_key: String,
#[cfg_attr(feature = "tabled", tabled(display_with = "display_arg_table"))]
pub arguments: XArguments,
#[cfg_attr(feature = "tabled", tabled(display_with = "display_option"))]
pub properties_key: Option<String>,
}

#[derive(Debug, Deserialize, Clone)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
#[allow(dead_code)]
Expand Down Expand Up @@ -802,6 +848,19 @@ pub struct RuntimeParameter {
pub value: RuntimeParameterValue,
}

/// Used in virtual host-specific definitions.
/// The virtual host is omitted so that such objects can
/// be imported into an arbitrary virtual host.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
#[allow(dead_code)]
pub struct RuntimeParameterWithoutVirtualHost {
pub name: String,
pub component: String,
#[serde(deserialize_with = "deserialize_runtime_parameter_value")]
pub value: RuntimeParameterValue,
}

#[derive(Debug, Deserialize, Clone)]
#[allow(dead_code)]
pub struct ClusterIdentity {
Expand Down Expand Up @@ -834,6 +893,21 @@ pub struct Policy {
pub definition: PolicyDefinition,
}

/// Used in virtual host-specific definitions.
/// The virtual host is omitted so that such objects can
/// be imported into an arbitrary virtual host.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
#[allow(dead_code)]
pub struct PolicyWithoutVirtualHost {
pub name: String,
pub pattern: String,
#[serde(rename(deserialize = "apply-to"))]
pub apply_to: PolicyTarget,
pub priority: i16,
pub definition: PolicyDefinition,
}

#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
#[allow(dead_code)]
Expand All @@ -845,9 +919,10 @@ pub struct Permissions {
pub write: String,
}

/// Represents definitions of an entire cluster (all virtual hosts).
#[derive(Debug, Serialize, Deserialize, Clone)]
#[allow(dead_code)]
pub struct DefinitionSet {
pub struct ClusterDefinitionSet {
#[serde(rename(deserialize = "rabbitmq_version"))]
pub server_version: String,
pub users: Vec<User>,
Expand All @@ -859,10 +934,27 @@ pub struct DefinitionSet {
pub policies: Vec<Policy>,

pub queues: Vec<QueueDefinition>,
pub exchanges: Vec<ExchangeDefinition>,
pub exchanges: Vec<ExchangeInfo>,
pub bindings: Vec<BindingInfo>,
}

/// Represents definitions of a single virtual host.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[allow(dead_code)]
pub struct VirtualHostDefinitionSet {
#[serde(rename(deserialize = "rabbitmq_version"))]
pub server_version: String,
/// All virtual host metadata combined
pub metadata: VirtualHostMetadata,

pub parameters: Vec<RuntimeParameterWithoutVirtualHost>,
pub policies: Vec<PolicyWithoutVirtualHost>,

pub queues: Vec<QueueDefinitionWithoutVirtualHost>,
pub exchanges: Vec<ExchangeInfoWithoutVirtualHost>,
pub bindings: Vec<BindingInfoWithoutVirtualHost>,
}

#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[serde(untagged)]
pub enum HealthCheckFailureDetails {
Expand Down
Loading

0 comments on commit 3de8cc7

Please sign in to comment.