Skip to content

Commit

Permalink
Backout conversion of public app to swagger because of increased erro…
Browse files Browse the repository at this point in the history
…r rate (#313). r=rail
  • Loading branch information
bhearsum committed May 4, 2017
1 parent 19b506d commit 7beaaf3
Show file tree
Hide file tree
Showing 36 changed files with 381 additions and 1,016 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ include version.txt

recursive-include auslib/migrate *
recursive-include auslib/blobs/schemas *
recursive-include auslib/web *.yml
recursive-include ui/dist *
recursive-exclude * *.py[co]
File renamed without changes.
10 changes: 5 additions & 5 deletions auslib/web/admin/base.py → auslib/admin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
app = Flask(__name__)
sentry = Sentry()

from auslib.web.admin.views.csrf import CSRFView
from auslib.web.admin.views.permissions import UsersView, PermissionsView, \
from auslib.admin.views.csrf import CSRFView
from auslib.admin.views.permissions import UsersView, PermissionsView, \
SpecificPermissionView, UserRolesView, UserRoleView, AllRolesView, \
PermissionScheduledChangesView, PermissionScheduledChangeView, \
EnactPermissionScheduledChangeView, PermissionScheduledChangeHistoryView, \
PermissionScheduledChangeSignoffsView, SpecificUserView
from auslib.web.admin.views.releases import SingleLocaleView, \
from auslib.admin.views.releases import SingleLocaleView, \
SingleReleaseView, ReleaseHistoryView, \
ReleasesAPIView, SingleReleaseColumnView, ReleaseReadOnlyView, \
ReleaseScheduledChangesView, ReleaseScheduledChangeView, \
EnactReleaseScheduledChangeView, ReleaseScheduledChangeHistoryView, \
ReleaseScheduledChangeSignoffsView, ReleaseFieldView, ReleaseDiffView
from auslib.web.admin.views.required_signoffs import ProductRequiredSignoffsView, \
from auslib.admin.views.required_signoffs import ProductRequiredSignoffsView, \
ProductRequiredSignoffsHistoryAPIView, \
ProductRequiredSignoffsScheduledChangesView, \
ProductRequiredSignoffScheduledChangeView, \
Expand All @@ -37,7 +37,7 @@
EnactPermissionsRequiredSignoffScheduledChangeView, \
PermissionsRequiredSignoffScheduledChangeSignoffsView, \
PermissionsRequiredSignoffScheduledChangeHistoryView
from auslib.web.admin.views.rules import RulesAPIView, \
from auslib.admin.views.rules import RulesAPIView, \
SingleRuleView, RuleHistoryAPIView, SingleRuleColumnView, \
RuleScheduledChangesView, RuleScheduledChangeView, \
EnactRuleScheduledChangeView, RuleScheduledChangeHistoryView, \
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from flask import Response
from flask_wtf import Form

from auslib.web.admin.views.base import AdminView
from auslib.admin.views.base import AdminView

__all__ = ["CSRFView"]

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flask import Response, jsonify, request
from sqlalchemy import and_

from auslib.web.admin.views.base import AdminView
from auslib.admin.views.base import AdminView
from auslib.util.timesince import timesince


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from flask import request, Response, jsonify

from auslib.global_state import dbo
from auslib.web.admin.views.base import requirelogin, AdminView
from auslib.web.admin.views.forms import NewPermissionForm, ExistingPermissionForm, DbEditableForm, \
from auslib.admin.views.base import requirelogin, AdminView
from auslib.admin.views.forms import NewPermissionForm, ExistingPermissionForm, DbEditableForm, \
ScheduledChangeNewPermissionForm, ScheduledChangeExistingPermissionForm, \
EditScheduledChangeNewPermissionForm, EditScheduledChangeExistingPermissionForm, \
ScheduledChangeDeletePermissionForm
from auslib.web.admin.views.scheduled_changes import ScheduledChangesView, \
from auslib.admin.views.scheduled_changes import ScheduledChangesView, \
ScheduledChangeView, EnactScheduledChangeView, ScheduledChangeHistoryView,\
SignoffsView

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
from auslib.global_state import dbo
from auslib.blobs.base import createBlob, BlobValidationError
from auslib.db import OutdatedDataError, ReadOnlyError
from auslib.web.admin.views.base import (
from auslib.admin.views.base import (
requirelogin, AdminView
)
from auslib.web.admin.views.csrf import get_csrf_headers
from auslib.web.admin.views.forms import PartialReleaseForm, CompleteReleaseForm, DbEditableForm, ReadOnlyForm, \
from auslib.admin.views.csrf import get_csrf_headers
from auslib.admin.views.forms import PartialReleaseForm, CompleteReleaseForm, DbEditableForm, ReadOnlyForm, \
ScheduledChangeNewReleaseForm, ScheduledChangeExistingReleaseForm, ScheduledChangeDeleteReleaseForm, \
EditScheduledChangeNewReleaseForm, EditScheduledChangeExistingReleaseForm
from auslib.web.admin.views.scheduled_changes import ScheduledChangesView, \
from auslib.admin.views.scheduled_changes import ScheduledChangesView, \
ScheduledChangeView, EnactScheduledChangeView, ScheduledChangeHistoryView, \
SignoffsView
from auslib.web.admin.views.history import HistoryView
from auslib.admin.views.history import HistoryView


__all__ = ["SingleReleaseView", "SingleLocaleView"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from flask import jsonify, Response, request

from auslib.web.admin.views.base import requirelogin, AdminView
from auslib.web.admin.views.forms import ProductRequiredSignoffForm, \
from auslib.admin.views.base import requirelogin, AdminView
from auslib.admin.views.forms import ProductRequiredSignoffForm, \
ProductRequiredSignoffHistoryForm, \
ScheduledChangeExistingProductRequiredSignoffForm, \
ScheduledChangeNewProductRequiredSignoffForm, \
Expand All @@ -19,8 +19,8 @@
ScheduledChangeDeletePermissionsRequiredSignoffForm, \
EditScheduledChangeNewPermissionsRequiredSignoffForm, \
EditScheduledChangeExistingPermissionsRequiredSignoffForm
from auslib.web.admin.views.history import HistoryView
from auslib.web.admin.views.scheduled_changes import ScheduledChangesView, \
from auslib.admin.views.history import HistoryView
from auslib.admin.views.scheduled_changes import ScheduledChangesView, \
ScheduledChangeView, EnactScheduledChangeView, SignoffsView, \
ScheduledChangeHistoryView
from auslib.db import SignoffRequiredError
Expand Down
10 changes: 5 additions & 5 deletions auslib/web/admin/views/rules.py → auslib/admin/views/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
from flask import Response, request, jsonify

from auslib.global_state import dbo
from auslib.web.admin.views.base import (
from auslib.admin.views.base import (
requirelogin, AdminView
)
from auslib.web.admin.views.csrf import get_csrf_headers
from auslib.web.admin.views.forms import EditRuleForm, RuleForm, DbEditableForm, \
from auslib.admin.views.csrf import get_csrf_headers
from auslib.admin.views.forms import EditRuleForm, RuleForm, DbEditableForm, \
ScheduledChangeNewRuleForm, ScheduledChangeExistingRuleForm, \
ScheduledChangeDeleteRuleForm, EditScheduledChangeNewRuleForm, \
EditScheduledChangeExistingRuleForm, EditScheduledChangeDeleteRuleForm
from auslib.web.admin.views.scheduled_changes import ScheduledChangesView, \
from auslib.admin.views.scheduled_changes import ScheduledChangesView, \
ScheduledChangeView, EnactScheduledChangeView, ScheduledChangeHistoryView,\
SignoffsView
from auslib.web.admin.views.history import HistoryView
from auslib.admin.views.history import HistoryView


class RulesAPIView(AdminView):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from flask import jsonify, request, Response
from flask_wtf import Form

from auslib.web.admin.views.base import AdminView, requirelogin
from auslib.web.admin.views.forms import DbEditableForm, SignoffForm
from auslib.web.admin.views.history import HistoryView
from auslib.admin.views.base import AdminView, requirelogin
from auslib.admin.views.forms import DbEditableForm, SignoffForm
from auslib.admin.views.history import HistoryView


class ScheduledChangesView(AdminView):
Expand Down
69 changes: 28 additions & 41 deletions auslib/dockerflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,7 @@
from auslib.global_state import dbo


def _heartbeat_database_fn(dbo):
return dbo.dockerflow.incrementWatchdogValue(changed_by='dockerflow')


def heartbeat_response(heartbeat_database_fn):
"""Per the Dockerflow spec:
Respond to /__heartbeat__ with a HTTP 200 or 5xx on error. This should
depend on services like the database to also ensure they are healthy."""
try:
database_entry_value = heartbeat_database_fn(dbo)
return Response(str(database_entry_value), headers={"Cache-Control": "public, max-age=60"})
except Exception:
return Response(status=502, response="Can't connect to the database.", headers={"Cache-Control": "public, max-age=60"})


def lbheartbeat_response():
"""Per the Dockerflow spec:
Respond to /__lbheartbeat__ with an HTTP 200. This is for load balancer
checks and should not check any dependent services."""
return Response("OK!", headers={"Cache-Control": "no-cache"})


def get_version(version_file):
if version_file and path.exists(version_file):
with open(version_file) as f:
version_json = f.read()
return Response(version_json, mimetype="application/json", headers={"Cache-Control": "no-cache"})
else:
return jsonify({
"source": "https://github.com/mozilla/balrog",
"version": "unknown",
"commit": "unknown",
})


# Keeping flask dockerflow endpoints here to maintain the admin api compatibility.
def create_dockerflow_endpoints(app,
heartbeat_database_fn=_heartbeat_database_fn):
def create_dockerflow_endpoints(app, heartbeat_database_fn=None):
""" Wrapper that creates the endpoints required by CloudOps' Dockerflow spec:
https://github.com/mozilla-services/Dockerflow. This gets used by both the admin and public apps.
:param heartbeat_database_fn: Function that calls the database when reponding to /__heartbeat__.
Expand All @@ -53,15 +16,39 @@ def create_dockerflow_endpoints(app,
allows us to see if the connection to the database exists, is active, and if the credentials given
are the correct ones. For more context see bug 1289178.
"""

if heartbeat_database_fn is None:
def heartbeat_database_fn(dbo):
return dbo.dockerflow.incrementWatchdogValue(changed_by='dockerflow')

@app.route("/__heartbeat__")
def heartbeat():
return heartbeat_response(heartbeat_database_fn)
"""Per the Dockerflow spec:
Respond to /__heartbeat__ with a HTTP 200 or 5xx on error. This should
depend on services like the database to also ensure they are healthy."""
try:
database_entry_value = heartbeat_database_fn(dbo)
return Response(str(database_entry_value), headers={"Cache-Control": "public, max-age=60"})
except Exception:
return Response(status=502, response="Can't connect to the database.", headers={"Cache-Control": "public, max-age=60"})

@app.route("/__lbheartbeat__")
def lbheartbeat():
return lbheartbeat_response()
"""Per the Dockerflow spec:
Respond to /__lbheartbeat__ with an HTTP 200. This is for load balancer
checks and should not check any dependent services."""
return Response("OK!", headers={"Cache-Control": "no-cache"})

@app.route("/__version__")
def version():
version_file = app.config.get("VERSION_FILE")
return get_version(version_file)
if version_file and path.exists(version_file):
with open(app.config["VERSION_FILE"]) as f:
version_json = f.read()
return Response(version_json, mimetype="application/json", headers={"Cache-Control": "no-cache"})
else:
return jsonify({
"source": "https://github.com/mozilla/balrog",
"version": "unknown",
"commit": "unknown",
})
2 changes: 1 addition & 1 deletion auslib/test/admin/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import unittest

from auslib.global_state import dbo, cache
from auslib.web.admin.base import app
from auslib.admin.base import app
from auslib.blobs.base import createBlob


Expand Down
2 changes: 1 addition & 1 deletion auslib/test/admin/views/test_csrf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import flask_wtf.form

from auslib.web.admin.base import app
from auslib.admin.base import app
from auslib.test.admin.views.base import ViewTest


Expand Down
2 changes: 1 addition & 1 deletion auslib/test/blobs/test_apprelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from auslib.global_state import dbo
from auslib.errors import BadDataError
from auslib.web.public.base import app
from auslib.web.base import app
from auslib.blobs.base import BlobValidationError, createBlob
from auslib.blobs.apprelease import ReleaseBlobBase, ReleaseBlobV1, ReleaseBlobV2, \
ReleaseBlobV3, ReleaseBlobV4, ReleaseBlobV5, ReleaseBlobV6, ReleaseBlobV7, DesupportBlob, \
Expand Down

0 comments on commit 7beaaf3

Please sign in to comment.