@@ -107,11 +107,15 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet
107107 if (callback == null ) {
108108 throw new InvalidParameterValueException ("createAsync: callback should not be null" );
109109 }
110+ if (!isValidName (dataObject .getName ())) {
111+ errMsg = "createAsync: Invalid dataObject name [" + dataObject .getName () + "]. It must start with a letter and can only contain letters, digits, and underscores, and be up to 200 characters long." ;
112+ s_logger .error (errMsg );
113+ throw new InvalidParameterValueException (errMsg );
114+ }
110115 try {
111116 s_logger .info ("createAsync: Started for data store name [{}] and data object name [{}] of type [{}]" , dataStore .getName (), dataObject .getName (), dataObject .getType ());
112-
113117 StoragePoolVO storagePool = storagePoolDao .findById (dataStore .getId ());
114- if (storagePool == null ) {
118+ if (storagePool == null ) {
115119 s_logger .error ("createCloudStackVolume : Storage Pool not found for id: " + dataStore .getId ());
116120 throw new CloudRuntimeException ("createCloudStackVolume : Storage Pool not found for id: " + dataStore .getId ());
117121 }
@@ -133,6 +137,16 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet
133137 }
134138 }
135139
140+ public boolean isValidName (String name ) {
141+ // Check for null and length constraint first
142+ if (name == null || name .length () > 200 ) {
143+ return false ;
144+ }
145+ // Regex: Starts with a letter, followed by letters, digits, or underscores
146+ String regex = "^[a-zA-Z][a-zA-Z0-9_]*$" ;
147+ return name .matches (regex );
148+ }
149+
136150 private String createCloudStackVolumeForTypeVolume (StoragePoolVO storagePool , VolumeInfo volumeInfo ) {
137151 Map <String , String > details = storagePoolDetailsDao .listDetailsKeyPairs (storagePool .getId ());
138152 StorageStrategy storageStrategy = Utility .getStrategyByStoragePoolDetails (details );
@@ -218,7 +232,7 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore
218232 }
219233 try {
220234 StoragePoolVO storagePool = storagePoolDao .findById (dataStore .getId ());
221- if (storagePool == null ) {
235+ if (storagePool == null ) {
222236 s_logger .error ("grantAccess : Storage Pool not found for id: " + dataStore .getId ());
223237 throw new CloudRuntimeException ("grantAccess : Storage Pool not found for id: " + dataStore .getId ());
224238 }
@@ -229,7 +243,7 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore
229243
230244 if (dataObject .getType () == DataObjectType .VOLUME ) {
231245 VolumeVO volumeVO = volumeDao .findById (dataObject .getId ());
232- if (volumeVO == null ) {
246+ if (volumeVO == null ) {
233247 s_logger .error ("grantAccess : Cloud Stack Volume not found for id: " + dataObject .getId ());
234248 throw new CloudRuntimeException ("grantAccess : Cloud Stack Volume not found for id: " + dataObject .getId ());
235249 }
@@ -252,12 +266,12 @@ private void grantAccessForVolume(StoragePoolVO storagePool, VolumeVO volumeVO,
252266 //TODO- verify scopeId DatacenterId is zoneId
253267 long scopeId = (storagePool .getScope () == ScopeType .CLUSTER ) ? host .getClusterId () : host .getDataCenterId ();
254268
255- if (ProtocolType .ISCSI .name ().equalsIgnoreCase (details .get (Constants .PROTOCOL ))) {
269+ if (ProtocolType .ISCSI .name ().equalsIgnoreCase (details .get (Constants .PROTOCOL ))) {
256270 String accessGroupName = Utility .getIgroupName (svmName , scopeId );
257271 CloudStackVolume cloudStackVolume = getCloudStackVolumeByName (storageStrategy , svmName , volumeVO .getPath ());
258272 s_logger .info ("grantAccessForVolume: Retrieved LUN [{}] details for volume [{}]" , cloudStackVolume .getLun ().getName (), volumeVO .getName ());
259273 AccessGroup accessGroup = getAccessGroupByName (storageStrategy , svmName , accessGroupName );
260- if (!hostInitiatorFoundInIgroup (host .getStorageUrl (), accessGroup .getIgroup ())) {
274+ if (!hostInitiatorFoundInIgroup (host .getStorageUrl (), accessGroup .getIgroup ())) {
261275 s_logger .error ("grantAccess: initiator [{}] is not present in iGroup [{}]" , host .getStorageUrl (), accessGroupName );
262276 throw new CloudRuntimeException ("grantAccess: initiator [" + host .getStorageUrl () + "] is not present in iGroup [" + accessGroupName + "]" );
263277 }
@@ -297,7 +311,7 @@ public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore)
297311 }
298312 try {
299313 StoragePoolVO storagePool = storagePoolDao .findById (dataStore .getId ());
300- if (storagePool == null ) {
314+ if (storagePool == null ) {
301315 s_logger .error ("revokeAccess : Storage Pool not found for id: " + dataStore .getId ());
302316 throw new CloudRuntimeException ("revokeAccess : Storage Pool not found for id: " + dataStore .getId ());
303317 }
@@ -308,7 +322,7 @@ public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore)
308322
309323 if (dataObject .getType () == DataObjectType .VOLUME ) {
310324 VolumeVO volumeVO = volumeDao .findById (dataObject .getId ());
311- if (volumeVO == null ) {
325+ if (volumeVO == null ) {
312326 s_logger .error ("revokeAccess : Cloud Stack Volume not found for id: " + dataObject .getId ());
313327 throw new CloudRuntimeException ("revokeAccess : Cloud Stack Volume not found for id: " + dataObject .getId ());
314328 }
@@ -329,12 +343,12 @@ private void revokeAccessForVolume(StoragePoolVO storagePool, VolumeVO volumeVO,
329343 String svmName = details .get (Constants .SVM_NAME );
330344 long scopeId = (storagePool .getScope () == ScopeType .CLUSTER ) ? host .getClusterId () : host .getDataCenterId ();
331345
332- if (ProtocolType .ISCSI .name ().equalsIgnoreCase (details .get (Constants .PROTOCOL ))) {
346+ if (ProtocolType .ISCSI .name ().equalsIgnoreCase (details .get (Constants .PROTOCOL ))) {
333347 String accessGroupName = Utility .getIgroupName (svmName , scopeId );
334348 CloudStackVolume cloudStackVolume = getCloudStackVolumeByName (storageStrategy , svmName , volumeVO .getPath ());
335349 AccessGroup accessGroup = getAccessGroupByName (storageStrategy , svmName , accessGroupName );
336350 //TODO check if initiator does exits in igroup, will throw the error ?
337- if (!hostInitiatorFoundInIgroup (host .getStorageUrl (), accessGroup .getIgroup ())) {
351+ if (!hostInitiatorFoundInIgroup (host .getStorageUrl (), accessGroup .getIgroup ())) {
338352 s_logger .error ("revokeAccessForVolume: initiator [{}] is not present in iGroup [{}]" , host .getStorageUrl (), accessGroupName );
339353 return ;
340354 }
@@ -352,7 +366,7 @@ private CloudStackVolume getCloudStackVolumeByName(StorageStrategy storageStrate
352366 getCloudStackVolumeMap .put (Constants .NAME , cloudStackVolumeName );
353367 getCloudStackVolumeMap .put (Constants .SVM_DOT_NAME , svmName );
354368 CloudStackVolume cloudStackVolume = storageStrategy .getCloudStackVolume (getCloudStackVolumeMap );
355- if (cloudStackVolume == null || cloudStackVolume .getLun () == null || cloudStackVolume .getLun ().getName () == null ) {
369+ if (cloudStackVolume == null || cloudStackVolume .getLun () == null || cloudStackVolume .getLun ().getName () == null ) {
356370 s_logger .error ("getCloudStackVolumeByName: Failed to get LUN details [{}]" , cloudStackVolumeName );
357371 throw new CloudRuntimeException ("getCloudStackVolumeByName: Failed to get LUN [" + cloudStackVolumeName + "]" );
358372 }
0 commit comments