Skip to content

Commit d9bbe41

Browse files
committed
Revert registerUserKeys back to a synchronous command
1 parent dbee809 commit d9bbe41

6 files changed

Lines changed: 16 additions & 82 deletions

File tree

‎api/src/main/java/org/apache/cloudstack/api/BaseAsyncCmd.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public abstract class BaseAsyncCmd extends BaseCmd {
2929
public static final String migrationSyncObject = "migration";
3030
public static final String snapshotHostSyncObject = "snapshothost";
3131
public static final String gslbSyncObject = "globalserverloadbalancer";
32-
public static final String user = "user";
3332

3433
private Object job;
3534

‎api/src/main/java/org/apache/cloudstack/api/command/admin/user/DeleteUserKeysCmd.java‎

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.user;
1818

19-
import com.cloud.event.EventTypes;
2019
import com.cloud.user.Account;
2120
import org.apache.cloudstack.acl.apikeypair.ApiKeyPair;
2221
import org.apache.cloudstack.api.ACL;
2322
import org.apache.cloudstack.api.APICommand;
2423
import org.apache.cloudstack.api.ApiCommandResourceType;
2524
import org.apache.cloudstack.api.ApiConstants;
26-
import org.apache.cloudstack.api.BaseAsyncCmd;
25+
import org.apache.cloudstack.api.BaseCmd;
2726
import org.apache.cloudstack.api.Parameter;
2827
import org.apache.cloudstack.api.response.ApiKeyPairResponse;
2928
import org.apache.cloudstack.api.response.SuccessResponse;
3029

3130
@APICommand(name = "deleteUserKeys", description = "Deletes a keypair from a user", responseObject = SuccessResponse.class,
3231
since = "4.23.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
33-
public class DeleteUserKeysCmd extends BaseAsyncCmd {
32+
public class DeleteUserKeysCmd extends BaseCmd {
3433
@ACL
3534
@Parameter(name = ApiConstants.KEYPAIR_ID, type = CommandType.UUID, entityType = ApiKeyPairResponse.class, required = true, description = "ID of the keypair to be deleted.")
3635
private Long id;
@@ -60,22 +59,4 @@ public void execute() {
6059
SuccessResponse response = new SuccessResponse(getCommandName());
6160
this.setResponseObject(response);
6261
}
63-
64-
@Override
65-
public String getEventType() {
66-
return EventTypes.EVENT_DELETE_SECRET_API_KEY;
67-
}
68-
69-
@Override
70-
public String getEventDescription() {
71-
ApiKeyPair keyPair = apiKeyPairService.findById(id);
72-
return String.format("Deleting API key pair with ID [%s]%s",
73-
keyPair == null ? id : keyPair.getUuid(),
74-
keyPair == null ? "." : String.format(" and name [%s].", keyPair.getName()));
75-
}
76-
77-
@Override
78-
public Long getSyncObjId() {
79-
return getId();
80-
}
8162
}

‎api/src/main/java/org/apache/cloudstack/api/command/admin/user/RegisterUserKeysCmd.java‎

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.user;
1818

19-
import com.cloud.event.EventTypes;
2019
import com.cloud.user.Account;
2120
import com.cloud.user.User;
2221
import org.apache.cloudstack.acl.Rule;
2322
import org.apache.cloudstack.acl.apikeypair.ApiKeyPair;
2423
import org.apache.cloudstack.api.ApiCommandResourceType;
2524
import org.apache.cloudstack.api.ApiErrorCode;
26-
import org.apache.cloudstack.api.BaseAsyncCmd;
25+
import org.apache.cloudstack.api.BaseCmd;
2726
import org.apache.cloudstack.api.ServerApiException;
2827
import org.apache.commons.lang3.StringUtils;
2928

@@ -43,7 +42,7 @@
4342
responseObject = ApiKeyPairResponse.class,
4443
description = "Registers an API key pair (API and secret keys) for a user.",
4544
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
46-
public class RegisterUserKeysCmd extends BaseAsyncCmd {
45+
public class RegisterUserKeysCmd extends BaseCmd {
4746
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = UserResponse.class, required = true, description = "ID of the user.")
4847
private Long id;
4948

@@ -61,7 +60,7 @@ public class RegisterUserKeysCmd extends BaseAsyncCmd {
6160
ApiConstants.PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS)
6261
private Date endDate;
6362

64-
@Parameter(name = ApiConstants.RULES, type = CommandType.MAP, description = "The rules of the API key pair. If no rules are informed, " +
63+
@Parameter(name = ApiConstants.RULES, type = BaseCmd.CommandType.MAP, description = "The rules of the API key pair. If no rules are informed, " +
6564
"defaults to allowing all account permissions. Otherwise, only the explicitly informed permissions for the key pair will be " +
6665
"considered. Lower indexed rules take precedence over higher. Thus, in the following example: " +
6766
"\"rules[0].rule=deleteUserKeys rules[0].permission=deny rules[1].rule=*UserKey* rules[1].permission=allow\", all rules matching " +
@@ -188,25 +187,4 @@ public void execute() {
188187
response.setResponseName(getCommandName());
189188
this.setResponseObject(response);
190189
}
191-
192-
@Override
193-
public String getEventType() {
194-
return EventTypes.EVENT_REGISTER_FOR_SECRET_API_KEY;
195-
}
196-
197-
@Override
198-
public String getEventDescription() {
199-
String userUuid = getResourceUuid(ApiConstants.ID);
200-
return String.format("Registering API keypair for user [%s].", userUuid == null ? id : userUuid);
201-
}
202-
203-
@Override
204-
public String getSyncObjType() {
205-
return BaseAsyncCmd.user;
206-
}
207-
208-
@Override
209-
public Long getSyncObjId() {
210-
return getUserId();
211-
}
212190
}

‎server/src/main/java/com/cloud/user/AccountManagerImpl.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,6 +3399,7 @@ private void removeApiKeyPairIfExpired(ApiKeyPair apiKeyPair) {
33993399
}
34003400
}
34013401

3402+
@ActionEvent(eventType = EventTypes.EVENT_DELETE_SECRET_API_KEY, eventDescription = "deleting API key pair")
34023403
public void deleteApiKey(DeleteUserKeysCmd cmd) {
34033404
ApiKeyPair keyPair = apiKeyPairService.findById(cmd.getId());
34043405
if (keyPair == null) {

‎ui/src/components/view/ApiKeyPairsTab.vue‎

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -287,34 +287,17 @@ export default {
287287
this.fetchLoading = true
288288
try {
289289
await Promise.all(keypairs.map(async keypair => {
290-
try {
291-
const jobId = await this.deleteKeyPair({
292-
keypairid: keypair.id
293-
})
294-
await this.$pollJob({
295-
jobId,
296-
action: {
297-
isFetchData: false
298-
},
299-
successMethod: () => {
300-
eventBus.emit('update-resource-state', { selectedItems: this.selectedItems, resource: keypair.id, state: 'success' })
301-
},
302-
catchMethod: () => {
303-
eventBus.emit('update-resource-state', { selectedItems: this.selectedItems, resource: keypair.id, state: 'failed' })
304-
}
305-
})
306-
} catch (e) {
290+
await postAPI('deleteUserKeys', { keypairid: keypair.id }).then(response => {
291+
eventBus.emit('update-resource-state', { selectedItems: this.selectedItems, resource: keypair.id, state: 'success' })
292+
}).catch(error => {
307293
eventBus.emit('update-resource-state', { selectedItems: this.selectedItems, resource: keypair.id, state: 'failed' })
308-
}
294+
this.$notifyError(error)
295+
})
309296
}))
310297
} finally {
311298
this.fetchLoading = false
312299
}
313300
},
314-
async deleteKeyPair (args) {
315-
const response = await postAPI('deleteUserKeys', args)
316-
return response.deleteuserkeysresponse.jobid
317-
},
318301
bulkActionConfirmation () {
319302
this.showConfirmationAction = true
320303
this.selectedColumns = this.columns.filter(column => {

‎ui/src/views/iam/GenerateApiKeyPair.vue‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,12 @@ export default {
166166
const params = this.buildRequestParams()
167167
this.loading = true
168168
postAPI('registerUserKeys', params).then(response => {
169-
this.$pollJob({
170-
jobId: response.registeruserkeysresponse.jobid,
171-
successMessage: this.$t('message.success.register.user.keypair', { user: this.resource.username }),
172-
successMethod: () => {
173-
this.fetchData()
174-
},
175-
errorMessage: this.$t('message.register.keypair.failed'),
176-
errorMethod: () => {
177-
this.fetchData()
178-
},
179-
loadingMessage: this.$t('label.registering.keypair', { user: this.resource.username }),
180-
catchMessage: this.$t('error.fetching.async.job.result')
169+
this.$notification.success({
170+
message: this.$t('label.action.create.api.key'),
171+
description: this.$t('message.success.register.user.keypair', { user: this.resource.username })
181172
})
173+
this.fetchData()
174+
this.closeModal()
182175
}).catch(error => {
183176
this.$notification.error({
184177
message: this.$t('message.request.failed'),
@@ -187,7 +180,6 @@ export default {
187180
})
188181
}).finally(() => {
189182
this.loading = false
190-
this.closeModal()
191183
})
192184
})
193185
},

0 commit comments

Comments
 (0)