Skip to content

Commit 37b2a48

Browse files
api/server: add project id/name in ssh keypair response (#7100)
1 parent 792f835 commit 37b2a48

3 files changed

Lines changed: 32 additions & 4 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/response/SSHKeyPairResponse.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ public class SSHKeyPairResponse extends BaseResponseWithAnnotations {
4646
@SerializedName(ApiConstants.DOMAIN) @Param(description="the domain name of the keypair owner")
4747
private String domain;
4848

49+
@SerializedName(ApiConstants.PROJECT_ID)
50+
@Param(description = "the project id of the keypair owner")
51+
private String projectId;
52+
53+
@SerializedName(ApiConstants.PROJECT)
54+
@Param(description = "the project name of the keypair owner")
55+
private String projectName;
56+
4957
@SerializedName("fingerprint")
5058
@Param(description = "Fingerprint of the public key")
5159
private String fingerprint;
@@ -106,4 +114,12 @@ public String getId() {
106114
public void setId(String id) {
107115
this.id = id;
108116
}
117+
118+
public void setProjectId(String projectId) {
119+
this.projectId = projectId;
120+
}
121+
122+
public void setProjectName(String projectName) {
123+
this.projectName = projectName;
124+
}
109125
}

server/src/main/java/com/cloud/api/ApiResponseHelper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4556,7 +4556,13 @@ public SSHKeyPairResponse createSSHKeyPairResponse(SSHKeyPair sshkeyPair, boolea
45564556
sshkeyPair.getFingerprint(), sshkeyPair.getPrivateKey());
45574557
}
45584558
Account account = ApiDBUtils.findAccountById(sshkeyPair.getAccountId());
4559-
response.setAccountName(account.getAccountName());
4559+
if (account.getType() == Account.Type.PROJECT) {
4560+
Project project = ApiDBUtils.findProjectByProjectAccountIdIncludingRemoved(account.getAccountId());
4561+
response.setProjectId(project.getUuid());
4562+
response.setProjectName(project.getName());
4563+
} else {
4564+
response.setAccountName(account.getAccountName());
4565+
}
45604566
Domain domain = ApiDBUtils.findDomainById(sshkeyPair.getDomainId());
45614567
response.setDomainId(domain.getUuid());
45624568
response.setDomainName(domain.getName());

ui/src/config/section/compute.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ export default {
576576
return fields
577577
},
578578
resourceType: 'SSHKeyPair',
579-
details: ['id', 'name', 'fingerprint', 'account', 'domain'],
579+
details: ['id', 'name', 'fingerprint', 'account', 'domain', 'project'],
580580
related: [{
581581
name: 'vm',
582582
title: 'label.instances',
@@ -608,11 +608,14 @@ export default {
608608
label: 'label.remove.ssh.key.pair',
609609
message: 'message.please.confirm.remove.ssh.key.pair',
610610
dataView: true,
611-
args: ['name', 'account', 'domainid'],
611+
args: ['name', 'account', 'domainid', 'projectid'],
612612
mapping: {
613613
name: {
614614
value: (record, params) => { return record.name }
615615
},
616+
projectid: {
617+
value: (record, params) => { return record.projectid }
618+
},
616619
account: {
617620
value: (record, params) => { return record.account }
618621
},
@@ -626,7 +629,10 @@ export default {
626629
return selection.map(x => {
627630
const data = record.filter(y => { return y.id === x })
628631
return {
629-
name: data[0].name, account: data[0].account, domainid: data[0].domainid
632+
name: data[0].name,
633+
account: data[0].account,
634+
domainid: data[0].domainid,
635+
projectid: data[0].projectid
630636
}
631637
})
632638
}

0 commit comments

Comments
 (0)