-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e793177
commit 93511a4
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package v3 | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/identity/v3.0/agency" | ||
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" | ||
) | ||
|
||
func TestAgencyAllProjectsLifecycle(t *testing.T) { | ||
if os.Getenv("OS_TENANT_ADMIN") == "" { | ||
t.Skip("Policy doesn't allow NewIdentityV3AdminClient() to be initialized.") | ||
} | ||
|
||
var agencyId, roleId string | ||
if agencyId = os.Getenv("OS_AGENCY_ID"); agencyId == "" { | ||
t.Skip("Agency id required to run this test") | ||
} | ||
if roleId = os.Getenv("OS_ROLE_ID"); roleId == "" { | ||
t.Skip("Role id required to run this test") | ||
} | ||
|
||
client, err := clients.NewIdentityV30AdminClient() | ||
th.AssertNoErr(t, err) | ||
|
||
err = agency.GrantAgencyAllProjects(client, client.DomainID, agencyId, roleId) | ||
th.AssertNoErr(t, err) | ||
|
||
t.Cleanup(func() { | ||
th.AssertNoErr(t, agency.RemoveAgencyAllProjects(client, client.DomainID, agencyId, roleId)) | ||
}) | ||
|
||
err = agency.CheckAgencyAllProjects(client, client.DomainID, agencyId, roleId) | ||
th.AssertNoErr(t, err) | ||
|
||
resp, err := agency.ListAgencyAllProjects(client, client.DomainID, agencyId) | ||
th.AssertNoErr(t, err) | ||
th.AssertEquals(t, true, len(resp.Roles) > 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package agency | ||
|
||
import golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
|
||
func CheckAgencyAllProjects(client *golangsdk.ServiceClient, domainId, agencyId, roleId string) (err error) { | ||
// HEAD /v3.0/OS-INHERIT/domains/{domain_id}/agencies/{agency_id}/roles/{role_id}/inherited_to_projects | ||
_, err = client.Head(client.ServiceURL("OS-INHERIT", "domains", domainId, "agencies", agencyId, "roles", roleId, "inherited_to_projects"), nil) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package agency | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
) | ||
|
||
func GrantAgencyAllProjects(client *golangsdk.ServiceClient, domainId, agencyId, roleId string) (err error) { | ||
// PUT /v3.0/OS-INHERIT/domains/{domain_id}/agencies/{agency_id}/roles/{role_id}/inherited_to_projects | ||
_, err = client.Put(client.ServiceURL("OS-INHERIT", "domains", domainId, "agencies", agencyId, "roles", roleId, "inherited_to_projects"), nil, | ||
nil, &golangsdk.RequestOpts{ | ||
OkCodes: []int{204}, | ||
}) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package agency | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
func ListAgencyAllProjects(client *golangsdk.ServiceClient, domainId, agencyId string) (*Roles, error) { | ||
// GET /v3.0/OS-INHERIT/domains/{domain_id}/agencies/{agency_id}/roles/inherited_to_projects | ||
raw, err := client.Get(client.ServiceURL("OS-INHERIT", "domains", domainId, "agencies", agencyId, "roles", "inherited_to_projects"), nil, | ||
nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res Roles | ||
|
||
err = extract.Into(raw.Body, &res) | ||
return &res, err | ||
} | ||
|
||
type Roles struct { | ||
Roles []Role `json:"roles"` | ||
Links Link `json:"links"` | ||
} | ||
|
||
type Role struct { | ||
Id string `json:"id"` | ||
Links Link `json:"links"` | ||
Name string `json:"name"` | ||
} | ||
|
||
type Link struct { | ||
Self string `json:"self"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package agency | ||
|
||
import golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
|
||
func RemoveAgencyAllProjects(client *golangsdk.ServiceClient, domainId, agencyId, roleId string) (err error) { | ||
// DELETE /v3.0/OS-INHERIT/domains/{domain_id}/agencies/{agency_id}/roles/{role_id}/inherited_to_projects | ||
_, err = client.Delete(client.ServiceURL("OS-INHERIT", "domains", domainId, "agencies", agencyId, "roles", roleId, "inherited_to_projects"), nil) | ||
return err | ||
} |