ssh array complete

This commit is contained in:
Drew Ansbacher
2021-09-20 10:03:50 -06:00
committed by Drew Ansbacher
parent b7799b8c62
commit d936cea2be
4 changed files with 27 additions and 36 deletions

View File

@@ -46,14 +46,14 @@
<!-- not loading --> <!-- not loading -->
<ng-container *ngIf="!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-icon slot="start" name="key-outline" size="large"></ion-icon>
<ion-label> <ion-label>
<h1>{{ ssh.value.hostname }}</h1> <h1>{{ ssh.hostname }}</h1>
<h2>{{ ssh.value['created-at'] | date: 'short' }}</h2> <h2>{{ ssh['created-at'] | date: 'short' }}</h2>
<p>{{ ssh.value.alg }} {{ ssh.key }}</p> <p>{{ ssh.alg }} {{ ssh.hash }}</p>
</ion-label> </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> <ion-icon slot="start" name="close"></ion-icon>
Remove Remove
</ion-button> </ion-button>

View File

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

View File

@@ -832,28 +832,26 @@ export module Mock {
}, },
} }
export const SshKeys: RR.GetSSHKeysRes = { export const SshKeys: RR.GetSSHKeysRes = [
'28:d2:7e:78:61:b4:bf:g2:de:24:15:96:4e:d4:15:53': { {
'created-at': new Date().toISOString(), 'created-at': new Date().toISOString(),
alg: 'ed25519', alg: 'ed25519',
hostname: 'Matt Key', 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(), 'created-at': new Date().toISOString(),
alg: 'ed25519', alg: 'ed25519',
hostname: 'Aiden Key', 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 = { 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(),
'created-at': new Date().toISOString(), alg: 'ed25519',
alg: 'ed25519', hostname: 'Lucy Key',
hostname: 'Lucy Key', hash: '44:44:7e:78:61:b4:bf:g2:de:24:15:96:4e:d4:15:53',
hash: 'VeryLongHashOfSSHKey3',
},
} }
export const Wifi: RR.GetWifiRes = { export const Wifi: RR.GetWifiRes = {

View File

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