From a197068d474b5277cab122b22e5dd96c4d475363 Mon Sep 17 00:00:00 2001 From: michealroberts Date: Mon, 14 Oct 2024 19:27:24 +0100 Subject: [PATCH] feat: amend GetFITSAsTIFFHandler() to route middleware.MustHaveAuthentication in @observerly/birpc feat: amend GetFITSAsTIFFHandler() to route middleware.MustHaveAuthentication in @observerly/birpc --- service/storage/tiff.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/service/storage/tiff.go b/service/storage/tiff.go index 3fc878c..1b13457 100644 --- a/service/storage/tiff.go +++ b/service/storage/tiff.go @@ -18,6 +18,7 @@ import ( "time" pb "birpc/internal/gen/store/v1" + "birpc/internal/middleware" "birpc/internal/stores" cloud "cloud.google.com/go/storage" @@ -29,7 +30,7 @@ import ( /*****************************************************************************************************************/ -func (s *server) GetFITSAsTIFFHandler(ctx context.Context, req *connect.Request[pb.GetFITSAsGenericHandlerRequest]) (*connect.Response[pb.GetFITSAsGenericHandlerResponse], error) { +func (s *server) getFITSAsTIFF(ctx context.Context, req *connect.Request[pb.GetFITSAsGenericHandlerRequest]) (*connect.Response[pb.GetFITSAsGenericHandlerResponse], error) { now := time.Now() s.Logger = log.With().Str("owner", req.Msg.Owner).Str("bucket", req.Msg.BucketName).Str("location", req.Msg.Location).Str("rfc3339", now.Format(time.RFC3339)).Logger() @@ -142,3 +143,18 @@ func (s *server) GetFITSAsTIFFHandler(ctx context.Context, req *connect.Request[ } /*****************************************************************************************************************/ + +func (s *server) GetFITSAsTIFFHandler(ctx context.Context, req *connect.Request[pb.GetFITSAsGenericHandlerRequest]) (*connect.Response[pb.GetFITSAsGenericHandlerResponse], error) { + auth, err := s.App.Auth(ctx) + + if err != nil { + s.Logger.Error().Err(err).Msg("Failed to authenticate user") + return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("failed to authenticate user: %w", err)) + } + + return middleware.MustHaveAuthentication(ctx, req, auth, func() (*connect.Response[pb.GetFITSAsGenericHandlerResponse], error) { + return s.getFITSAsTIFF(ctx, req) + }) +} + +/*****************************************************************************************************************/