cloudstack-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CLOUDSTACK-8562) User Definable Roles
Date Fri, 22 Apr 2016 17:16:12 GMT

    [ https://issues.apache.org/jira/browse/CLOUDSTACK-8562?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15254241#comment-15254241
] 

ASF GitHub Bot commented on CLOUDSTACK-8562:
--------------------------------------------

Github user bhaisaab commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1489#discussion_r60772392
  
    --- Diff: server/src/com/cloud/api/dispatch/ParamProcessWorker.java ---
    @@ -92,6 +94,55 @@ public void handle(final DispatchTask task) {
             processParameters(task.getCmd(), task.getParams());
         }
     
    +    private void validateNonEmptyString(final Object param, final String argName) {
    +        if (param == null || Strings.isNullOrEmpty(param.toString())) {
    +            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, String.format("Empty
or null value provided for API arg: %s", argName));
    +        }
    +    }
    +
    +    private void validateNaturalNumber(final Object param, final String argName) {
    +        Long value = null;
    +        if (param != null && param instanceof Long) {
    +            value = (Long) param;
    +        } else if (param != null) {
    +            value = Long.valueOf(param.toString());
    +        }
    +        if (value == null || value < 1L) {
    +            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, String.format("Invalid
value provided for API arg: %s", argName));
    +        }
    +    }
    +
    +    private void validateField(final Object paramObj, final Parameter annotation) throws
ServerApiException {
    +        if (annotation == null) {
    +            return;
    +        }
    +        final String argName = annotation.name();
    +        for (final ApiArgValidator validator : annotation.validations()) {
    +            if (validator == null) {
    +                continue;
    +            }
    +            switch (validator) {
    +                case NotNullOrEmpty:
    +                    switch (annotation.type()) {
    +                        case UUID:
    +                        case STRING:
    +                            validateNonEmptyString(paramObj, argName);
    +                            break;
    +                    }
    +                    break;
    +                case PositiveNumber:
    +                    switch (annotation.type()) {
    +                        case SHORT:
    +                        case INTEGER:
    +                        case LONG:
    +                            validateNaturalNumber(paramObj, argName);
    +                            break;
    +                    }
    --- End diff --
    
    annotation fields need an exact value, so it could either have a list of enum or classes;
using a list of classes would make implementation complex and creation of several classes
for each new validator. We also needed to know what the annotation type is to only execute
operation based on type, for example PositiveNumber validator on a  string or boolean field/arg
type won't make sense. It was easiest in terms of maintainability and implementation to pass
in enum, and handle them here like this. I'm not sure the best way of doing this, advise if
there are better ways of doing validation?


> User Definable Roles
> --------------------
>
>                 Key: CLOUDSTACK-8562
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-8562
>             Project: CloudStack
>          Issue Type: New Feature
>      Security Level: Public(Anyone can view this level - this is the default.) 
>          Components: Management Server
>            Reporter: Paul Angus
>            Assignee: Rohit Yadav
>
> Static command.properties moved to database and made user definable



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message