Skip to content
Merged
Changes from all commits
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
22 changes: 17 additions & 5 deletions plugins/modules/env_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
choices:
- http
- https
noProxyHosts:
description:
- List of hosts that should note be proxied.
- Format can be CIDR, [.]host[:port] (can be a subdomain) or IP[:port]. Wildcards are not accepted
type: list
required: False
user:
description:
- The proxy user
Expand Down Expand Up @@ -176,6 +182,7 @@ def __init__(self, module):
self.protocol = self._get_param('protocol')

self.description = self._get_param('description')
self.no_proxy_hosts = self._get_param('noProxyHosts')
self.user = self._get_param('user')
self.password = self._get_param('password')

Expand All @@ -191,17 +198,17 @@ def __init__(self, module):
def process(self):
existing = self.cdpy.environments.describe_proxy_config(self.name)

if existing is None:
if existing is None or len(existing) == 0:
if self.state == 'present':
self._create_core_payload()
self.changed = True
self._create_auth_payload()
self.proxy_config = self.cdpy.environments.create_proxy_config(self._payload)
self.proxy_config = self.cdpy.environments.create_proxy_config(**self._payload)
else:
if self.state == 'present':
self._create_core_payload()

test = dict(existing[0])
test = existing
del test['crn']

if self._payload != test:
Expand All @@ -214,9 +221,9 @@ def process(self):

if self.changed:
self.cdpy.environments.delete_proxy_config(self.name)
self.proxy_config = self.cdpy.environments.create_proxy_config(self._payload)
self.proxy_config = self.cdpy.environments.create_proxy_config(**self._payload)
else:
self.proxy_config = existing[0]
self.proxy_config = existing
else:
self.changed = True
self.cdpy.environments.delete_proxy_config(self.name)
Expand All @@ -232,6 +239,10 @@ def _create_core_payload(self):
if self.description is not None:
self._payload.update(description=self.description)

if self.no_proxy_hosts is not None:
# convert no_proxy_hosts list to a comma separated string
self._payload.update(noProxyHosts=(','.join(self.no_proxy_hosts)))

def _create_auth_payload(self):
if self.user is not None:
self._payload.update(user=self.user)
Expand All @@ -248,6 +259,7 @@ def main():
host=dict(required=False, type='str'),
port=dict(required=False, type='int'),
protocol=dict(required=False, type='str'),
noProxyHosts=dict(required=False, type='list', elements='str'),
user=dict(required=False, type='str'),
password=dict(required=False, type='str', no_log=True),
state=dict(required=False, type='str', choices=['present', 'absent'], default='present')
Expand Down