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

feat(warden): added API for wardenTeamList and updateGroupByShieldMetaData #72

Merged
merged 28 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
780a7cb
feat(warden): added API for teamList
Oct 4, 2023
628335d
chore: format
Oct 4, 2023
84f99ab
feat(warden): updated getTeam call
Oct 5, 2023
6a235a1
feat(warden): updated error handling
Oct 5, 2023
f7a73b9
feat(warden): refactor
Oct 5, 2023
f6ee803
chore: format
Oct 5, 2023
bb7415f
chore: formatting
Oct 6, 2023
49dd47d
feat(warden): updateGroupMetaData with warden team
Oct 9, 2023
6c42045
chore: refactor
Oct 9, 2023
6351b57
chore: lint resolved
Oct 9, 2023
2a07820
test(warden): added test for teamList, updateGroup
Oct 9, 2023
a32bc10
test(warden) : more test added
Oct 9, 2023
d345518
feat(warden): test, error refactored
Oct 10, 2023
d3cd79b
chore: format and lint resolved
Oct 10, 2023
d1f60e8
feat(warden): added warden host as a config
Oct 11, 2023
9f3e743
feat(warden) : added warden client
Oct 12, 2023
5b465ef
feat(warden): replaced warden route by iam
Oct 12, 2023
d69a46d
feat(warden): updated tests
Oct 13, 2023
9cc8f7d
Merge branch 'main' into warden-api
Oct 13, 2023
cb35f97
feat(warden): updated test names
Oct 16, 2023
97f59b2
feat(warden): updated unit test timezone
Oct 16, 2023
e885442
feat(warden): added team-name & product-group-name
Oct 16, 2023
d2968d8
feat(warden): route updated
Oct 17, 2023
c284a9e
feat(warden): updated errors
Oct 20, 2023
4677041
feat(warden): error handled
Oct 23, 2023
05abd06
feat(warden): error handling
Oct 23, 2023
7860372
feat(warden): error updated.
Oct 23, 2023
b1830bd
feat(warden): client error handling updated
sudheerpal Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)
}
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) teamList(w http.ResponseWriter, r *http.Request) {
StewartJingga marked this conversation as resolved.
Show resolved Hide resolved
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.TeamList(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) updateGroupMetadata(w http.ResponseWriter, r *http.Request) {
StewartJingga marked this conversation as resolved.
Show resolved Hide resolved
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.UpdateGroupMetadata(r.Context(), groupID, body.WardenTeamID)
if err != nil {
utils.WriteErr(w, err)
return
}

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