Skip to content

Commit

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

feat: amend GetFITSAsJPEGHandler() to route middleware.MustHaveAuthentication in @observerly/birpc
  • Loading branch information
michealroberts authored Oct 14, 2024
2 parents 3dc5501 + dad68ee commit 483f29c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion service/storage/jpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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) GetFITSAsJPEGHandler(ctx context.Context, req *connect.Request[pb.GetFITSAsGenericHandlerRequest]) (*connect.Response[pb.GetFITSAsGenericHandlerResponse], error) {
func (s *server) getFITSAsJPEG(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) GetFITSAsJPEGHandler(ctx context.Context, req *connect.Request[
}

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

func (s *server) GetFITSAsJPEGHandler(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.getFITSAsJPEG(ctx, req)
})
}

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

0 comments on commit 483f29c

Please sign in to comment.