Skip to content

Commit

Permalink
Merge pull request #168 from Holo-Host/re-enable-ssh
Browse files Browse the repository at this point in the history
Re-enable SSH toggle
  • Loading branch information
alastairong1 authored Aug 6, 2024
2 parents 16417e6 + eb659d2 commit 5ac699a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/components/settings/SettingsHoloportSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const props = withDefaults(
}
)
const emit = defineEmits(['update:device-name'])
const emit = defineEmits(['update:device-name', 'update:ssh-access'])
const isEditingDeviceName = ref(false)
const editedDeviceName = ref('')
Expand All @@ -38,6 +38,10 @@ function cancelEditDeviceName(): void {
isEditingDeviceName.value = false
editedDeviceName.value = ''
}
function toggleSshAccess(): void {
emit('update:ssh-access', !props.settings.sshAccess)
}
</script>

<template>
Expand Down Expand Up @@ -92,8 +96,8 @@ function cancelEditDeviceName(): void {
<SettingsRow :label="$t('settings.ssh_access')">
<BaseCheckbox
id="sshAccess"
is-disabled
:checked="props.settings.sshAccess"
@change="toggleSshAccess"
/>
</SettingsRow>

Expand Down
24 changes: 22 additions & 2 deletions src/interfaces/HposInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface HposInterface {
getKycLevel: () => Promise<EUserKycLevel | null>
getHposStatus: () => Promise<HPosStatus>
updateHoloportName: (name: string) => Promise<void>
updateSshSettings: (access: boolean) => Promise<void>
getHoloFuelProfile: () => unknown
updateHoloFuelProfile: ({ nickname, avatarUrl }: UpdateHoloFuelProfilePayload) => Promise<boolean>
getPaidInvoices: () => Promise<HposHolochainCallResponse>
Expand Down Expand Up @@ -246,6 +247,7 @@ interface HPosStatus {
networkFlavour?: string
hposVersion?: string
name?: string
ssh_enabled?: boolean
}

interface CoreAppVersion {
Expand Down Expand Up @@ -726,7 +728,7 @@ export function useHposInterface(): HposInterface {
try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const { holo_nixpkgs, holoport } = await hposAdminCall({
const { holo_nixpkgs, holoport, ssh } = await hposAdminCall({
method: 'get',
path: '/status'
})
Expand All @@ -737,7 +739,8 @@ export function useHposInterface(): HposInterface {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
hposVersion: formatHposVersion(holo_nixpkgs),
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
name: holoport.name
name: holoport.name,
ssh_enabled: holoport.ssh_enabled
}
} catch (err) {
return {}
Expand Down Expand Up @@ -794,6 +797,22 @@ export function useHposInterface(): HposInterface {
}
}

async function updateSshSettings(access: boolean): Promise<void> {
try {
await hposAdminCall({
method: 'put',
path: '/ssh',
params: {
enable: access,
include_default: access,
pubkeys: []
}
})
} catch (error) {
console.error('updateSshSettings failed: ', error)
}
}

async function updateHoloFuelProfile({
nickname,
avatarUrl
Expand Down Expand Up @@ -978,6 +997,7 @@ export function useHposInterface(): HposInterface {
getUser,
getHposStatus,
updateHoloportName,
updateSshSettings,
getHoloFuelProfile,
updateHoloFuelProfile,
getPaidInvoices,
Expand Down
5 changes: 5 additions & 0 deletions src/pages/SettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ const user = computed(() => userStore)
async function onDeviceNameUpdate(deviceName: string): Promise<void> {
await userStore.updateDeviceName(deviceName)
}
async function onSshAccessUpdate(sshAccess: boolean): Promise<void> {
await userStore.updateSshAccess(sshAccess)
}
</script>

<template>
<PrimaryLayout :title="$t('settings.header')">
<SettingsHoloportSection
:settings="user"
@update:device-name="onDeviceNameUpdate"
@update:ssh-access="onSshAccessUpdate"
/>

<SettingsHolofuelSection
Expand Down
10 changes: 8 additions & 2 deletions src/store/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EUserKycLevel } from '@/types/types'
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
const { showModal } = useModals()

const { getCoreAppVersion, getUser, updateHoloFuelProfile, updateHoloportName, getKycLevel } =
const { getCoreAppVersion, getUser, updateHoloFuelProfile, updateHoloportName, getKycLevel, updateSshSettings } =
useHposInterface()

interface State {
Expand All @@ -29,7 +29,7 @@ export const useUserStore = defineStore('user', {
publicKey: undefined,
email: '',
networkFlavour: '',
sshAccess: true,
sshAccess: false,
deviceName: '',
hposVersion: '',
holoFuel: {
Expand All @@ -52,6 +52,7 @@ export const useUserStore = defineStore('user', {
this.publicKey = user.hostPubKey
this.email = user.registrationEmail ?? ''
this.networkFlavour = holoport.networkFlavour ?? ''
this.sshAccess = holoport.ssh_enabled ?? false
this.deviceName = holoport.name ?? ''
this.hposVersion = holoport.hposVersion ?? ''
this.holoFuel = holoFuelProfile
Expand Down Expand Up @@ -90,6 +91,11 @@ export const useUserStore = defineStore('user', {
this.deviceName = name

await updateHoloportName(name)
},

async updateSshAccess(access: boolean): Promise<void> {
this.sshAccess = access
await updateSshSettings(access)
}
}
})

0 comments on commit 5ac699a

Please sign in to comment.