37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { useAuthStore } from '~/stores/auth.store'
|
|
|
|
export function useVault() {
|
|
const auth = useAuthStore()
|
|
const headers = () => ({ Authorization: `Bearer ${auth.token}` })
|
|
|
|
// SSH Keys
|
|
async function listKeys() {
|
|
return $fetch('/api/ssh-keys', { headers: headers() })
|
|
}
|
|
async function importKey(data: { name: string; privateKey: string; passphrase?: string; publicKey?: string }) {
|
|
return $fetch('/api/ssh-keys', { method: 'POST', body: data, headers: headers() })
|
|
}
|
|
async function deleteKey(id: number) {
|
|
return $fetch(`/api/ssh-keys/${id}`, { method: 'DELETE', headers: headers() })
|
|
}
|
|
|
|
// Credentials
|
|
async function listCredentials() {
|
|
return $fetch('/api/credentials', { headers: headers() })
|
|
}
|
|
async function createCredential(data: any) {
|
|
return $fetch('/api/credentials', { method: 'POST', body: data, headers: headers() })
|
|
}
|
|
async function updateCredential(id: number, data: any) {
|
|
return $fetch(`/api/credentials/${id}`, { method: 'PUT', body: data, headers: headers() })
|
|
}
|
|
async function deleteCredential(id: number) {
|
|
return $fetch(`/api/credentials/${id}`, { method: 'DELETE', headers: headers() })
|
|
}
|
|
|
|
return {
|
|
listKeys, importKey, deleteKey,
|
|
listCredentials, createCredential, updateCredential, deleteCredential,
|
|
}
|
|
}
|