ssh array complete

This commit is contained in:
Drew Ansbacher
2021-09-20 10:03:50 -06:00
committed by Aiden McClelland
parent 7320abf317
commit 926c74a1b1
4 changed files with 27 additions and 36 deletions

View File

@@ -46,14 +46,14 @@
<!-- not loading -->
<ng-container *ngIf="!loading">
<ion-item *ngFor="let ssh of sshKeys | keyvalue : asIsOrder">
<ion-item *ngFor="let ssh of sshKeys; let i = index">
<ion-icon slot="start" name="key-outline" size="large"></ion-icon>
<ion-label>
<h1>{{ ssh.value.hostname }}</h1>
<h2>{{ ssh.value['created-at'] | date: 'short' }}</h2>
<p>{{ ssh.value.alg }} {{ ssh.key }}</p>
<h1>{{ ssh.hostname }}</h1>
<h2>{{ ssh['created-at'] | date: 'short' }}</h2>
<p>{{ ssh.alg }} {{ ssh.hash }}</p>
</ion-label>
<ion-button slot="end" fill="clear" color="danger" (click)="presentAlertDelete(ssh.key)">
<ion-button slot="end" fill="clear" color="danger" (click)="presentAlertDelete(i)">
<ion-icon slot="start" name="close"></ion-icon>
Remove
</ion-button>

View File

@@ -1,6 +1,6 @@
import { Component } from '@angular/core'
import { AlertController, LoadingController, ModalController } from '@ionic/angular'
import { SSHKeys } from 'src/app/services/api/api.types'
import { SSHKey } from 'src/app/services/api/api.types'
import { ErrorToastService } from 'src/app/services/error-toast.service'
import { ApiService } from 'src/app/services/api/embassy-api.service'
import { GenericInputComponent } from 'src/app/modals/generic-input/generic-input.component'
@@ -12,7 +12,7 @@ import { GenericInputComponent } from 'src/app/modals/generic-input/generic-inpu
})
export class SSHKeysPage {
loading = true
sshKeys: SSHKeys
sshKeys: SSHKey[]
readonly docsUrl = 'https://docs.start9.com/user-manual/general/developer-options/ssh-setup.html'
constructor (
@@ -63,7 +63,7 @@ export class SSHKeysPage {
try {
const key = await this.embassyApi.addSshKey({ key: pubkey })
this.sshKeys = { ...this.sshKeys, ...key }
this.sshKeys.push(key)
} catch (e) {
this.errToast.present(e)
} finally {
@@ -71,7 +71,7 @@ export class SSHKeysPage {
}
}
async presentAlertDelete (hash: string) {
async presentAlertDelete (i: number) {
const alert = await this.alertCtrl.create({
header: 'Caution',
message: `Are you sure you want to delete this key?`,
@@ -83,7 +83,7 @@ export class SSHKeysPage {
{
text: 'Delete',
handler: () => {
this.delete(hash)
this.delete(i)
},
cssClass: 'enter-click',
},
@@ -92,7 +92,7 @@ export class SSHKeysPage {
await alert.present()
}
async delete (hash: string): Promise<void> {
async delete (i: number): Promise<void> {
const loader = await this.loadingCtrl.create({
spinner: 'lines',
message: 'Deleting...',
@@ -101,18 +101,15 @@ export class SSHKeysPage {
await loader.present()
try {
await this.embassyApi.deleteSshKey({ hash })
delete this.sshKeys[hash]
const entry = this.sshKeys[i]
await this.embassyApi.deleteSshKey({ hash: entry.hash })
delete this.sshKeys[i]
} catch (e) {
this.errToast.present(e)
} finally {
loader.dismiss()
}
}
asIsOrder (a: any, b: any) {
return 0
}
}
const sshSpec = {

View File

@@ -832,28 +832,26 @@ export module Mock {
},
}
export const SshKeys: RR.GetSSHKeysRes = {
'28:d2:7e:78:61:b4:bf:g2:de:24:15:96:4e:d4:15:53': {
export const SshKeys: RR.GetSSHKeysRes = [
{
'created-at': new Date().toISOString(),
alg: 'ed25519',
hostname: 'Matt Key',
hash: 'VeryLongHashOfSSHKey1',
hash: '28:d2:7e:78:61:b4:bf:g2:de:24:15:96:4e:d4:15:53',
},
'12:f8:7e:78:61:b4:bf:e2:de:24:15:96:4e:d4:72:53': {
{
'created-at': new Date().toISOString(),
alg: 'ed25519',
hostname: 'Aiden Key',
hash: 'VeryLongHashOfSSHKey2',
hash: '12:f8:7e:78:61:b4:bf:e2:de:24:15:96:4e:d4:72:53',
},
}
]
export const SshKey: RR.AddSSHKeyRes = {
'44:44:7e:78:61:b4:bf:g2:de:24:15:96:4e:d4:15:53': {
'created-at': new Date().toISOString(),
alg: 'ed25519',
hostname: 'Lucy Key',
hash: 'VeryLongHashOfSSHKey3',
},
'created-at': new Date().toISOString(),
alg: 'ed25519',
hostname: 'Lucy Key',
hash: '44:44:7e:78:61:b4:bf:g2:de:24:15:96:4e:d4:15:53',
}
export const Wifi: RR.GetWifiRes = {

View File

@@ -108,10 +108,10 @@ export module RR {
// ssh
export type GetSSHKeysReq = { } // ssh.list
export type GetSSHKeysRes = SSHKeys
export type GetSSHKeysRes = SSHKey[]
export type AddSSHKeyReq = { key: string } // ssh.add
export type AddSSHKeyRes = SSHKeys
export type AddSSHKeyRes = SSHKey
export type DeleteSSHKeyReq = { hash: string } // ssh.delete
export type DeleteSSHKeyRes = null
@@ -312,11 +312,7 @@ export interface ServerSpecs {
[key: string]: string | number
}
export interface SSHKeys {
[hash: string]: SSHKeyEntry
}
export interface SSHKeyEntry {
export interface SSHKey {
'created-at': string
alg: string
hostname: string