2021-09-23 23:01:43 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright 2021 Google Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License")
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2021-08-18 01:35:08 +03:00
|
|
|
from flask import Flask
|
|
|
|
import logging
|
|
|
|
|
2021-09-23 23:01:43 +03:00
|
|
|
from api import accounts_api
|
|
|
|
from api import approvals_api
|
|
|
|
from api import channels_api
|
|
|
|
from api import comments_api
|
|
|
|
from api import cues_api
|
|
|
|
from api import features_api
|
2022-06-25 02:34:24 +03:00
|
|
|
from api import fielddefs_api
|
2021-09-23 23:01:43 +03:00
|
|
|
from api import login_api
|
|
|
|
from api import logout_api
|
|
|
|
from api import metricsdata
|
2022-06-25 17:54:02 +03:00
|
|
|
from api import permissions_api
|
2022-06-25 02:34:24 +03:00
|
|
|
from api import processes_api
|
2021-09-23 23:01:43 +03:00
|
|
|
from api import stars_api
|
|
|
|
from api import token_refresh_api
|
|
|
|
from framework import basehandlers
|
|
|
|
from framework import csp
|
2022-06-11 00:56:40 +03:00
|
|
|
from framework import sendemail
|
2021-09-29 00:57:37 +03:00
|
|
|
from internals import detect_intent
|
2021-09-23 23:01:43 +03:00
|
|
|
from internals import fetchmetrics
|
2021-09-25 01:19:17 +03:00
|
|
|
from internals import notifier
|
2021-09-23 23:01:43 +03:00
|
|
|
from pages import blink_handler
|
|
|
|
from pages import featuredetail
|
|
|
|
from pages import featurelist
|
2022-04-08 03:40:39 +03:00
|
|
|
from pages import newfeaturelist
|
2021-09-23 23:01:43 +03:00
|
|
|
from pages import guide
|
|
|
|
from pages import intentpreview
|
|
|
|
from pages import metrics
|
|
|
|
from pages import myfeatures
|
|
|
|
from pages import roadmap
|
|
|
|
from pages import users
|
|
|
|
import settings
|
|
|
|
|
2021-10-06 01:15:47 +03:00
|
|
|
# Sets up Cloud Logging client library.
|
|
|
|
if not settings.UNIT_TEST_MODE and not settings.DEV_MODE:
|
|
|
|
import google.cloud.logging
|
|
|
|
client = google.cloud.logging.Client()
|
|
|
|
client.get_default_handler()
|
|
|
|
client.setup_logging()
|
2021-08-18 01:35:08 +03:00
|
|
|
|
2021-10-07 22:48:30 +03:00
|
|
|
# Sets up Cloud Debugger client library.
|
|
|
|
if not settings.UNIT_TEST_MODE and not settings.DEV_MODE:
|
|
|
|
try:
|
|
|
|
import googleclouddebugger
|
|
|
|
googleclouddebugger.enable(breakpoint_enable_canary=False)
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2021-10-20 02:56:37 +03:00
|
|
|
# Note: In the URLs below, parameters like <int:feature_id> are
|
|
|
|
# required for the URL to match the route, but we still accecpt
|
|
|
|
# those parameters as keywords in those handlers where the same
|
|
|
|
# handler might be used for multiple routes that have the field
|
|
|
|
# or not.
|
|
|
|
|
|
|
|
|
2021-09-23 23:01:43 +03:00
|
|
|
metrics_chart_routes = [
|
|
|
|
('/data/timeline/cssanimated', metricsdata.AnimatedTimelineHandler),
|
|
|
|
('/data/timeline/csspopularity', metricsdata.PopularityTimelineHandler),
|
|
|
|
('/data/timeline/featurepopularity',
|
|
|
|
metricsdata.FeatureObserverTimelineHandler),
|
|
|
|
('/data/csspopularity', metricsdata.CSSPopularityHandler),
|
|
|
|
('/data/cssanimated', metricsdata.CSSAnimatedHandler),
|
|
|
|
('/data/featurepopularity', metricsdata.FeatureObserverPopularityHandler),
|
|
|
|
('/data/blink/<string:prop_type>', metricsdata.FeatureBucketsHandler),
|
|
|
|
]
|
|
|
|
|
|
|
|
# TODO(jrobbins): Advance this to v1 once we have it fleshed out
|
|
|
|
API_BASE = '/api/v0'
|
|
|
|
api_routes = [
|
|
|
|
(API_BASE + '/features', features_api.FeaturesAPI),
|
|
|
|
(API_BASE + '/features/<int:feature_id>', features_api.FeaturesAPI),
|
2021-10-20 02:56:37 +03:00
|
|
|
(API_BASE + '/features/<int:feature_id>/approvals',
|
|
|
|
approvals_api.ApprovalsAPI),
|
2021-09-23 23:01:43 +03:00
|
|
|
(API_BASE + '/features/<int:feature_id>/approvals/<int:field_id>',
|
|
|
|
approvals_api.ApprovalsAPI),
|
2021-12-02 00:40:00 +03:00
|
|
|
(API_BASE + '/features/<int:feature_id>/configs',
|
|
|
|
approvals_api.ApprovalConfigsAPI),
|
2021-10-20 02:56:37 +03:00
|
|
|
(API_BASE + '/features/<int:feature_id>/approvals/comments',
|
|
|
|
comments_api.CommentsAPI),
|
2021-09-23 23:01:43 +03:00
|
|
|
(API_BASE + '/features/<int:feature_id>/approvals/<int:field_id>/comments',
|
|
|
|
comments_api.CommentsAPI),
|
2022-06-25 02:34:24 +03:00
|
|
|
(API_BASE + '/features/<int:feature_id>/process', processes_api.ProcessesAPI),
|
|
|
|
|
|
|
|
(API_BASE + '/fielddefs', fielddefs_api.FieldDefsAPI),
|
2021-09-23 23:01:43 +03:00
|
|
|
|
|
|
|
(API_BASE + '/login', login_api.LoginAPI),
|
|
|
|
(API_BASE + '/logout', logout_api.LogoutAPI),
|
2022-06-25 17:54:02 +03:00
|
|
|
(API_BASE + '/currentuser/permissions', permissions_api.PermissionsAPI),
|
2021-09-23 23:01:43 +03:00
|
|
|
(API_BASE + '/currentuser/stars', stars_api.StarsAPI),
|
|
|
|
(API_BASE + '/currentuser/cues', cues_api.CuesAPI),
|
|
|
|
(API_BASE + '/currentuser/token', token_refresh_api.TokenRefreshAPI),
|
|
|
|
# (API_BASE + '/currentuser/autosaves', TODO),
|
|
|
|
# (API_BASE + '/currentuser/settings', TODO),
|
|
|
|
|
|
|
|
# Admin operations for user accounts
|
|
|
|
(API_BASE + '/accounts', accounts_api.AccountsAPI),
|
|
|
|
(API_BASE + '/accounts/<int:account_id>', accounts_api.AccountsAPI),
|
|
|
|
|
|
|
|
(API_BASE + '/channels', channels_api.ChannelsAPI), # omaha data
|
|
|
|
# (API_BASE + '/schedule', TODO), # chromiumdash data
|
|
|
|
# (API_BASE + '/metrics/<str:kind>', TODO), # uma-export data
|
|
|
|
# (API_BASE + '/metrics/<str:kind>/<int:bucket_id>', TODO),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
page_routes = [
|
|
|
|
('/admin/subscribers', blink_handler.SubscribersHandler),
|
|
|
|
('/admin/blink', blink_handler.BlinkHandler),
|
|
|
|
|
|
|
|
('/feature/<int:feature_id>', featuredetail.FeatureDetailHandler),
|
|
|
|
|
|
|
|
# Note: The only requests being made now hit /features.json and
|
|
|
|
# /features_v2.json, but both of those cause version == 2.
|
|
|
|
# There was logic to accept another version value, but it it was not used.
|
|
|
|
(r'/features.json', featurelist.FeaturesJsonHandler),
|
|
|
|
(r'/features_v2.json', featurelist.FeaturesJsonHandler),
|
|
|
|
|
|
|
|
('/', basehandlers.Redirector,
|
|
|
|
{'location': '/features'}),
|
|
|
|
|
2022-04-08 03:40:39 +03:00
|
|
|
('/newfeatures', newfeaturelist.NewFeatureListHandler),
|
2021-09-23 23:01:43 +03:00
|
|
|
('/features', featurelist.FeatureListHandler),
|
|
|
|
('/features/<int:feature_id>', featurelist.FeatureListHandler),
|
|
|
|
('/features.xml', featurelist.FeatureListXMLHandler),
|
|
|
|
|
|
|
|
('/guide/new', guide.FeatureNew),
|
|
|
|
('/guide/edit/<int:feature_id>', guide.ProcessOverview),
|
|
|
|
('/guide/stage/<int:feature_id>/<int:stage_id>', guide.FeatureEditStage),
|
|
|
|
('/guide/editall/<int:feature_id>', guide.FeatureEditAllFields),
|
|
|
|
|
|
|
|
('/admin/features/launch/<int:feature_id>',
|
|
|
|
intentpreview.IntentEmailPreviewHandler),
|
|
|
|
('/admin/features/launch/<int:feature_id>/<int:stage_id>',
|
|
|
|
intentpreview.IntentEmailPreviewHandler),
|
|
|
|
|
|
|
|
('/metrics', basehandlers.Redirector,
|
|
|
|
{'location': '/metrics/css/popularity'}),
|
|
|
|
('/metrics/css', basehandlers.Redirector,
|
|
|
|
{'location': '/metrics/css/popularity'}),
|
|
|
|
|
|
|
|
# TODO(jrobbins): These seem like they belong in metrics.py.
|
|
|
|
('/metrics/css/popularity', basehandlers.ConstHandler,
|
|
|
|
{'template_path': 'metrics/css/popularity.html'}),
|
|
|
|
('/metrics/css/animated', basehandlers.ConstHandler,
|
|
|
|
{'template_path': 'metrics/css/animated.html'}),
|
|
|
|
('/metrics/css/timeline/popularity', metrics.CssPopularityHandler),
|
|
|
|
('/metrics/css/timeline/popularity/<int:bucket_id>',
|
|
|
|
metrics.CssPopularityHandler),
|
|
|
|
('/metrics/css/timeline/animated', metrics.CssAnimatedHandler),
|
|
|
|
('/metrics/css/timeline/animated/<int:bucket_id>',
|
|
|
|
metrics.CssAnimatedHandler),
|
|
|
|
('/metrics/feature/popularity', basehandlers.ConstHandler,
|
|
|
|
{'template_path': 'metrics/feature/popularity.html'}),
|
|
|
|
('/metrics/feature/timeline/popularity', metrics.FeaturePopularityHandler),
|
|
|
|
('/metrics/feature/timeline/popularity/<int:bucket_id>',
|
|
|
|
metrics.FeaturePopularityHandler),
|
|
|
|
('/omaha_data', metrics.OmahaDataHandler),
|
|
|
|
|
|
|
|
('/myfeatures', myfeatures.MyFeaturesHandler),
|
|
|
|
|
|
|
|
('/roadmap', roadmap.RoadmapHandler),
|
|
|
|
|
|
|
|
('/settings', users.SettingsHandler),
|
|
|
|
('/admin/users/new', users.UserListHandler),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
internals_routes = [
|
|
|
|
('/cron/metrics', fetchmetrics.YesterdayHandler),
|
|
|
|
('/cron/histograms', fetchmetrics.HistogramsHandler),
|
|
|
|
('/cron/update_blink_components', fetchmetrics.BlinkComponentHandler),
|
2021-09-25 01:19:17 +03:00
|
|
|
|
|
|
|
('/tasks/email-subscribers', notifier.FeatureChangeHandler),
|
2021-09-29 00:57:37 +03:00
|
|
|
|
|
|
|
('/tasks/detect-intent', detect_intent.IntentEmailHandler),
|
2021-09-23 23:01:43 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
# All requests to the app-py3 GAE service are handled by this Flask app.
|
|
|
|
app = basehandlers.FlaskApplication(
|
2022-02-16 00:31:27 +03:00
|
|
|
__name__,
|
2021-09-23 23:01:43 +03:00
|
|
|
(metrics_chart_routes + api_routes + page_routes +
|
2022-01-25 22:11:39 +03:00
|
|
|
internals_routes))
|
2021-09-23 23:01:43 +03:00
|
|
|
|
|
|
|
# TODO(jrobbins): Make the CSP handler be a class like our others.
|
|
|
|
app.add_url_rule(
|
|
|
|
'/csp', view_func=csp.report_handler,
|
|
|
|
methods=['POST'])
|
2021-08-18 01:35:08 +03:00
|
|
|
|
2022-06-11 00:56:40 +03:00
|
|
|
sendemail.add_routes(app)
|
2021-08-18 01:35:08 +03:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# This is used when running locally only. When deploying to Google App
|
|
|
|
# Engine, a webserver process such as Gunicorn will serve the app. This
|
|
|
|
# can be configured by adding an `entrypoint` to app.yaml.
|
2022-01-25 22:11:39 +03:00
|
|
|
app.run(host='127.0.0.1', port=8080)
|