Exemple #1
0
 def post_write(self):
     # NOTE: don't recurse
     utils.ensure_permissions('/etc/ssh',
                              'root',
                              'root',
                              0o0755,
                              maxdepth=0)
Exemple #2
0
 def pre_write(self):
     settings = utils.get_settings('ssh')
     apt_update(fatal=True)
     apt_install(settings['server']['package'])
     if not os.path.exists('/etc/ssh'):
         os.makedir('/etc/ssh')
         # NOTE: don't recurse
         utils.ensure_permissions('/etc/ssh', 'root', 'root', 0o0755,
                                  maxdepth=0)
Exemple #3
0
    def comply(self, path):
        """Ensures the contents and the permissions of the file.

        :param path: the path to correct
        """
        dirname = os.path.dirname(path)
        if not os.path.exists(dirname):
            os.makedirs(dirname)

        self.pre_write()
        render_and_write(self.template_dir, path, self.context())
        utils.ensure_permissions(path, self.user, self.group, self.mode)
        self.run_service_actions()
        self.save_checksum(path)
        self.post_write()
Exemple #4
0
    def test_ensure_permissions(self, mock_os, mock_getpwnam, mock_getgrnam):
        user = MagicMock()
        user.pw_uid = '12'
        mock_getpwnam.return_value = user
        group = MagicMock()
        group.gr_gid = '23'
        mock_getgrnam.return_value = group

        with tempfile.NamedTemporaryFile() as tmp:
            utils.ensure_permissions(tmp.name, 'testuser', 'testgroup', 0o0440)

        mock_getpwnam.assert_has_calls([call('testuser')])
        mock_getgrnam.assert_has_calls([call('testgroup')])
        mock_os.chown.assert_has_calls([call(tmp.name, '12', '23')])
        mock_os.chmod.assert_has_calls([call(tmp.name, 0o0440)])
Exemple #5
0
 def comply(self, path):
     """Issues a chown and chmod to the file paths specified."""
     utils.ensure_permissions(path, self.user.pw_name, self.group.gr_name,
                              self.mode)
 def post_write(self):
     # NOTE: don't recurse
     utils.ensure_permissions('/etc/ssh', 'root', 'root', 0o0755,
                              maxdepth=0)