Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions apps/auth-service/src/cli/admin.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Granting, revoking and listing administrators.

use super::{
CliError, Confirm, Console,
CliError, Confirm, Console, WhyOwnerSees,
output::{Cell, report},
};
use crate::{Reason, UserRef};
use crate::UserRef;
use clap::Subcommand;
use sourceorigin_common::admin::Administrator;

Expand All @@ -20,20 +20,18 @@ pub(super) enum AdminCommand {
Grant {
/// The account: its handle, ID or verified email.
user: UserRef,
/// Why, recorded with the change and shown to the owner in their history:
/// 1 to 500 characters.
#[arg(long)]
reason: Reason,
/// Why.
#[command(flatten)]
why: WhyOwnerSees,
},
/// Remove an account's administrator rights. The last active administrator
/// keeps theirs.
Revoke {
/// The account: its handle, ID or verified email.
user: UserRef,
/// Why, recorded with the change and shown to the owner in their history:
/// 1 to 500 characters.
#[arg(long)]
reason: Reason,
/// Why.
#[command(flatten)]
why: WhyOwnerSees,
/// Confirmation.
#[command(flatten)]
confirm: Confirm,
Expand All @@ -52,22 +50,22 @@ impl AdminCommand {
..
} = console;
match self {
Self::Grant { user, reason } => {
Self::Grant { user, why } => {
let id = console.user(&user).await?;
service.grant_administrator(operator, id, reason).await?;
service
.grant_administrator(operator, id, why.reason)
.await?;
out.info(format_args!("Made {user} an administrator."))?;
}
Self::Revoke {
user,
reason,
confirm,
} => {
Self::Revoke { user, why, confirm } => {
let id = console.user(&user).await?;
confirm.ask(
out,
&format!("Remove the administrator rights of {user} ({id})"),
)?;
service.revoke_administrator(operator, id, reason).await?;
service
.revoke_administrator(operator, id, why.reason)
.await?;
out.info(format_args!("Removed the administrator rights of {user}."))?;
}
Self::List => out.emit(&service.list_administrators(operator).await?[..])?,
Expand Down
14 changes: 7 additions & 7 deletions apps/auth-service/src/cli/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//! over them (see `docs/dev/security/audit-history.md`).

use super::{
CliError, Confirm, Console,
CliError, Confirm, Console, Why,
output::{Cell, Style, report},
};
use crate::{
AuditError, AuditKeys, PUBLIC_BASE_URL, Reason, UserRef,
AuditError, AuditKeys, PUBLIC_BASE_URL, UserRef,
audit::{AuditVerification, ChainPoint},
};
use clap::{Args, Subcommand};
Expand Down Expand Up @@ -40,9 +40,9 @@ pub(super) enum AuditCommand {
/// The keys to check checkpoints against.
#[command(flatten)]
keys: AuditKeyArgs,
/// Why, recorded with the change: 1 to 500 characters.
#[arg(long)]
reason: Reason,
/// Why.
#[command(flatten)]
why: Why,
/// Confirmation.
#[command(flatten)]
confirm: Confirm,
Expand Down Expand Up @@ -93,15 +93,15 @@ impl AuditCommand {
Self::Prune {
through,
keys,
reason,
why,
confirm,
} => {
confirm.ask(
out,
&format!("This deletes every audit event through position {through}"),
)?;
let deleted = service
.prune_audit_chain(operator, &keys.keys()?, through, reason)
.prune_audit_chain(operator, &keys.keys()?, through, why.reason)
.await?;
out.info(format_args!(
"Pruned {deleted} events through position {through}."
Expand Down
112 changes: 50 additions & 62 deletions apps/auth-service/src/cli/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Registering, inspecting and changing OIDC clients.

use super::{
CliError, Confirm, Console,
CliError, Confirm, Console, Why,
output::{Cell, Joined, Single, Style, report},
};
use crate::{Applied, ClientDetails, GracePeriod, PUBLIC_BASE_URL, Reason};
Expand Down Expand Up @@ -40,9 +40,9 @@ pub(super) enum ClientCommand {
Disable {
/// The client's ID.
id: ClientId,
/// Why, recorded with the change: 1 to 500 characters.
#[arg(long)]
reason: Reason,
/// Why.
#[command(flatten)]
why: Why,
/// Confirmation.
#[command(flatten)]
confirm: Confirm,
Expand All @@ -52,9 +52,9 @@ pub(super) enum ClientCommand {
Delete {
/// The client's ID.
id: ClientId,
/// Why, recorded with the change: 1 to 500 characters.
#[arg(long)]
reason: Reason,
/// Why.
#[command(flatten)]
why: Why,
/// Confirmation.
#[command(flatten)]
confirm: Confirm,
Expand All @@ -63,18 +63,18 @@ pub(super) enum ClientCommand {
Enable {
/// The client's ID.
id: ClientId,
/// Why, recorded with the change: 1 to 500 characters.
#[arg(long)]
reason: Reason,
/// Why.
#[command(flatten)]
why: Why,
},
/// Block a client: it is disabled, and its owner cannot enable it again
/// until `unsuspend`.
Suspend {
/// The client's ID.
id: ClientId,
/// Why, recorded with the change: 1 to 500 characters.
#[arg(long)]
reason: Reason,
/// Why.
#[command(flatten)]
why: Why,
/// Confirmation.
#[command(flatten)]
confirm: Confirm,
Expand All @@ -83,9 +83,9 @@ pub(super) enum ClientCommand {
Unsuspend {
/// The client's ID.
id: ClientId,
/// Why, recorded with the change: 1 to 500 characters.
#[arg(long)]
reason: Reason,
/// Why.
#[command(flatten)]
why: Why,
},
/// Print a new secret for a confidential client. Earlier secrets keep working
/// during the grace period, while the client switches to the new one.
Expand All @@ -96,9 +96,9 @@ pub(super) enum ClientCommand {
/// now, which asks first.
#[arg(long, default_value = "24h")]
grace: GracePeriod,
/// Why, recorded with the change: 1 to 500 characters.
#[arg(long)]
reason: Reason,
/// Why.
#[command(flatten)]
why: Why,
/// Confirmation, which `--grace 0` needs.
#[command(flatten)]
confirm: Confirm,
Expand All @@ -120,19 +120,19 @@ pub(super) enum OriginCommand {
id: ClientId,
/// The origin, as browsers send it, e.g. `https://notes.example`.
origin: RelatedOrigin,
/// Why, recorded with the change: 1 to 500 characters.
#[arg(long)]
reason: Reason,
/// Why.
#[command(flatten)]
why: Why,
},
/// Remove an origin: its pages stop signing users in.
Remove {
/// The client's ID.
id: ClientId,
/// The origin, as approved.
origin: RelatedOrigin,
/// Why, recorded with the change: 1 to 500 characters.
#[arg(long)]
reason: Reason,
/// Why.
#[command(flatten)]
why: Why,
},
/// List every approved origin.
List,
Expand All @@ -148,18 +148,18 @@ impl OriginCommand {
..
} = console;
match self {
Self::Add { id, origin, reason } => {
Self::Add { id, origin, why } => {
// Tells hosts within auth's own domain, which browsers accept without the
// list, from public suffixes.
let auth: Origin = PUBLIC_BASE_URL.parse()?;
service
.approve_related_origin(operator, &id, &origin, auth.host(), reason)
.approve_related_origin(operator, &id, &origin, auth.host(), why.reason)
.await?;
out.info(format_args!("Approved {origin} for client {id}."))
}
Self::Remove { id, origin, reason } => {
Self::Remove { id, origin, why } => {
service
.remove_related_origin(operator, &id, &origin, reason)
.remove_related_origin(operator, &id, &origin, why.reason)
.await?;
out.info(format_args!("Removed {origin} from client {id}."))
}
Expand All @@ -181,7 +181,7 @@ impl ClientCommand {
} = console;
match self {
Self::Create(create) => {
let (id, reason) = (create.id.clone(), create.reason.clone());
let (id, reason) = (create.id.clone(), create.why.reason.clone());
let secret = service
.create_client(operator, &create.registration()?, reason)
.await?;
Expand All @@ -194,76 +194,64 @@ impl ClientCommand {
Self::List => out.emit(&service.list_clients(operator).await?[..]),
Self::Show { id } => out.emit(&service.client_details(operator, &id).await?),
Self::Update(update) => {
let (id, reason) = (update.id.clone(), update.reason.clone());
let (id, reason) = (update.id.clone(), update.why.reason.clone());
service
.update_client(operator, &id, reason, |client| update.apply(client))
.await?;
out.info(format_args!("Updated client {id}."))
}
Self::Disable {
id,
reason,
confirm,
} => {
Self::Disable { id, why, confirm } => {
confirm.ask(
out,
&format!("Disable client {id}: it stops working at once"),
)?;
service
.set_client_enabled(operator, &id, false, reason)
.set_client_enabled(operator, &id, false, why.reason)
.await?;
out.info(format_args!("Disabled client {id}."))
}
Self::Enable { id, reason } => {
Self::Enable { id, why } => {
service
.set_client_enabled(operator, &id, true, reason)
.set_client_enabled(operator, &id, true, why.reason)
.await?;
out.info(format_args!("Enabled client {id}."))
}
Self::Suspend {
id,
reason,
confirm,
} => {
Self::Suspend { id, why, confirm } => {
confirm.ask(
out,
&format!(
"Suspend client {id}: it stops working, and its owner cannot enable it"
),
)?;
service
.set_client_suspended(operator, &id, true, reason)
.set_client_suspended(operator, &id, true, why.reason)
.await?;
out.info(format_args!("Suspended client {id}."))
}
Self::Unsuspend { id, reason } => {
Self::Unsuspend { id, why } => {
service
.set_client_suspended(operator, &id, false, reason)
.set_client_suspended(operator, &id, false, why.reason)
.await?;
out.info(format_args!(
"Lifted the suspension of client {id}: it stays disabled until enabled."
))
}
Self::Delete {
id,
reason,
confirm,
} => {
Self::Delete { id, why, confirm } => {
confirm.ask(
out,
&format!(
"Delete client {id}: it stops working at once, and its ID can never be reused"
),
)?;
service.delete_client(operator, &id, reason).await?;
service.delete_client(operator, &id, why.reason).await?;
out.info(format_args!("Deleted client {id}."))
}
Self::RotateSecret {
id,
grace,
reason,
why,
confirm,
} => Self::rotate_secret(console, &id, grace, reason, &confirm).await,
} => Self::rotate_secret(console, &id, grace, why.reason, &confirm).await,
Self::Origin(command) => command.run(console).await,
}
}
Expand Down Expand Up @@ -462,9 +450,9 @@ pub(super) struct CreateClient {
/// ends (OIDC Back-Channel Logout); HTTPS with a public address.
#[arg(long)]
backchannel_logout_uri: Option<BackchannelLogoutUri>,
/// Why, recorded with the change: 1 to 500 characters.
#[arg(long)]
reason: Reason,
/// Why.
#[command(flatten)]
why: Why,
}

/// A client a deployment manages, as `client apply` makes it.
Expand All @@ -489,7 +477,7 @@ impl ApplyClient {
async fn run(self, console: &Console) -> Result<(), CliError> {
let secret = self.secret()?;
let id = self.client.id.clone();
let reason = self.client.reason.clone();
let reason = self.client.why.reason.clone();
let registration = self.client.registration()?;
let applied = console
.service
Expand Down Expand Up @@ -599,9 +587,9 @@ pub(super) struct UpdateClient {
/// Stop posting logout tokens to the client.
#[arg(long)]
no_backchannel_logout_uri: bool,
/// Why, recorded with the change: 1 to 500 characters.
#[arg(long)]
reason: Reason,
/// Why.
#[command(flatten)]
why: Why,
}

impl UpdateClient {
Expand Down
Loading