1
0
Fork 0
mirror of https://codeberg.org/tyy/aspm synced 2024-12-22 20:39:29 -07:00

Fix migration naming, export by alias using COLLATE NOCASE

This commit is contained in:
Tyler Beckman 2024-03-20 21:50:45 -06:00
parent 6559f676c3
commit bb43c833fc
Signed by: Ty
GPG key ID: 2813440C772555A4
5 changed files with 37 additions and 30 deletions

View file

@ -17,5 +17,6 @@
"userid",
"writedoc"
],
"rust-analyzer.check.command": "clippy"
"rust-analyzer.check.command": "clippy",
"rust-analyzer.showUnlinkedFileNotification": false
}

View file

@ -1,5 +1,5 @@
mod m_20230701_000001_create_keys_table;
mod m_20242801_000002_create_profiles_table;
mod m20230701_000001_create_keys_table;
mod m20242801_000002_create_profiles_table;
use sea_orm_migration::prelude::*;
@ -10,8 +10,8 @@ pub struct Migrator;
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![
Box::new(m_20230701_000001_create_keys_table::Migration),
Box::new(m_20242801_000002_create_profiles_table::Migration),
Box::new(m20230701_000001_create_keys_table::Migration),
Box::new(m20242801_000002_create_profiles_table::Migration),
]
}
}

View file

@ -1,13 +1,8 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str {
"m_20230701_000001_create_keys_table"
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
// Define how to apply this migration: Create the Keys table.

View file

@ -1,13 +1,8 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str {
"m_20242801_000002_create_profiles_table"
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
// Define how to apply this migration: Create the Keys table.
@ -52,13 +47,19 @@ impl MigrationTrait for Migration {
.name("fk-profiles_key-keys_fingerprint")
.from(Profiles::Table, Profiles::Key)
.to(
super::m_20230701_000001_create_keys_table::Keys::Table,
super::m_20230701_000001_create_keys_table::Keys::Fingerprint,
super::m20230701_000001_create_keys_table::Keys::Table,
super::m20230701_000001_create_keys_table::Keys::Fingerprint,
)
.on_update(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::Description).string().null())
.col(ColumnDef::new(Profiles::AvatarUrl).string().null())

View file

@ -13,26 +13,37 @@ use clap::Parser;
use data_encoding::BASE64_NOPAD;
use dialoguer::{theme::ColorfulTheme, Password};
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
#[derive(Parser, Debug)]
pub struct ProfilesExportCommand {
/// The fingerprint of the profile to export
fingerprint: String,
/// The fingerprint or alias of the profile to export
profile: String,
/// The key to sign this profile with
#[clap(short, long)]
key: Option<String>,
}
#[async_trait::async_trait]
impl AspmSubcommand for ProfilesExportCommand {
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)
.await
.context("Unable to query for profiles with fingerprint")?
.context("Unable to query for profiles with fingerprint or alias")?
else {
bail!("No profile found with that fingerprint");
bail!("No profile found with that fingerprint or alias");
};
let claims = profile
@ -41,13 +52,12 @@ impl AspmSubcommand for ProfilesExportCommand {
.await
.context("Unable to query for related claims")?;
let Some(key) = profile
.find_related(Keys)
let Some(key) = Keys::find_by_id(self.key.unwrap_or(profile.key))
.one(&state.db)
.await
.context("Unable to query database for key")?
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 {