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 { ...@@ -44,12 +44,7 @@ export class SshkeysComponent implements OnInit {
} }
uploadKey() { uploadKey() {
const formData = new FormData() this.userService.uploadSshKey(this.formKey.name, this.formKey.key);
formData.append('type', 'add');
formData.append('name', this.formKey.name);
formData.append('key', this.formKey.key);
this.userService.uploadSshKey(formData);
this.resetKeyUpload(); this.resetKeyUpload();
} }
...@@ -72,11 +67,11 @@ export class SshkeysComponent implements OnInit { ...@@ -72,11 +67,11 @@ export class SshkeysComponent implements OnInit {
this.files.forEach( this.files.forEach(
file => { file => {
const formData = new FormData(); const reader = new FileReader();
formData.append('type', 'add'); reader.onload = (e) => {
formData.append('name', file.name); this.userService.uploadSshKey(file.name, reader.result);
formData.append('file', file, file.name); };
this.userService.uploadSshKey(formData); reader.readAsText(file);
} }
); );
......
...@@ -212,11 +212,6 @@ export class UserService { ...@@ -212,11 +212,6 @@ export class UserService {
(state: State) => this.updateState(state), (state: State) => this.updateState(state),
this.handleError(false, 'Error fetching state. Try again later'), 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) { private handleError(fetch: boolean, msg?: string) {
...@@ -289,8 +284,8 @@ export class UserService { ...@@ -289,8 +284,8 @@ export class UserService {
); );
} }
public uploadSshKey(formData: FormData): void { public uploadSshKey(name: string, key: string | ArrayBuffer): void {
this.http.post<SSHKey>('/backend/api/sshkey', formData).pipe( this.http.post<SSHKey>('/rest/ssh-keys', {'name': name, 'key': key}).pipe(
catchError(this.handleError(true, "Error changing deployment")), catchError(this.handleError(true, "Error changing deployment")),
).subscribe( ).subscribe(
(newKey: SSHKey) => { (newKey: SSHKey) => {
...@@ -303,19 +298,14 @@ export class UserService { ...@@ -303,19 +298,14 @@ export class UserService {
public removeSshKey(key: SSHKey) { public removeSshKey(key: SSHKey) {
console.log('Deleting key:', key); console.log('Deleting key:', key);
return this.http.post('/backend/api/sshkey', { return this.http.delete('/rest/ssh-key?id='+key.id.toString()).pipe(
'type': 'remove',
'id': key.id,
}).pipe(
catchError(this.handleError(true, "Error changing deployment")), catchError(this.handleError(true, "Error changing deployment")),
).subscribe( ).subscribe(
(data: {deleted: boolean}) => { _ => {
if (data && data.deleted) {
this.sshKeys = this.sshKeys.filter( this.sshKeys = this.sshKeys.filter(
k => key.id != k.id k => key.id != k.id
); );
this.sshKeys$.next(this.sshKeys); this.sshKeys$.next(this.sshKeys);
}
}, },
this.logErrorAndFetch, 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