Skip to content

Commit

Permalink
Revert "serde privileges"
Browse files Browse the repository at this point in the history
This reverts commit 52925fa.
  • Loading branch information
de-sh committed Jan 19, 2025
1 parent 1d94ae7 commit fa0ab08
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
11 changes: 9 additions & 2 deletions src/handlers/http/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::HTTP_CLIENT;
use actix_web::http::header::{self, HeaderMap};
use actix_web::web::{Json, Path};
use actix_web::Responder;
use bytes::Bytes;
use chrono::Utc;
use http::{header as http_header, StatusCode};
use itertools::Itertools;
Expand Down Expand Up @@ -322,13 +323,19 @@ pub async fn sync_password_reset_with_ingestors(username: &String) -> Result<(),
// forward the put role request to all ingestors to keep them in sync
pub async fn sync_role_update_with_ingestors(
name: String,
privileges: Vec<DefaultPrivilege>,
body: Vec<DefaultPrivilege>,
) -> Result<(), RoleError> {
let ingestor_infos = get_ingestor_info().await.map_err(|err| {
error!("Fatal: failed to get ingestor info: {:?}", err);
RoleError::Anyhow(err)
})?;

let roles = to_vec(&body).map_err(|err| {
error!("Fatal: failed to serialize roles: {:?}", err);
RoleError::SerdeError(err)
})?;
let roles = Bytes::from(roles);

for ingestor in ingestor_infos.iter() {
if !utils::check_liveness(&ingestor.domain_name).await {
warn!("Ingestor {} is not live", ingestor.domain_name);
Expand All @@ -345,7 +352,7 @@ pub async fn sync_role_update_with_ingestors(
.put(url)
.header(header::AUTHORIZATION, &ingestor.token)
.header(header::CONTENT_TYPE, "application/json")
.json(&privileges)
.body(roles.clone())
.send()
.await
.map_err(|err| {
Expand Down
14 changes: 5 additions & 9 deletions src/handlers/http/modal/ingest/ingestor_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
*
*/

use actix_web::{
web::{self, Json},
HttpResponse, Responder,
};
use actix_web::{web, HttpResponse, Responder};
use bytes::Bytes;

use crate::{
handlers::http::{modal::utils::rbac_utils::get_metadata, role::RoleError},
Expand All @@ -29,16 +27,14 @@ use crate::{

// Handler for PUT /api/v1/role/{name}
// Creates a new role or update existing one
pub async fn put(
name: web::Path<String>,
Json(privileges): Json<Vec<DefaultPrivilege>>,
) -> Result<impl Responder, RoleError> {
pub async fn put(name: web::Path<String>, body: Bytes) -> Result<impl Responder, RoleError> {
let name = name.into_inner();
let privileges = serde_json::from_slice::<Vec<DefaultPrivilege>>(&body)?;
let mut metadata = get_metadata().await?;
metadata.roles.insert(name.clone(), privileges.clone());

let _ = storage::put_staging_metadata(&metadata);
mut_roles().insert(name.clone(), privileges);
mut_roles().insert(name.clone(), privileges.clone());

Ok(HttpResponse::Ok().finish())
}
12 changes: 4 additions & 8 deletions src/handlers/http/modal/query/querier_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
*
*/

use actix_web::{
web::{self, Json},
HttpResponse, Responder,
};
use actix_web::{web, HttpResponse, Responder};
use bytes::Bytes;

use crate::{
handlers::http::{
Expand All @@ -32,11 +30,9 @@ use crate::{

// Handler for PUT /api/v1/role/{name}
// Creates a new role or update existing one
pub async fn put(
name: web::Path<String>,
Json(privileges): Json<Vec<DefaultPrivilege>>,
) -> Result<impl Responder, RoleError> {
pub async fn put(name: web::Path<String>, body: Bytes) -> Result<impl Responder, RoleError> {
let name = name.into_inner();
let privileges = serde_json::from_slice::<Vec<DefaultPrivilege>>(&body)?;
let mut metadata = get_metadata().await?;
metadata.roles.insert(name.clone(), privileges.clone());

Expand Down
13 changes: 4 additions & 9 deletions src/handlers/http/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
*
*/

use actix_web::{
http::header::ContentType,
web::{self, Json},
HttpResponse, Responder,
};
use actix_web::{http::header::ContentType, web, HttpResponse, Responder};
use bytes::Bytes;
use http::StatusCode;

use crate::{
Expand All @@ -34,11 +31,9 @@ use crate::{

// Handler for PUT /api/v1/role/{name}
// Creates a new role or update existing one
pub async fn put(
name: web::Path<String>,
Json(privileges): Json<Vec<DefaultPrivilege>>,
) -> Result<impl Responder, RoleError> {
pub async fn put(name: web::Path<String>, body: Bytes) -> Result<impl Responder, RoleError> {
let name = name.into_inner();
let privileges = serde_json::from_slice::<Vec<DefaultPrivilege>>(&body)?;
let mut metadata = get_metadata().await?;
metadata.roles.insert(name.clone(), privileges.clone());

Expand Down

0 comments on commit fa0ab08

Please sign in to comment.