Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
feat(warden): added warden host as a config
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudheer Pal committed Oct 11, 2023
1 parent d3cd79b commit d1f60e8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
5 changes: 5 additions & 0 deletions cli/server/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ type serverConfig struct {
Compass compassConfig `mapstructure:"compass"`
Optimus optimusConfig `mapstructure:"optimus"`
StencilAddr string `mapstructure:"stencil_addr"`
Warden wardenConfig `mapstructure:"warden"`
}

type wardenConfig struct {
Addr string `mapstructure:"addr"`
}

type odinConfig struct {
Expand Down
1 change: 1 addition & 0 deletions cli/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@ func runServer(baseCtx context.Context, nrApp *newrelic.Application, zapLog *zap
&gcs.Client{StorageClient: gcsClient},
cfg.Odin.Addr,
cfg.StencilAddr,
cfg.Warden.Addr,
)
}
3 changes: 2 additions & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func Serve(ctx context.Context, addr string,
gcsClient gcs.BlobStorageClient,
odinAddr string,
stencilAddr string,
wardenAddr string,
) error {
alertSvc := alertsv1.NewService(sirenClient)

Expand Down Expand Up @@ -67,7 +68,7 @@ func Serve(ctx context.Context, addr string,
r.Route("/dlq", dlqv1.Routes(entropyClient, gcsClient))
r.Route("/firehoses", firehosev1.Routes(entropyClient, shieldClient, alertSvc, compassClient, odinAddr, stencilAddr))
r.Route("/kubernetes", kubernetesv1.Routes(entropyClient))
r.Route("/warden", warden.Routes(shieldClient, http.DefaultClient))
r.Route("/warden", warden.Routes(shieldClient, http.DefaultClient, wardenAddr))
})

logger.Info("starting server", zap.String("addr", addr))
Expand Down
12 changes: 6 additions & 6 deletions internal/server/v1/warden/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestHandler_teamList(t *testing.T) {
req.Header.Add("X-Auth-Email", "[email protected]")
router := chi.NewRouter()
router.Use(reqctx.WithRequestCtx())
warden.Routes(nil, doer)(router)
warden.Routes(nil, doer, "")(router)
router.ServeHTTP(resp, req)

assert.Equal(t, http.StatusOK, resp.Code)
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestHandler_teamList(t *testing.T) {
req.Header.Add("X-Auth-Email", "[email protected]")
router := chi.NewRouter()
router.Use(reqctx.WithRequestCtx())
warden.Routes(shieldClient, doer)(router)
warden.Routes(shieldClient, doer, "")(router)
router.ServeHTTP(resp, req)

assert.Equal(t, http.StatusNotFound, resp.Code)
Expand All @@ -127,7 +127,7 @@ func TestHandler_teamList(t *testing.T) {
require.NoError(t, err)
router := chi.NewRouter()
router.Use(reqctx.WithRequestCtx())
warden.Routes(shieldClient, doer)(router)
warden.Routes(shieldClient, doer, "")(router)
router.ServeHTTP(resp, req)

assert.Equal(t, http.StatusUnauthorized, resp.Code)
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestHandler_updateGroup(t *testing.T) {
require.NoError(t, err)
router := chi.NewRouter()
router.Use(reqctx.WithRequestCtx())
warden.Routes(shieldClient, doer)(router)
warden.Routes(shieldClient, doer, "")(router)
router.ServeHTTP(resp, req)

assert.Equal(t, http.StatusOK, resp.Code)
Expand Down Expand Up @@ -235,7 +235,7 @@ func TestHandler_updateGroup(t *testing.T) {
require.NoError(t, err)
router := chi.NewRouter()
router.Use(reqctx.WithRequestCtx())
warden.Routes(shieldClient, doer)(router)
warden.Routes(shieldClient, doer, "")(router)
router.ServeHTTP(resp, req)

assert.Equal(t, http.StatusInternalServerError, resp.Code)
Expand All @@ -250,7 +250,7 @@ func TestHandler_updateGroup(t *testing.T) {
require.NoError(t, err)
router := chi.NewRouter()
router.Use(reqctx.WithRequestCtx())
warden.Routes(shieldClient, doer)(router)
warden.Routes(shieldClient, doer, "")(router)
router.ServeHTTP(resp, req)

assert.Equal(t, http.StatusBadRequest, resp.Code)
Expand Down
4 changes: 2 additions & 2 deletions internal/server/v1/warden/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
chiv5 "github.com/go-chi/chi/v5"
)

func Routes(shieldClient shieldv1beta1rpc.ShieldServiceClient, doer HTTPClient) func(r chiv5.Router) {
service := NewService(shieldClient, doer)
func Routes(shieldClient shieldv1beta1rpc.ShieldServiceClient, doer HTTPClient, wardenAddr string) func(r chiv5.Router) {
service := NewService(shieldClient, doer, wardenAddr)
handler := NewHandler(service)
return func(r chiv5.Router) {
r.Get("/users/me/warden_teams", handler.teamList)
Expand Down
12 changes: 5 additions & 7 deletions internal/server/v1/warden/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,21 @@ import (

//go:generate mockery --with-expecter --keeptree --case snake --name Doer

const (
baseURL = "https://go-cloud.golabs.io"
)

type Service struct {
shieldClient shieldv1beta1rpc.ShieldServiceClient
doer HTTPClient
wardenAddr string
}

type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}

func NewService(shieldClient shieldv1beta1rpc.ShieldServiceClient, doer HTTPClient) *Service {
func NewService(shieldClient shieldv1beta1rpc.ShieldServiceClient, doer HTTPClient, wardenAddr string) *Service {
return &Service{
shieldClient: shieldClient,
doer: doer,
wardenAddr: wardenAddr,
}
}

Expand All @@ -38,7 +36,7 @@ func (c *Service) TeamList(ctx context.Context, userEmail string) (*TeamData, er
userPath := "/users/"
teamsEndpoint := "/teams"

url := baseURL + endpoint + userPath + userEmail + teamsEndpoint
url := c.wardenAddr + endpoint + userPath + userEmail + teamsEndpoint

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
Expand Down Expand Up @@ -112,7 +110,7 @@ func (c *Service) TeamByUUID(ctx context.Context, teamByUUID string) (*Team, err
endpoint := "/api/v2"
teamPath := "/teams/"

url := baseURL + endpoint + teamPath + teamByUUID
url := c.wardenAddr + endpoint + teamPath + teamByUUID

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
Expand Down

0 comments on commit d1f60e8

Please sign in to comment.