def user_role_to_cfg(username, urole, cfg):
    tmp = ['roles', 'subroles'] \
      + urole['path'].replace('/', '/subroles/').split('/')

    tmp = get_subdict(cfg, tmp, default_empty=True)
    setdefault_none(setdefault_none(tmp, 'members', {}), urole['level'],
                    []).append(username)
Ejemplo n.º 2
0
    def _handle_specifics_presub(self, cfg, my_subcfg, cfgpath_abs):
        pacfg = self.get_parentcfg(cfg, cfgpath_abs)

        tmp = pathlib.PureWindowsPath(pacfg['_target_windir']) \
            / self._get_profsubpath()

        setdefault_none(my_subcfg, 'path', '{}'.format(tmp))
        setdefault_none(my_subcfg, '_path_quoted', '"{}"'.format(tmp))

        return my_subcfg
    def _handle_specifics_presub(self, cfg, my_subcfg, cfgpath_abs):
        gb_path = cfg['use_gitbash']

        if gb_path:
            ## if we use gitbash make sure it is on the path so that stuff
            ## like ssh-agent can be found by jenkins
            cpadd = setdefault_none(
                setdefault_none(my_subcfg, 'custom_pathvar', {}), 'append', [])

            cpadd.append(str(pathlib.PureWindowsPath(gb_path) / 'usr' / 'bin'))

        return my_subcfg
Ejemplo n.º 4
0
    def _handle_specifics_postsub(self, cfg, my_subcfg, cfgpath_abs):
        mc = my_subcfg['connection']
        my_subcfg['url'] = connection_as_url(mc)

        extra_conns = my_subcfg.get(self.extraconns_key, None)

        if extra_conns:
            # if extra connections are specified
            for (k, v) in iteritems(extra_conns):
                setdefault_none(v, 'host', mc['host'])
                v['url'] = connection_as_url(v)

        return super(
          ConfigNormerWebservice, self
        )._handle_specifics_postsub(cfg, my_subcfg, cfgpath_abs)
    def _handle_specifics_presub(self, cfg, my_subcfg, cfgpath_abs):
        # do config subkey
        c = setdefault_none(my_subcfg, 'config', defval={})
        setdefault_none(c, 'name', defval=cfgpath_abs[-1])

        # build role hierarchy path and parent
        if cfgpath_abs[-1] == 'roles':
            ## top level
            parent = []
        else:
            ## subrole
            parent = get_subdict(cfg, cfgpath_abs[:-2])
            parent = parent['role_abspath']

        my_subcfg['role_abspath'] = parent + [c['name']]
        c['parent'] = '/'.join(parent)

        return my_subcfg
    def _handle_specifics_presub(self, cfg, my_subcfg, cfgpath_abs):
        self._name_from_parent(cfg, my_subcfg, cfgpath_abs)

        custom_pvar = self.get_parentcfg(cfg, cfgpath_abs).get(
            'custom_pathvar', {}).get('_export', None)

        if custom_pvar:
            appenv = setdefault_none(my_subcfg, 'app_environment', {})
            appenv['Path'] = custom_pvar

        return my_subcfg
    def _handle_specifics_presub(self, cfg, my_subcfg, cfgpath_abs):
        setdefault_none(my_subcfg, 'user',
                        self.pluginref.get_become_settings()['become_user'])

        custom_pvar = my_subcfg.get('custom_pathvar', None)

        if custom_pvar:
            tmp = custom_pvar.get('prepend', [])

            if not custom_pvar.get('replace', False):
                # determine how default $PATH var looks like
                # on target system for service user
                tmp += self.pluginref.exec_powershell_script(
                    '(Get-Childitem -LiteralPath env:path).Value',
                    data_return=True)['result_json'].split(';')

            tmp += custom_pvar.get('append', [])

            custom_pvar['_export'] = ';'.join(tmp)

        return my_subcfg
    def _handle_specifics_presub(self, cfg, my_subcfg, cfgpath_abs):
        shell_type = self.get_parentcfg(cfg, cfgpath_abs, level=2)
        shell_type = shell_type['type']

        paths = setdefault_none(my_subcfg, 'paths', {})

        tmp = pathlib.PosixPath(self.pluginref.get_ansible_var('role_path')) \
            / 'templates' / 'shell_profiling' / shell_type

        if tmp.exists():
            tmp = str(tmp) + '/'
            paths[tmp] = None

        return my_subcfg
Ejemplo n.º 9
0
    def _handle_specifics_presub(self, cfg, my_subcfg, cfgpath_abs):
        ## set dest for all given paths to profiling dir
        paths = setdefault_none(my_subcfg, 'paths', {})

        profdir = cfg['profiling_dir']['path'] + '\\'

        for k in list(paths.keys()):
            v = paths[k]

            if isinstance(v, collections.abc.Mapping):
                v['dest'] = profdir
            else:
                v = profdir

            paths[k] = v

        return my_subcfg
    def _handle_specifics_presub(self, cfg, my_subcfg, cfgpath_abs):
        ## normalize command spec to absolute binary path
        cmd = my_subcfg['command']

        tmp = {
          'command': cmd,
          'type': 'Application',
        }

        tmp = self.pluginref.run_other_action_plugin(
          command_info.ActionModule, plugin_args=tmp
        )

        tmp = tmp['command_info']

        if tmp:

            if len(tmp) > 1:
                raise AnsibleOptionsError(
                  "Given shell command specifier '{}' was ambiguos. It must"\
                  " uniquely identify a single application on target.".format(cmd)
                )

            cmd = tmp[0]['Path']

        else:

            if not pathlib.PureWindowsPath(cmd).is_absolute():
                raise AnsibleOptionsError(
                   "Given shell command specifier '{}' did not match anything"\
                   " on target. Make sure the application is installed and"\
                   " that command specifier is correct.".format(cmd)
                )

            stat = self.pluginref.exec_module(
               'ansible.windows.win_stat', modargs={'path': cmd}
            )

            if not stat['stat']['exists']:
                raise AnsibleOptionsError(
                   "Given shell command specifier absolute path '{}'"\
                   " does not exist on target. Make sure the"\
                   " application is installed and the path is"\
                   " correct.".format(cmd)
                )

            if stat['stat']['isdir']:
                raise AnsibleOptionsError(
                   "Given shell command specifier absolute path '{}'"\
                   " is a directory not an application, check your"\
                   " path.".format(cmd)
                )

            # path is not recognized by powershell as application, 
            # but it is absolute, does exits, is no dir etc., so 
            # we will allow it as it is unchanged

        my_subcfg['command'] = cmd

        setdefault_none(my_subcfg, 'type', get_shell_type(cmd.lower()))
        return my_subcfg
Ejemplo n.º 11
0
 def _handle_specifics_presub(self, cfg, my_subcfg, cfgpath_abs):
     cfg = my_subcfg['config']
     setdefault_none(cfg, 'name', cfgpath_abs[-1])
     return my_subcfg