Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup_ansible(config, secrets):
try:
ansible_tpl_path = config.ansible_config_template_path
except AttributeError:
ansible_tpl_path = None
try:
ansible_cfg_path = config.ansible_config_path
except AttributeError:
ansible_cfg_path = None
if ansible_cfg_path and ansible_tpl_path:
with open(ansible_tpl_path, 'rb') as fh:
ansible_cfg_tpl_params = munch.unmunchify(config)
ansible_cfg = utils.render_template(fh.read(),
ansible_cfg_tpl_params)
utils.safe_make_dirs(os.path.dirname(ansible_cfg_path))
with open(ansible_cfg_path, 'wb') as fh:
fh.write(ansible_cfg)
def edit_release(user: str, password: str, url: str, debug: bool, composed_by_bodhi: bool,
openid_api: str, **kwargs):
"""Edit an existing release."""
client = bindings.BodhiClient(base_url=url, username=user, password=password,
staging=kwargs['staging'], openid_api=openid_api)
csrf = client.csrf()
edited = kwargs.pop('name')
if edited is None:
click.echo("ERROR: Please specify the name of the release to edit", err=True)
return
res = client.send_request(f'releases/{edited}', verb='GET', auth=True)
data = munch.unmunchify(res)
if 'errors' in data:
print_errors(data)
data['edited'] = edited
data['csrf_token'] = csrf
data['composed_by_bodhi'] = composed_by_bodhi
new_name = kwargs.pop('new_name')
if new_name is not None:
data['name'] = new_name
for k, v in kwargs.items():
if v is not None:
data[k] = v
""" Create new filesystem or update existing one"""
changed = False
name = module.params['name']
client_list = module.params['client_list']
if export is None:
if not module.check_mode:
export = system.exports.create(export_path=name, filesystem=filesystem)
if client_list:
export.update_permissions(client_list)
changed = True
else:
if client_list:
if set(map(transform, unmunchify(export.get_permissions()))) != set(map(transform, client_list)):
if not module.check_mode:
export.update_permissions(client_list)
changed = True
module.exit_json(changed=changed)
def reply_config(self, req, req_match):
resp = Response()
resp.content_type = 'application/json'
resp.status = 200
tmp_config = copy.deepcopy(self.bot.config)
tmp_config = munch.unmunchify(tmp_config)
tmp_config = utils.mask_dict_password(tmp_config)
resp_body = tmp_config
resp_body = utils.dump_json(resp_body, pretty=True)
resp.text = resp_body + "\n"
return resp
def delete_client(module, export):
"""Update export client list"""
changed = False
client = module.params['client']
client_list = export.get_permissions()
for index, item in enumerate(client_list):
if item.client == client:
changed = True
del client_list[index]
if changed:
for index, item in enumerate(client_list):
client_list[index] = unmunchify(item)
if not module.check_mode:
export.update_permissions(client_list)
module.exit_json(changed=changed)
if item.access != access_mode:
item.access = access_mode
changed = True
if item.no_root_squash is not no_root_squash:
item.no_root_squash = no_root_squash
changed = True
# If access_mode and/or no_root_squash not passed as arguments to the module,
# use access_mode with RW value and set no_root_squash to False
if client_not_in_list:
changed = True
client_list.append(Munch(client=client, access=access_mode, no_root_squash=no_root_squash))
if changed:
for index, item in enumerate(client_list):
client_list[index] = unmunchify(item)
if not module.check_mode:
export.update_permissions(client_list)
module.exit_json(changed=changed)
def print_mcus():
"""print boards from boards.txt."""
ls = unmunchify(mcus())
print('\n'.join(ls))
def from_file(fname=DEFAULT_CONFIG_FILENAME, testing=False):
if testing:
return TEST
try:
with open(os.path.expanduser(fname)) as fd:
conf = yaml.load(fd)
conf = munchify(conf)
return conf
except IOError:
print("A configuration file named '%s' is missing" % fname)
s_conf = yaml.dump(unmunchify(DEFAULT), explicit_start=True, indent=True, default_flow_style=False)
print("""
Creating this file
%s
You still have to create directories with data and put your data in!
""" % s_conf)
time.sleep(3)
try:
with open(os.path.expanduser(fname), "w") as fd:
fd.write(s_conf)
except IOError:
print("Can create '%s'" % fname)
print("Trying anyway with default configuration")
return DEFAULT