apache / cloudstack Public
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLOUDSTACK-3049: update dynamic role for an account #3058
Conversation
40b1d13
to
f2cac02
Compare
|
Can you instead implement a cleaner approach, say create a new API? |
Thanks @bwsw. I have only one comment regarding a set of nested IFs that can be improved.
Differently from @rhtyd I do not think we need another API method. From my perspective, the role is part of the account. Therefore, when updating the account I should/"would want to" be able to change the role as well.
| if (duplicateAcccount != null && duplicateAcccount.getId() != account.getId()) { | ||
| throw new InvalidParameterValueException( | ||
| "There already exists an account with the name:" + newAccountName + " in the domain:" + domainId + " with existing account id:" + duplicateAcccount.getId()); | ||
| if(newAccountName != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use StringUtils.isEmpty here. Then, you do not need all of these netsting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelweingartner
Hm, I don't think so or don't get the idea. I would like to distinguish three situations:
- newAccountName is not specified
- newAccountName is specified but empty string -> exception 1
- newAccountName is specified and not empty string -> action or exception
So, don't get how StringUtils.isEmpty() helps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I am saying is the following:
Instead of (the current code):
if(newAccountName != null) {
if (newAccountName.isEmpty()) {
throw new InvalidParameterValueException("The new account name for account '" + account.getUuid() + "' " +
"within domain '" + domainId + "' is empty string. Account will be not renamed.");
}
// check if the new proposed account name is absent in the domain
Account existingAccount = _accountDao.findActiveAccount(newAccountName, domainId);
if (existingAccount != null && existingAccount.getId() != account.getId()) {
throw new InvalidParameterValueException("The account with the proposed name '" +
newAccountName + "' exists in the domain '" +
domainId + "' with existing account id '" + existingAccount.getId() + "'");
}
acctForUpdate.setAccountName(newAccountName);
}
You can do the following:
if(StringUtils.isBlank(newAccountName)) {
throw new InvalidParameterValueException("The new account name for account '" + account.getUuid() + "' " +
"within domain '" + domainId + "' is an empty string. Account will be not renamed.");
}
// check if the new proposed account name is absent in the domain
Account existingAccount = _accountDao.findActiveAccount(newAccountName, domainId);
if (existingAccount != null && existingAccount.getId() != account.getId()) {
throw new InvalidParameterValueException("The account with the proposed name '" +
newAccountName + "' exists in the domain '" +
domainId + "' with existing account id '" + existingAccount.getId() + "'");
}
acctForUpdate.setAccountName(newAccountName);
By doing that you remove one nesting level.
Did you understand what I am saying now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelweingartner But how it will behave if newAccountName is null which is normal if API is not intending to change that. It is a normal case and whole code block must be skipped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. I was not paying attention to this detail. Then, I would simply do newAccountName != null && StringUtils.isBlank(newAccountName).
That is only a suggestion. You can leave the code as is if you think it is better this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelweingartner ok. I'll leave as is.
|
@blueorangutan package |
|
@borisstoyanov a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. |
|
Packaging result: |
|
@blueorangutan test |
|
@borisstoyanov a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests |
@rhtyd I considered both alternatives. My arguments for the current implementation:
What do you think? |
|
It's end of my day, let me get back to you soon. In short, my hesitation stems from the fact that the operation in question has some security and privileges implications. As a general rule such an update param/operation must be privileged and checked. It's better to have this as separate api. Take example of other apis which change ownership, transfer relationships etc all cases which could too be solved by an update api as well. |
|
Another note that there is a translation implication of accounttype that maybe implemented as well. Due to backward compatibility, we support both account type and roleid for the create api for example. |
@rhtyd Well, if we decide that only global admin (not domain admin) can change that, then you are right, it's better to implement as a separate API call. |
|
@bwsw if you use the |
|
Trillian test result (tid-3220)
|
|
@rhtyd @rafaelweingartner Please, approve the basic design and then I write the tests for security assurance. Just don't want to spend the time if the design initially doesn't fit. |
|
@blueorangutan package |
|
@rafaelweingartner a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. |
|
Packaging result: |
|
@blueorangutan test |
|
@GabrielBrascher a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests |
|
Trillian test result (tid-3303)
|
| "There already exists an account with the name:" + newAccountName + " in the domain:" + domainId + " with existing account id:" + duplicateAcccount.getId()); | ||
| if(newAccountName != null) { | ||
|
|
||
| if (newAccountName.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bwsw could you please add a comment here to specify that you are checking that the user did not pass an empty string for an optional parameter. Otherwise I think it is a bit confusing why you check if a not null string is empty. At least I found it confusing until I saw the conversation between you and @rafaelweingartner. Overall LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@GabrielBrascher Hi, Gabriel, you have mentioned this PR as a problematic. It has got two LGTM. Please, comment on what do you want me to improve to be merged? |
|
@bwsw this one is looking good indeed, I must have dropped this PR on the wrong list. Just to mention, independently of the "list" that the issue/PR was placed I will be getting in touch and help reviewing, testing, and pinging contributors/reviewers. Thanks for pinging me, keep the good work |
|
@blueorangutan package |
|
@GabrielBrascher a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress. |
|
Packaging result: |
|
@GabrielBrascher Sounds great. |
|
@blueorangutan test |
|
@GabrielBrascher a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests |
|
Trillian test result (tid-3344)
|
|
Thanks for the work guys, this one looks ready to merge (LGTMs + tests are good). |
Description
Existing 'updateAccount' API call now can update role as well as account name and network domain. During the implementation 'newname' attribute was marked as optional, previously in the API was annotated as required, which is not a right behavior.
New Dockerfile was added Dockerfile.smokedev which is convenient if you develop smoke tests.
Helper script was added to deploy datacenter and run tests from the same docker image which guarantees a predictable environment.
Implements #3049
Types of changes
Screenshots (if appropriate):
How Has This Been Tested?