Skip to content

Commit

Permalink
created decorator function and applied to arrow function for injectin…
Browse files Browse the repository at this point in the history
…g the user detail:wq

Signed-off-by: Abdul Hameed <ahameed@redhat.com>
Signed-off-by: Lokesh Rangineni <19699092+lokeshrangineni@users.noreply.github.com>
  • Loading branch information
redhatHameed authored and lokeshrangineni committed Aug 7, 2024
1 parent 245e68b commit 7b25fda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sdk/python/feast/offline_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from feast.permissions.server.arrow import (
arrowflight_middleware,
inject_user_details,
inject_user_details_decorator,
)
from feast.permissions.server.utils import (
ServerType,
Expand Down Expand Up @@ -57,6 +58,7 @@ def _make_flight_info(self, key: Any, descriptor: fl.FlightDescriptor):

return fl.FlightInfo(schema, descriptor, endpoints, -1, -1)

@inject_user_details_decorator
def get_flight_info(
self, context: fl.ServerCallContext, descriptor: fl.FlightDescriptor
):
Expand All @@ -65,6 +67,7 @@ def get_flight_info(
return self._make_flight_info(key, descriptor)
raise KeyError("Flight not found.")

@inject_user_details_decorator
def list_flights(self, context: fl.ServerCallContext, criteria: bytes):
for key, table in self.flights.items():
if key[1] is not None:
Expand All @@ -76,6 +79,7 @@ def list_flights(self, context: fl.ServerCallContext, criteria: bytes):

# Expects to receive request parameters and stores them in the flights dictionary
# Indexed by the unique command
@inject_user_details_decorator
def do_put(
self,
context: fl.ServerCallContext,
Expand Down Expand Up @@ -172,8 +176,8 @@ def _validate_do_get_parameters(self, command: dict):

# Extracts the API parameters from the flights dictionary, delegates the execution to the FeatureStore instance
# and returns the stream of data
@inject_user_details_decorator
def do_get(self, context: fl.ServerCallContext, ticket: fl.Ticket):
# TODO RBAC: add the same to all the authorized endpoints
inject_user_details(context)

key = ast.literal_eval(ticket.ticket.decode())
Expand Down
10 changes: 10 additions & 0 deletions sdk/python/feast/permissions/server/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import asyncio
import functools
import logging
from typing import Optional, cast

Expand Down Expand Up @@ -99,3 +100,12 @@ def inject_user_details(context: ServerCallContext):
print(f"extracted user: {current_user}")

sm.set_current_user(current_user)


def inject_user_details_decorator(func):
@functools.wraps(func)
def wrapper(self, context, *args, **kwargs):
inject_user_details(context)
return func(self, context, *args, **kwargs)

return wrapper

0 comments on commit 7b25fda

Please sign in to comment.