mirror of
https://github.com/unraid/api.git
synced 2026-02-17 21:48:34 -06:00
refactor(web): WIP renewed key file check
This commit is contained in:
@@ -7,10 +7,10 @@ import { storeToRefs } from 'pinia';
|
||||
|
||||
import { DOCS_REGISTRATION_REPLACE_KEY } from '~/helpers/urls';
|
||||
import BrandLoadingWhite from '~/components/Brand/LoadingWhite.vue';
|
||||
import { useReplaceCheckStore } from '~/store/replaceCheck';
|
||||
import { useReplaceRenewStore } from '~/store/replaceRenew';
|
||||
|
||||
const replaceCheckStore = useReplaceCheckStore();
|
||||
const { status, statusOutput } = storeToRefs(replaceCheckStore);
|
||||
const replaceRenewStore = useReplaceRenewStore();
|
||||
const { status, statusOutput } = storeToRefs(replaceRenewStore);
|
||||
|
||||
defineProps<{
|
||||
t: any;
|
||||
@@ -21,10 +21,10 @@ defineProps<{
|
||||
<div class="flex flex-wrap items-start justify-between gap-8px">
|
||||
<BrandButton
|
||||
v-if="status === 'checking' || status === 'ready'"
|
||||
@click="replaceCheckStore.check"
|
||||
@click="replaceRenewStore.check"
|
||||
:disabled="status !== 'ready'"
|
||||
:icon="status === 'checking' ? BrandLoadingWhite : KeyIcon"
|
||||
:text="status === 'checking' ? t('Checking…') : t('Check Eligibility')"
|
||||
:text="status === 'checking' ? t('Checking...') : t('Check Eligibility')"
|
||||
class="flex-grow" />
|
||||
|
||||
<UiBadge
|
||||
|
||||
@@ -6,6 +6,7 @@ import { useI18n } from 'vue-i18n';
|
||||
|
||||
import { useCallbackStore } from '~/store/callbackActions';
|
||||
import { useDropdownStore } from '~/store/dropdown';
|
||||
import { useReplaceRenewStore } from '~/store/replaceRenew';
|
||||
import { useServerStore } from '~/store/server';
|
||||
import { useThemeStore } from '~/store/theme';
|
||||
import { useUpdateOsStore, useUpdateOsActionsStore } from '~/store/updateOsActions';
|
||||
@@ -23,6 +24,7 @@ const { t } = useI18n();
|
||||
|
||||
const callbackStore = useCallbackStore();
|
||||
const dropdownStore = useDropdownStore();
|
||||
const replaceRenewCheckStore = useReplaceRenewStore();
|
||||
const serverStore = useServerStore();
|
||||
const updateOsStore = useUpdateOsStore();
|
||||
const updateOsActionsStore = useUpdateOsActionsStore();
|
||||
@@ -99,6 +101,10 @@ onBeforeMount(() => {
|
||||
}
|
||||
|
||||
if (guid.value && keyfile.value) {
|
||||
// automatically check for replacement and renewal eligibility…will prompt user if eligible for a renewal / key re-roll for legacy keys
|
||||
replaceRenewCheckStore.check();
|
||||
|
||||
// automatically check for OS updates for global notifications
|
||||
updateOsStore.checkForUpdate({
|
||||
cache: true,
|
||||
guid: guid.value,
|
||||
@@ -107,7 +113,7 @@ onBeforeMount(() => {
|
||||
osVersion: osVersion.value,
|
||||
});
|
||||
} else {
|
||||
console.warn('A valid keyfile and USB Flash boot device are required to check for updates.');
|
||||
console.warn('A valid keyfile and USB Flash boot device are required to check for key renewals, key replacement eligibiliy, and OS update availability.');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
import { defineStore, createPinia, setActivePinia } from 'pinia';
|
||||
import type { WretchError } from 'wretch';
|
||||
|
||||
import { validateGuid, type ValidateGuidPayload } from '~/composables/services/keyServer';
|
||||
import { validateGuid, type ValidateGuidResponse } from '~/composables/services/keyServer';
|
||||
import { useServerStore } from '~/store/server';
|
||||
import type { UiBadgeProps } from '~/types/ui/badge';
|
||||
/**
|
||||
@@ -21,7 +21,7 @@ export interface UiBadgePropsExtended extends UiBadgeProps {
|
||||
|
||||
export const REPLACE_CHECK_LOCAL_STORAGE_KEY = 'unraidReplaceCheck';
|
||||
|
||||
export const useReplaceCheckStore = defineStore('replaceCheck', () => {
|
||||
export const useReplaceRenewStore = defineStore('replaceRenewCheck', () => {
|
||||
const serverStore = useServerStore();
|
||||
|
||||
const guid = computed(() => serverStore.guid);
|
||||
@@ -34,7 +34,7 @@ export const useReplaceCheckStore = defineStore('replaceCheck', () => {
|
||||
cause?: unknown;
|
||||
} | null>(null);
|
||||
const status = ref<'checking' | 'eligible' | 'error' | 'ineligible' | 'ready'>(guid.value ? 'ready' : 'error');
|
||||
const statusOutput = computed((): UiBadgePropsExtended => {
|
||||
const statusOutput = computed((): UiBadgePropsExtended | undefined => {
|
||||
// text values are translated in the component
|
||||
switch (status.value) {
|
||||
case 'eligible':
|
||||
@@ -55,10 +55,10 @@ export const useReplaceCheckStore = defineStore('replaceCheck', () => {
|
||||
icon: ShieldExclamationIcon,
|
||||
text: error.value?.message || 'Unknown error',
|
||||
};
|
||||
default: return null;
|
||||
default: return undefined;
|
||||
}
|
||||
});
|
||||
const validationResponse = ref<ValidateGuidPayload | undefined>(
|
||||
const validationResponse = ref<ValidateGuidResponse | undefined>(
|
||||
sessionStorage.getItem(REPLACE_CHECK_LOCAL_STORAGE_KEY)
|
||||
? JSON.parse(sessionStorage.getItem(REPLACE_CHECK_LOCAL_STORAGE_KEY) as string)
|
||||
: undefined
|
||||
@@ -83,15 +83,25 @@ export const useReplaceCheckStore = defineStore('replaceCheck', () => {
|
||||
* this should happen automatically when the web components are mounted…
|
||||
* account.unraid.net will do a similar thing`
|
||||
*/
|
||||
const response: ValidateGuidPayload = await validateGuid({
|
||||
const response: ValidateGuidResponse = await validateGuid({
|
||||
guid: guid.value,
|
||||
keyfile: keyfile.value,
|
||||
}).json();
|
||||
/** @todo fix type issue */
|
||||
console.log('[ReplaceCheck.check] response', response);
|
||||
|
||||
status.value = response?.replaceable ? 'eligible' : 'ineligible';
|
||||
|
||||
if (status.value === 'eligible' || status.value === 'ineligible') {
|
||||
sessionStorage.setItem(REPLACE_CHECK_LOCAL_STORAGE_KEY, JSON.stringify(response));
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo if response?.hasNewerKeyfile then we need to prompt the user to replace the keyfile. This will be a separate request to the key server.
|
||||
* @todo we don't want to automatically make this request for the new keyfile.
|
||||
*/
|
||||
if (response?.hasNewerKeyfile) {
|
||||
console.log('[ReplaceCheck.check] hasNewerKeyfile');
|
||||
}
|
||||
} catch (err) {
|
||||
const catchError = err as WretchError;
|
||||
status.value = 'error';
|
||||
Reference in New Issue
Block a user