Daniel Erez has uploaded a new change for review.

Change subject: core: introduce LibvirtSecretValidator
......................................................................

core: introduce LibvirtSecretValidator

Added LibvirtSecretValidator to validate
on CRUD commands.

Change-Id: I3d80f1b1966b90f4f8c9edb4b5ee37ead513d3a5
Bug-Url: https://bugzilla.redhat.com/1185826
Signed-off-by: Daniel Erez <[email protected]>
---
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/storage/LibvirtSecretValidator.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/LibvirtSecret.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
8 files changed, 91 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/54/41554/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/storage/LibvirtSecretValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/storage/LibvirtSecretValidator.java
new file mode 100644
index 0000000..0352b53
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/provider/storage/LibvirtSecretValidator.java
@@ -0,0 +1,47 @@
+package org.ovirt.engine.core.bll.provider.storage;
+
+import org.apache.commons.lang.StringUtils;
+import org.ovirt.engine.core.bll.ValidationResult;
+import org.ovirt.engine.core.common.businessentities.storage.LibvirtSecret;
+import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.dal.dbbroker.DbFacade;
+import org.ovirt.engine.core.dao.LibvirtSecretDao;
+import org.ovirt.engine.core.dao.provider.ProviderDao;
+
+public class LibvirtSecretValidator {
+
+    private final LibvirtSecret libvirtSecret;
+    private final ProviderDao providerDao;
+    private final LibvirtSecretDao libvirtSecretDao;
+
+    public LibvirtSecretValidator(LibvirtSecret libvirtSecret, DbFacade 
dbFacade) {
+        this.libvirtSecret = libvirtSecret;
+        this.providerDao = dbFacade.getProviderDao();
+        this.libvirtSecretDao = dbFacade.getLibvirtSecretDao();
+    }
+
+    public ValidationResult uuidNotEmpty() {
+        return 
ValidationResult.failWith(VdcBllMessages.LIBVIRT_SECRET_UUID_CANNOT_BE_EMPTY)
+                .when(StringUtils.isEmpty(libvirtSecret.getId().toString()));
+    }
+
+    public ValidationResult uuidNotExist() {
+        return 
ValidationResult.failWith(VdcBllMessages.LIBVIRT_SECRET_UUID_ALREADY_EXISTS)
+                .unless(libvirtSecretDao.get(libvirtSecret.getId()) == null);
+    }
+
+    public ValidationResult uuidExist() {
+        return 
ValidationResult.failWith(VdcBllMessages.LIBVIRT_SECRET_UUID_NOT_EXISTS)
+                .unless(libvirtSecretDao.get(libvirtSecret.getId()) != null);
+    }
+
+    public ValidationResult valueNotEmpty() {
+        return 
ValidationResult.failWith(VdcBllMessages.LIBVIRT_SECRET_VALUE_CANNOT_BE_EMPTY)
+                .when(StringUtils.isEmpty(libvirtSecret.getValue()));
+    }
+
+    public ValidationResult providerExist() {
+        return 
ValidationResult.failWith(VdcBllMessages.ACTION_TYPE_FAILED_PROVIDER_DOESNT_EXIST)
+                .when(providerDao.get(libvirtSecret.getProviderId()) == null);
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/LibvirtSecret.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/LibvirtSecret.java
index d2526b9..859d610 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/LibvirtSecret.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/storage/LibvirtSecret.java
@@ -2,13 +2,16 @@
 
 import org.ovirt.engine.core.common.businessentities.BusinessEntity;
 import org.ovirt.engine.core.common.businessentities.IVdcQueryable;
+import org.ovirt.engine.core.common.utils.ValidationUtils;
 import org.ovirt.engine.core.compat.Guid;
 
+import javax.validation.constraints.Pattern;
 import java.util.Date;
 
 public class LibvirtSecret extends IVdcQueryable implements 
BusinessEntity<Guid> {
 
     private Guid id;
+    @Pattern(regexp = ValidationUtils.BASE_64_PATTERN, message = 
"LIBVIRT_SECRET_VALUE_ILLEGAL_FORMAT")
     private String value;
     private LibvirtSecretUsageType usageType;
     private String description;
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
index d92e9a4..6377a53 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
@@ -51,6 +51,7 @@
     VAR__TYPE__DISK_PROFILE,
     VAR__TYPE__CPU_PROFILE,
     VAR__TYPE__USER_PROFILE,
+    VAR__TYPE__AUTHENTICATION_KEY,
 
     // Gluster types
     VAR__TYPE__GLUSTER_VOLUME,
@@ -1225,6 +1226,13 @@
     CANNOT_ADD_CINDER_DISK_VOLUME_LIMIT_EXCEEDED(ErrorType.CONFLICT),
     CINDER_DISK_ALREADY_REGISTERED(ErrorType.CONFLICT),
     ERROR_CANNOT_DETACH_CINDER_PROVIDER_WITH_IMAGES(ErrorType.CONFLICT),
+    LIBVIRT_SECRET_USAGE_NAME_CANNOT_BE_EMPTY(ErrorType.BAD_PARAMETERS),
+    LIBVIRT_SECRET_USAGE_NAME_ALREADY_EXISTS(ErrorType.CONFLICT),
+    LIBVIRT_SECRET_UUID_CANNOT_BE_EMPTY(ErrorType.BAD_PARAMETERS),
+    LIBVIRT_SECRET_VALUE_CANNOT_BE_EMPTY(ErrorType.BAD_PARAMETERS),
+    LIBVIRT_SECRET_VALUE_ILLEGAL_FORMAT(ErrorType.BAD_PARAMETERS),
+    LIBVIRT_SECRET_UUID_ALREADY_EXISTS(ErrorType.CONFLICT),
+    LIBVIRT_SECRET_UUID_NOT_EXISTS(ErrorType.CONFLICT),
 
     NO_HOST_PROVIDER_FOR_SYSTEM(ErrorType.NOT_SUPPORTED),
 
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java
index 8e2c26b..329961f 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java
@@ -29,6 +29,8 @@
     public static final String CIDR_FORMAT_PATTERN = "^" + 
IP_PATTERN_NON_EMPTY + "/" + SUBNET_PREFIX_PATTERN + "$";
     public static final String ISO_SUFFIX = ".iso";
     public static final String ISO_SUFFIX_PATTERN = "^$|^.+\\.iso$";
+    public static final String BASE_64_PATTERN =
+            
"^([A-Za-z0-9+/]{4})*(()|[A-Za-z0-9+/][AQgw]==|[A-Za-z0-9+/]{2}[AEIMQUYcgkosw048]=)$";
 
     /**
      * the mask will be replaced with zero-padded number in the generated 
names of the VMs in the pool, see
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index 51c5fba..3ea9daa 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -331,6 +331,7 @@
 VAR__TYPE__DISK__SNAPSHOT=$type Disk Snapshot
 VAR__TYPE__DISK_PROFILE=$type Disk Profile
 VAR__TYPE__CPU_PROFILE=$type CPU Profile
+VAR__TYPE__AUTHENTICATION_KEY=$type Authentication Key
 VAR__ACTION__RUN=$action run
 VAR__ACTION__REMOVE=$action remove
 VAR__ACTION__ADD=$action add
@@ -1421,6 +1422,11 @@
 CINDER_DISK_ALREADY_REGISTERED=Cannot ${action} ${type}. Cinder disk is 
already registered (${diskAlias}).
 ERROR_CANNOT_DETACH_CINDER_PROVIDER_WITH_IMAGES=Cannot detach a non empty 
Cinder provider.\n\
         -Please remove all VMs / Templates / Disks and try again.
+LIBVIRT_SECRET_UUID_CANNOT_BE_EMPTY=Cannot ${action} ${type}. Authentication 
Key UUID cannot be empty.
+LIBVIRT_SECRET_VALUE_CANNOT_BE_EMPTY=Cannot ${action} ${type}. Authentication 
Key value cannot be empty.
+LIBVIRT_SECRET_VALUE_ILLEGAL_FORMATCannot ${action} ${type}. Authentication 
Key value should be encoded in Base64.
+LIBVIRT_SECRET_UUID_ALREADY_EXISTS=Cannot ${action} ${type}. Authentication 
Key UUID already exists.
+LIBVIRT_SECRET_UUID_NOT_EXISTS=Cannot ${action} ${type}. Authentication Key 
UUID does not exists.
 
 NO_HOST_PROVIDER_FOR_SYSTEM=The engine server is not associated with any host 
provider.
 ACTION_TYPE_FAILED_VM_USES_SCSI_RESERVATION=Cannot ${action} ${type}. VM uses 
SCSI reservation.
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index 8eba193..7e2c46f 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -913,6 +913,9 @@
     @DefaultStringValue("$type CPU Profile")
     String VAR__TYPE__CPU_PROFILE();
 
+    @DefaultStringValue("$type Authentication Key")
+    String VAR__TYPE__AUTHENTICATION_KEY();
+
     @DefaultStringValue("$type Gluster Volume Snapshot")
     String VAR__TYPE__GLUSTER_VOLUME_SNAPSHOT();
 
@@ -3835,4 +3838,19 @@
 
     @DefaultStringValue("Cannot detach a non empty Cinder provider.\n -Please 
remove all VMs / Templates / Disks and try again.")
     String ERROR_CANNOT_DETACH_CINDER_PROVIDER_WITH_IMAGES();
+
+    @DefaultStringValue("Cannot ${action} ${type}. Authentication Key UUID 
cannot be empty.")
+    String LIBVIRT_SECRET_UUID_CANNOT_BE_EMPTY();
+
+    @DefaultStringValue("Cannot ${action} ${type}. Authentication Key value 
cannot be empty.")
+    String LIBVIRT_SECRET_VALUE_CANNOT_BE_EMPTY();
+
+    @DefaultStringValue("Cannot ${action} ${type}. Authentication Key value 
should be encoded in Base64.")
+    String LIBVIRT_SECRET_VALUE_ILLEGAL_FORMAT();
+
+    @DefaultStringValue("Cannot ${action} ${type}. Authentication Key UUID 
already exists.")
+    String LIBVIRT_SECRET_UUID_ALREADY_EXISTS();
+
+    @DefaultStringValue("Cannot ${action} ${type}. Authentication Key UUID 
does not exists.")
+    String LIBVIRT_SECRET_UUID_NOT_EXISTS();
 }
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 28223ab..13956fe 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -295,6 +295,7 @@
 VAR__TYPE__DISK__SNAPSHOT=$type Disk Snapshot
 VAR__TYPE__DISK_PROFILE=$type Disk Profile
 VAR__TYPE__CPU_PROFILE=$type CPU Profile
+VAR__TYPE__AUTHENTICATION_KEY=$type Authentication Key
 VAR__ACTION__RUN=$action run
 VAR__ACTION__REMOVE=$action remove
 VAR__ACTION__ADD=$action add
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 0928b92..0dbbf03 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -339,6 +339,7 @@
 VAR__TYPE__DISK__SNAPSHOT=$type Disk Snapshot
 VAR__TYPE__DISK_PROFILE=$type Disk Profile
 VAR__TYPE__CPU_PROFILE=$type CPU Profile
+VAR__TYPE__AUTHENTICATION_KEY=$type Authentication Key
 VAR__ACTION__RUN=$action run
 VAR__ACTION__REMOVE=$action remove
 VAR__ACTION__ADD=$action add
@@ -1366,6 +1367,11 @@
 CINDER_DISK_ALREADY_REGISTERED=Cannot ${action} ${type}. Cinder disk is 
already registered (${diskAlias}).
 ERROR_CANNOT_DETACH_CINDER_PROVIDER_WITH_IMAGES=Cannot detach a non empty 
Cinder provider.\n\
         -Please remove all VMs / Templates / Disks and try again.
+LIBVIRT_SECRET_UUID_CANNOT_BE_EMPTY=Cannot ${action} ${type}. Authentication 
Key UUID cannot be empty.
+LIBVIRT_SECRET_VALUE_CANNOT_BE_EMPTY=Cannot ${action} ${type}. Authentication 
Key value cannot be empty.
+LIBVIRT_SECRET_VALUE_ILLEGAL_FORMATCannot ${action} ${type}. Authentication 
Key value should be encoded in Base64.
+LIBVIRT_SECRET_UUID_ALREADY_EXISTS=Cannot ${action} ${type}. Authentication 
Key UUID already exists.
+LIBVIRT_SECRET_UUID_NOT_EXISTS=Cannot ${action} ${type}. Authentication Key 
UUID does not exists.
 
 NO_HOST_PROVIDER_FOR_SYSTEM=The engine server is not associated with any host 
provider.
 ACTION_TYPE_FAILED_VM_USES_SCSI_RESERVATION=Cannot ${action} ${type}. VM uses 
SCSI reservation.


-- 
To view, visit https://gerrit.ovirt.org/41554
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3d80f1b1966b90f4f8c9edb4b5ee37ead513d3a5
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Daniel Erez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to