Skip to content

Commit

Permalink
reorg organization methods, add new method, update linter/CI (#131)
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Hwang <[email protected]>
  • Loading branch information
sthwang-metal authored Jan 7, 2025
1 parent c60c2d0 commit f4adeb8
Show file tree
Hide file tree
Showing 6 changed files with 578 additions and 423 deletions.
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ steps:
- docker#v5.11.0:
environment:
- GOFLAGS=-buildvcs=false
image: "registry.hub.docker.com/golangci/golangci-lint:v1.57-alpine"
image: "registry.hub.docker.com/golangci/golangci-lint:v1.60.3-alpine"
command: ["golangci-lint", "run", "-v", "--timeout", "5m"]

- label: ":test_tube: test"
Expand Down
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ linters:
- bodyclose
- gocritic
- gocyclo
- goerr113
- err113
- gofmt
- gofumpt
- goimports
- gomnd
- mnd
- govet
- misspell
- noctx
Expand Down
60 changes: 0 additions & 60 deletions pkg/client/governor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ package client

import (
"context"
"fmt"
"net/http"
"net/url"
"sync"
"time"

"github.com/goccy/go-json"
"go.uber.org/zap"
"golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials"

"github.com/metal-toolbox/governor-api/pkg/api/v1alpha1"
)

const (
Expand Down Expand Up @@ -153,59 +149,3 @@ func (c *Client) newGovernorRequest(ctx context.Context, method, u string) (*htt

return req, nil
}

// Organizations gets the list of organizations from governor
func (c *Client) Organizations(ctx context.Context) ([]*v1alpha1.Organization, error) {
req, err := c.newGovernorRequest(ctx, http.MethodGet, fmt.Sprintf("%s/api/%s/organizations", c.url, governorAPIVersionAlpha))
if err != nil {
return nil, err
}

resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return nil, err
}

defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, ErrRequestNonSuccess
}

out := []*v1alpha1.Organization{}
if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
return nil, err
}

return out, nil
}

// Organization gets the details of an org from governor
func (c *Client) Organization(ctx context.Context, id string) (*v1alpha1.Organization, error) {
if id == "" {
return nil, ErrMissingOrganizationID
}

req, err := c.newGovernorRequest(ctx, http.MethodGet, fmt.Sprintf("%s/api/%s/organizations/%s", c.url, governorAPIVersionAlpha, id))
if err != nil {
return nil, err
}

resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return nil, err
}

defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, ErrRequestNonSuccess
}

out := v1alpha1.Organization{}
if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
return nil, err
}

return &out, nil
}
Loading

0 comments on commit f4adeb8

Please sign in to comment.