| 40 | |
| 41 | |
| 42 | class OfflineServer(fl.FlightServerBase): |
| 43 | def __init__( |
| 44 | self, |
| 45 | store: FeatureStore, |
| 46 | location: str, |
| 47 | host: str = "localhost", |
| 48 | tls_certificates: List = [], |
| 49 | **kwargs, |
| 50 | ): |
| 51 | super(OfflineServer, self).__init__( |
| 52 | location=location, |
| 53 | middleware=self.arrow_flight_auth_middleware( |
| 54 | str_to_auth_manager_type(store.config.auth_config.type) |
| 55 | ), |
| 56 | tls_certificates=tls_certificates, |
| 57 | verify_client=False, # this is needed for when we don't need mTLS |
| 58 | **kwargs, |
| 59 | ) |
| 60 | self._location = location |
| 61 | # A dictionary of configured flights, e.g. API calls received and not yet served |
| 62 | self.flights: Dict[str, Any] = {} |
| 63 | self.store = store |
| 64 | self.offline_store = get_offline_store_from_config(store.config.offline_store) |
| 65 | self.host = host |
| 66 | self.tls_certificates = tls_certificates |
| 67 | |
| 68 | def arrow_flight_auth_middleware( |
| 69 | self, |
| 70 | auth_type: AuthManagerType, |
| 71 | ) -> dict[str, fl.ServerMiddlewareFactory]: |
| 72 | """ |
| 73 | A dictionary with the configured middlewares to support extracting the user details when the authorization manager is defined. |
| 74 | The authorization middleware key is `auth`. |
| 75 | |
| 76 | Returns: |
| 77 | dict[str, fl.ServerMiddlewareFactory]: Optional dictionary of middlewares. If the authorization type is set to `NONE`, it returns an empty dict. |
| 78 | """ |
| 79 | |
| 80 | if auth_type == AuthManagerType.NONE: |
| 81 | return {} |
| 82 | |
| 83 | return { |
| 84 | "auth": AuthorizationMiddlewareFactory(), |
| 85 | } |
| 86 | |
| 87 | @classmethod |
| 88 | def descriptor_to_key(self, descriptor: fl.FlightDescriptor): |
| 89 | return ( |
| 90 | descriptor.descriptor_type.value, |
| 91 | descriptor.command, |
| 92 | tuple(descriptor.path or tuple()), |
| 93 | ) |
| 94 | |
| 95 | def _make_flight_info(self, key: Any, descriptor: fl.FlightDescriptor): |
| 96 | if len(self.tls_certificates) != 0: |
| 97 | location = fl.Location.for_grpc_tls(self.host, self.port) |
| 98 | else: |
| 99 | location = fl.Location.for_grpc_tcp(self.host, self.port) |
no outgoing calls