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

Site and org associations #669

Merged
merged 48 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
0d5104b
enable query orgs
Aug 25, 2023
7f6efca
add compangnion functions and tests
Aug 25, 2023
e55b18e
add compangnion functions and tests
Aug 25, 2023
783edbd
fixing tests
Aug 25, 2023
39759f6
bugs fixed, lifted Query*Org to VCDClient-level
Aug 25, 2023
78835aa
merge fixes
Aug 25, 2023
1c33597
review requested changes
Aug 27, 2023
00ec4e1
Add types and basic methods to retrieve associations
dataclouder Apr 22, 2024
92a2695
Add more associations retrieval functions
dataclouder Apr 24, 2024
d7c4d4c
Update associations types
dataclouder Apr 24, 2024
87b16ad
Merge branch 'main' of https://github.com/medea61/go-vcloud-director …
dataclouder Apr 24, 2024
a0340fc
Merge branch 'org-query' into site-org-associations
dataclouder Apr 24, 2024
320f7e0
Update cumulative query for Orgs
dataclouder Apr 24, 2024
1b4f0fd
Check unhandled errors
dataclouder Apr 24, 2024
1a2489e
Add functions to get associations data from site/org
dataclouder Apr 24, 2024
fe29a6d
Rename associations*.go to multi_site*.go
dataclouder Apr 24, 2024
c98c011
Add methods to set and remove Org associations
dataclouder Apr 24, 2024
58695f5
Add functions to set/remove site associations
dataclouder Apr 25, 2024
5a8f935
Add type Site
dataclouder Apr 29, 2024
4a56d82
Add methods GetSite, CheckSiteAssociation, CheckOrgAssociation
dataclouder Apr 29, 2024
c32bbd8
Merge branch 'main' into site-org-associations
dataclouder Apr 29, 2024
fb9d9ec
Decouple function newOrgUserConnection
dataclouder May 1, 2024
53c9cdb
Add full multi-site test
dataclouder May 1, 2024
9545ac1
Update tests
dataclouder May 4, 2024
dff9744
Add method AdminOrg.GetAllOpenApiOrgVdcNetworks
dataclouder May 6, 2024
59f2809
Add method client.GetAllOrgs for multi-site retrieval of organizations
dataclouder May 6, 2024
86ac52d
Improve multi-site test
dataclouder May 6, 2024
7e4f9cc
update test
dataclouder May 6, 2024
264f4ab
Remove spurious test
dataclouder May 7, 2024
3966399
Fix gosec false positive complaint
dataclouder May 7, 2024
b50f4cc
Merge branch 'main' into site-org-associations
dataclouder May 14, 2024
ea07087
Merge branch 'main' into site-org-associations
dataclouder May 17, 2024
546b408
Merge branch 'main' into site-org-associations
dataclouder May 21, 2024
d2a2a92
Update test
dataclouder May 31, 2024
a5679a0
Merge branch 'main' into site-org-associations
dataclouder Jun 3, 2024
4e7793b
Update cse_util.go (missed from merge)
dataclouder Jun 3, 2024
bd2e5ee
Merge branch 'main' into site-org-associations
dataclouder Jun 3, 2024
cca57e6
Improve tests
dataclouder Jun 5, 2024
bd51ec4
Fix function comment
dataclouder Jun 12, 2024
613e1e7
Add changelog entry
dataclouder Jun 12, 2024
1650941
Merge branch 'main' into site-org-associations
dataclouder Jun 12, 2024
2818fe1
Merge branch 'main' into site-org-associations
dataclouder Jun 13, 2024
7565683
Merge branch 'main' into site-org-associations
dataclouder Jun 13, 2024
7f67778
Merge branch 'main' into site-org-associations
dataclouder Jun 17, 2024
4bf46ca
Merge branch 'main' into site-org-associations
dataclouder Jun 17, 2024
781eb7c
Merge branch 'main' into site-org-associations
dataclouder Jun 19, 2024
7e1c605
Address review requests
dataclouder Jun 19, 2024
217a353
Merge branch 'main' into site-org-associations
dataclouder Jun 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changes/v2.25.0/669-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
* Added `Client` method `GetSite` to retrieve generic data about the current site [GH-669]
* Added `Client` methods `GetSiteAssociationData` and `GetSiteRawAssociationData` to retrieve association about from current site [GH-669]
* Added `Client` methods `GetSiteAssociations` and `QueryAllSiteAssociations` to retrieve all site associations from current site [GH-669]
* Added `Client` method `GetSiteAssociationBySiteId` to retrieve a specific site association from current site [GH-669]
* Added `Client` method `CheckSiteAssociation` to check the status of a site association [GH-669]
* Added `Client` methods `SetSiteAssociationAsync` and `SetSiteAssociation` to set a site association with current site [GH-669]
* Added `Client` methods `RemoveSiteAssociationAsync` and `RemoveSiteAssociation` to delete a site association from current site [GH-669]
* Added `Client` method `QueryAllOrgAssociations` and `GetOrgAssociations` to retrieve all org associations visible to current user [GH-669]
* Added `AdminOrg` method `GetOrgAssociationByOrgId` to retrieve a specific organization association from current org [GH-669]
* Added `AdminOrg` methods `GetOrgAssociationData` and `GetOrgRawAssociationData` to retrieve association about from current org [GH-669]
* Added `AdminOrg` method `CheckOrgAssociation` to check the status of an org association [GH-669]
* Added `AdminOrg` methods `SetOrgAssociationAsync` and `SetOrgAssociation` to set an organization association with current org [GH-669]
* Added `AdminOrg` methods `RemoveOrgAssociationAsync` and `RemoveOrgAssociation` to delete an organization association from current org [GH-669]
* Added function `RawDataToStructuredXml` and `ReadXmlDataFromFile` to extract specific data from string or file [GH-669]
* Added `AdminOrg` methods `QueryAllOrgs`, `QueryOrgByName`, `QueryOrgByID` to query organizations [GH-612,GH-669]
* Added `AdminOrg` methods `GetAllOrgs` and `GetAllOpenApiOrgVdcNetworks` to retrieve organizations and networks available to current user [GH-669]
31 changes: 19 additions & 12 deletions govcd/api_vcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2064,16 +2064,25 @@ func skipOpenApiEndpointTest(vcd *TestVCD, check *C, endpoint string) {
}
}

// newOrgUserConnection creates a new Org User and returns a connection to it.
// Attention: Set the user to use only lowercase letters. If you put upper case letters the function fails on waiting
// because VCD creates the user with lowercase letters.
func newOrgUserConnection(adminOrg *AdminOrg, userName, password, href string, insecure bool) (*VCDClient, *OrgUser, error) {
// newUserConnection returns a connection for a given user
func newUserConnection(href, userName, password, orgName string, insecure bool) (*VCDClient, error) {
u, err := url.ParseRequestURI(href)
if err != nil {
return nil, nil, fmt.Errorf("[newOrgUserConnection] unable to pass url: %s", err)
return nil, fmt.Errorf("[newUserConnection] unable to pass url: %s", err)
}
vcdClient := NewVCDClient(*u, insecure)
err = vcdClient.Authenticate(userName, password, orgName)
if err != nil {
return nil, fmt.Errorf("[newUserConnection] unable to authenticate: %s", err)
}
return vcdClient, nil
}

_, err = adminOrg.GetUserByName(userName, false)
// newOrgUserConnection creates a new Org User and returns a connection to it.
// Attention: Set the user to use only lowercase letters. If you put upper case letters the function fails on waiting
// because VCD creates the user with lowercase letters.
func newOrgUserConnection(adminOrg *AdminOrg, userName, password, href string, insecure bool) (*VCDClient, *OrgUser, error) {
_, err := adminOrg.GetUserByName(userName, false)
if err == nil {
// user exists
return nil, nil, fmt.Errorf("user %s already exists", userName)
Expand All @@ -2096,16 +2105,14 @@ func newOrgUserConnection(adminOrg *AdminOrg, userName, password, href string, i
AddToCleanupList(userName, "user", adminOrg.AdminOrg.Name, "newOrgUserConnection")

_ = adminOrg.Refresh()
vcdClient := NewVCDClient(*u, insecure)
err = vcdClient.Authenticate(userName, password, adminOrg.AdminOrg.Name)
newUser, err := adminOrg.GetUserByName(userName, false)
if err != nil {
return nil, nil, fmt.Errorf("[newOrgUserConnection] unable to authenticate: %s", err)
return nil, nil, fmt.Errorf("[newOrgUserConnection] unable to retrieve newly created user: %s", err)
}

// return newUser
newUser, err := adminOrg.GetUserByName(userName, false)
vcdClient, err := newUserConnection(href, userName, password, adminOrg.AdminOrg.Name, insecure)
if err != nil {
return nil, nil, fmt.Errorf("[newOrgUserConnection] unable to retrieve newly created user: %s", err)
return nil, nil, fmt.Errorf("[newOrgUserConnection] error connecting new user: %s", err)
}

return vcdClient, newUser, nil
Expand Down
2 changes: 1 addition & 1 deletion govcd/cse_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func cseConvertToCseKubernetesClusterType(rde *DefinedEntity) (*CseKubernetesClu
params.Add("filter", fmt.Sprintf("name==%s", result.capvcdType.Status.Capvcd.VcdProperties.OrgVdcs[0].OvdcNetworkName))
params = queryParameterFilterAnd("orgVdc.id=="+result.VdcId, params)
params = queryParameterFilterAnd("_context==includeAccessible", params)
networks, err := getAllOpenApiOrgVdcNetworks(rde.client, params)
networks, err := getAllOpenApiOrgVdcNetworks(rde.client, params, nil)
if err != nil {
return nil, fmt.Errorf("could not read Org VDC Network from Capvcd type: %s", err)
}
Expand Down
19 changes: 19 additions & 0 deletions govcd/filter_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type (
QueryOrgVdc types.QueryResultOrgVdcRecordType
QueryTask types.QueryResultTaskRecordType
QueryAdminTask types.QueryResultTaskRecordType
QueryOrg types.QueryResultOrgRecordType
)

// getMetadataValue is a generic metadata lookup for all query items
Expand Down Expand Up @@ -230,6 +231,20 @@ func (vm QueryVm) GetMetadataValue(key string) string {
return getMetadataValue(vm.MetaData, key)
}

// --------------------------------------------------------------
// Organization
// --------------------------------------------------------------
func (org QueryOrg) GetHref() string { return org.HREF }
func (org QueryOrg) GetName() string { return org.Name }
func (org QueryOrg) GetType() string { return "organization" }
func (org QueryOrg) GetDate() string { return "" }
func (org QueryOrg) GetIp() string { return "" }
func (org QueryOrg) GetParentId() string { return "" }
func (org QueryOrg) GetParentName() string { return "" }
func (org QueryOrg) GetMetadataValue(key string) string {
return getMetadataValue(org.Metadata, key)
}

// --------------------------------------------------------------
// result conversion
// --------------------------------------------------------------
Expand Down Expand Up @@ -273,6 +288,10 @@ func resultToQueryItems(queryType string, results Results) ([]QueryItem, error)
for i, item := range results.Results.OrgVdcNetworkRecord {
items[i] = QueryOrgVdcNetwork(*item)
}
case types.QtOrg:
for i, item := range results.Results.OrgRecord {
items[i] = QueryOrg(*item)
}
case types.QtCatalog:
for i, item := range results.Results.CatalogRecord {
items[i] = QueryCatalog(*item)
Expand Down
Loading
Loading