Add a copy of the nginx builder module
This commit is contained in:
parent
ee9e06b1ee
commit
261e9d9fbb
14 changed files with 1237 additions and 0 deletions
65
sysadmin/nginx/config/api/__init__.py
Normal file
65
sysadmin/nginx/config/api/__init__.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
"""
|
||||
The Block API provides objects to programatically generate nginx configurations.
|
||||
|
||||
Example::
|
||||
|
||||
>>> from nginx.config.api import Config, Section, Location
|
||||
>>> events = Section('events', worker_connections='1024')
|
||||
>>> http = Section('http', include='../conf/mime.types')
|
||||
>>> http.sections.add(
|
||||
... Section(
|
||||
... 'server',
|
||||
... Location(
|
||||
... '/foo',
|
||||
... proxy_pass='upstream',
|
||||
... ),
|
||||
... server_name='_',
|
||||
... )
|
||||
... )
|
||||
>>> nginx = Config(
|
||||
... events,
|
||||
... http,
|
||||
... worker_processes='auto',
|
||||
... daemon='on',
|
||||
... error_log='var/error.log',
|
||||
... )
|
||||
>>> print(nginx)
|
||||
|
||||
error_log var/error.log;
|
||||
worker_processes auto;
|
||||
daemon on;
|
||||
http {
|
||||
include ../conf/mime.types;
|
||||
server {
|
||||
server_name _;
|
||||
location /foo {
|
||||
proxy_pass upstream;
|
||||
}
|
||||
}
|
||||
}
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
.. The objects in this submodule are largely inspired by code found in https://github.com/FeroxTL/pynginxconfig-new.
|
||||
|
||||
"""
|
||||
from .blocks import EmptyBlock, Block, Location
|
||||
from .options import Comment, KeyOption, KeyValueOption, KeyMultiValueOption
|
||||
|
||||
__all__ = [
|
||||
'EmptyBlock',
|
||||
'Block',
|
||||
'Location',
|
||||
'KeyOption',
|
||||
'KeyValueOption',
|
||||
'KeyValueMultilines',
|
||||
'KeyMultiValueOption',
|
||||
'Comment',
|
||||
'Config',
|
||||
'Section'
|
||||
]
|
||||
|
||||
# aliases
|
||||
Config = EmptyBlock
|
||||
Section = Block
|
Loading…
Add table
Add a link
Reference in a new issue