mirror of
https://codeberg.org/tyy/aspm
synced 2024-12-23 02:29:29 -07:00
Fix migration naming, export by alias using COLLATE NOCASE
This commit is contained in:
parent
6559f676c3
commit
bb43c833fc
5 changed files with 37 additions and 30 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -17,5 +17,6 @@
|
||||||
"userid",
|
"userid",
|
||||||
"writedoc"
|
"writedoc"
|
||||||
],
|
],
|
||||||
"rust-analyzer.check.command": "clippy"
|
"rust-analyzer.check.command": "clippy",
|
||||||
|
"rust-analyzer.showUnlinkedFileNotification": false
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
mod m_20230701_000001_create_keys_table;
|
mod m20230701_000001_create_keys_table;
|
||||||
mod m_20242801_000002_create_profiles_table;
|
mod m20242801_000002_create_profiles_table;
|
||||||
|
|
||||||
use sea_orm_migration::prelude::*;
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
|
@ -10,8 +10,8 @@ pub struct Migrator;
|
||||||
impl MigratorTrait for Migrator {
|
impl MigratorTrait for Migrator {
|
||||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||||
vec![
|
vec![
|
||||||
Box::new(m_20230701_000001_create_keys_table::Migration),
|
Box::new(m20230701_000001_create_keys_table::Migration),
|
||||||
Box::new(m_20242801_000002_create_profiles_table::Migration),
|
Box::new(m20242801_000002_create_profiles_table::Migration),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
use sea_orm_migration::prelude::*;
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
|
#[derive(DeriveMigrationName)]
|
||||||
pub struct Migration;
|
pub struct Migration;
|
||||||
|
|
||||||
impl MigrationName for Migration {
|
|
||||||
fn name(&self) -> &str {
|
|
||||||
"m_20230701_000001_create_keys_table"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
// Define how to apply this migration: Create the Keys table.
|
// Define how to apply this migration: Create the Keys table.
|
|
@ -1,13 +1,8 @@
|
||||||
use sea_orm_migration::prelude::*;
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
|
#[derive(DeriveMigrationName)]
|
||||||
pub struct Migration;
|
pub struct Migration;
|
||||||
|
|
||||||
impl MigrationName for Migration {
|
|
||||||
fn name(&self) -> &str {
|
|
||||||
"m_20242801_000002_create_profiles_table"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
// Define how to apply this migration: Create the Keys table.
|
// Define how to apply this migration: Create the Keys table.
|
||||||
|
@ -52,13 +47,19 @@ impl MigrationTrait for Migration {
|
||||||
.name("fk-profiles_key-keys_fingerprint")
|
.name("fk-profiles_key-keys_fingerprint")
|
||||||
.from(Profiles::Table, Profiles::Key)
|
.from(Profiles::Table, Profiles::Key)
|
||||||
.to(
|
.to(
|
||||||
super::m_20230701_000001_create_keys_table::Keys::Table,
|
super::m20230701_000001_create_keys_table::Keys::Table,
|
||||||
super::m_20230701_000001_create_keys_table::Keys::Fingerprint,
|
super::m20230701_000001_create_keys_table::Keys::Fingerprint,
|
||||||
)
|
)
|
||||||
.on_update(ForeignKeyAction::Cascade)
|
.on_update(ForeignKeyAction::Cascade)
|
||||||
.on_delete(ForeignKeyAction::Cascade),
|
.on_delete(ForeignKeyAction::Cascade),
|
||||||
)
|
)
|
||||||
.col(ColumnDef::new(Profiles::Alias).string().not_null())
|
.col(
|
||||||
|
ColumnDef::new(Profiles::Alias)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
.extra("COLLATE NOCASE")
|
||||||
|
.unique_key(),
|
||||||
|
)
|
||||||
.col(ColumnDef::new(Profiles::Name).string().not_null())
|
.col(ColumnDef::new(Profiles::Name).string().not_null())
|
||||||
.col(ColumnDef::new(Profiles::Description).string().null())
|
.col(ColumnDef::new(Profiles::Description).string().null())
|
||||||
.col(ColumnDef::new(Profiles::AvatarUrl).string().null())
|
.col(ColumnDef::new(Profiles::AvatarUrl).string().null())
|
|
@ -13,26 +13,37 @@ use clap::Parser;
|
||||||
use data_encoding::BASE64_NOPAD;
|
use data_encoding::BASE64_NOPAD;
|
||||||
use dialoguer::{theme::ColorfulTheme, Password};
|
use dialoguer::{theme::ColorfulTheme, Password};
|
||||||
use josekit::jwk::Jwk;
|
use josekit::jwk::Jwk;
|
||||||
use sea_orm::{EntityTrait, ModelTrait};
|
use sea_orm::{ColumnTrait, Condition, EntityTrait, ModelTrait, QueryFilter};
|
||||||
|
|
||||||
use crate::{commands::AspmSubcommand, entities::prelude::*};
|
use crate::{
|
||||||
|
commands::AspmSubcommand,
|
||||||
|
entities::{prelude::*, profiles},
|
||||||
|
};
|
||||||
|
|
||||||
/// Exports a profile in JWT format
|
/// Exports a profile in JWT format
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
pub struct ProfilesExportCommand {
|
pub struct ProfilesExportCommand {
|
||||||
/// The fingerprint of the profile to export
|
/// The fingerprint or alias of the profile to export
|
||||||
fingerprint: String,
|
profile: String,
|
||||||
|
/// The key to sign this profile with
|
||||||
|
#[clap(short, long)]
|
||||||
|
key: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl AspmSubcommand for ProfilesExportCommand {
|
impl AspmSubcommand for ProfilesExportCommand {
|
||||||
async fn execute(self, state: crate::AspmState) -> Result<(), anyhow::Error> {
|
async fn execute(self, state: crate::AspmState) -> Result<(), anyhow::Error> {
|
||||||
let Some(profile) = Profiles::find_by_id(&self.fingerprint)
|
let Some(profile) = Profiles::find()
|
||||||
|
.filter(
|
||||||
|
Condition::any()
|
||||||
|
.add(profiles::Column::Key.eq(&self.profile))
|
||||||
|
.add(profiles::Column::Alias.eq(&self.profile)),
|
||||||
|
)
|
||||||
.one(&state.db)
|
.one(&state.db)
|
||||||
.await
|
.await
|
||||||
.context("Unable to query for profiles with fingerprint")?
|
.context("Unable to query for profiles with fingerprint or alias")?
|
||||||
else {
|
else {
|
||||||
bail!("No profile found with that fingerprint");
|
bail!("No profile found with that fingerprint or alias");
|
||||||
};
|
};
|
||||||
|
|
||||||
let claims = profile
|
let claims = profile
|
||||||
|
@ -41,13 +52,12 @@ impl AspmSubcommand for ProfilesExportCommand {
|
||||||
.await
|
.await
|
||||||
.context("Unable to query for related claims")?;
|
.context("Unable to query for related claims")?;
|
||||||
|
|
||||||
let Some(key) = profile
|
let Some(key) = Keys::find_by_id(self.key.unwrap_or(profile.key))
|
||||||
.find_related(Keys)
|
|
||||||
.one(&state.db)
|
.one(&state.db)
|
||||||
.await
|
.await
|
||||||
.context("Unable to query database for key")?
|
.context("Unable to query database for key")?
|
||||||
else {
|
else {
|
||||||
bail!("The key associated with the queried profile could not be found")
|
bail!("The key to sign the profile with could not be found")
|
||||||
};
|
};
|
||||||
|
|
||||||
let asp = AriadneSignatureProfile {
|
let asp = AriadneSignatureProfile {
|
||||||
|
|
Loading…
Reference in a new issue