Certificates: profile modal with notes, note tooltip; async PKI init

- Profiler: UserProfile.note (nullable, startup migration), PUT
  /profiles/{id}/note (max 1000 chars); add missing `requests`
  dependency (client creation failed without Public IP set).
- UI: clickable rows on Certificates open a compact profile details
  modal with an editable note; tooltip with the note on the client
  name (v-note-tooltip) and a note icon.
- PKI init runs in a background thread: POST /system/init returns 202,
  GET /system/init/status, 409 for a second start, Clear PKI and client
  creation are blocked while it runs. A marker file identifies an
  interrupted run (only such a PKI is wiped on the next Init).
- PKI Configuration page: state from the server, progress spinner and
  step text, polling, Init/Clear/Save locked while running, Init locked
  once initialized.
- Tests: one pytest each for notes and async init (requirements-dev.txt).
- Docs: plans and summaries in DOCS/Changes, API reference, README, Index.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Sonnet 5.5 committed 2026-10-04 20:56:36 +03:00
1 parent 3836049230
commit d251ec73d0
24 files changed
+722 -39

No files matched your search

+71 -10
View File
@@ -149,21 +149,23 @@
<div class="btn-action-group">
<button type="button" class="btn-action btn-action-save" @click="handleSave" :disabled="isLoading">
<button type="button" class="btn-action btn-action-save" @click="handleSave" :disabled="isBusy">
<i class="fas fa-save"></i>
Save PKI
</button>
<button type="button" class="btn-action btn-action-primary" @click="handleInit" :disabled="isLoading">
<i v-if="isLoading && action==='init'" class="fas fa-spinner fa-spin"></i>
<button type="button" class="btn-action btn-action-primary" @click="handleInit" :disabled="isBusy || initStatus.initialized"
:title="initStatus.initialized ? 'PKI is already initialized. Use Clear PKI to start over' : ''">
<i v-if="isInitRunning" class="fas fa-spinner fa-spin"></i>
<i v-else class="fas fa-play-circle"></i>
Init PKI
</button>
<button type="button" class="btn-action btn-action-danger" @click="handleClear" :disabled="isLoading">
<button type="button" class="btn-action btn-action-danger" @click="handleClear" :disabled="isBusy">
<i v-if="isLoading && action==='clear'" class="fas fa-spinner fa-spin"></i>
<i v-else class="fas fa-trash-alt"></i>
Clear PKI
</button>
</div>
<div v-if="isInitRunning" class="config-label">{{ stepText }}</div>
</form>
</div>
@@ -171,7 +173,7 @@
</template>
<script setup>
import { ref, onMounted, reactive } from 'vue';
import { ref, computed, onMounted, onUnmounted, reactive } from 'vue';
import { useApi } from '../composables/useApi';
@@ -205,6 +207,23 @@ const message = reactive({
const isLoading = ref(false);
const action = ref(''); // 'save', 'init', 'clear'
// PKI init job state, taken from the server (GET /system/init/status)
const initStatus = reactive({ state: 'idle', step: null, initialized: false, error: null });
const isInitRunning = computed(() => initStatus.state === 'running' || action.value === 'init');
const isBusy = computed(() => isLoading.value || isInitRunning.value);
const STEP_TEXTS = {
'init-pki': 'Initializing PKI...',
'ca': 'Building CA...',
'server-cert': 'Building server certificate...',
'dh': 'Generating DH parameters (this can take several minutes)...',
'ta-key': 'Generating TLS key...',
'crl': 'Generating CRL...'
};
const stepText = computed(() => STEP_TEXTS[initStatus.step] || 'Initializing PKI...');
let pollTimer = null;
// Methods
const showMessage = (text, type = 'success') => {
message.text = text;
@@ -238,6 +257,39 @@ const loadConfig = async () => {
}
};
const stopPolling = () => {
if (pollTimer) {
clearInterval(pollTimer);
pollTimer = null;
}
};
const startPolling = () => {
if (!pollTimer) pollTimer = setInterval(() => loadStatus(), 3000);
};
const loadStatus = async (initial = false) => {
const wasRunning = initStatus.state === 'running';
try {
const res = await profilesApiClient.get('/system/init/status');
Object.assign(initStatus, res.data);
} catch (err) {
console.error(err);
return; // keep polling, the next tick may succeed
}
if (initStatus.state === 'running') {
startPolling();
return;
}
stopPolling();
// Report the result once: a job seen running on this page, or a failure found on page load
if (wasRunning && initStatus.state === 'done') {
showMessage('PKI initialized successfully!', 'success');
} else if ((wasRunning || initial) && initStatus.state === 'error') {
showMessage(`Error initializing: ${initStatus.error}`, 'error');
}
};
const handleSave = async () => {
isLoading.value = true;
action.value = 'save';
@@ -256,13 +308,18 @@ const handleInit = async () => {
if (!confirm('Are you sure you want to Initialize system? This will start the PKI initialization process.')) return;
isLoading.value = true;
action.value = 'init';
action.value = 'init'; // locks the button until the server confirms the job state
try {
const res = await profilesApiClient.post('/system/init');
const data = res.data;
showMessage(data.message || 'System initialized successfully!', 'success');
await profilesApiClient.post('/system/init');
initStatus.state = 'running'; // 202: the job is running in the background
startPolling();
} catch (err) {
showMessage(`Error initializing: ${err.message}`, 'error');
if (err.response && err.response.status === 409) {
// Already running (second tab) or already initialized: attach to the server state
await loadStatus();
} else {
showMessage(`Error initializing: ${err.message}`, 'error');
}
} finally {
isLoading.value = false;
action.value = '';
@@ -278,6 +335,7 @@ const handleClear = async () => {
const res = await profilesApiClient.delete('/system/pki');
const data = res.data;
showMessage(data.message || 'PKI cleared successfully!', 'warning');
await loadStatus();
} catch (err) {
showMessage(`Error clearing PKI: ${err.message}`, 'error');
} finally {
@@ -288,5 +346,8 @@ const handleClear = async () => {
onMounted(() => {
loadConfig();
loadStatus(true);
});
onUnmounted(stopPolling);
</script>