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

Add --paste-global-conf option #1304

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 gunicorn/app/wsgiapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def load_pasteapp(self):

# load the paste app
from .pasterapp import load_pasteapp
return load_pasteapp(self.cfgurl, self.relpath, global_conf=None)
return load_pasteapp(self.cfgurl, self.relpath, global_conf=self.cfg.paste_global_conf)

def load(self):
if self.cfg.paste is not None:
Expand Down
39 changes: 39 additions & 0 deletions gunicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from . import argparse_compat as argparse
import os
import pwd
import re
import ssl
import sys
import textwrap
Expand Down Expand Up @@ -203,6 +204,25 @@ def sendfile(self):

return True

@property
def paste_global_conf(self):
raw_global_conf = self.settings['raw_paste_global_conf'].get()
if raw_global_conf is None:
return None

global_conf = {}
for e in raw_global_conf:
s = _compat.bytes_to_str(e)
try:
k, v = re.split(r'(?<!\\)=', s, 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regular expression here is a raw string, so should there be only one backslash?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore me. Right. The backslash here is not for character escape but for regular expression escape. Whole reason for the raw is to not have \\\\.

👾 🌔 🚀

except ValueError:
raise RuntimeError("environment setting %r invalid" % s)
k = k.replace('\\=', '=')
v = v.replace('\\=', '=')
global_conf[k] = v

return global_conf


class SettingMeta(type):
def __new__(cls, name, bases, attrs):
Expand Down Expand Up @@ -1765,3 +1785,22 @@ class Ciphers(Setting):
desc = """\
Ciphers to use (see stdlib ssl module's)
"""


class PasteGlobalConf(Setting):
name = "raw_paste_global_conf"
action = "append"
section = "Server Mechanics"
cli = ["--paste-global-conf"]
meta = "CONF"
validator = validate_list_string
default = []

desc = """\
Set a PasteDeploy global config variable (key=value).

The variables are passed to the the PasteDeploy entrypoint. Ex.::

$ gunicorn -b 127.0.0.1:8000 --paste development.ini --paste-global-conf FOO=1

"""