flytekit.clients.auth.auth_client
Directory
Classes
Class | Description |
---|---|
AuthorizationClient |
Authorization client that stores the credentials in keyring and uses oauth2 standard flow to retrieve the. |
AuthorizationCode |
None. |
Credentials |
Stores the credentials together. |
EndpointMetadata |
This class can be used to control the rendering of the page on login successful or failure. |
OAuthCallbackHandler |
A simple wrapper around BaseHTTPServer. |
OAuthHTTPServer |
A simple wrapper around the BaseHTTPServer. |
Queue |
Create a queue object with a given maximum size. |
Errors
flytekit.clients.auth.auth_client.AccessTokenNotFoundError
This error is raised with Access token is not found or if Refreshing the token fails
flytekit.clients.auth.auth_client.AuthorizationClient
Authorization client that stores the credentials in keyring and uses oauth2 standard flow to retrieve the credentials. NOTE: This will open an web browser to retrieve the credentials.
def AuthorizationClient(
endpoint: str,
auth_endpoint: str,
token_endpoint: str,
audience: typing.Optional[str],
scopes: typing.Optional[typing.List[str]],
client_id: typing.Optional[str],
redirect_uri: typing.Optional[str],
endpoint_metadata: typing.Optional[EndpointMetadata],
verify: typing.Optional[typing.Union[bool, str]],
session: typing.Optional[requests.Session],
request_auth_code_params: typing.Optional[typing.Dict[str, str]],
request_access_token_params: typing.Optional[typing.Dict[str, str]],
refresh_access_token_params: typing.Optional[typing.Dict[str, str]],
add_request_auth_code_params_to_request_access_token_params: typing.Optional[bool],
):
Create new AuthorizationClient
Parameter | Type |
---|---|
endpoint |
str |
auth_endpoint |
str |
token_endpoint |
str |
audience |
typing.Optional[str] |
scopes |
typing.Optional[typing.List[str]] |
client_id |
typing.Optional[str] |
redirect_uri |
typing.Optional[str] |
endpoint_metadata |
typing.Optional[EndpointMetadata] |
verify |
typing.Optional[typing.Union[bool, str]] |
session |
typing.Optional[requests.Session] |
request_auth_code_params |
typing.Optional[typing.Dict[str, str]] |
request_access_token_params |
typing.Optional[typing.Dict[str, str]] |
refresh_access_token_params |
typing.Optional[typing.Dict[str, str]] |
add_request_auth_code_params_to_request_access_token_params |
typing.Optional[bool] |
Methods
Method | Description |
---|---|
get_creds_from_remote() |
This is the entrypoint method |
refresh_access_token() |
None |
get_creds_from_remote()
def get_creds_from_remote()
This is the entrypoint method. It will kickoff the full authentication flow and trigger a web-browser to retrieve credentials. Because this needs to open a port on localhost and may be called from a multithreaded context (e.g. pyflyte register), this call may block multiple threads and return a cached result for up to 60 seconds.
refresh_access_token()
def refresh_access_token(
credentials: Credentials,
):
Parameter | Type |
---|---|
credentials |
Credentials |
flytekit.clients.auth.auth_client.AuthorizationCode
def AuthorizationCode(
code,
state,
):
Parameter | Type |
---|---|
code |
|
state |
Properties
Property | Type | Description |
---|---|---|
code | ||
state |
flytekit.clients.auth.auth_client.Credentials
Stores the credentials together
def Credentials(
access_token: str,
refresh_token: typing.Optional[str],
for_endpoint: str,
expires_in: typing.Optional[int],
id_token: typing.Optional[str],
):
Parameter | Type |
---|---|
access_token |
str |
refresh_token |
typing.Optional[str] |
for_endpoint |
str |
expires_in |
typing.Optional[int] |
id_token |
typing.Optional[str] |
flytekit.clients.auth.auth_client.EndpointMetadata
This class can be used to control the rendering of the page on login successful or failure
def EndpointMetadata(
endpoint: str,
success_html: typing.Optional[bytes],
failure_html: typing.Optional[bytes],
):
Parameter | Type |
---|---|
endpoint |
str |
success_html |
typing.Optional[bytes] |
failure_html |
typing.Optional[bytes] |
flytekit.clients.auth.auth_client.OAuthCallbackHandler
A simple wrapper around BaseHTTPServer.BaseHTTPRequestHandler that handles a callback URL that accepts an authorization token.
def OAuthCallbackHandler(
request,
client_address,
server,
):
Parameter | Type |
---|---|
request |
|
client_address |
|
server |
Methods
Method | Description |
---|---|
address_string() |
Return the client address |
date_time_string() |
Return the current date and time formatted for a message header |
do_GET() |
None |
end_headers() |
Send the blank line ending the MIME headers |
finish() |
None |
flush_headers() |
None |
handle() |
Handle multiple requests if necessary |
handle_expect_100() |
Decide what to do with an “Expect: 100-continue” header |
handle_login() |
None |
handle_one_request() |
Handle a single HTTP request |
log_date_time_string() |
Return the current time formatted for logging |
log_error() |
Log an error |
log_message() |
Log an arbitrary message |
log_request() |
Log an accepted request |
parse_request() |
Parse a request (internal) |
send_error() |
Send and log an error reply |
send_header() |
Send a MIME header to the headers buffer |
send_response() |
Add the response header to the headers buffer and log the |
send_response_only() |
Send the response header only |
setup() |
None |
version_string() |
Return the server software version string |
address_string()
def address_string()
Return the client address.
date_time_string()
def date_time_string(
timestamp,
):
Return the current date and time formatted for a message header.
Parameter | Type |
---|---|
timestamp |
do_GET()
def do_GET()
end_headers()
def end_headers()
Send the blank line ending the MIME headers.
finish()
def finish()
flush_headers()
def flush_headers()
handle()
def handle()
Handle multiple requests if necessary.
handle_expect_100()
def handle_expect_100()
Decide what to do with an “Expect: 100-continue” header.
If the client is expecting a 100 Continue response, we must respond with either a 100 Continue or a final response before waiting for the request body. The default is to always respond with a 100 Continue. You can behave differently (for example, reject unauthorized requests) by overriding this method.
This method should either return True (possibly after sending a 100 Continue response) or send an error response and return False.
handle_login()
def handle_login(
data: dict,
):
Parameter | Type |
---|---|
data |
dict |
handle_one_request()
def handle_one_request()
Handle a single HTTP request.
You normally don’t need to override this method; see the class doc string for information on how to handle specific HTTP commands such as GET and POST.
log_date_time_string()
def log_date_time_string()
Return the current time formatted for logging.
log_error()
def log_error(
format,
args,
):
Log an error.
This is called when a request cannot be fulfilled. By default it passes the message on to log_message().
Arguments are the same as for log_message().
XXX This should go to the separate error log.
Parameter | Type |
---|---|
format |
|
args |
*args |
log_message()
def log_message(
format,
args,
):
Log an arbitrary message.
This is used by all other logging functions. Override it if you have specific logging wishes.
The first argument, FORMAT, is a format string for the message to be logged. If the format string contains any % escapes requiring parameters, they should be specified as subsequent arguments (it’s just like printf!).
The client ip and current date/time are prefixed to every message.
Unicode control characters are replaced with escaped hex before writing the output to stderr.
Parameter | Type |
---|---|
format |
|
args |
*args |
log_request()
def log_request(
code,
size,
):
Log an accepted request.
This is called by send_response().
Parameter | Type |
---|---|
code |
|
size |
parse_request()
def parse_request()
Parse a request (internal).
The request should be stored in self.raw_requestline; the results are in self.command, self.path, self.request_version and self.headers.
Return True for success, False for failure; on failure, any relevant error response has already been sent back.
send_error()
def send_error(
code,
message,
explain,
):
Send and log an error reply.
Arguments are
- code: an HTTP error code 3 digits
- message: a simple optional 1 line reason phrase. *( HTAB / SP / VCHAR / %x80-FF ) defaults to short entry matching the response code
- explain: a detailed message defaults to the long entry matching the response code.
This sends an error response (so it must be called before any output has been generated), logs the error, and finally sends a piece of HTML explaining the error to the user.
Parameter | Type |
---|---|
code |
|
message |
|
explain |
send_header()
def send_header(
keyword,
value,
):
Send a MIME header to the headers buffer.
Parameter | Type |
---|---|
keyword |
|
value |
send_response()
def send_response(
code,
message,
):
Add the response header to the headers buffer and log the response code.
Also send two standard headers with the server software version and the current date.
Parameter | Type |
---|---|
code |
|
message |
send_response_only()
def send_response_only(
code,
message,
):
Send the response header only.
Parameter | Type |
---|---|
code |
|
message |
setup()
def setup()
version_string()
def version_string()
Return the server software version string.
flytekit.clients.auth.auth_client.OAuthHTTPServer
A simple wrapper around the BaseHTTPServer.HTTPServer implementation that binds an authorization_client for handling authorization code callbacks.
def OAuthHTTPServer(
server_address: typing.Tuple[str, int],
remote_metadata: EndpointMetadata,
request_handler_class: typing.Type[_BaseHTTPServer.BaseHTTPRequestHandler],
bind_and_activate: bool,
redirect_path: str,
queue: Queue,
):
Constructor. May be extended, do not override.
Parameter | Type |
---|---|
server_address |
typing.Tuple[str, int] |
remote_metadata |
EndpointMetadata |
request_handler_class |
typing.Type[_BaseHTTPServer.BaseHTTPRequestHandler] |
bind_and_activate |
bool |
redirect_path |
str |
queue |
Queue |
Methods
Method | Description |
---|---|
close_request() |
Called to clean up an individual request |
fileno() |
Return socket file number |
finish_request() |
Finish one request by instantiating RequestHandlerClass |
get_request() |
Get the request and client address from the socket |
handle_authorization_code() |
None |
handle_error() |
Handle an error gracefully |
handle_request() |
Handle one request, possibly blocking |
handle_timeout() |
Called if no new request arrives within self |
process_request() |
Call finish_request |
serve_forever() |
Handle one request at a time until shutdown |
server_activate() |
Called by constructor to activate the server |
server_bind() |
Override server_bind to store the server name |
server_close() |
Called to clean-up the server |
service_actions() |
Called by the serve_forever() loop |
shutdown() |
Stops the serve_forever loop |
shutdown_request() |
Called to shutdown and close an individual request |
verify_request() |
Verify the request |
close_request()
def close_request(
request,
):
Called to clean up an individual request.
Parameter | Type |
---|---|
request |
fileno()
def fileno()
Return socket file number.
Interface required by selector.
finish_request()
def finish_request(
request,
client_address,
):
Finish one request by instantiating RequestHandlerClass.
Parameter | Type |
---|---|
request |
|
client_address |
get_request()
def get_request()
Get the request and client address from the socket.
May be overridden.
handle_authorization_code()
def handle_authorization_code(
auth_code: str,
):
Parameter | Type |
---|---|
auth_code |
str |
handle_error()
def handle_error(
request,
client_address,
):
Handle an error gracefully. May be overridden.
The default is to print a traceback and continue.
Parameter | Type |
---|---|
request |
|
client_address |
handle_request()
def handle_request(
queue: Queue,
):
Handle one request, possibly blocking.
Respects self.timeout.
Parameter | Type |
---|---|
queue |
Queue |
handle_timeout()
def handle_timeout()
Called if no new request arrives within self.timeout.
Overridden by ForkingMixIn.
process_request()
def process_request(
request,
client_address,
):
Call finish_request.
Overridden by ForkingMixIn and ThreadingMixIn.
Parameter | Type |
---|---|
request |
|
client_address |
serve_forever()
def serve_forever(
poll_interval,
):
Handle one request at a time until shutdown.
Polls for shutdown every poll_interval seconds. Ignores self.timeout. If you need to do periodic tasks, do them in another thread.
Parameter | Type |
---|---|
poll_interval |
server_activate()
def server_activate()
Called by constructor to activate the server.
May be overridden.
server_bind()
def server_bind()
Override server_bind to store the server name.
server_close()
def server_close()
Called to clean-up the server.
May be overridden.
service_actions()
def service_actions()
Called by the serve_forever() loop.
May be overridden by a subclass / Mixin to implement any code that needs to be run during the loop.
shutdown()
def shutdown()
Stops the serve_forever loop.
Blocks until the loop has finished. This must be called while serve_forever() is running in another thread, or it will deadlock.
shutdown_request()
def shutdown_request(
request,
):
Called to shutdown and close an individual request.
Parameter | Type |
---|---|
request |
verify_request()
def verify_request(
request,
client_address,
):
Verify the request. May be overridden.
Return True if we should proceed with this request.
Parameter | Type |
---|---|
request |
|
client_address |
Properties
Property | Type | Description |
---|---|---|
redirect_path | ||
remote_metadata |
flytekit.clients.auth.auth_client.Queue
Create a queue object with a given maximum size.
If maxsize is <= 0, the queue size is infinite.
def Queue(
maxsize,
):
Parameter | Type |
---|---|
maxsize |
Methods
Method | Description |
---|---|
empty() |
Return True if the queue is empty, False otherwise (not reliable!) |
full() |
Return True if the queue is full, False otherwise (not reliable!) |
get() |
Remove and return an item from the queue |
get_nowait() |
Remove and return an item from the queue without blocking |
join() |
Blocks until all items in the Queue have been gotten and processed |
put() |
Put an item into the queue |
put_nowait() |
Put an item into the queue without blocking |
qsize() |
Return the approximate size of the queue (not reliable!) |
task_done() |
Indicate that a formerly enqueued task is complete |
empty()
def empty()
Return True if the queue is empty, False otherwise (not reliable!).
This method is likely to be removed at some point. Use qsize() == 0 as a direct substitute, but be aware that either approach risks a race condition where a queue can grow before the result of empty() or qsize() can be used.
To create code that needs to wait for all queued tasks to be completed, the preferred technique is to use the join() method.
full()
def full()
Return True if the queue is full, False otherwise (not reliable!).
This method is likely to be removed at some point. Use qsize() >= n as a direct substitute, but be aware that either approach risks a race condition where a queue can shrink before the result of full() or qsize() can be used.
get()
def get(
block,
timeout,
):
Remove and return an item from the queue.
If optional args ‘block’ is true and ’timeout’ is None (the default), block if necessary until an item is available. If ’timeout’ is a non-negative number, it blocks at most ’timeout’ seconds and raises the Empty exception if no item was available within that time. Otherwise (‘block’ is false), return an item if one is immediately available, else raise the Empty exception (’timeout’ is ignored in that case).
Parameter | Type |
---|---|
block |
|
timeout |
get_nowait()
def get_nowait()
Remove and return an item from the queue without blocking.
Only get an item if one is immediately available. Otherwise raise the Empty exception.
join()
def join()
Blocks until all items in the Queue have been gotten and processed.
The count of unfinished tasks goes up whenever an item is added to the queue. The count goes down whenever a consumer thread calls task_done() to indicate the item was retrieved and all work on it is complete.
When the count of unfinished tasks drops to zero, join() unblocks.
put()
def put(
item,
block,
timeout,
):
Put an item into the queue.
If optional args ‘block’ is true and ’timeout’ is None (the default), block if necessary until a free slot is available. If ’timeout’ is a non-negative number, it blocks at most ’timeout’ seconds and raises the Full exception if no free slot was available within that time. Otherwise (‘block’ is false), put an item on the queue if a free slot is immediately available, else raise the Full exception (’timeout’ is ignored in that case).
Parameter | Type |
---|---|
item |
|
block |
|
timeout |
put_nowait()
def put_nowait(
item,
):
Put an item into the queue without blocking.
Only enqueue the item if a free slot is immediately available. Otherwise raise the Full exception.
Parameter | Type |
---|---|
item |
qsize()
def qsize()
Return the approximate size of the queue (not reliable!).
task_done()
def task_done()
Indicate that a formerly enqueued task is complete.
Used by Queue consumer threads. For each get() used to fetch a task, a subsequent call to task_done() tells the queue that the processing on the task is complete.
If a join() is currently blocking, it will resume when all items have been processed (meaning that a task_done() call was received for every item that had been put() into the queue).
Raises a ValueError if called more times than there were items placed in the queue.