Skip to content

Commit

Permalink
Merge pull request #93 from haarchri/feature/robot-teammembership
Browse files Browse the repository at this point in the history
feat(robot): add options for robot teammembership + typed team responses
  • Loading branch information
haarchri authored Jun 19, 2024
2 parents 1bb2f53 + 101d5e6 commit 774ea60
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
27 changes: 25 additions & 2 deletions service/robots/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import (
)

const (
basePath = "v2/robots"
tokensPath = "tokens"
basePath = "v2/robots"
tokensPath = "tokens"
teamsRelationPath = "relationships/teams"
)

// Client is an robots client.
Expand Down Expand Up @@ -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)
}
14 changes: 13 additions & 1 deletion service/robots/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"`
}
16 changes: 9 additions & 7 deletions service/teams/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 774ea60

Please sign in to comment.