mirror of
https://github.com/warp-tech/warpgate.git
synced 2025-09-07 07:04:22 +08:00
Add title when adding public keys (#1171)
This commit is contained in:
parent
409b382e8f
commit
1dec4c98d4
13 changed files with 104 additions and 13 deletions
|
@ -48,6 +48,7 @@ def setup_user_and_target(
|
||||||
api.create_public_key_credential(
|
api.create_public_key_credential(
|
||||||
user.id,
|
user.id,
|
||||||
sdk.NewPublicKeyCredential(
|
sdk.NewPublicKeyCredential(
|
||||||
|
label="Public Key",
|
||||||
openssh_public_key=open("ssh-keys/id_ed25519.pub").read().strip(),
|
openssh_public_key=open("ssh-keys/id_ed25519.pub").read().strip(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -35,6 +35,7 @@ class Test:
|
||||||
api.create_public_key_credential(
|
api.create_public_key_credential(
|
||||||
user.id,
|
user.id,
|
||||||
sdk.NewPublicKeyCredential(
|
sdk.NewPublicKeyCredential(
|
||||||
|
label="Public Key",
|
||||||
openssh_public_key=open("ssh-keys/id_ed25519.pub").read().strip()
|
openssh_public_key=open("ssh-keys/id_ed25519.pub").read().strip()
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -29,6 +29,7 @@ class Test:
|
||||||
api.create_public_key_credential(
|
api.create_public_key_credential(
|
||||||
user.id,
|
user.id,
|
||||||
sdk.NewPublicKeyCredential(
|
sdk.NewPublicKeyCredential(
|
||||||
|
label="Public Key",
|
||||||
openssh_public_key=open("ssh-keys/id_ed25519.pub").read().strip()
|
openssh_public_key=open("ssh-keys/id_ed25519.pub").read().strip()
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -104,6 +105,7 @@ class Test:
|
||||||
api.create_public_key_credential(
|
api.create_public_key_credential(
|
||||||
user.id,
|
user.id,
|
||||||
sdk.NewPublicKeyCredential(
|
sdk.NewPublicKeyCredential(
|
||||||
|
label="Public Key",
|
||||||
openssh_public_key=open("ssh-keys/id_rsa.pub").read().strip()
|
openssh_public_key=open("ssh-keys/id_rsa.pub").read().strip()
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -18,11 +18,13 @@ use super::AnySecurityScheme;
|
||||||
#[derive(Object)]
|
#[derive(Object)]
|
||||||
struct ExistingPublicKeyCredential {
|
struct ExistingPublicKeyCredential {
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
|
label: String,
|
||||||
openssh_public_key: String,
|
openssh_public_key: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Object)]
|
#[derive(Object)]
|
||||||
struct NewPublicKeyCredential {
|
struct NewPublicKeyCredential {
|
||||||
|
label: String,
|
||||||
openssh_public_key: String,
|
openssh_public_key: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +32,7 @@ impl From<PublicKeyCredential::Model> for ExistingPublicKeyCredential {
|
||||||
fn from(credential: PublicKeyCredential::Model) -> Self {
|
fn from(credential: PublicKeyCredential::Model) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: credential.id,
|
id: credential.id,
|
||||||
|
label: credential.label,
|
||||||
openssh_public_key: credential.openssh_public_key,
|
openssh_public_key: credential.openssh_public_key,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,6 +115,7 @@ impl ListApi {
|
||||||
let object = PublicKeyCredential::ActiveModel {
|
let object = PublicKeyCredential::ActiveModel {
|
||||||
id: Set(Uuid::new_v4()),
|
id: Set(Uuid::new_v4()),
|
||||||
user_id: Set(*user_id),
|
user_id: Set(*user_id),
|
||||||
|
label: Set(body.label.clone()),
|
||||||
..PublicKeyCredential::ActiveModel::from(UserPublicKeyCredential::try_from(&*body)?)
|
..PublicKeyCredential::ActiveModel::from(UserPublicKeyCredential::try_from(&*body)?)
|
||||||
}
|
}
|
||||||
.insert(&*db)
|
.insert(&*db)
|
||||||
|
@ -154,6 +158,7 @@ impl DetailApi {
|
||||||
let model = PublicKeyCredential::ActiveModel {
|
let model = PublicKeyCredential::ActiveModel {
|
||||||
id: Set(id.0),
|
id: Set(id.0),
|
||||||
user_id: Set(*user_id),
|
user_id: Set(*user_id),
|
||||||
|
label: Set(body.label.clone()),
|
||||||
..<_>::from(UserPublicKeyCredential::try_from(&*body)?)
|
..<_>::from(UserPublicKeyCredential::try_from(&*body)?)
|
||||||
}
|
}
|
||||||
.update(&*db)
|
.update(&*db)
|
||||||
|
|
|
@ -11,6 +11,7 @@ pub struct Model {
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub user_id: Uuid,
|
pub user_id: Uuid,
|
||||||
|
pub label: String,
|
||||||
pub openssh_public_key: String,
|
pub openssh_public_key: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ mod m00008_users;
|
||||||
mod m00009_credential_models;
|
mod m00009_credential_models;
|
||||||
mod m00010_parameters;
|
mod m00010_parameters;
|
||||||
mod m00011_rsa_key_algos;
|
mod m00011_rsa_key_algos;
|
||||||
|
mod m00012_add_openssh_public_key_label;
|
||||||
|
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ impl MigratorTrait for Migrator {
|
||||||
Box::new(m00009_credential_models::Migration),
|
Box::new(m00009_credential_models::Migration),
|
||||||
Box::new(m00010_parameters::Migration),
|
Box::new(m00010_parameters::Migration),
|
||||||
Box::new(m00011_rsa_key_algos::Migration),
|
Box::new(m00011_rsa_key_algos::Migration),
|
||||||
|
Box::new(m00012_add_openssh_public_key_label::Migration),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
|
pub struct Migration;
|
||||||
|
|
||||||
|
impl MigrationName for Migration {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"m00012_add_openssh_public_key_label"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
use crate::m00009_credential_models::public_key_credential;
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl MigrationTrait for Migration {
|
||||||
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.alter_table(
|
||||||
|
Table::alter()
|
||||||
|
.table(public_key_credential::Entity)
|
||||||
|
.add_column(
|
||||||
|
ColumnDef::new(Alias::new("label"))
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
.default("Public Key")
|
||||||
|
)
|
||||||
|
.to_owned()
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.alter_table(
|
||||||
|
Table::alter()
|
||||||
|
.table(public_key_credential::Entity)
|
||||||
|
.drop_column(Alias::new("label"))
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -72,6 +72,7 @@ enum CredentialsStateResponse {
|
||||||
|
|
||||||
#[derive(Object)]
|
#[derive(Object)]
|
||||||
struct NewPublicKeyCredential {
|
struct NewPublicKeyCredential {
|
||||||
|
label: String,
|
||||||
openssh_public_key: String,
|
openssh_public_key: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,14 +80,19 @@ struct NewPublicKeyCredential {
|
||||||
struct ExistingPublicKeyCredential {
|
struct ExistingPublicKeyCredential {
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
label: String,
|
label: String,
|
||||||
|
abbreviated: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn abbreviate_public_key(k: &str) -> String {
|
fn abbreviate_public_key(k: &str) -> String {
|
||||||
let l = 10;
|
let l = 10;
|
||||||
|
if k.len() <= l {
|
||||||
|
return k.to_string(); // Return the full key if it's shorter than or equal to `l`.
|
||||||
|
}
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"{}...{}",
|
"{}...{}",
|
||||||
&k[..l.min(k.len())],
|
&k[..l.min(k.len())], // Take the first `l` characters.
|
||||||
&k[(k.len() - l).max(l).min(k.len() - 1)..]
|
&k[k.len().saturating_sub(l)..] // Take the last `l` characters safely.
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +100,8 @@ impl From<entities::PublicKeyCredential::Model> for ExistingPublicKeyCredential
|
||||||
fn from(credential: entities::PublicKeyCredential::Model) -> Self {
|
fn from(credential: entities::PublicKeyCredential::Model) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: credential.id,
|
id: credential.id,
|
||||||
label: abbreviate_public_key(&credential.openssh_public_key),
|
label: credential.label,
|
||||||
|
abbreviated: abbreviate_public_key(&credential.openssh_public_key),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -288,6 +295,7 @@ impl Api {
|
||||||
let object = PublicKeyCredential::ActiveModel {
|
let object = PublicKeyCredential::ActiveModel {
|
||||||
id: Set(Uuid::new_v4()),
|
id: Set(Uuid::new_v4()),
|
||||||
user_id: Set(user_model.id),
|
user_id: Set(user_model.id),
|
||||||
|
label: Set(body.label.clone()),
|
||||||
openssh_public_key: Set(body.openssh_public_key.clone()),
|
openssh_public_key: Set(body.openssh_public_key.clone()),
|
||||||
}
|
}
|
||||||
.insert(&*db)
|
.insert(&*db)
|
||||||
|
|
|
@ -184,8 +184,9 @@
|
||||||
editingSsoCredentialInstance = null
|
editingSsoCredentialInstance = null
|
||||||
}
|
}
|
||||||
|
|
||||||
async function savePublicKeyCredential (opensshPublicKey: string) {
|
async function savePublicKeyCredential (label: string, opensshPublicKey: string) {
|
||||||
if (editingPublicKeyCredentialInstance) {
|
if (editingPublicKeyCredentialInstance) {
|
||||||
|
editingPublicKeyCredentialInstance.label = label
|
||||||
editingPublicKeyCredentialInstance.opensshPublicKey = opensshPublicKey
|
editingPublicKeyCredentialInstance.opensshPublicKey = opensshPublicKey
|
||||||
await api.updatePublicKeyCredential({
|
await api.updatePublicKeyCredential({
|
||||||
userId,
|
userId,
|
||||||
|
@ -196,6 +197,7 @@
|
||||||
const credential = await api.createPublicKeyCredential({
|
const credential = await api.createPublicKeyCredential({
|
||||||
userId,
|
userId,
|
||||||
newPublicKeyCredential: {
|
newPublicKeyCredential: {
|
||||||
|
label,
|
||||||
opensshPublicKey,
|
opensshPublicKey,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -250,7 +252,7 @@
|
||||||
{/if}
|
{/if}
|
||||||
{#if credential.kind === 'PublicKey'}
|
{#if credential.kind === 'PublicKey'}
|
||||||
<Fa fw icon={faKey} />
|
<Fa fw icon={faKey} />
|
||||||
<span class="type">Public key</span>
|
<span class="type">{credential.label}</span>
|
||||||
<span class="text-muted ms-2">{abbreviatePublicKey(credential.opensshPublicKey)}</span>
|
<span class="text-muted ms-2">{abbreviatePublicKey(credential.opensshPublicKey)}</span>
|
||||||
{/if}
|
{/if}
|
||||||
{#if credential.kind === 'Totp'}
|
{#if credential.kind === 'Totp'}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
interface Props {
|
interface Props {
|
||||||
isOpen: boolean
|
isOpen: boolean
|
||||||
instance?: ExistingPublicKeyCredential
|
instance?: ExistingPublicKeyCredential
|
||||||
save: (opensshPublicKey: string) => void
|
save: (label: string, opensshPublicKey: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
|
@ -25,11 +25,12 @@
|
||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
|
|
||||||
let field: HTMLInputElement|undefined = $state()
|
let field: HTMLInputElement|undefined = $state()
|
||||||
|
let label: string = $state('')
|
||||||
let opensshPublicKey: string = $state('')
|
let opensshPublicKey: string = $state('')
|
||||||
let validated = $state(false)
|
let validated = $state(false)
|
||||||
|
|
||||||
function _save () {
|
function _save () {
|
||||||
if (!opensshPublicKey) {
|
if (!opensshPublicKey || !label) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (opensshPublicKey.includes(' ')) {
|
if (opensshPublicKey.includes(' ')) {
|
||||||
|
@ -37,7 +38,7 @@
|
||||||
opensshPublicKey = `${parts[0]} ${parts[1]}`
|
opensshPublicKey = `${parts[0]} ${parts[1]}`
|
||||||
}
|
}
|
||||||
isOpen = false
|
isOpen = false
|
||||||
save(opensshPublicKey)
|
save(label, opensshPublicKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
function _cancel () {
|
function _cancel () {
|
||||||
|
@ -47,6 +48,7 @@
|
||||||
|
|
||||||
<Modal toggle={_cancel} isOpen={isOpen} on:open={() => {
|
<Modal toggle={_cancel} isOpen={isOpen} on:open={() => {
|
||||||
if (instance) {
|
if (instance) {
|
||||||
|
label = instance.label
|
||||||
opensshPublicKey = instance.opensshPublicKey
|
opensshPublicKey = instance.opensshPublicKey
|
||||||
}
|
}
|
||||||
field?.focus()
|
field?.focus()
|
||||||
|
@ -56,9 +58,16 @@
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
}}>
|
}}>
|
||||||
<ModalHeader toggle={_cancel}>
|
<ModalHeader toggle={_cancel}>
|
||||||
Public key
|
Add an SSH public key
|
||||||
</ModalHeader>
|
</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
|
<FormGroup floating label="Label">
|
||||||
|
<Input
|
||||||
|
bind:inner={field}
|
||||||
|
type="text"
|
||||||
|
required
|
||||||
|
bind:value={label} />
|
||||||
|
</FormGroup>
|
||||||
<FormGroup floating label="Public key in OpenSSH format">
|
<FormGroup floating label="Public key in OpenSSH format">
|
||||||
<Input
|
<Input
|
||||||
style="font-family: monospace; height: 15rem"
|
style="font-family: monospace; height: 15rem"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"openapi": "3.0.0",
|
"openapi": "3.0.0",
|
||||||
"info": {
|
"info": {
|
||||||
"title": "Warpgate Web Admin",
|
"title": "Warpgate Web Admin",
|
||||||
"version": "0.11.0"
|
"version": "0.12.0"
|
||||||
},
|
},
|
||||||
"servers": [
|
"servers": [
|
||||||
{
|
{
|
||||||
|
@ -2154,6 +2154,7 @@
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"id",
|
"id",
|
||||||
|
"label",
|
||||||
"openssh_public_key"
|
"openssh_public_key"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -2161,6 +2162,9 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "uuid"
|
"format": "uuid"
|
||||||
},
|
},
|
||||||
|
"label": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"openssh_public_key": {
|
"openssh_public_key": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
@ -2272,9 +2276,13 @@
|
||||||
"NewPublicKeyCredential": {
|
"NewPublicKeyCredential": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
|
"label",
|
||||||
"openssh_public_key"
|
"openssh_public_key"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"label": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"openssh_public_key": {
|
"openssh_public_key": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,9 +31,10 @@
|
||||||
creds!.password = state
|
creds!.password = state
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createPublicKey (opensshPublicKey: string) {
|
async function createPublicKey (label: string, opensshPublicKey: string) {
|
||||||
const credential = await api.addMyPublicKey({
|
const credential = await api.addMyPublicKey({
|
||||||
newPublicKeyCredential: {
|
newPublicKeyCredential: {
|
||||||
|
label,
|
||||||
opensshPublicKey,
|
opensshPublicKey,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -156,6 +157,7 @@
|
||||||
<div class="list-group-item credential">
|
<div class="list-group-item credential">
|
||||||
<Fa fw icon={faKey} />
|
<Fa fw icon={faKey} />
|
||||||
<span class="label">{credential.label}</span>
|
<span class="label">{credential.label}</span>
|
||||||
|
<span class="text-muted ms-2">{credential.abbreviated}</span>
|
||||||
<span class="ms-auto"></span>
|
<span class="ms-auto"></span>
|
||||||
<a
|
<a
|
||||||
class="hover-reveal ms-2"
|
class="hover-reveal ms-2"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"openapi": "3.0.0",
|
"openapi": "3.0.0",
|
||||||
"info": {
|
"info": {
|
||||||
"title": "Warpgate HTTP proxy",
|
"title": "Warpgate HTTP proxy",
|
||||||
"version": "0.11.0"
|
"version": "0.12.0"
|
||||||
},
|
},
|
||||||
"servers": [
|
"servers": [
|
||||||
{
|
{
|
||||||
|
@ -688,7 +688,8 @@
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"id",
|
"id",
|
||||||
"label"
|
"label",
|
||||||
|
"abbreviated"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
|
@ -697,6 +698,9 @@
|
||||||
},
|
},
|
||||||
"label": {
|
"label": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"abbreviated": {
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -799,9 +803,13 @@
|
||||||
"NewPublicKeyCredential": {
|
"NewPublicKeyCredential": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
|
"label",
|
||||||
"openssh_public_key"
|
"openssh_public_key"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"label": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"openssh_public_key": {
|
"openssh_public_key": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue