Reputation: 1
I'm currently developing a Python interface for Keystone to manage users credentials, tokens, and other related functionalities. This involves interacting with Keystone's APIs to perform operations such as credentials creation, deletion, and token management.
As I delve into the keystone community codebase, I've noticed that the provided APIs utilize Flask for request handling. While I'm very new to Flask, my understanding thus far is that Flask avoids passing the request explicitly as a parameter to the API functions. Instead, it maintains the request within the worker's environment, making it accessible to each thread that handles a request.
However, I'm facing some confusion regarding how to properly prepare the request before invoking the Keystone API. I'm unsure how to ensure that the request contains all the necessary arguments for the Keystone API to process it effectively.
For example: Here, you can find the keystone community code for 'credentials' api: ""https://opendev.org/openstack/keystone/src/branch/master/keystone/api/credentials.py"" Let's say I need to implement an interface for creating a new credential. This is handled in CredentialResource.post(..) withing this file. However, in the implementation of this API, it gets the arguments from a Flask request.
credential = self.request_body_json.get('credential', {})
This calls (as you can see in this file https://opendev.org/openstack/keystone/src/commit/8c2d5769a16c1cb041701c73efa661b3cbeef482/keystone/server/flask/common.py):
@property
def request_body_json(self):
return flask.request.get_json(silent=True, force=True) or {}
So it seems that as a client, you'll need to ensure that the request context is appropriately prepared before invoking the API. This entails setting up the necessary parameters and data within the request context to facilitate processing by the API. A pseudo code for my interface would be:
from keystone.api import credentials
class KeystoneInterface():
def __init__(self):
self.cred_res = credentials.CredentialResource()
def create_ec2credentials(self, credential):
# Here I need to prepare a request context with 'credential' argument
# Then return the result
return self.cred_res.post()
How can I do that from my code?
I've read about creating a request using app.test_request_context, something like:
ctx = app.test_request_context(...)
ctx.push()
# Call the keystone api
ctx.pop()
However, this is mostly used in testing and would not be useful for my actual request.
What I need to do is something like '''GET /credentials/{credential_id}'''. But how can I do that in python?
Upvotes: 0
Views: 31