Skip to content

Commit

Permalink
feat: add project organization handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-savciuc committed Dec 28, 2023
1 parent 62a14b2 commit c4df0fe
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type Client struct {
OrganizationUserGroupMembers *OrganizationUserGroupMembersHandler
OpenSearchSecurityPluginHandler *OpenSearchSecurityPluginHandler
OpenSearchACLs *OpenSearchACLsHandler
ProjectOrganization *ProjectOrgHandler
}

// GetUserAgentOrDefault configures a default userAgent value, if one has not been provided.
Expand Down Expand Up @@ -272,6 +273,7 @@ func (c *Client) Init() {
c.OrganizationUserGroupMembers = &OrganizationUserGroupMembersHandler{c}
c.OpenSearchSecurityPluginHandler = &OpenSearchSecurityPluginHandler{c}
c.OpenSearchACLs = &OpenSearchACLsHandler{c}
c.ProjectOrganization = &ProjectOrgHandler{c}
}

func (c *Client) doGetRequest(ctx context.Context, endpoint string, req interface{}) ([]byte, error) {
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand All @@ -31,6 +32,7 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/ginkgo/v2 v2.1.3 h1:e/3Cwtogj0HA+25nMP1jCMDIf8RtRYbGwGGuBIFztkc=
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
Expand Down Expand Up @@ -85,6 +87,7 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
Expand Down
1 change: 1 addition & 0 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type (
BillingGroupId string `json:"billing_group_id"`
BillingGroupName string `json:"billing_group_name"`
Tags map[string]string `json:"tags"`
OrganizationId string `json:"organization_id"`
}

// ProjectsHandler is the client which interacts with the Projects endpoints
Expand Down
74 changes: 74 additions & 0 deletions project_organization_groups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package aiven

import "context"

// ProjectOrgHandler is the client that interacts with
// projects and organizations relations on Aiven.
type ProjectOrgHandler struct {
client *Client
}

// ProjectUserGroupRequest is the request from Aiven for the project user group endpoints.
type ProjectUserGroupRequest struct {
Role string `json:"role"`
}

// ProjectListResponse is the response from Aiven for the project endpoints.
type ProjectUserGroupListResponse struct {
APIResponse
AccessList []*ProjectUserGroup `json:"resource_access_list"`
}

// ProjectUserGroup is the response from Aiven for the project user group endpoints.
type ProjectUserGroup struct {
OrganizationGroupID string `json:"user_group_id"`
Role string `json:"role"`
CreateTime string `json:"create_time"`
UpdateTime string `json:"update_time"`
}

// Add or update direct access to a project for a group with a given role.
// API endpoint: PUT /project/<project>/access/groups/<user_group_id>
func (h *ProjectOrgHandler) Add(ctx context.Context, project, userGroupID, role string) error {
path := buildPath("project", project, "access", "groups", userGroupID)
_, err := h.client.doPutRequest(ctx, path, ProjectUserGroupRequest{Role: role})
return err
}

// Delete removes direct access to a project for a group.
// API endpoint: DELETE /project/<project>/access/groups/<user_group_id>
func (h *ProjectOrgHandler) Delete(ctx context.Context, project, userGroupID string) error {
path := buildPath("project", project, "access", "groups", userGroupID)
_, err := h.client.doDeleteRequest(ctx, path, nil)
return err
}

// List all project that have a direct access for an organization.
// API endpoint: GET /organization/{organization_id}/projects
func (h *ProjectOrgHandler) OrganizationProjects(ctx context.Context, organizationID string) ([]*Project, error) {
path := buildPath("organization", organizationID, "projects")
bts, err := h.client.doGetRequest(ctx, path, nil)
if err != nil {
return nil, err
}

var r ProjectListResponse
errR := checkAPIResponse(bts, &r)

return r.Projects, errR
}

// Retrieve the list of resource access entries for the given project.
// API endpoint: GET /project/<project>/access
func (h *ProjectOrgHandler) List(ctx context.Context, project string) ([]*ProjectUserGroup, error) {
path := buildPath("project", project, "access")
bts, err := h.client.doGetRequest(ctx, path, nil)
if err != nil {
return nil, err
}

var r ProjectUserGroupListResponse
errR := checkAPIResponse(bts, &r)

return r.AccessList, errR
}

0 comments on commit c4df0fe

Please sign in to comment.