Skip to content

Commit d5a259d

Browse files
committed
Prevent printing mount opts which may include password by removing from response
1 parent 64db486 commit d5a259d

File tree

6 files changed

+50
-15
lines changed

6 files changed

+50
-15
lines changed

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ public class BackupRepositoryResponse extends BaseResponse {
5757
@Param(description = "backup type")
5858
private String type;
5959

60-
@SerializedName(ApiConstants.MOUNT_OPTIONS)
61-
@Param(description = "mount options for the backup repository")
62-
private String mountOptions;
63-
6460
@SerializedName(ApiConstants.CAPACITY_BYTES)
6561
@Param(description = "capacity of the backup repository")
6662
private Long capacityBytes;
@@ -112,14 +108,6 @@ public void setAddress(String address) {
112108
this.address = address;
113109
}
114110

115-
public String getMountOptions() {
116-
return mountOptions;
117-
}
118-
119-
public void setMountOptions(String mountOptions) {
120-
this.mountOptions = mountOptions;
121-
}
122-
123111
public String getProviderName() {
124112
return providerName;
125113
}

scripts/vm/hypervisor/kvm/nasbackup.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ mount_operation() {
100100
mount_point=$(mktemp -d -t csbackup.XXXXX)
101101
dest="$mount_point/${BACKUP_DIR}"
102102
mount -t ${NAS_TYPE} ${NAS_ADDRESS} ${mount_point} $([[ ! -z "${MOUNT_OPTS}" ]] && echo -o ${MOUNT_OPTS})
103+
if [ $? -eq 0 ]; then
104+
echo "Successfully mounted ${NAS_TYPE} store"
105+
else
106+
echo "Failed to mount ${NAS_TYPE} store"
107+
exit 1
108+
fi
103109
}
104110

105111
function usage {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5439,7 +5439,6 @@ public BackupRepositoryResponse createBackupRepositoryResponse(BackupRepository
54395439
response.setAddress(backupRepository.getAddress());
54405440
response.setProviderName(backupRepository.getProvider());
54415441
response.setType(backupRepository.getType());
5442-
response.setMountOptions(backupRepository.getMountOptions());
54435442
response.setCapacityBytes(backupRepository.getCapacityBytes());
54445443
response.setObjectName("backuprepository");
54455444
DataCenter zone = ApiDBUtils.findZoneById(backupRepository.getZoneId());

server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,33 @@
1919
import java.util.ArrayList;
2020
import java.util.Arrays;
2121
import java.util.Collections;
22+
import java.util.Comparator;
2223
import java.util.Date;
2324
import java.util.HashMap;
2425
import java.util.List;
2526
import java.util.Map;
27+
import java.util.Objects;
2628
import java.util.TimeZone;
2729
import java.util.Timer;
2830
import java.util.TimerTask;
2931
import java.util.stream.Collectors;
3032

3133
import com.amazonaws.util.CollectionUtils;
34+
import com.cloud.network.dao.NetworkDao;
35+
import com.cloud.network.dao.NetworkVO;
36+
import com.cloud.storage.VMTemplateVO;
3237
import com.cloud.storage.VolumeApiService;
38+
import com.cloud.storage.dao.VMTemplateDao;
3339
import com.cloud.utils.fsm.NoTransitionException;
40+
import com.cloud.vm.NicVO;
3441
import com.cloud.vm.UserVmManager;
42+
import com.cloud.vm.UserVmService;
3543
import com.cloud.vm.UserVmVO;
3644
import com.cloud.vm.VirtualMachineManager;
3745
import javax.inject.Inject;
3846
import javax.naming.ConfigurationException;
3947

48+
import com.cloud.vm.dao.NicDao;
4049
import org.apache.cloudstack.api.ApiCommandResourceType;
4150
import org.apache.cloudstack.api.ApiConstants;
4251
import org.apache.cloudstack.api.command.admin.backup.DeleteBackupOfferingCmd;
@@ -166,6 +175,14 @@ public class BackupManagerImpl extends ManagerBase implements BackupManager {
166175
private VolumeApiService volumeApiService;
167176
@Inject
168177
private VolumeOrchestrationService volumeOrchestrationService;
178+
@Inject
179+
private VMTemplateDao templateDao;
180+
@Inject
181+
private NicDao nicDao;
182+
@Inject
183+
private NetworkDao networkDao;
184+
@Inject
185+
protected UserVmService userVmService;
169186

170187
private AsyncJobDispatcher asyncJobDispatcher;
171188
private Timer backupTimer;
@@ -645,6 +662,9 @@ public boolean restoreBackup(final Long backupId) {
645662
!vm.getState().equals(VirtualMachine.State.Destroyed)) {
646663
throw new CloudRuntimeException("Existing VM should be stopped before being restored from backup");
647664
}
665+
if (VirtualMachine.State.Expunging.equals(vm.getState()) && vm.getRemoved() != null) {
666+
restoreExpungedVm(vm);
667+
}
648668
// This is done to handle historic backups if any with Veeam / Networker plugins
649669
List<Backup.VolumeInfo> backupVolumes = CollectionUtils.isNullOrEmpty(backup.getBackedUpVolumes()) ?
650670
vm.getBackupVolumeList() : backup.getBackedUpVolumes();
@@ -705,6 +725,28 @@ protected void tryRestoreVM(BackupVO backup, VMInstanceVO vm, BackupOffering off
705725
}
706726
}
707727

728+
private void restoreExpungedVm(VMInstanceVO vm) {
729+
VMTemplateVO template = templateDao.findById(vm.getTemplateId());
730+
if (Objects.isNull(template)) {
731+
throw new CloudRuntimeException("Failed to find VM template to restore the VM");
732+
}
733+
List<Long> networkIds = nicDao.listByVmId(vm.getId()).stream().sorted(Comparator.comparing(NicVO::getDeviceId)).map(NicVO::getNetworkId).collect(Collectors.toList());
734+
for (Long networkId : networkIds) {
735+
NetworkVO networkVO = networkDao.findById(networkId);
736+
if (Objects.isNull(networkVO)) {
737+
throw new CloudRuntimeException("Failed to find network all networks the VM was previously attached to");
738+
}
739+
}
740+
741+
CallContext ctx = CallContext.current();
742+
final Account owner = ctx.getCallingAccount();
743+
// userVmService.createAdvancedVirtualMachine(vm.getDataCenterId(), vm.getServiceOfferingId(), template.getId(), networkIds, owner,
744+
// vm.getHostName(), vm.getHostName(), null, null, null,
745+
// Hypervisor.HypervisorType.None, BaseCmd.HTTPMethod.POST, null, null, null, keypairs,
746+
// requestedIps, addrs, null, null, null, customParameterMap, null, null, null, null, true, null, null);
747+
748+
}
749+
708750
/**
709751
* Tries to update the state of given VM, given specified event
710752
* @param vm The VM to update its state

tools/marvin/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
raise RuntimeError("python setuptools is required to build Marvin")
2828

2929

30-
VERSION = "4.20.0.0-SNAPSHOT"
30+
VERSION = "4.20.0.0"
3131

3232
setup(name="Marvin",
3333
version=VERSION,

ui/src/config/section/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export default {
151151
],
152152
mapping: {
153153
type: {
154-
options: ['nfs']
154+
options: ['nfs', 'cifs']
155155
},
156156
provider: {
157157
value: (record) => { return 'nas' }

0 commit comments

Comments
 (0)