python - 如何将烧瓶应用程序转换为谷歌云功能
问题描述
我想将我的烧瓶应用程序转换为谷歌云功能。函数是无状态的,我不知道该怎么做。我已经简化了我的应用程序,因此如果有人可以帮助我将其简单地转换为纯 python,以便我可以将其部署为谷歌云功能。
OAUTH = OAuth(APP)
MSGRAPH = OAUTH.remote_app(
'microsoft', consumer_key=config.CLIENT_ID, consumer_secret=config.CLIENT_SECRET,
request_token_params={'scope': config.SCOPES},
base_url=config.RESOURCE + config.API_VERSION + '/',
request_token_url=None, access_token_method='POST',
access_token_url=config.AUTHORITY_URL + config.TOKEN_ENDPOINT,
authorize_url=config.AUTHORITY_URL + config.AUTH_ENDPOINT)
@APP.route('/login')
def login():
"""Prompt user to authenticate."""
flask.session['state'] = str(uuid.uuid4())
return MSGRAPH.authorize(callback=config.REDIRECT_URI, state=flask.session['state'])
@APP.route('/login/authorized')
def authorized():
"""Handler for the application's Redirect Uri."""
if str(flask.session['state']) != str(flask.request.args['state']):
raise Exception('state returned to redirect URL does not match!')
response = MSGRAPH.authorized_response()
flask.session['access_token'] = response['access_token']
return return "200"
@MSGRAPH.tokengetter
def get_token():
"""Called by flask_oauthlib.client to retrieve current access token."""
return (flask.session.get('access_token'), '')
解决方案
此应用程序无法很好地转换为 Cloud Functions:您在每个路由之间共享会话状态,而 Cloud Functions 是无状态的。
根据您存储此状态的方式(即,如果它不只是在内存中),您最好将应用程序部署到Cloud Run。
推荐阅读
- java - 膨胀类 com.google.android.youtube.player.YouTubeThumbnailView 时出错
- javascript - Django JsonResponse 使用 JavaScript 在模板中显示而不刷新页面
- gitlab - Gitlab 跑步者不会杀死取消的工作
- java - 带有 OrderBy 和 MaxResult 的 CriteriaQuery 仅返回非 NULL 行
- java - 扩展生成器类
- java - 通过 Java 访问 Windows 文件属性详细信息,例如作者?
- xml - 如何使用 XSLT 将元素添加为属性
- qt - 如何访问随机中继器孩子的属性?
- javascript - javascript中的日期比较不起作用
- sql - 如果在表中找不到数据,则打印一条消息