From 101d5e647bf4e55c36689917c9ef3564e909ce80 Mon Sep 17 00:00:00 2001 From: Christopher Haar Date: Sun, 16 Jun 2024 15:53:27 +0200 Subject: [PATCH] feat(robot): add options for robot teammembership + typed team responses Signed-off-by: Christopher Haar --- service/robots/client.go | 27 +++++++++++++++++++++++++-- service/robots/types.go | 14 +++++++++++++- service/teams/types.go | 16 +++++++++------- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/service/robots/client.go b/service/robots/client.go index 99b6cfe..beb7b90 100644 --- a/service/robots/client.go +++ b/service/robots/client.go @@ -26,8 +26,9 @@ import ( ) const ( - basePath = "v2/robots" - tokensPath = "tokens" + basePath = "v2/robots" + tokensPath = "tokens" + teamsRelationPath = "relationships/teams" ) // Client is an robots client. @@ -96,3 +97,25 @@ func (c *Client) Delete(ctx context.Context, id uuid.UUID) error { // nolint:int } return c.Client.Do(req, nil) } + +// CreateTeamMembership create a robot team membership on Upbound. +func (c *Client) CreateTeamMembership(ctx context.Context, id uuid.UUID, params *RobotTeamMembershipResourceIdentifier) error { + req, err := c.Client.NewRequest(ctx, http.MethodPost, basePath, path.Join(id.String(), teamsRelationPath), &RobotTeamMembershipRelationshipList{ + Data: []RobotTeamMembershipResourceIdentifier{*params}, + }) + if err != nil { + return err + } + return c.Client.Do(req, nil) +} + +// DeleteTeamMembership delete a robot team membership on Upbound. +func (c *Client) DeleteTeamMembership(ctx context.Context, id uuid.UUID, params *RobotTeamMembershipResourceIdentifier) error { + req, err := c.Client.NewRequest(ctx, http.MethodDelete, basePath, path.Join(id.String(), teamsRelationPath), &RobotTeamMembershipRelationshipList{ + Data: []RobotTeamMembershipResourceIdentifier{*params}, + }) + if err != nil { + return err + } + return c.Client.Do(req, nil) +} diff --git a/service/robots/types.go b/service/robots/types.go index b8ef899..77253a0 100644 --- a/service/robots/types.go +++ b/service/robots/types.go @@ -23,7 +23,8 @@ type RobotOwnerType string // Robots can be owned by an organization. const ( - RobotOwnerOrganization RobotOwnerType = "organization" + RobotOwnerOrganization RobotOwnerType = "organization" + RobotTeamMembershipTypeTeam string = "teams" ) // bodyType is the type of request in the data body. @@ -87,3 +88,14 @@ type RobotAttributes struct { Name string `json:"name"` Description string `json:"description"` } + +// RobotTeamMembershipResourceIdentifier are the attributes of a robot team membership. +type RobotTeamMembershipResourceIdentifier struct { + Type string `json:"type"` + ID string `json:"id"` +} + +// RobotTeamMembershipRelationshipList represents RobotTeamMembershipResourceIdentifier relationships. +type RobotTeamMembershipRelationshipList struct { + Data []RobotTeamMembershipResourceIdentifier `json:"data"` +} diff --git a/service/teams/types.go b/service/teams/types.go index a6074a0..d0ca596 100644 --- a/service/teams/types.go +++ b/service/teams/types.go @@ -15,7 +15,9 @@ package teams import ( - "github.com/upbound/up-sdk-go/service/common" + "time" + + "github.com/google/uuid" ) // TeamCreateParameters are the parameters for creating a team. @@ -24,14 +26,14 @@ type TeamCreateParameters struct { OrganizationID uint `json:"organizationId"` } -// TeamsResponse is the response returned from team operations. -type TeamsResponse struct { //nolint:golint - DataSet []common.DataSet `json:"data"` -} - // TeamResponse is the response returned from team operations. type TeamResponse struct { - common.DataSet `json:"data"` + ID uuid.UUID `json:"id"` + OrganizationID uint `json:"organizationId"` + AccountID uint `json:"accountId"` + Name string `json:"name"` + CreatorID uint `json:"creatorId"` + CreatedAt *time.Time `json:"createdAt,omitempty"` } // TeamAttributes are the attributes of a team.