Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions pkg/adapter/clients.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package adapter

import (
"log/slog"
"net/http"

"github.com/m-mizutani/opac"
Expand All @@ -16,6 +17,16 @@ type Clients struct {
s3Client interfaces.AmazonS3
}

func (x *Clients) LogValue() slog.Value {
return slog.GroupValue(
slog.Bool("HTTPClient", x.httpClient != nil),
slog.Bool("Query", x.query != nil),
slog.Bool("GoogleCloudStorage", x.gcsClient != nil),
slog.Bool("AzureBlobStorage", x.absClient != nil),
slog.Bool("AmazonS3", x.s3Client != nil),
)
}

func (x *Clients) HTTPClient() interfaces.HTTPClient { return x.httpClient }
func (x *Clients) Query() *opac.Client { return x.query }
func (x *Clients) GoogleCloudStorage() interfaces.GoogleCloudStorage {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func cmdServe() *cli.Command {
}

clients := adapter.New(adaptorOptions...)

logging.Default().Debug("create clients", "clients", clients)
uc := usecase.New(clients)

mux := server.New(uc)
Expand Down
8 changes: 8 additions & 0 deletions pkg/controller/server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/secmon-as-code/nydus/pkg/domain/context/logging"
"github.com/secmon-as-code/nydus/pkg/domain/interfaces"
"github.com/secmon-as-code/nydus/pkg/domain/model"
"github.com/secmon-as-code/nydus/pkg/usecase"
)

type Server struct {
Expand All @@ -22,6 +23,10 @@ func (x *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func New(uc interfaces.UseCase) *Server {
route := chi.NewRouter()

if v, ok := uc.(*usecase.UseCase); ok {
logging.Default().Debug("[tmp] check client: new server", "client", v.Clients())
}

route.Route("/google/pubsub", func(r chi.Router) {
r.Post("/cloud-storage", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotImplemented)
Expand Down Expand Up @@ -60,6 +65,9 @@ func handleAzureEventGridMessage(uc interfaces.UseCase) http.HandlerFunc {
http.Error(w, "bad request", http.StatusBadRequest)
return
}
if v, ok := uc.(*usecase.UseCase); ok {
logger.Debug("[tmp] check client: received Azure CloudEvent", "client", v.Clients())
}

if ev.Type == "Microsoft.Storage.BlobCreated" {
if err := uc.HandleAzureCloudEvent(r.Context(), &ev); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion pkg/usecase/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ func (x *UseCase) Route(ctx context.Context, input *model.RouteInput) error {
var output model.RouteOutput

logger := logging.From(ctx)
logger.Debug("Route query", "input", input)
logger.Debug("Route query", "input", input, "clients", x.clients)
logger.Debug("[tmp] client", "clients", x.clients)

if err := x.clients.Query().Query(ctx, "data.route", input, &output); err != nil {
return goerr.Wrap(err, "failed to route query").With("input", input)
}
Expand Down Expand Up @@ -44,6 +46,8 @@ func (x *UseCase) Route(ctx context.Context, input *model.RouteInput) error {
}

func newReaderFromRouteInput(ctx context.Context, clients *adapter.Clients, input *model.RouteInput) (io.ReadCloser, error) {
logging.From(ctx).Info("Create reader from route input", "input", input, "clients", clients)

switch {
case input.AzureBlobStorage != nil:
return clients.AzureBlobStorage().NewReader(ctx,
Expand Down
4 changes: 4 additions & 0 deletions pkg/usecase/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ func New(clients *adapter.Clients) *UseCase {
clients: clients,
}
}

func (x *UseCase) Clients() *adapter.Clients {
return x.clients
}