mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 07:26:29 +00:00
Merge pull request #214 from jerrykan/aptproxy
Add authentication support to the apt proxy plugin
This commit is contained in:
commit
9ad83a37a0
3 changed files with 20 additions and 2 deletions
|
@ -14,6 +14,12 @@ Settings
|
||||||
*``required``*
|
*``required``*
|
||||||
- ``port``: The port (integer) of the proxy server.
|
- ``port``: The port (integer) of the proxy server.
|
||||||
*``required``*
|
*``required``*
|
||||||
|
- ``username``: The username for authentication against the proxy server.
|
||||||
|
This is ignored if ``password`` is not also set.
|
||||||
|
*``optional``*
|
||||||
|
- ``password``: The password for authentication against the proxy server.
|
||||||
|
This is ignored if ``username`` is not also set.
|
||||||
|
*``optional``*
|
||||||
- ``persistent``: Whether the proxy configuration file should remain on
|
- ``persistent``: Whether the proxy configuration file should remain on
|
||||||
the machine or not.
|
the machine or not.
|
||||||
Valid values: true, false
|
Valid values: true, false
|
||||||
|
|
|
@ -10,8 +10,10 @@ properties:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
address: {type: string}
|
address: {type: string}
|
||||||
|
password: {type: string}
|
||||||
port: {type: integer}
|
port: {type: integer}
|
||||||
persistent: {type: boolean}
|
persistent: {type: boolean}
|
||||||
|
username: {type: string}
|
||||||
required:
|
required:
|
||||||
- address
|
- address
|
||||||
- port
|
- port
|
||||||
|
|
|
@ -34,11 +34,21 @@ class SetAptProxy(Task):
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(cls, info):
|
def run(cls, info):
|
||||||
proxy_path = os.path.join(info.root, 'etc/apt/apt.conf.d/02proxy')
|
proxy_path = os.path.join(info.root, 'etc/apt/apt.conf.d/02proxy')
|
||||||
|
proxy_username = info.manifest.plugins['apt_proxy'].get('username')
|
||||||
|
proxy_password = info.manifest.plugins['apt_proxy'].get('password')
|
||||||
proxy_address = info.manifest.plugins['apt_proxy']['address']
|
proxy_address = info.manifest.plugins['apt_proxy']['address']
|
||||||
proxy_port = info.manifest.plugins['apt_proxy']['port']
|
proxy_port = info.manifest.plugins['apt_proxy']['port']
|
||||||
|
|
||||||
|
if None not in (proxy_username, proxy_password):
|
||||||
|
proxy_auth = '{username}:{password}@'.format(
|
||||||
|
username=proxy_username, password=proxy_password)
|
||||||
|
else:
|
||||||
|
proxy_auth = ''
|
||||||
|
|
||||||
with open(proxy_path, 'w') as proxy_file:
|
with open(proxy_path, 'w') as proxy_file:
|
||||||
proxy_file.write('Acquire::http {{ Proxy "http://{address}:{port}"; }};\n'
|
proxy_file.write(
|
||||||
.format(address=proxy_address, port=proxy_port))
|
'Acquire::http {{ Proxy "http://{auth}{address}:{port}"; }};\n'
|
||||||
|
.format(auth=proxy_auth, address=proxy_address, port=proxy_port))
|
||||||
|
|
||||||
|
|
||||||
class RemoveAptProxy(Task):
|
class RemoveAptProxy(Task):
|
||||||
|
|
Loading…
Add table
Reference in a new issue