Skip to content

Commit

Permalink
Merge pull request #92 from haarchri/feature/teams-service-client
Browse files Browse the repository at this point in the history
feat(teams): add teams service client
  • Loading branch information
haarchri authored Jun 14, 2024
2 parents d06a099 + 27165ca commit 1bb2f53
Show file tree
Hide file tree
Showing 5 changed files with 470 additions and 0 deletions.
16 changes: 16 additions & 0 deletions service/organizations/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ func (c *Client) ListRobots(ctx context.Context, id uint) ([]Robot, error) {
return rs, nil
}

// ListTeams list all teams the user can access in the organization on
// Upbound.
// TODO(haarchri): move this to teams client when API is updated.
func (c *Client) ListTeams(ctx context.Context, id uint) ([]Team, error) {
req, err := c.Client.NewRequest(ctx, http.MethodGet, basePath, path.Join(strconv.FormatUint(uint64(id), 10), "teams"), nil)
if err != nil {
return nil, err
}
rs := []Team{}
err = c.Client.Do(req, &rs)
if err != nil {
return nil, err
}
return rs, nil
}

// Delete an organization on Upbound.
func (c *Client) Delete(ctx context.Context, id uint) error {
req, err := c.Client.NewRequest(ctx, http.MethodDelete, basePath, strconv.FormatUint(uint64(id), 10), nil)
Expand Down
7 changes: 7 additions & 0 deletions service/organizations/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ type Robot struct {
CreatedAt time.Time `json:"createdAt"`
}

// Team is a team on Upbound.
type Team struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"createdAt"`
}

// OrganizationPermissionGroup is the type of permission a user has in the
// organization.
type OrganizationPermissionGroup string
Expand Down
74 changes: 74 additions & 0 deletions service/teams/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2021 Upbound Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package teams

import (
"context"
"net/http"

"github.com/google/uuid"
"github.com/pkg/errors"

"github.com/upbound/up-sdk-go"
)

const (
basePath = "v1/teams"
)

// Client is an teams client.
type Client struct {
*up.Config
}

// NewClient builds an teams client from the passed config.
func NewClient(cfg *up.Config) *Client {
return &Client{
cfg,
}
}

// Create creates a team on Upbound.
func (c *Client) Create(ctx context.Context, params *TeamCreateParameters) (*TeamResponse, error) { // nolint:interfacer
req, err := c.Client.NewRequest(ctx, http.MethodPost, basePath, "", params)
if err != nil {
return nil, err
}
t := &TeamResponse{}
err = c.Client.Do(req, &t)
if err != nil {
return nil, errors.Wrap(err, "cannot build request")
}
return t, nil
}

// Get gets a team on Upbound.
func (c *Client) Get(ctx context.Context, id uuid.UUID) (*TeamResponse, error) { // nolint:interfacer
req, err := c.Client.NewRequest(ctx, http.MethodGet, basePath, id.String(), nil)
if err != nil {
return nil, err
}
t := &TeamResponse{}
return t, c.Client.Do(req, t)
}

// Delete delete an team on Upbound.
func (c *Client) Delete(ctx context.Context, id uuid.UUID) error { // nolint:interfacer
req, err := c.Client.NewRequest(ctx, http.MethodDelete, basePath, id.String(), nil)
if err != nil {
return err
}
return c.Client.Do(req, nil)
}
Loading

0 comments on commit 1bb2f53

Please sign in to comment.