Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 56b6990

Browse files
author
Olivier Gambier
committed
Re-express CORS as extra
Docker-DCO-1.1-Signed-off-by: Olivier Gambier <[email protected]> (github: dmp42)
1 parent f7c23c4 commit 56b6990

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ add ./config/boto.cfg /etc/boto.cfg
2525
run pip install /docker-registry/depends/docker-registry-core
2626

2727
# Install registry
28-
run pip install file:///docker-registry#egg=docker-registry[bugsnag,newrelic]
28+
run pip install file:///docker-registry#egg=docker-registry[bugsnag,newrelic,cors]
2929

3030
env DOCKER_REGISTRY_CONFIG /docker-registry/config/config_sample.yml
3131
env SETTINGS_FLAVOR dev

config/config_sample.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ common: &common
5656

5757
# CORS support is not enabled by default
5858
cors:
59-
origins: _env:CORS_ORIGINS:["null"]
59+
origins: _env:CORS_ORIGINS
6060
methods: _env:CORS_METHODS
6161
headers: _env:CORS_HEADERS:[Content-Type]
6262
expose_headers: _env:CORS_EXPOSE_HEADERS

docker_registry/app.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
from . import toolkit
99
from .extras import bugsnag
10+
from .extras import cors
1011
from .lib import config
1112
from .server import __version__
1213
import flask
13-
from flask.ext.cors import CORS # noqa
1414

1515
# configure logging prior to subsequent imports which assume
1616
# logging has been configured
@@ -79,11 +79,10 @@ def init():
7979
secure=secure_args)
8080
mail_handler.setLevel(logging.ERROR)
8181
app.logger.addHandler(mail_handler)
82+
# Optional bugsnag support
8283
bugsnag.boot(app, cfg.bugsnag, cfg.flavor, __version__)
83-
# Configure flask_cors
84-
for i in cfg.cors.keys():
85-
app.config['CORS_%s' % i.upper()] = cfg.cors[i]
86-
CORS(app)
84+
# Optional cors support
85+
cors.boot(app, cfg.cors)
8786

8887

8988
def _adapt_smtp_secure(value):

docker_registry/extras/cors.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
def boot(application, config):
5+
if config and config['origins']:
6+
try:
7+
from flask.ext.cors import CORS
8+
for i in config.keys():
9+
application.config['CORS_%s' % i.upper()] = config[i]
10+
CORS(application)
11+
except Exception as e:
12+
raise Exception('Failed to init cors support %s' % e)

requirements/main.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
blinker==1.3
22
Flask==0.10.1
3-
Flask-cors==1.8.0
43
gevent==1.0.1
54
gunicorn==19.1
65
PyYAML==3.11

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,6 @@
9898
extras_require={
9999
'bugsnag': ['bugsnag>=2.0,<2.1'],
100100
'newrelic': ['newrelic>=2.22,<2.23'],
101+
'cors': ['Flask-cors>=1.8,<2.0'],
101102
}
102103
)

0 commit comments

Comments
 (0)