Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Mar 4, 2024
1 parent f3dc1ad commit bcba676
Show file tree
Hide file tree
Showing 21 changed files with 180 additions and 74 deletions.
80 changes: 80 additions & 0 deletions oidc-test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
version: '3'
services:
oidc-server-mock:
container_name: oidc-server-mock
image: ghcr.io/soluto/oidc-server-mock:latest
ports:
- '4011:80'
environment:
ASPNETCORE_ENVIRONMENT: Development
SERVER_OPTIONS_INLINE: |
{
"AccessTokenJwtType": "JWT",
"Discovery": {
"ShowKeySet": true
},
"Authentication": {
"CookieSameSiteMode": "Lax",
"CheckSessionCookieSameSiteMode": "Lax"
}
}
LOGIN_OPTIONS_INLINE: |
{
"AllowRememberLogin": false
}
LOGOUT_OPTIONS_INLINE: |
{
"AutomaticRedirectAfterSignOut": true
}
API_SCOPES_INLINE: |
- Name: some-app-scope-1
- Name: some-app-scope-2
API_RESOURCES_INLINE: |
- Name: some-app
Scopes:
- some-app-scope-1
- some-app-scope-2
USERS_CONFIGURATION_INLINE: |
[
{
"SubjectId":"1",
"Username":"User1",
"Password":"pwd",
"Claims": [
{
"Type": "name",
"Value": "Sam Tailor",
"ValueType": "string"
},
{
"Type": "email",
"Value": "sam.tailor@gmail.com",
"ValueType": "string"
},
{
"Type": "some-api-resource-claim",
"Value": "Sam's Api Resource Custom Claim",
"ValueType": "string"
},
{
"Type": "some-api-scope-claim",
"Value": "Sam's Api Scope Custom Claim",
"ValueType": "string"
},
{
"Type": "some-identity-resource-claim",
"Value": "Sam's Identity Resource Custom Claim",
"ValueType": "string"
}
]
}
]
CLIENTS_CONFIGURATION_PATH: /tmp/config/clients-config.json
ASPNET_SERVICES_OPTIONS_INLINE: |
{
"ForwardedHeadersOptions": {
"ForwardedHeaders" : "All"
}
}
volumes:
- .:/tmp/config:ro
8 changes: 4 additions & 4 deletions warpgate-admin/src/api/recordings_detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ pub async fn api_get_recording_cast(
.map_err(InternalServerError)?;

let Some(recording) = recording else {
return Err(NotFoundError.into())
};
return Err(NotFoundError.into());
};

if recording.kind != RecordingKind::Terminal {
return Err(NotFoundError.into());
Expand Down Expand Up @@ -128,8 +128,8 @@ pub async fn api_get_recording_tcpdump(
.map_err(poem::error::InternalServerError)?;

let Some(recording) = recording else {
return Err(NotFoundError.into())
};
return Err(NotFoundError.into());
};

if recording.kind != RecordingKind::Traffic {
return Err(NotFoundError.into());
Expand Down
43 changes: 25 additions & 18 deletions warpgate-admin/src/api/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ impl DetailApi {
let Some(target) = Target::Entity::find_by_id(id.0)
.one(&*db)
.await
.map_err(poem::error::InternalServerError)? else {
return Ok(GetTargetResponse::NotFound);
};
.map_err(poem::error::InternalServerError)?
else {
return Ok(GetTargetResponse::NotFound);
};

Ok(GetTargetResponse::Ok(Json(
target
Expand All @@ -162,7 +163,8 @@ impl DetailApi {
let Some(target) = Target::Entity::find_by_id(id.0)
.one(&*db)
.await
.map_err(poem::error::InternalServerError)? else {
.map_err(poem::error::InternalServerError)?
else {
return Ok(UpdateTargetResponse::NotFound);
};

Expand Down Expand Up @@ -199,9 +201,10 @@ impl DetailApi {
let Some(target) = Target::Entity::find_by_id(id.0)
.one(&*db)
.await
.map_err(poem::error::InternalServerError)? else {
return Ok(DeleteTargetResponse::NotFound);
};
.map_err(poem::error::InternalServerError)?
else {
return Ok(DeleteTargetResponse::NotFound);
};

if target.kind == TargetKind::WebAdmin {
return Ok(DeleteTargetResponse::Forbidden);
Expand Down Expand Up @@ -268,8 +271,9 @@ impl RolesApi {
.all(&*db)
.await
.map(|x| x.into_iter().next())
.map_err(WarpgateError::from)? else {
return Ok(GetTargetRolesResponse::NotFound)
.map_err(WarpgateError::from)?
else {
return Ok(GetTargetRolesResponse::NotFound);
};

Ok(GetTargetRolesResponse::Ok(Json(
Expand Down Expand Up @@ -328,16 +332,18 @@ impl RolesApi {
let Some(target) = Target::Entity::find_by_id(id.0)
.one(&*db)
.await
.map_err(poem::error::InternalServerError)? else {
return Ok(DeleteTargetRoleResponse::NotFound);
};
.map_err(poem::error::InternalServerError)?
else {
return Ok(DeleteTargetRoleResponse::NotFound);
};

let Some(role) = Role::Entity::find_by_id(role_id.0)
.one(&*db)
.await
.map_err(poem::error::InternalServerError)? else {
return Ok(DeleteTargetRoleResponse::NotFound);
};
.map_err(poem::error::InternalServerError)?
else {
return Ok(DeleteTargetRoleResponse::NotFound);
};

if role.name == BUILTIN_ADMIN_ROLE_NAME && target.kind == TargetKind::WebAdmin {
return Ok(DeleteTargetRoleResponse::Forbidden);
Expand All @@ -348,9 +354,10 @@ impl RolesApi {
.filter(TargetRoleAssignment::Column::RoleId.eq(role_id.0))
.one(&*db)
.await
.map_err(WarpgateError::from)? else {
return Ok(DeleteTargetRoleResponse::NotFound);
};
.map_err(WarpgateError::from)?
else {
return Ok(DeleteTargetRoleResponse::NotFound);
};

model.delete(&*db).await.map_err(WarpgateError::from)?;

Expand Down
43 changes: 25 additions & 18 deletions warpgate-admin/src/api/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ impl DetailApi {
let Some(user) = User::Entity::find_by_id(id.0)
.one(&*db)
.await
.map_err(poem::error::InternalServerError)? else {
return Ok(GetUserResponse::NotFound);
};
.map_err(poem::error::InternalServerError)?
else {
return Ok(GetUserResponse::NotFound);
};

Ok(GetUserResponse::Ok(Json(
user.try_into().map_err(poem::error::InternalServerError)?,
Expand All @@ -155,7 +156,8 @@ impl DetailApi {
let Some(user) = User::Entity::find_by_id(id.0)
.one(&*db)
.await
.map_err(poem::error::InternalServerError)? else {
.map_err(poem::error::InternalServerError)?
else {
return Ok(UpdateUserResponse::NotFound);
};

Expand Down Expand Up @@ -196,9 +198,10 @@ impl DetailApi {
let Some(user) = User::Entity::find_by_id(id.0)
.one(&*db)
.await
.map_err(poem::error::InternalServerError)? else {
return Ok(DeleteUserResponse::NotFound);
};
.map_err(poem::error::InternalServerError)?
else {
return Ok(DeleteUserResponse::NotFound);
};

UserRoleAssignment::Entity::delete_many()
.filter(UserRoleAssignment::Column::UserId.eq(user.id))
Expand Down Expand Up @@ -270,8 +273,9 @@ impl RolesApi {
.all(&*db)
.await
.map(|x| x.into_iter().next())
.map_err(WarpgateError::from)? else {
return Ok(GetUserRolesResponse::NotFound)
.map_err(WarpgateError::from)?
else {
return Ok(GetUserRolesResponse::NotFound);
};

Ok(GetUserRolesResponse::Ok(Json(
Expand Down Expand Up @@ -330,25 +334,28 @@ impl RolesApi {
let Some(_user) = User::Entity::find_by_id(id.0)
.one(&*db)
.await
.map_err(poem::error::InternalServerError)? else {
return Ok(DeleteUserRoleResponse::NotFound);
};
.map_err(poem::error::InternalServerError)?
else {
return Ok(DeleteUserRoleResponse::NotFound);
};

let Some(_role) = Role::Entity::find_by_id(role_id.0)
.one(&*db)
.await
.map_err(poem::error::InternalServerError)? else {
return Ok(DeleteUserRoleResponse::NotFound);
};
.map_err(poem::error::InternalServerError)?
else {
return Ok(DeleteUserRoleResponse::NotFound);
};

let Some(model) = UserRoleAssignment::Entity::find()
.filter(UserRoleAssignment::Column::UserId.eq(id.0))
.filter(UserRoleAssignment::Column::RoleId.eq(role_id.0))
.one(&*db)
.await
.map_err(WarpgateError::from)? else {
return Ok(DeleteUserRoleResponse::NotFound);
};
.map_err(WarpgateError::from)?
else {
return Ok(DeleteUserRoleResponse::NotFound);
};

model.delete(&*db).await.map_err(WarpgateError::from)?;

Expand Down
4 changes: 2 additions & 2 deletions warpgate-core/src/auth_state_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl AuthStateStore {
.get_credential_policy(username, supported_credential_types)
.await?;
let Some(policy) = policy else {
return Err(WarpgateError::UserNotFound)
return Err(WarpgateError::UserNotFound);
};

let state = AuthState::new(
Expand Down Expand Up @@ -93,7 +93,7 @@ impl AuthStateStore {

pub async fn complete(&mut self, id: &Uuid) {
let Some((state, _)) = self.store.get(id) else {
return
return;
};
if let Some(sig) = self.completion_signals.remove(id) {
let _ = sig.sender.send(state.lock().await.verify());
Expand Down
12 changes: 8 additions & 4 deletions warpgate-core/src/config_providers/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ impl ConfigProvider for DatabaseConfigProvider {
&mut self,
client_credential: &AuthCredential,
) -> Result<Option<String>, WarpgateError> {
let AuthCredential::Sso { provider: client_provider, email : client_email} = client_credential else {
let AuthCredential::Sso {
provider: client_provider,
email: client_email,
} = client_credential
else {
return Ok(None);
};

Expand Down Expand Up @@ -171,9 +175,9 @@ impl ConfigProvider for DatabaseConfigProvider {
.await?;

let Some(user_model) = user_model else {
error!("Selected user not found: {}", username);
return Ok(false);
};
error!("Selected user not found: {}", username);
return Ok(false);
};

let user: UserConfig = user_model.try_into()?;

Expand Down
6 changes: 5 additions & 1 deletion warpgate-core/src/config_providers/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ impl ConfigProvider for FileConfigProvider {
&mut self,
client_credential: &AuthCredential,
) -> Result<Option<String>, WarpgateError> {
let AuthCredential::Sso { provider: client_provider, email : client_email} = client_credential else {
let AuthCredential::Sso {
provider: client_provider,
email: client_email,
} = client_credential
else {
return Ok(None);
};

Expand Down
4 changes: 1 addition & 3 deletions warpgate-core/src/logging/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ where
id: &tracing_core::span::Id,
ctx: Context<'_, S>,
) {
let Some(span) = ctx.span(id) else {
return
};
let Some(span) = ctx.span(id) else { return };
if !span.metadata().target().starts_with("warpgate") {
return;
}
Expand Down
8 changes: 3 additions & 5 deletions warpgate-core/src/logging/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ where

tokio::spawn(async move {
while let Some(values) = rx.recv().await {
let Some(ref socket) = socket else {
return
};
let Some(ref socket) = socket else { return };
let Some(ref socket_address) = socket_address else {
return
return;
};

let Ok(serialized) = serde_json::to_vec(&values) else {
eprintln!("Failed to serialize log entry {values:?}");
continue
continue;
};

let buffer = BytesMut::from(&serialized[..]);
Expand Down
Loading

0 comments on commit bcba676

Please sign in to comment.