feat(ssh-keys): add ssh key endpoints and ui components

This commit is contained in:
Matthew Penner 2021-07-17 15:45:46 -06:00
parent 9d64c6751b
commit f9114e2de0
17 changed files with 375 additions and 7 deletions

View file

@ -0,0 +1,10 @@
import http from '@/api/http';
import { SSHKey, rawDataToSSHKey } from '@/api/account/ssh/getSSHKeys';
export default (name: string, publicKey: string): Promise<SSHKey> => {
return new Promise((resolve, reject) => {
http.post('/api/client/account/ssh', { name, public_key: publicKey })
.then(({ data }) => resolve(rawDataToSSHKey(data.attributes)))
.catch(reject);
});
};

View file

@ -0,0 +1,9 @@
import http from '@/api/http';
export default (id: number): Promise<void> => {
return new Promise((resolve, reject) => {
http.delete(`/api/client/account/ssh/${id}`)
.then(() => resolve())
.catch(reject);
});
};

View file

@ -0,0 +1,23 @@
import http from '@/api/http';
export interface SSHKey {
id: number;
name: string;
publicKey: string;
createdAt: Date;
}
export const rawDataToSSHKey = (data: any): SSHKey => ({
id: data.id,
name: data.name,
publicKey: data.public_key,
createdAt: new Date(data.created_at),
});
export default (): Promise<SSHKey[]> => {
return new Promise((resolve, reject) => {
http.get('/api/client/account/ssh')
.then(({ data }) => resolve((data.data || []).map((d: any) => rawDataToSSHKey(d.attributes))))
.catch(reject);
});
};