Skip to content

Commit

Permalink
all projects
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-lifshits committed Oct 22, 2024
1 parent e793177 commit 84d9b52
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
41 changes: 41 additions & 0 deletions acceptance/openstack/identity/v3.0/agency_test.go
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)
}
9 changes: 9 additions & 0 deletions openstack/identity/v3.0/agency/CheckAgencyAllProjects.go
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
}
14 changes: 14 additions & 0 deletions openstack/identity/v3.0/agency/GrantAgenctAllProjects.go
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
}
35 changes: 35 additions & 0 deletions openstack/identity/v3.0/agency/ListAgencyAllProjects.go
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"`
}
9 changes: 9 additions & 0 deletions openstack/identity/v3.0/agency/RemoveAgencyAllProjects.go
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
}

0 comments on commit 84d9b52

Please sign in to comment.