コード例 #1
0
ファイル: flight.py プロジェクト: timeseer-ai/kukur
 def is_valid(self, token: bytes):
     """Check if the supplied token is valid."""
     if token == "" or token is None:
         raise fl.FlightUnauthenticatedError("invalid token")
     if not self._app.get_api_keys().has_api_key(token.decode("UTF-8")):
         raise fl.FlightUnauthenticatedError("invalid token")
     return token
コード例 #2
0
 def is_valid(self, token):
     logging.info('HttpBasicServerAuthHandler: is_valid()')
     if not token:
         raise flight.FlightUnauthenticatedError("token not provided")
     if token.decode() not in self.creds:
         raise flight.FlightUnauthenticatedError("unknown user")
     return token
コード例 #3
0
 def authenticate(self, outgoing, incoming):
     buf = incoming.read()
     auth = flight.BasicAuth.deserialize(buf)
     if auth.username not in self.creds:
         raise flight.FlightUnauthenticatedError("unknown user")
     if self.creds[auth.username] != auth.password:
         raise flight.FlightUnauthenticatedError("wrong password")
     outgoing.write(tobytes(auth.username))
コード例 #4
0
 def authenticate(self, outgoing, incoming):
     buf = incoming.read()
     auth = flight.BasicAuth.deserialize(buf)
     logging.info('HttpBasicServerAuthHandler: authenticate(). username: {}'.format(auth.username.decode()))
     if auth.username.decode() not in self.creds:
         raise flight.FlightUnauthenticatedError("unknown user")
     if self.creds[auth.username.decode()] != auth.password.decode():
         raise flight.FlightUnauthenticatedError("wrong password")
     outgoing.write(auth.username)
コード例 #5
0
 def is_valid(self, token):
     if not token:
         raise flight.FlightUnauthenticatedError("token not provided")
     token = base64.b64decode(token)
     username, password = token.split(b':')
     if username not in self.creds:
         raise flight.FlightUnauthenticatedError("unknown user")
     if self.creds[username] != password:
         raise flight.FlightUnauthenticatedError("wrong password")
     return username
コード例 #6
0
 def authenticate(self, outgoing, incoming):
     buf = incoming.read()
     auth = flight.BasicAuth.deserialize(buf)
     logger.info('basic authentication',
                 extra={'username': auth.username.decode()})
     if auth.username.decode() not in self.creds:
         raise flight.FlightUnauthenticatedError("unknown user")
     if self.creds[auth.username.decode()] != auth.password.decode():
         raise flight.FlightUnauthenticatedError("wrong password")
     outgoing.write(auth.username)
コード例 #7
0
ファイル: flight.py プロジェクト: timeseer-ai/kukur
 def authenticate(self, outgoing, incoming):
     """Check the authentication."""
     buf = incoming.read()
     auth = fl.BasicAuth.deserialize(buf)
     if auth.username is None:
         raise fl.FlightUnauthenticatedError("invalid username")
     if auth.password is None:
         raise fl.FlightUnauthenticatedError("invalid password")
     if not self._app.get_api_keys().is_valid(
             auth.username.decode("UTF-8"), auth.password.decode("UTF-8")):
         raise fl.FlightUnauthenticatedError("invalid token")
     outgoing.write(auth.username)
コード例 #8
0
    def start_call(self, info, headers):
        if info.method == flight.FlightMethod.LIST_ACTIONS:
            # No auth needed
            return

        token = headers.get("x-auth-token")
        if not token:
            raise flight.FlightUnauthenticatedError("No token")

        token = token[0]
        if token != "password":
            raise flight.FlightUnauthenticatedError("Invalid token")

        return HeaderServerMiddleware(token)
コード例 #9
0
 def authenticate(self, outgoing, incoming):
     username = incoming.read()
     password = incoming.read()
     if username in self.creds and self.creds[username] == password:
         outgoing.write(base64.b64encode(b'secret:' + username))
     else:
         raise flight.FlightUnauthenticatedError(
             "invalid username/password")
コード例 #10
0
 def do_action(self, context, action):
     if action.type == "internal":
         raise flight.FlightInternalError("foo")
     elif action.type == "timedout":
         raise flight.FlightTimedOutError("foo")
     elif action.type == "cancel":
         raise flight.FlightCancelledError("foo")
     elif action.type == "unauthenticated":
         raise flight.FlightUnauthenticatedError("foo")
     elif action.type == "unauthorized":
         raise flight.FlightUnauthorizedError("foo")
     raise NotImplementedError
コード例 #11
0
 def do_action(self, context, action):
     if action.type == "internal":
         raise flight.FlightInternalError("foo")
     elif action.type == "timedout":
         raise flight.FlightTimedOutError("foo")
     elif action.type == "cancel":
         raise flight.FlightCancelledError("foo")
     elif action.type == "unauthenticated":
         raise flight.FlightUnauthenticatedError("foo")
     elif action.type == "unauthorized":
         raise flight.FlightUnauthorizedError("foo")
     elif action.type == "protobuf":
         err_msg = b'this is an error message'
         raise flight.FlightUnauthorizedError("foo", err_msg)
     raise NotImplementedError
コード例 #12
0
 def is_valid(self, token):
     token = base64.b64decode(token)
     if not token.startswith(b'secret:'):
         raise flight.FlightUnauthenticatedError("invalid token")
     return token[7:]
コード例 #13
0
 def is_valid(self, token):
     if not token:
         raise flight.FlightUnauthenticatedError("token not provided")
     if token not in self.creds:
         raise flight.FlightUnauthenticatedError("unknown user")
     return token