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 API for wardenTeamList and updateGroupByShieldMet…
Browse files Browse the repository at this point in the history
…aData (#72)

* feat(warden): added API for teamList

* chore: format

* feat(warden): updated getTeam call

* feat(warden): updated error handling

* feat(warden): refactor

* chore: format

* chore: formatting

* feat(warden): updateGroupMetaData with warden team

* chore: refactor

* chore: lint resolved

* test(warden): added test for teamList, updateGroup

* test(warden) : more test added

* feat(warden): test, error refactored

* chore: format and lint resolved

* feat(warden): added warden host as a  config

* feat(warden) : added warden client

* feat(warden): replaced warden route by iam

* feat(warden): updated tests

* feat(warden): updated test names

* feat(warden): updated unit test timezone

* feat(warden): added team-name & product-group-name

* feat(warden): route updated

* feat(warden): updated errors

* feat(warden): error handled

* feat(warden): error handling

* feat(warden): error updated.

* feat(warden): client error handling updated

---------

Co-authored-by: Sudheer Pal <[email protected]>
  • Loading branch information
sudheerpal and Sudheer Pal authored Oct 24, 2023
1 parent 89f65a0 commit 8f39ef9
Show file tree
Hide file tree
Showing 20 changed files with 4,792 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ generate:
@make format

generate-mocks:
@mockery --srcpkg=buf.build/gen/go/gotocompany/proton/grpc/go/gotocompany/siren/v1beta1/sirenv1beta1grpc --name=SirenServiceClient
@mockery --srcpkg=buf.build/gen/go/gotocompany/proton/grpc/go/gotocompany/shield/v1beta1/shieldv1beta1grpc --name=ShieldServiceClient
@mockery --srcpkg=buf.build/gen/go/gotocompany/proton/grpc/go/gotocompany/optimus/core/v1beta1/corev1beta1grpc --name=JobSpecificationServiceClient
@mockery --srcpkg=buf.build/gen/go/gotocompany/proton/grpc/go/gotocompany/entropy/v1beta1/entropyv1beta1grpc --name=ResourceServiceClient
@mockery --srcpkg=./internal/server/gcs --name=BlobStorageClient
@mockery --srcpkg=./internal/server/gcs --name=BlobObjectClient
@mockery --srcpkg=./internal/server/gcs --name=ObjectIterator
@mockery --with-expecter --srcpkg=buf.build/gen/go/gotocompany/proton/grpc/go/gotocompany/siren/v1beta1/sirenv1beta1grpc --name=SirenServiceClient
@mockery --with-expecter --srcpkg=buf.build/gen/go/gotocompany/proton/grpc/go/gotocompany/shield/v1beta1/shieldv1beta1grpc --name=ShieldServiceClient
@mockery --with-expecter --srcpkg=buf.build/gen/go/gotocompany/proton/grpc/go/gotocompany/optimus/core/v1beta1/corev1beta1grpc --name=JobSpecificationServiceClient
@mockery --with-expecter --srcpkg=buf.build/gen/go/gotocompany/proton/grpc/go/gotocompany/entropy/v1beta1/entropyv1beta1grpc --name=ResourceServiceClient
@mockery --with-expecter --srcpkg=./internal/server/gcs --name=BlobStorageClient
@mockery --with-expecter --srcpkg=./internal/server/gcs --name=BlobObjectClient
@mockery --with-expecter --srcpkg=./internal/server/gcs --name=ObjectIterator

clean: tidy
@echo "Cleaning up build directories..."
Expand Down
5 changes: 5 additions & 0 deletions cli/server/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ type serverConfig struct {
Optimus optimusConfig `mapstructure:"optimus"`
StencilAddr string `mapstructure:"stencil_addr"`
Dlq dlqConfig `mapstructure:"dlq"`
Warden wardenConfig `mapstructure:"warden"`
}

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

type odinConfig struct {
Expand Down
3 changes: 3 additions & 0 deletions cli/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/goto/dex/internal/server/v1/optimus"
"github.com/goto/dex/pkg/logger"
"github.com/goto/dex/pkg/telemetry"
"github.com/goto/dex/warden"
)

func Commands() *cobra.Command {
Expand Down Expand Up @@ -102,6 +103,7 @@ func runServer(baseCtx context.Context, nrApp *newrelic.Application, zapLog *zap
return err
}

wardenClient := warden.NewClient(cfg.Warden.Addr)
dlqConfig := &dlq.DlqJobConfig{
// TODO: map cfg.Dlq\
DlqJobImage: cfg.Dlq.DlqJobImage,
Expand All @@ -117,6 +119,7 @@ func runServer(baseCtx context.Context, nrApp *newrelic.Application, zapLog *zap
&gcs.Client{StorageClient: gcsClient},
cfg.Odin.Addr,
cfg.StencilAddr,
wardenClient,
dlqConfig,
)
}
1 change: 1 addition & 0 deletions dex
Submodule dex added at 786037
4 changes: 4 additions & 0 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import (
alertsv1 "github.com/goto/dex/internal/server/v1/alert"
dlqv1 "github.com/goto/dex/internal/server/v1/dlq"
firehosev1 "github.com/goto/dex/internal/server/v1/firehose"
iamv1 "github.com/goto/dex/internal/server/v1/iam"
kubernetesv1 "github.com/goto/dex/internal/server/v1/kubernetes"
optimusv1 "github.com/goto/dex/internal/server/v1/optimus"
projectsv1 "github.com/goto/dex/internal/server/v1/project"
"github.com/goto/dex/warden"
)

// Serve initialises all the HTTP API routes, starts listening for requests at addr, and blocks until
Expand All @@ -37,6 +39,7 @@ func Serve(ctx context.Context, addr string,
gcsClient gcs.BlobStorageClient,
odinAddr string,
stencilAddr string,
wardenClient *warden.Client,
dlqConfig *dlqv1.DlqJobConfig,
) error {
alertSvc := alertsv1.NewService(sirenClient)
Expand Down Expand Up @@ -66,6 +69,7 @@ func Serve(ctx context.Context, addr string,
r.Route("/dlq", dlqv1.Routes(entropyClient, gcsClient, dlqConfig))
r.Route("/firehoses", firehosev1.Routes(entropyClient, shieldClient, alertSvc, compassClient, odinAddr, stencilAddr))
r.Route("/kubernetes", kubernetesv1.Routes(entropyClient))
r.Route("/iam", iamv1.Routes(shieldClient, wardenClient))
})

logger.Info("starting server", zap.String("addr", addr))
Expand Down
61 changes: 61 additions & 0 deletions internal/server/v1/iam/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package iam

import (
"net/http"

"github.com/go-chi/chi/v5"

"github.com/goto/dex/internal/server/reqctx"
"github.com/goto/dex/internal/server/utils"
)

type handler struct {
service *Service
}

func NewHandler(service *Service) *handler {
return &handler{service: service}
}

func (h *handler) listUserWardenTeams(w http.ResponseWriter, r *http.Request) {
reqCtx := reqctx.From(r.Context())
const errEmailMissedInHeader = "user email not in header"

if reqCtx.UserEmail == "" {
utils.WriteErrMsg(w, http.StatusUnauthorized, errEmailMissedInHeader)
return
}

teamListResp, err := h.service.UserWardenTeamList(r.Context(), reqCtx.UserEmail)
if err != nil {
utils.WriteErr(w, err)
return
}

utils.WriteJSON(w, http.StatusOK, map[string]any{
"teams": teamListResp,
})
}

func (h *handler) linkGroupToWarden(w http.ResponseWriter, r *http.Request) {
groupID := chi.URLParam(r, "group_id")

var body struct {
WardenTeamID string `json:"warden_team_id"`
}
if err := utils.ReadJSON(r, &body); err != nil {
utils.WriteErr(w, err)
return
} else if body.WardenTeamID == "" {
utils.WriteErrMsg(w, http.StatusBadRequest, "missing warden_team_id")
return
}

resShield, err := h.service.LinkGroupToWarden(r.Context(), groupID, body.WardenTeamID)
if err != nil {
utils.WriteErr(w, err)
return
}

utils.WriteJSON(w, http.StatusOK, resShield)
}
Loading

0 comments on commit 8f39ef9

Please sign in to comment.