Add option to define password during password reset (#6863)

Co-authored-by: Stephan Krug <stephan.krug@scclouds.com.br>
Co-authored-by: Gabriel <gabriel.fernandes@scclouds.com.br>
Co-authored-by: GaOrtiga <49285692+GaOrtiga@users.noreply.github.com>
Co-authored-by: dahn <daan.hoogland@gmail.com>
This commit is contained in:
Stephan Krug 2023-10-13 10:44:34 -03:00 committed by GitHub
parent 3486a3c310
commit 55bef2b069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -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;
@ -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;
@ -118,7 +118,14 @@ public class ResetVMPasswordCmd extends BaseAsyncCmd implements UserCmd {
@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){

View File

@ -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 {