mirror of
https://github.com/certbot/certbot.git
synced 2026-08-02 00:22:28 +02:00
Merge pull request #1388 from bit/bug942
nginx: Only insert directive if its not already in block
This commit is contained in:
@@ -257,6 +257,8 @@ class NginxParser(object):
|
|||||||
|
|
||||||
..note :: If replace is True, this raises a misconfiguration error
|
..note :: If replace is True, this raises a misconfiguration error
|
||||||
if the directive does not already exist.
|
if the directive does not already exist.
|
||||||
|
..note :: If replace is False nothing gets added if an identical
|
||||||
|
block exists already.
|
||||||
|
|
||||||
..todo :: Doesn't match server blocks whose server_name directives are
|
..todo :: Doesn't match server blocks whose server_name directives are
|
||||||
split across multiple conf files.
|
split across multiple conf files.
|
||||||
@@ -480,6 +482,8 @@ def _add_directives(block, directives, replace=False):
|
|||||||
if not replace:
|
if not replace:
|
||||||
# We insert new directives at the top of the block, mostly
|
# We insert new directives at the top of the block, mostly
|
||||||
# to work around https://trac.nginx.org/nginx/ticket/810
|
# to work around https://trac.nginx.org/nginx/ticket/810
|
||||||
|
# Only add directive if its not already in the block
|
||||||
|
if directive not in block:
|
||||||
block.insert(0, directive)
|
block.insert(0, directive)
|
||||||
else:
|
else:
|
||||||
changed = False
|
changed = False
|
||||||
|
|||||||
@@ -133,11 +133,11 @@ class NginxParserTest(util.NginxTest):
|
|||||||
self.assertEqual(1, len(re.findall(ssl_re, dump)))
|
self.assertEqual(1, len(re.findall(ssl_re, dump)))
|
||||||
|
|
||||||
server_conf = nparser.abs_path('server.conf')
|
server_conf = nparser.abs_path('server.conf')
|
||||||
nparser.add_server_directives(server_conf,
|
names = set(['alias', 'another.alias', 'somename'])
|
||||||
set(['alias', 'another.alias',
|
nparser.add_server_directives(server_conf, names,
|
||||||
'somename']),
|
|
||||||
[['foo', 'bar'], ['ssl_certificate',
|
[['foo', 'bar'], ['ssl_certificate',
|
||||||
'/etc/ssl/cert2.pem']])
|
'/etc/ssl/cert2.pem']])
|
||||||
|
nparser.add_server_directives(server_conf, names, [['foo', 'bar']])
|
||||||
self.assertEqual(nparser.parsed[server_conf],
|
self.assertEqual(nparser.parsed[server_conf],
|
||||||
[['ssl_certificate', '/etc/ssl/cert2.pem'],
|
[['ssl_certificate', '/etc/ssl/cert2.pem'],
|
||||||
['foo', 'bar'],
|
['foo', 'bar'],
|
||||||
|
|||||||
Reference in New Issue
Block a user