Skip to content

Commit

Permalink
Support GET /api/auth
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelklishin committed Dec 28, 2024
1 parent 7e04de1 commit 2812b73
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/blocking_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

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

//
// OAuth 2 Configuration
//

pub fn oauth_configuration(&self) -> Result<OAuthConfiguration> {
let response = self.http_get("auth", None, None)?;
let response = response.json()?;

Ok(response)
}

//
// Implementation
//
Expand Down
8 changes: 8 additions & 0 deletions src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ impl fmt::Display for NodeMemoryBreakdown {
}
}

/// Represents a number of key OAuth 2 configuration settings.
#[derive(Serialize, Deserialize)]
pub struct OAuthConfiguration {
pub oauth_enabled: bool,
pub oauth_client_id: Option<String>,
pub oauth_provider_url: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[allow(dead_code)]
pub struct VirtualHostMetadata {
Expand Down
30 changes: 30 additions & 0 deletions tests/auth_configuration_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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;

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

//
// Authentication configuration info
//

#[test]
pub fn oauth_configuration() {
let endpoint = endpoint();
let rc = Client::new(&endpoint, USERNAME, PASSWORD);

let result = rc.oauth_configuration();
assert!(result.is_ok());
}

0 comments on commit 2812b73

Please sign in to comment.