问题
Is there a way to port the functionality of
from google.appengine.api import app_identity
from google.appengine.api import urlfetch
in the flexible environment?
I have a service running on the flex environment which needs to make a request to the standard environment and would like to use App Engine's native app identity and X-Appengine-Inbound-Appid
header to do so.
It seems that if the origin of the request is from the standard environment, the header is passed on to the flex environment but not the other way around?
回答1:
Update: It is not possible to use the X-Appengine-Inbound-Appid
header in this case because, as you observed, it is removed on the ingress side of the standard env service after being specifically set on the egress side of the flexible env service, following the suggested experiment:
Original post:
From App identity:
When running on the flexible environment, you can use a combination of environment variables and the Google Compute Engine Metadata service to obtain information about your application:
Application / project ID
Either the GCLOUD_PROJECT environment variable or the /project/project-id resource in the metadata server
So you could try to get the app ID in the flex env service as mentioned above and manually set the X-Appengine-Inbound-Appid
response header. It might not be removed on the ingress side of the standard env service (it's not explicitly mentioned to be removed in Request headers).
As for the urlfetch porting, from URL Fetch:
The flexible environment has no sandbox restrictions, so you can use any HTTP library. We recommend using Requests.
So check for the specific method to set the response header for whichever HTTP library you decide to use.
来源:https://stackoverflow.com/questions/46355236/app-engine-flexible-app-identity-python