Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New model definitions for version 2 API #64

Merged
merged 30 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d070f9c
Switch to absolute imports
jonathansick Oct 5, 2020
263e7c4
Add Organization model
jonathansick Oct 5, 2020
7c37101
Add Tag and ProductTags models
jonathansick Oct 5, 2020
51549f1
Fix use of datetime.now default
jonathansick Oct 16, 2020
5f61bde
Add DashboardTemplate model
jonathansick Oct 16, 2020
58e91bf
Add relationship from Product to Organization
jonathansick Oct 16, 2020
c2d9774
Add Build.git_ref column
jonathansick Oct 16, 2020
06b9dc6
Add Build.uploaded_by relationship
jonathansick Oct 16, 2020
90e465b
Add Edition.kind column
jonathansick Oct 16, 2020
21184b8
Use UniqueConstraint from flask-sqlalchemy
jonathansick Oct 16, 2020
01f068a
Fixup Organization constraint
jonathansick Oct 19, 2020
2e1c39a
Adjust mutual relationship
jonathansick Oct 22, 2020
c8a490e
Simplify DashboardTemplate Organization relation
jonathansick Oct 22, 2020
4da2cc7
Change Tag unique constraints to __table_args__
jonathansick Jun 27, 2021
f736f8f
Add Organization Fastly service ID and key
jonathansick Jun 27, 2021
ef54fa5
Fix relationship between between DT and org
jonathansick Jun 27, 2021
94cddb3
Use IntEnum to store enums as ints in DB
jonathansick Jul 5, 2021
2648dbb
Fix EditionKind.minor enum type
jonathansick Jul 5, 2021
4860a17
Update make worker to connect to pg by default
jonathansick Jul 6, 2021
9d4830b
Make Edition.kind nullable
jonathansick Jul 6, 2021
8f323c5
Add Config.DEFAULT_EDITION_KIND
jonathansick Jul 6, 2021
98ce3a8
Switch OrganizationLayoutModel to IntEnum too
jonathansick Jul 6, 2021
14d99c3
Add migration for version 2 tables
jonathansick Jul 6, 2021
71ecee5
Run postgres in tox on port 3309
jonathansick Jul 6, 2021
d35057a
Make Edition.kind non-nullable
jonathansick Jul 10, 2021
bea7d9c
Make Product.organization_id non-nullable
jonathansick Jul 10, 2021
75dcd6d
Make v1 API for POST /products/ use default org
jonathansick Jul 12, 2021
6fd401d
Create default org to tests of the v1 API
jonathansick Jul 12, 2021
96e7f83
Include event string with error log messages
jonathansick Jul 12, 2021
b92770f
Fix IntEnum binding
jonathansick Jul 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ redis:

.PHONY: worker
worker:
celery -A keeper.celery.celery_app worker -E -l DEBUG
FLASK_APP=keeper LTD_KEEPER_PROFILE=development LTD_KEEPER_DEV_DB_URL="postgresql+psycopg2://user:password@localhost:3308/db" celery -A keeper.celery.celery_app worker -E -l DEBUG

.PHONY: flower
flower:
Expand Down
8 changes: 4 additions & 4 deletions keeper/api/errorhandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
def bad_request(e: Exception) -> Response:
"""Handler for ValidationError exceptions."""
logger = structlog.get_logger()
logger.error(status=400, message=e.args[0])
logger.error("bad request", status=400, message=e.args[0])

response = jsonify(
{"status": 400, "error": "bad request", "message": e.args[0]}
Expand All @@ -43,7 +43,7 @@ def bad_request(e: Exception) -> Response:
def not_found(e: Exception) -> Response:
"""App-wide handler for HTTP 404 errors."""
logger = structlog.get_logger()
logger.error(status=400)
logger.error("not found", status=400)

response = jsonify(
{
Expand All @@ -60,7 +60,7 @@ def not_found(e: Exception) -> Response:
def method_not_supported(e: Exception) -> Response:
"""Handler for HTTP 405 exceptions."""
logger = structlog.get_logger()
logger.error(status=405)
logger.error("method not support", status=405)

response = jsonify(
{
Expand All @@ -77,7 +77,7 @@ def method_not_supported(e: Exception) -> Response:
def internal_server_error(e: Exception) -> Response:
"""App-wide handler for HTTP 500 errors."""
logger = structlog.get_logger()
logger.error(status=500, message=e.args[0])
logger.error("internal server error", status=500, message=e.args[0])

response = jsonify(
{"status": 500, "error": "internal server error", "message": e.args[0]}
Expand Down
5 changes: 4 additions & 1 deletion keeper/api/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from keeper.api import api
from keeper.auth import permission_required, token_auth
from keeper.logutils import log_route
from keeper.models import Edition, Permission, Product, db
from keeper.models import Edition, Organization, Permission, Product, db
from keeper.taskrunner import (
append_task_to_chain,
insert_task_url_in_response,
Expand Down Expand Up @@ -216,8 +216,11 @@ def new_product() -> Tuple[str, int, Dict[str, str]]:
"""
product = Product()
try:
# Get default organization (v1 API adapter for organizations)
org = Organization.query.order_by(Organization.id).first_or_404()
request_json = request.json
product.import_data(request_json)
product.organization = org
db.session.add(product)
db.session.flush() # Because Edition._validate_slug does not autoflush

Expand Down
3 changes: 3 additions & 0 deletions keeper/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import structlog

from keeper.models import EditionKind

if TYPE_CHECKING:
from flask import Flask

Expand Down Expand Up @@ -42,6 +44,7 @@ class Config(abc.ABC):
CELERY_RESULT_URL: str = os.getenv("REDIS_URL", "redis://localhost:6379")
CELERY_BROKER_URL: str = os.getenv("REDIS_URL", "redis://localhost:6379")
LTD_EVENTS_URL: Optional[str] = os.getenv("LTD_EVENTS_URL", None)
DEFAULT_EDITION_KIND: EditionKind = EditionKind.draft

# Suppresses a warning until Flask-SQLAlchemy 3
# See http://stackoverflow.com/a/33790196
Expand Down
Loading