Skip to content
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

Add CRUD operations for Org user #210

Merged
merged 13 commits into from
Jul 5, 2019
Merged

Add CRUD operations for Org user #210

merged 13 commits into from
Jul 5, 2019

Conversation

dataclouder
Copy link
Contributor

  • Update AdminOrg structure to include roles and users
  • Define the new type User
  • Define auxiliary types RoleReference, RightReference
  • Add AdminOrg methods GetRole, GetUserByNameOrId
  • Add AdminOrg methods CreateUser, SimpleCreateUser
  • Add OrgUser methods GetRoleName, Update, Enable, Disable
  • Add OrgUser methods UnconditionalDelete, SafeDelete
  • Add OrgUser methods ChangePassword, Unlock, TakeOwnership
  • Add tests for org user retrieval, creation, update, deletion

* Update AdminOrg structure to include roles and users
* Define the new type User
* Define auxiliary types RoleReference, RightReference
* Add AdminOrg methods GetRole, GetUserByNameOrId
* Add AdminOrg methods CreateUser, SimpleCreateUser
* Add OrgUser methods GetRoleName, Update, Enable, Disable
* Add OrgUser methods UnconditionalDelete, SafeDelete
* Add OrgUser methods ChangePassword, Unlock, TakeOwnership
* Add tests for org user retrieval, creation, update, deletion
@dataclouder dataclouder requested review from Didainius, lvirbalas and vbauzys and removed request for lvirbalas July 3, 2019 16:00
@dataclouder dataclouder requested a review from lvirbalas July 4, 2019 03:26
Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass. Looking forward to this as it will complete the provider workflow of full environment creation!

govcd/user.go Outdated Show resolved Hide resolved
govcd/user.go Outdated Show resolved Hide resolved
govcd/user.go Outdated Show resolved Hide resolved
govcd/user.go Outdated Show resolved Hide resolved
govcd/user.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of my initial thoughts.
Tests pass for me and +1 for nice test Test_UserCRUD

govcd/user.go Outdated Show resolved Hide resolved
govcd/user.go Outdated Show resolved Hide resolved
govcd/user.go Outdated Show resolved Hide resolved
govcd/user.go Outdated Show resolved Hide resolved
govcd/user.go Show resolved Hide resolved
govcd/user.go Show resolved Hide resolved
govcd/user.go Show resolved Hide resolved
Change return object for Role on failure
Remove explicit timeout from CreateUser (use MaxRetryTimeout instead)
Improve structure checking
Add comment about field order in User type
Change field AdminOrg in OrgUser structure to be public
Copy link
Contributor

@vbauzys vbauzys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, it's big progress!

CHANGELOG.md Show resolved Hide resolved
govcd/api_vcd_test.go Show resolved Hide resolved
govcd/user.go Outdated Show resolved Hide resolved
govcd/user.go Outdated
// by either name or ID
// Returns a valid user if it exists. If it doesn't, returns nil and ErrorEntityNotFound
func (adminOrg *AdminOrg) GetUserByNameOrId(identifier string, willRefresh bool) (*OrgUser, error) {
if willRefresh {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am kind'a lost here with context willRefresh - what it means

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like other functions where we search the parent to find the entity, we need to refresh the entity to make sure we have a fresh image. However, since the refresh is costly, if we know that we want to get what is already there (such as when we want to get all the current users, we don't need to refresh every time) we set willRefhesh to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant 'willRefresh -> 'refresh' or something else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"refresh" can be either a verb or a noun, while willRefresh shows that I want it to do something.

Copy link
Contributor

@vbauzys vbauzys Jul 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lvirbalas @Didainius what is your opinion? willRefresh, Refresh, toRefresh, withRefresh

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add one more withRefresh :) but it won't change too much so it can be even as it is for me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a pretty strong opinion on this one. It should be just refresh and we should use the same approach in other places if/when we need it.

govcd/user.go Outdated
// GetUserByNameOrId retrieves an user within an admin organization
// by either name or ID
// Returns a valid user if it exists. If it doesn't, returns nil and ErrorEntityNotFound
func (adminOrg *AdminOrg) GetUserByNameOrId(identifier string, willRefresh bool) (*OrgUser, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems here we explicitly state that identifier can hold name of ID. Or maybe have seperata method GetUserByNameOrId(identifier string, identifier name, refresh bool).. O wrappers - GetUserByName, GetUserById

Copy link
Contributor Author

@dataclouder dataclouder Jul 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned above, it's unlikely that we can mistake an ID for a name, and for OrgUsers it is impossible, as names can't contain some of the characters we find in IDs.

I don't see the risk of this approach: even if it were possible to use a name that looks like urn:vcloud:user:440a94b2-414b-4923-aff7-439603c8dd48, what's the risk, since we check both fields and return a match if they are the same?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just personally don't like implicit behaviour - double meaning parameters. Especially in public API. If everyone else ok with this - I can live with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not implicit. It does what it says. Finds "By name or by ID".
This is also on line with what I propose in #211

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like opinion @lvirbalas and @Didainius here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO probably separate fields would be clearer here.

govcd/user.go Outdated Show resolved Hide resolved
govcd/user.go Show resolved Hide resolved
govcd/user.go Outdated Show resolved Hide resolved
govcd/user.go Show resolved Hide resolved
govcd/user_test.go Show resolved Hide resolved
Giuseppe Maxia added 5 commits July 4, 2019 13:43
Remove function GetUserByNameOrId
Add function FetchUserByName
Add function FetchUserById
Add function FetchUserByNameOrId
Remove SafeDelete and UnconditionalDelete
Add function Delete with takeOwnership parameter
Copy link
Contributor

@vbauzys vbauzys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

govcd/user_test.go Outdated Show resolved Hide resolved
govcd/user.go Outdated Show resolved Hide resolved
govcd/user.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now!

We now have the new kind of Fetch... function and all its variants. It's clear, intuitive and we could use that as a role model going forward:

The core:

  • func (adminOrg *AdminOrg) FetchUserByHref(href string) (*OrgUser, error)

The two variants:

  • func (adminOrg *AdminOrg) FetchUserByName(name string, refresh bool) (*OrgUser, error)
  • func (adminOrg *AdminOrg) FetchUserById(id string, refresh bool) (*OrgUser, error)

And the helper:

  • func (adminOrg *AdminOrg) FetchUserByNameOrId(identifier string, refresh bool) (*OrgUser, error)

@dataclouder dataclouder merged commit ed123fe into vmware:master Jul 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants