Skip to content

Commit

Permalink
Support 'GET /api/deprecated-features'
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelklishin committed Dec 28, 2024
1 parent 2812b73 commit 9509e85
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::fmt;

use crate::error::Error;
use crate::error::Error::{ClientErrorResponse, NotFound, ServerErrorResponse};
use crate::responses::MessageList;
use crate::responses::{DeprecatedFeatureList, MessageList};
use crate::{
commons::{BindingDestinationType, UserLimitTarget, VirtualHostLimitTarget},
path,
Expand Down Expand Up @@ -1172,6 +1172,16 @@ where
Ok(response)
}

//
// Deprecated Features
//

pub async fn list_deprecated_features(&self) -> Result<DeprecatedFeatureList> {
let response = self.http_get("deprecated-features", None, None).await?;
let response = response.json().await?;
Ok(response)
}

//
// Implementation
//
Expand Down
12 changes: 11 additions & 1 deletion src/blocking_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use crate::error::Error;
use crate::error::Error::{ClientErrorResponse, NotFound, ServerErrorResponse};
use crate::responses::OAuthConfiguration;
use crate::responses::{DeprecatedFeatureList, OAuthConfiguration};
use crate::{
commons::{BindingDestinationType, UserLimitTarget, VirtualHostLimitTarget},
path,
Expand Down Expand Up @@ -1029,6 +1029,16 @@ where
Ok(response)
}

//
// Deprecated Features
//

pub fn list_deprecated_features(&self) -> Result<DeprecatedFeatureList> {
let response = self.http_get("deprecated-features", None, None)?;
let response = response.json()?;
Ok(response)
}

//
// OAuth 2 Configuration
//
Expand Down
4 changes: 2 additions & 2 deletions src/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize};

/// Exchange types. Most variants are for exchange types included with modern RabbitMQ distributions.
/// For custom types provided by 3rd party plugins, use the `Plugin(String)` variant.
#[derive(Serialize, Debug, PartialEq, Eq, Clone)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all(serialize = "lowercase", deserialize = "PascalCase"))]
pub enum ExchangeType {
/// Fanout exchange
Expand Down Expand Up @@ -116,7 +116,7 @@ impl From<ExchangeType> for String {
}
}

#[derive(Debug, Serialize, Clone, Copy)]
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
#[serde(rename_all(serialize = "lowercase", deserialize = "PascalCase"))]
pub enum QueueType {
Classic,
Expand Down
99 changes: 98 additions & 1 deletion src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,13 @@ impl fmt::Display for NodeMemoryBreakdown {
}

/// Represents a number of key OAuth 2 configuration settings.
#[derive(Serialize, Deserialize)]
#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
pub struct OAuthConfiguration {
pub oauth_enabled: bool,
#[cfg_attr(feature = "tabled", tabled(display_with = "display_option"))]
pub oauth_client_id: Option<String>,
#[cfg_attr(feature = "tabled", tabled(display_with = "display_option"))]
pub oauth_provider_url: Option<String>,
}

Expand Down Expand Up @@ -923,6 +926,100 @@ pub struct Overview {
pub churn_rates: ChurnRates,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all = "snake_case")]
pub enum DeprecationPhase {
PermittedByDefault,
DeniedByDefault,
Disconnected,
Removed,
Undefined,
}

impl From<&str> for DeprecationPhase {
fn from(value: &str) -> Self {
match value {
"permitted_by_default" => DeprecationPhase::PermittedByDefault,
"denited_by_default" => DeprecationPhase::DeniedByDefault,
"disconnected" => DeprecationPhase::Disconnected,
"removed" => DeprecationPhase::Removed,
_ => DeprecationPhase::Undefined,
}
}
}

impl From<String> for DeprecationPhase {
fn from(value: String) -> Self {
match value.as_str() {
"permitted_by_default" => DeprecationPhase::PermittedByDefault,
"denited_by_default" => DeprecationPhase::DeniedByDefault,
"disconnected" => DeprecationPhase::Disconnected,
"removed" => DeprecationPhase::Removed,
_ => DeprecationPhase::Undefined,
}
}
}

impl From<DeprecationPhase> for String {
fn from(value: DeprecationPhase) -> Self {
match value {
DeprecationPhase::PermittedByDefault => "permitted_by_default".to_owned(),
DeprecationPhase::DeniedByDefault => "denied_by_default".to_owned(),
DeprecationPhase::Disconnected => "disconnected".to_owned(),
DeprecationPhase::Removed => "removed".to_owned(),
DeprecationPhase::Undefined => "undefined".to_owned(),
}
}
}

impl fmt::Display for DeprecationPhase {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DeprecationPhase::PermittedByDefault => writeln!(f, "permitted_by_default")?,
DeprecationPhase::DeniedByDefault => writeln!(f, "denied_by_default")?,
DeprecationPhase::Disconnected => writeln!(f, "disconnected")?,
DeprecationPhase::Removed => writeln!(f, "removed")?,
DeprecationPhase::Undefined => writeln!(f, "undefined")?,
}

Ok(())
}
}

#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "tabled", derive(Tabled))]
#[allow(dead_code)]
pub struct DeprecatedFeature {
pub name: String,
#[serde(rename = "desc")]
pub description: String,
pub deprecation_phase: DeprecationPhase,
}

impl Display for DeprecatedFeature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "name: {}", self.name)?;
writeln!(f, "description: {}", self.description)?;
writeln!(f, "deprecation_phase: {}", self.deprecation_phase)?;

Ok(())
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(transparent)]
pub struct DeprecatedFeatureList(pub Vec<DeprecatedFeature>);

impl Display for DeprecatedFeatureList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for df in &self.0 {
writeln!(f, "{}", df)?;
}

Ok(())
}
}

fn undefined() -> String {
"?".to_string()
}
Expand Down
32 changes: 32 additions & 0 deletions tests/deprecated_feature_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2023-2024 RabbitMQ Core Team ([email protected])
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use rabbitmq_http_client::blocking_api::Client;
use rabbitmq_http_client::responses::DeprecationPhase;

mod test_helpers;
use crate::test_helpers::{endpoint, PASSWORD, USERNAME};

#[test]
fn test_list_all_deprecated_features() {
let endpoint = endpoint();
let rc = Client::new(&endpoint, USERNAME, PASSWORD);
let result = rc.list_deprecated_features();

assert!(result.is_ok());
let vec = result.unwrap();
assert!(vec
.0
.into_iter()
.any(|df| df.deprecation_phase == DeprecationPhase::PermittedByDefault));
}

0 comments on commit 9509e85

Please sign in to comment.