From 20d7f7b236953a44674df7384deaf106688a87c8 Mon Sep 17 00:00:00 2001 From: Drew Ansbacher Date: Thu, 13 Jan 2022 15:01:50 -0700 Subject: [PATCH] suggest ssh key --- .../server-routes/preferences/preferences.page.ts | 2 -- .../server-backup/server-backup.page.ts | 4 +--- .../server-show/server-show.page.html | 1 + .../server-routes/server-show/server-show.page.ts | 14 ++++++++++++++ .../server-routes/ssh-keys/ssh-keys.page.html | 9 ++++++++- .../pages/server-routes/ssh-keys/ssh-keys.page.ts | 7 +++++-- ui/src/app/services/api/mock-patch.ts | 1 + ui/src/app/services/http.service.ts | 1 - ui/src/app/services/patch-db/data-model.ts | 1 + 9 files changed, 31 insertions(+), 9 deletions(-) diff --git a/ui/src/app/pages/server-routes/preferences/preferences.page.ts b/ui/src/app/pages/server-routes/preferences/preferences.page.ts index 258d140fe..0b0ec8587 100644 --- a/ui/src/app/pages/server-routes/preferences/preferences.page.ts +++ b/ui/src/app/pages/server-routes/preferences/preferences.page.ts @@ -65,8 +65,6 @@ export class PreferencesPage { try { await this.api.setDbValue({ pointer: `/${key}`, value }) - } catch (e) { - throw new Error(e) } finally { loader.dismiss() } diff --git a/ui/src/app/pages/server-routes/server-backup/server-backup.page.ts b/ui/src/app/pages/server-routes/server-backup/server-backup.page.ts index 34b23099e..3d0ddd149 100644 --- a/ui/src/app/pages/server-routes/server-backup/server-backup.page.ts +++ b/ui/src/app/pages/server-routes/server-backup/server-backup.page.ts @@ -91,7 +91,7 @@ export class ServerBackupPage { await this.createBackup(target.id, password) } catch (e) { if (oldPassword) { - throw new Error(e) + throw e } else { setTimeout(() => this.presentModalOldPassword(target, password), 500) } @@ -133,8 +133,6 @@ export class ServerBackupPage { 'old-password': oldPassword || null, password, }) - } catch (e) { - throw new Error(e) } finally { loader.dismiss() } diff --git a/ui/src/app/pages/server-routes/server-show/server-show.page.html b/ui/src/app/pages/server-routes/server-show/server-show.page.html index 4ef1fdf0b..771adf09c 100644 --- a/ui/src/app/pages/server-routes/server-show/server-show.page.html +++ b/ui/src/app/pages/server-routes/server-show/server-show.page.html @@ -39,6 +39,7 @@

+ diff --git a/ui/src/app/pages/server-routes/server-show/server-show.page.ts b/ui/src/app/pages/server-routes/server-show/server-show.page.ts index 96f70ba2a..629bc4417 100644 --- a/ui/src/app/pages/server-routes/server-show/server-show.page.ts +++ b/ui/src/app/pages/server-routes/server-show/server-show.page.ts @@ -112,6 +112,7 @@ export class ServerShowPage { action: () => this.navCtrl.navigateForward(['backup'], { relativeTo: this.route }), detail: true, disabled: of(false), + warning: of(false), }, { title: 'Restore From Backup', @@ -120,6 +121,7 @@ export class ServerShowPage { action: () => this.navCtrl.navigateForward(['restore'], { relativeTo: this.route }), detail: true, disabled: this.patch.watch$('server-info', 'status').pipe(map(status => [ServerStatus.Updated, ServerStatus.BackingUp].includes(status))), + warning: of(false), }, ], 'Insights': [ @@ -130,6 +132,7 @@ export class ServerShowPage { action: () => this.navCtrl.navigateForward(['specs'], { relativeTo: this.route }), detail: true, disabled: of(false), + warning: of(false), }, { title: 'Monitor', @@ -138,6 +141,7 @@ export class ServerShowPage { action: () => this.navCtrl.navigateForward(['metrics'], { relativeTo: this.route }), detail: true, disabled: of(false), + warning: of(false), }, { title: 'Logs', @@ -146,6 +150,7 @@ export class ServerShowPage { action: () => this.navCtrl.navigateForward(['logs'], { relativeTo: this.route }), detail: true, disabled: of(false), + warning: of(false), }, ], 'Settings': [ @@ -156,6 +161,7 @@ export class ServerShowPage { action: () => this.navCtrl.navigateForward(['preferences'], { relativeTo: this.route }), detail: true, disabled: of(false), + warning: of(false), }, { title: 'LAN', @@ -164,6 +170,7 @@ export class ServerShowPage { action: () => this.navCtrl.navigateForward(['lan'], { relativeTo: this.route }), detail: true, disabled: of(false), + warning: of(false), }, { title: 'SSH', @@ -172,6 +179,8 @@ export class ServerShowPage { action: () => this.navCtrl.navigateForward(['ssh'], { relativeTo: this.route }), detail: true, disabled: of(false), + warning: this.patch.watch$('ui', 'has-ssh-key').pipe(map(hasSSHKey => !hasSSHKey)), + }, { title: 'WiFi', @@ -180,6 +189,7 @@ export class ServerShowPage { action: () => this.navCtrl.navigateForward(['wifi'], { relativeTo: this.route }), detail: true, disabled: of(false), + warning: of(false), }, { title: 'Active Sessions', @@ -188,6 +198,7 @@ export class ServerShowPage { action: () => this.navCtrl.navigateForward(['sessions'], { relativeTo: this.route }), detail: true, disabled: of(false), + warning: of(false), }, ], 'Power': [ @@ -198,6 +209,7 @@ export class ServerShowPage { action: () => this.presentAlertRestart(), detail: false, disabled: of(false), + warning: of(false), }, { title: 'Shutdown', @@ -206,6 +218,7 @@ export class ServerShowPage { action: () => this.presentAlertShutdown(), detail: false, disabled: of(false), + warning: of(false), }, ], } @@ -223,5 +236,6 @@ interface ServerSettings { action: Function detail: boolean disabled: Observable + warning: Observable }[] } diff --git a/ui/src/app/pages/server-routes/ssh-keys/ssh-keys.page.html b/ui/src/app/pages/server-routes/ssh-keys/ssh-keys.page.html index 66d17fffa..81ab47821 100644 --- a/ui/src/app/pages/server-routes/ssh-keys/ssh-keys.page.html +++ b/ui/src/app/pages/server-routes/ssh-keys/ssh-keys.page.html @@ -13,7 +13,14 @@ -

+ + +

+ We highly recommend adding an SSH key to your Embassy. It can be useful for debugging should anything go wrong. We do not recommend using your SSH key unless (1) you have advanced technical knowledge of the command line or (2) are following the guidance of a Start 9 support representitive. + View instructions +

+
+

Adding SSH keys to your Embassy is useful for command line access, as well as for debugging purposes. View instructions

diff --git a/ui/src/app/pages/server-routes/ssh-keys/ssh-keys.page.ts b/ui/src/app/pages/server-routes/ssh-keys/ssh-keys.page.ts index f91dcbbcf..352f029df 100644 --- a/ui/src/app/pages/server-routes/ssh-keys/ssh-keys.page.ts +++ b/ui/src/app/pages/server-routes/ssh-keys/ssh-keys.page.ts @@ -4,6 +4,7 @@ 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, GenericInputOptions } from 'src/app/modals/generic-input/generic-input.component' +import { PatchDbService } from 'src/app/services/patch-db/patch-db.service' @Component({ selector: 'ssh-keys', @@ -21,6 +22,7 @@ export class SSHKeysPage { private readonly errToast: ErrorToastService, private readonly alertCtrl: AlertController, private readonly embassyApi: ApiService, + public readonly patch: PatchDbService, ) { } async ngOnInit () { @@ -66,8 +68,9 @@ export class SSHKeysPage { try { const key = await this.embassyApi.addSshKey({ key: pubkey }) this.sshKeys.push(key) - } catch (e) { - throw new Error(e) + if (!this.patch.getData().ui['has-ssh-key']) { + await this.embassyApi.setDbValue({ pointer: '/has-ssh-key', value: true }) + } } finally { loader.dismiss() } diff --git a/ui/src/app/services/api/mock-patch.ts b/ui/src/app/services/api/mock-patch.ts index bac9a344e..02254f186 100644 --- a/ui/src/app/services/api/mock-patch.ts +++ b/ui/src/app/services/api/mock-patch.ts @@ -7,6 +7,7 @@ export const mockPatchData: DataModel = { 'pkg-order': [], 'ack-welcome': '1.0.0', 'ack-share-stats': false, + 'has-ssh-key': false, }, 'server-info': { 'id': 'embassy-abcdefgh', diff --git a/ui/src/app/services/http.service.ts b/ui/src/app/services/http.service.ts index 630b8cd0d..32357045c 100644 --- a/ui/src/app/services/http.service.ts +++ b/ui/src/app/services/http.service.ts @@ -32,7 +32,6 @@ export class HttpService { if (rpcOpts.timeout) httpOpts.timeout = rpcOpts.timeout const res = await this.httpRequest>(httpOpts) - if (isRpcError(res)) { if (res.error.code === 34) this.auth.setUnverified() throw new RpcError(res.error) diff --git a/ui/src/app/services/patch-db/data-model.ts b/ui/src/app/services/patch-db/data-model.ts index 02a454f6d..85e351c6e 100644 --- a/ui/src/app/services/patch-db/data-model.ts +++ b/ui/src/app/services/patch-db/data-model.ts @@ -13,6 +13,7 @@ export interface UIData { 'pkg-order': string[] 'ack-welcome': string // EOS version 'ack-share-stats': boolean + 'has-ssh-key': boolean } export interface ServerInfo {