diff --git a/acceptance/openstack/identity/v3.0/agency_test.go b/acceptance/openstack/identity/v3.0/agency_test.go new file mode 100644 index 000000000..a97528f44 --- /dev/null +++ b/acceptance/openstack/identity/v3.0/agency_test.go @@ -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) +} diff --git a/openstack/identity/v3.0/agency/CheckAgencyAllProjects.go b/openstack/identity/v3.0/agency/CheckAgencyAllProjects.go new file mode 100644 index 000000000..75a2c3e80 --- /dev/null +++ b/openstack/identity/v3.0/agency/CheckAgencyAllProjects.go @@ -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 +} diff --git a/openstack/identity/v3.0/agency/GrantAgenctAllProjects.go b/openstack/identity/v3.0/agency/GrantAgenctAllProjects.go new file mode 100644 index 000000000..a9d64ceef --- /dev/null +++ b/openstack/identity/v3.0/agency/GrantAgenctAllProjects.go @@ -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 +} diff --git a/openstack/identity/v3.0/agency/ListAgencyAllProjects.go b/openstack/identity/v3.0/agency/ListAgencyAllProjects.go new file mode 100644 index 000000000..3ec262878 --- /dev/null +++ b/openstack/identity/v3.0/agency/ListAgencyAllProjects.go @@ -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"` +} diff --git a/openstack/identity/v3.0/agency/RemoveAgencyAllProjects.go b/openstack/identity/v3.0/agency/RemoveAgencyAllProjects.go new file mode 100644 index 000000000..34198d8b4 --- /dev/null +++ b/openstack/identity/v3.0/agency/RemoveAgencyAllProjects.go @@ -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 +}