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

Refactored Get* methods 1 #217

Merged
merged 22 commits into from
Aug 2, 2019
Merged

Refactored Get* methods 1 #217

merged 22 commits into from
Aug 2, 2019

Conversation

dataclouder
Copy link
Contributor

@dataclouder dataclouder commented Jul 17, 2019

This is the first batch of changes to support the creation of data sources in terraform-provider-vcd.

Changes:

  • Add Get* methods for Org and AdminOrg
  • Add function getUuidFromHref
  • Add function getOrgHREFById, to retrieve an HREF from an Org/AdminOrg ID
  • Add method vcdClient.GetOrgByName
  • Add method vcdClient.GetOrgById
  • Add method vcdClient.GetOrgByNameOrId
  • Add method vcdClient.GetAdminOrgByName
  • Add method vcdClient.GetAdminOrgById
  • Add method vcdClient.GetAdminOrgByNameOrId
  • Add Fix for values in OrgGeneralSettings, which are ignored unless some fields are always filled.
  • Add test for getUuidFromHref
  • Add tests for all Read* methods
  • Add more tests for Org creation
  • Deprecate functions GetOrgByName, GetAdminOrgByName
  • Replace all calls to the above function with the new vcdClient.Get* methods
  • Fix AdminOrg.Update method and add more tests
  • Add CODING_GUIDELINES.md

Note: when a function was returning Org and other entities, I have only changed the return type for Org (from structure to pointer), leaving the refactoring of the other return types when we tackle the other entities.

Giuseppe Maxia added 6 commits July 16, 2019 15:58
* Add function getUuidFromHref
* Add function getOrgHREFById, to retrieve an HREF from an Org/AdminOrg ID
* Add method vcdClient.ReadOrgByName
* Add method vcdClient.ReadOrgById
* Add method vcdClient.ReadOrgByNameOrId
* Add method vcdClient.ReadOrg (using a struct)
* Add method vcdClient.ReadAdminOrgByName
* Add method vcdClient.ReadAdminOrgById
* Add method vcdClient.ReadAdminOrgByNameOrId
* Add method vcdClient.ReadAdminOrg (using a struct)
* Add Fix for values in OrgGeneralSettings, which are ignored
  unless some fields are always filled.
* Add test for getUuidFromHref
* Add tests for all Read* methods
* Add more tests for Org creation
* Deprecate GetOrgByName, GetAdminOrgByName
* Replace all calls to the above function with the new Read* methods
The Update method was not updating the Org description
@dataclouder dataclouder changed the title Read methods 1 Refactored Get* methods 1 Jul 18, 2019
@dataclouder dataclouder requested a review from lvirbalas July 18, 2019 21:00
Giuseppe Maxia added 7 commits July 19, 2019 16:02
@dataclouder dataclouder requested review from vbauzys and Didainius July 30, 2019 06:48
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.

A lot of good things:

  • Thanks for the "it's" fixes...
  • +1 for fixed deprecation messages
  • Nice on the coding guidelines.

One spot/question - in many places I see:

check.Assert(org, NotNil)
check.Assert(err, IsNil)

Wouldn't it be more informative to swap them so that check.Assert(err, IsNil) is the first check. If it does not pass the dumped err should be more informative than a simply nil struct pointer of some type.

govcd/catalog_test.go Outdated Show resolved Hide resolved
govcd/system.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
govcd/user.go Show resolved Hide resolved
Giuseppe Maxia added 4 commits July 31, 2019 13:12
Fetch* functions were renamed in this PR, but they should have been
deprecated instead. They are now reinstated as wrappers to the
intended replacements
Make the flow easier to read and more robust
Make the functions that retrieve by name or ID easier to read
and more robust against corner cases where an error may occur
in the first search that is not a ErrorEntityNotFound, and would
possibly return stale results.
This move allows running org tests by tag.
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.

Just a few more unordered err assertions.

govcd/org_test.go Outdated Show resolved Hide resolved
govcd/system_test.go Show resolved Hide resolved
govcd/system_test.go Outdated Show resolved Hide resolved
@@ -337,6 +365,37 @@ func getOrgHREF(vcdClient *VCDClient, orgName string) (string, error) {
return "", fmt.Errorf("couldn't find org with name: %s. Please check Org name as it is case sensitive", orgName)
}

// Returns the HREF of the org from the org ID
func getOrgHREFById(vcdClient *VCDClient, orgId string) (string, error) {
orgListHREF := vcdClient.Client.VCDHREF
Copy link
Contributor

@vbauzys vbauzys Aug 1, 2019

Choose a reason for hiding this comment

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

Maybe it's possible to Query using href/id in filter? this would make function very simple

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Query struct doesn't have Organization info.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, It would be need to add.

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.

Nice code structure and a well written guideline too!

@dataclouder dataclouder merged commit 9e67a7d into vmware:master Aug 2, 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