Beispiel #1
0
    def __init__(self, groups=None, remove=False, debug=False):
        """Constructor.

    Args:
      groups: string, a comma separated list of groups.
      remove: bool, True if deprovisioning a user should be destructive.
      debug: bool, True if debug output should write to the console.
    """
        facility = logging.handlers.SysLogHandler.LOG_DAEMON
        self.logger = logger.Logger(name='google-accounts',
                                    debug=debug,
                                    facility=facility)
        self.watcher = metadata_watcher.MetadataWatcher(logger=self.logger)
        self.utils = accounts_utils.AccountsUtils(logger=self.logger,
                                                  groups=groups,
                                                  remove=remove)
        try:
            with file_utils.LockFile(LOCKFILE):
                self.logger.info('Starting Google Accounts daemon.')
                timeout = 60 + random.randint(0, 30)
                self.watcher.WatchMetadata(self.HandleAccounts,
                                           recursive=True,
                                           timeout=timeout)
        except (IOError, OSError) as e:
            self.logger.warning(str(e))
  def testAccountsUtils(self, mock_create, mock_group):
    mock_logger = mock.Mock()
    mock_group.side_effect = lambda group: 'google' in group

    utils = accounts_utils.AccountsUtils(
        logger=mock_logger, groups='foo,google,bar', remove=True)
    mock_create.assert_called_once_with()
    self.assertEqual(utils.logger, mock_logger)
    self.assertEqual(sorted(utils.groups), ['google', 'google-sudoers'])
    self.assertTrue(utils.remove)
Beispiel #3
0
    def __init__(self,
                 groups=None,
                 remove=False,
                 gpasswd_add_cmd=None,
                 gpasswd_remove_cmd=None,
                 groupadd_cmd=None,
                 useradd_cmd=None,
                 userdel_cmd=None,
                 usermod_cmd=None,
                 debug=False):
        """Constructor.

    Args:
      groups: string, a comma separated list of groups.
      remove: bool, True if deprovisioning a user should be destructive.
      useradd_cmd: string, command to create a new user.
      userdel_cmd: string, command to delete a user.
      usermod_cmd: string, command to modify user's groups.
      groupadd_cmd: string, command to add a new group.
      gpasswd_add_cmd: string, command to add an user to a group.
      gpasswd_remove_cmd: string, command to remove an user from a group.
      debug: bool, True if debug output should write to the console.
    """
        facility = logging.handlers.SysLogHandler.LOG_DAEMON
        self.logger = logger.Logger(name='google-accounts',
                                    debug=debug,
                                    facility=facility)
        self.watcher = metadata_watcher.MetadataWatcher(logger=self.logger)
        self.utils = accounts_utils.AccountsUtils(
            logger=self.logger,
            groups=groups,
            remove=remove,
            gpasswd_add_cmd=gpasswd_add_cmd,
            gpasswd_remove_cmd=gpasswd_remove_cmd,
            groupadd_cmd=groupadd_cmd,
            useradd_cmd=useradd_cmd,
            userdel_cmd=userdel_cmd,
            usermod_cmd=usermod_cmd)
        self.oslogin = oslogin_utils.OsLoginUtils(logger=self.logger)

        try:
            with file_utils.LockFile(LOCKFILE):
                self.logger.info('Starting Google Accounts daemon.')
                timeout = 60 + random.randint(0, 30)
                self.watcher.WatchMetadata(self.HandleAccounts,
                                           recursive=True,
                                           timeout=timeout)
        except (IOError, OSError) as e:
            self.logger.warning(str(e))