Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
feat(ssh-key): Store "SSH description" in account tags if supported (c…
Browse files Browse the repository at this point in the history
…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
HeyRoach committed Jan 9, 2018
1 parent ac06b31 commit 95d7947
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/app/shared/models/account.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TimeZone } from '../components/time-zone/time-zone.service';
import { AccountUser } from './account-user.model';
import { BaseModel } from './base.model';
import { Tag } from './tag.model';

export const enum AccountType {
User = 0,
Expand Down
3 changes: 3 additions & 0 deletions src/app/shared/services/tags/account-tag-keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const AccountTagKeys = {
sshDescription: 'csui.account.ssh-description'
};
58 changes: 58 additions & 0 deletions src/app/shared/services/tags/account-tag.service.ts
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)
});
}
}
14 changes: 0 additions & 14 deletions src/app/shared/services/tags/user-tag.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { EntityTagService } from './entity-tag-service.interface';
import { TagService } from './tag.service';
import { UserTagKeys } from './user-tag-keys';
import { SSHKeyPair } from '../../models/ssh-keypair.model';
import { Utils } from '../utils/utils.service';


Expand Down Expand Up @@ -117,15 +116,6 @@ export class UserTagService implements EntityTagService {
.map(() => +timeout);
}

public getSshKeyDescription(sshKey: SSHKeyPair): Observable<string> {
return this.readTag(this.getSshKeyDescriptionKey(sshKey));
}

public setSshKeyDescription(sshKey: SSHKeyPair, description: string): Observable<string> {
return this.writeTag(this.getSshKeyDescriptionKey(sshKey), description)
.map(() => description);
}

public getShowSystemTags(): Observable<boolean> {
return this.readTag(this.keys.showSystemTags)
.map(value => Utils.convertBooleanStringToBoolean(value));
Expand Down Expand Up @@ -194,8 +184,4 @@ export class UserTagService implements EntityTagService {

return Observable.of(null);
}

private getSshKeyDescriptionKey(sshKey: SSHKeyPair): string {
return `${this.keys.sshDescription}.${sshKey.fingerprint}`;
}
}
2 changes: 2 additions & 0 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ import { TemplateTagService } from './services/tags/template-tag.service';
import { UserTagService } from './services/tags/user-tag.service';
import { VmTagService } from './services/tags/vm-tag.service';
import { VolumeTagService } from './services/tags/volume-tag.service';
import { AccountTagService } from './services/tags/account-tag.service';
import { UserService } from './services/user.service';
import { VolumeService } from './services/volume.service';
import { ZoneService } from './services/zone.service';
Expand Down Expand Up @@ -394,6 +395,7 @@ import { ZoneService } from './services/zone.service';
TemplateTagService,
UserService,
UserTagService,
AccountTagService,
VmTagService,
ZoneService,
VmCreationSecurityGroupService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export class SshKeyPageContainerComponent implements OnInit, AfterViewInit {
) {
}


ngOnInit() {
this.store.dispatch(new sshKeyActions.LoadSshKeyRequest());
}
Expand Down
10 changes: 6 additions & 4 deletions src/app/ssh-keys/ssh-key-sidebar/ssh-key-sidebar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ <h4 class="details-header">{{ entity?.name }}</h4>
</button>
</div>

<cs-description
[description]="description"
(descriptionChange)="onDescriptionChange($event)"
></cs-description>
<ng-container *ngIf="showDescription">
<cs-description
[description]="description"
(descriptionChange)="onDescriptionChange($event)"
></cs-description>
</ng-container>

<cs-ssh-key-fingerprint [sshKeyPair]="entity"></cs-ssh-key-fingerprint>
</div>
Expand Down
27 changes: 20 additions & 7 deletions src/app/ssh-keys/ssh-key-sidebar/ssh-key-sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { SSHKeyPairService } from '../../shared/services/ssh-keypair.service';
import { UserTagService } from '../../shared/services/tags/user-tag.service';
import { EntityDoesNotExistError } from '../../shared/components/sidebar/entity-does-not-exist-error';
import { State } from '../../reducers/index';
import { ConfigService } from '../../shared/services/config.service';
import { AccountTagService } from '../../shared/services/tags/account-tag.service';

import * as sshKeyActions from '../../reducers/ssh-keys/redux/ssh-key.actions';

Expand All @@ -19,20 +21,26 @@ import * as sshKeyActions from '../../reducers/ssh-keys/redux/ssh-key.actions';
export class SshKeySidebarComponent extends SidebarComponent<SSHKeyPair> {
public description: string;

public get showDescription(): boolean {
return this.configService.get<boolean>('accountTagsEnabled');
}

constructor(
protected entityService: SSHKeyPairService,
protected notificationService: NotificationService,
protected route: ActivatedRoute,
protected router: Router,
protected userTagService: UserTagService,
protected store: Store<State>
protected store: Store<State>,
protected configService: ConfigService,
protected accountTagService: AccountTagService
) {
super(entityService, notificationService, route, router);
}

public onDescriptionChange(description: string): void {
this.description = description;
this.userTagService.setSshKeyDescription(this.entity, this.description).subscribe();
this.accountTagService.setSshKeyDescription(this.entity, this.description).subscribe();
}

protected loadEntity(name: string): Observable<SSHKeyPair> {
Expand All @@ -51,11 +59,16 @@ export class SshKeySidebarComponent extends SidebarComponent<SSHKeyPair> {
}
})
.switchMap(sshKeyPair => {
return Observable.forkJoin(
Observable.of(sshKeyPair),
this.userTagService.getSshKeyDescription(sshKeyPair)
);
})
return this.showDescription ?
Observable.forkJoin(
Observable.of(sshKeyPair),
this.accountTagService.getSshKeyDescription(sshKeyPair)
)
:
Observable.forkJoin(
Observable.of(sshKeyPair)
);
})
.map(([sshKeyPair, description]) => {
this.description = description;
return sshKeyPair;
Expand Down
3 changes: 2 additions & 1 deletion src/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,6 @@
"webShell": true,
"pulse": false
},
"templateGroups": []
"templateGroups": [],
"accountTagsEnabled": false
}

0 comments on commit 95d7947

Please sign in to comment.