Skip to content

Commit

Permalink
Merge pull request #44 from observerly/feature/service/storage/GetFIT…
Browse files Browse the repository at this point in the history
…SAsTIFFHandler

feat: amend GetFITSAsTIFFHandler() to route middleware.MustHaveAuthentication in @observerly/birpc
  • Loading branch information
michealroberts authored Oct 14, 2024
2 parents ccbdb17 + a197068 commit 3dc5501
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion service/storage/tiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"time"

pb "birpc/internal/gen/store/v1"
"birpc/internal/middleware"
"birpc/internal/stores"

cloud "cloud.google.com/go/storage"
Expand All @@ -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()
Expand Down Expand Up @@ -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)
})
}

/*****************************************************************************************************************/

0 comments on commit 3dc5501

Please sign in to comment.