Commit 9700e4ed authored by Lukas Burgey's avatar Lukas Burgey

Switch to new REST API for the ssh keys

parent 1b548a35
......@@ -44,12 +44,7 @@ export class SshkeysComponent implements OnInit {
}
uploadKey() {
const formData = new FormData()
formData.append('type', 'add');
formData.append('name', this.formKey.name);
formData.append('key', this.formKey.key);
this.userService.uploadSshKey(formData);
this.userService.uploadSshKey(this.formKey.name, this.formKey.key);
this.resetKeyUpload();
}
......@@ -72,11 +67,11 @@ export class SshkeysComponent implements OnInit {
this.files.forEach(
file => {
const formData = new FormData();
formData.append('type', 'add');
formData.append('name', file.name);
formData.append('file', file, file.name);
this.userService.uploadSshKey(formData);
const reader = new FileReader();
reader.onload = (e) => {
this.userService.uploadSshKey(file.name, reader.result);
};
reader.readAsText(file);
}
);
......
......@@ -212,11 +212,6 @@ export class UserService {
(state: State) => this.updateState(state),
this.handleError(false, 'Error fetching state. Try again later'),
);
this.http.post<SSHKey>('/rest/ssh-keys', {'name': 'foo', 'key': 'bar'}).subscribe(
(key: SSHKey) => console.log(key),
err => console.log(err),
);
}
private handleError(fetch: boolean, msg?: string) {
......@@ -289,8 +284,8 @@ export class UserService {
);
}
public uploadSshKey(formData: FormData): void {
this.http.post<SSHKey>('/backend/api/sshkey', formData).pipe(
public uploadSshKey(name: string, key: string | ArrayBuffer): void {
this.http.post<SSHKey>('/rest/ssh-keys', {'name': name, 'key': key}).pipe(
catchError(this.handleError(true, "Error changing deployment")),
).subscribe(
(newKey: SSHKey) => {
......@@ -303,19 +298,14 @@ export class UserService {
public removeSshKey(key: SSHKey) {
console.log('Deleting key:', key);
return this.http.post('/backend/api/sshkey', {
'type': 'remove',
'id': key.id,
}).pipe(
return this.http.delete('/rest/ssh-key?id='+key.id.toString()).pipe(
catchError(this.handleError(true, "Error changing deployment")),
).subscribe(
(data: {deleted: boolean}) => {
if (data && data.deleted) {
_ => {
this.sshKeys = this.sshKeys.filter(
k => key.id != k.id
);
this.sshKeys$.next(this.sshKeys);
}
},
this.logErrorAndFetch,
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment