This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ssh-key): Store "SSH description" in account tags if supported (c…
…loses #824) (#844) * feat(ssh-description): Store "SSH description" in account tags if supported * feat(ssh-description): Store "SSH description" in account tags if supported * feat(ssh-description): Store "SSH description" in account tags if supported * feat(ssh-description): Store "SSH description" in account tags if supported - fixes * feat(ssh-description): Store "SSH description" in account tags if supported - fixes
- Loading branch information
Showing
9 changed files
with
92 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const AccountTagKeys = { | ||
sshDescription: 'csui.account.ssh-description' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { EntityTagService } from './entity-tag-service.interface'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import { SSHKeyPair } from '../../models/ssh-keypair.model'; | ||
import { Injectable } from '@angular/core'; | ||
import { AccountTagKeys } from './account-tag-keys'; | ||
import { AccountService } from '../account.service'; | ||
import { AuthService } from '../auth.service'; | ||
import { TagService } from './tag.service'; | ||
import { User } from '../../models/user.model'; | ||
|
||
@Injectable() | ||
export class AccountTagService implements EntityTagService { | ||
public keys = AccountTagKeys; | ||
|
||
constructor( | ||
protected accountService: AccountService, | ||
protected authService: AuthService, | ||
protected tagService: TagService | ||
) { | ||
} | ||
|
||
public get user(): User { | ||
return this.authService.user; | ||
} | ||
|
||
public getSshKeyDescription(sshKey: SSHKeyPair): Observable<string> { | ||
return this.accountService.getAccount({name: this.user.account, domainid: this.user.domainid}) | ||
.switchMap(account => { | ||
return this.tagService.getTag(account, this.getSshKeyDescriptionKey(sshKey)) | ||
.map(tag => { | ||
if (tag) { | ||
return this.tagService.getValueFromTag(tag); | ||
} | ||
} | ||
); | ||
} | ||
); | ||
} | ||
|
||
public setSshKeyDescription(sshKey: SSHKeyPair, description: string): Observable<string> { | ||
return this.writeTag(this.getSshKeyDescriptionKey(sshKey), description).map(() => description); | ||
} | ||
|
||
private getSshKeyDescriptionKey(sshKey: SSHKeyPair): string { | ||
return `${this.keys.sshDescription}.${sshKey.fingerprint}`; | ||
} | ||
|
||
public writeTag(key: string, value: string): Observable<string> { | ||
return this.accountService.getAccount({name: this.user.account, domainid: this.user.domainid}) | ||
.switchMap(account => { | ||
return this.tagService.update( | ||
account, | ||
'Account', | ||
key, | ||
value) | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,5 +168,6 @@ | |
"webShell": true, | ||
"pulse": false | ||
}, | ||
"templateGroups": [] | ||
"templateGroups": [], | ||
"accountTagsEnabled": false | ||
} |