Skip to content

Commit

Permalink
Add option to define password during password reset (apache#6863)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan Krug <[email protected]>
Co-authored-by: Gabriel <[email protected]>
Co-authored-by: GaOrtiga <[email protected]>
Co-authored-by: dahn <[email protected]>
  • Loading branch information
5 people authored Oct 13, 2023
1 parent 3486a3c commit 55bef2b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.
package org.apache.cloudstack.api.command.user.vm;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import org.apache.cloudstack.acl.SecurityChecker.AccessType;
Expand Down Expand Up @@ -56,8 +57,7 @@ public class ResetVMPasswordCmd extends BaseAsyncCmd implements UserCmd {
required=true, description="The ID of the virtual machine")
private Long id;

// unexposed parameter needed for serializing/deserializing the command
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, expose=false)
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, description="The new password of the virtual machine. If null, a random password will be generated for the VM.", since="4.19.0")
protected String password;


Expand Down Expand Up @@ -118,7 +118,14 @@ public Long getApiResourceId() {

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException {
password = _mgr.generateRandomPassword();
password = getPassword();
UserVm vm = _responseGenerator.findUserVmById(getId());
if (StringUtils.isBlank(password)) {
password = _mgr.generateRandomPassword();
s_logger.debug(String.format("Resetting VM [%s] password to a randomly generated password.", vm.getUuid()));
} else {
s_logger.debug(String.format("Resetting VM [%s] password to password defined by user.", vm.getUuid()));
}
CallContext.current().setEventDetails("Vm Id: " + getId());
UserVm result = _userVmService.resetVMPassword(this, password);
if (result != null){
Expand Down
1 change: 1 addition & 0 deletions ui/src/config/section/compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ export default {
label: 'label.action.reset.password',
message: 'message.action.instance.reset.password',
dataView: true,
args: ['password'],
show: (record) => { return ['Stopped'].includes(record.state) && record.passwordenabled },
response: (result) => {
return {
Expand Down

0 comments on commit 55bef2b

Please sign in to comment.