Exemple #1
0
    def add_users(self, branch, usersfile):
        if self.config.readonly:
            yield error_log('This LDAP is configured as read-only')

        self.set_branch(branch)
        self.connect(auth=False)
        self.authenticate(
            username=self.effective_admin_dn,
            password=self.effective_admin_password)

        try:
            users = read_users_file(usersfile, required_fields=['username', 'fullname', 'password'])
        except Exception as exc:
            error_message = 'Error parsing users file {}: {{}}'.format(usersfile)
            yield raising_error_log(error_message.format(exc.message))

        try:
            self.check_users(users)
        except Exception as exc:
            yield raising_error_log(exc.message)

        yield step_log('Creating {} users '.format(len(users)))
        for count, user in enumerate(users, start=1):
            if not user:
                yield error_log('Error parsing user at line #{}'.format(count))
                continue
            try:
                self.add_ldap_user(**user)
                yield success_log('User {} created'.format(user['username']))
            except ldap.ALREADY_EXISTS:
                yield error_log('User {} already exists'.format(user['username']))
            except Exception as exc:
                yield error_log('Error creating user {}: {}'.format(user['username']), exc.__repr__())

        self.disconnect()
Exemple #2
0
    def test(self, instance_name, username, password):
        instance = self.get_instance(instance_name)
        try:
            yield step_log('Testing oauth server @ {}'.format(instance['server']['dns']))

            yield message_log('Checking server health')

            try:
                status = requests.get(instance['server']['dns'], verify=True).status_code
            except requests.exceptions.SSLError:
                yield error_log('SSL certificate verification failed')
                yield message_log('Continuing test without certificate check')

            try:
                status = requests.get(instance['server']['dns'], verify=False).status_code
            except requests.ConnectionError:
                yield raising_error_log('Connection error, check nginx is running, and dns resolves as expected.')
            except:
                yield raising_error_log('Unknown error trying to access oauth server. Check params and try again')
            else:
                if status == 500:
                    yield raising_error_log('Error on oauth server, Possible causes:\n  - ldap configuration error (bad server url?)\n  - Mongodb configuration error (bad replicaset name or hosts list?)\nCheck osiris log for more information.')
                elif status == 502:
                    yield raising_error_log('Server not respoding at {}. Check that:\n  - osiris process is running\n  - nginx upstream definition is pointing to the right host:port.'.format(instance['server']['dns']))
                elif status == 504:
                    yield raising_error_log('Gateway timeout. Probably oauth server is giving timeout trying to contact ldap server')
                elif status == 404:
                    yield raising_error_log('There\'s no oauth server at {}. Chech there\'s an nginx entry for this server.'.format(instance['server']['dns']))
                elif status != 200:
                    yield raising_error_log('Server {} responded with {} code. Check osiris logs.'.format(instance['server']['dns'], status))

            yield message_log('Retrieving token for "{}"'.format(username))
            token = self.get_token(instance['server']['dns'], username, password)
            succeeded_retrieve_token = token is not None

            if not succeeded_retrieve_token:
                yield raising_error_log('Error retreiving token. Check username/password and try again')

            yield message_log('Checking retreived token')
            succeeded_check_token = self.check_token(instance['server']['dns'], username, token)

            if not succeeded_check_token:
                yield raising_error_log('Error retreiving token')

            if succeeded_check_token and succeeded_retrieve_token:
                yield success_log('Oauth server check passed')
            else:
                yield raising_error_log('Oauth server check failed')

        except StepError as error:
            yield error_log(error.message)
Exemple #3
0
    def batch_add_users(self, instance, usersfile):
        site = UlearnSite(self.get_environment(instance["environment"]), instance["mountpoint"], instance["plonesite"])
        try:
            users = read_users_file(usersfile, required_fields=["username", "fullname", "email", "password"])
        except Exception as exc:
            error_message = "Error parsing users file {}: {{}}".format(usersfile)
            yield raising_error_log(error_message.format(exc.message))

        try:
            self.check_users(users)
        except Exception as exc:
            yield raising_error_log(exc.message)

        yield step_log("Creating {} users ".format(len(users)))
        for count, user in enumerate(users, start=1):
            if not user:
                yield error_log("Error parsing user at line #{}".format(count))
                continue
            succeeded = site.add_user(**user)
            if not succeeded.get("error", False):
                yield success_log(succeeded["message"])
            else:
                yield error_log(succeeded["message"])
Exemple #4
0
    def batch_subscribe_users(self, instance, subscriptionsfile):
        site = UlearnSite(self.get_environment(instance["environment"]), instance["mountpoint"], instance["plonesite"])
        try:
            communities = read_subscriptions_file(subscriptionsfile, required_fields=["owners", "readers", "editors"])
        except Exception as exc:
            error_message = "Error parsing subscriptionsfile file {}: {{}}".format(subscriptionsfile)
            yield raising_error_log(error_message.format(exc.message))

        for community in communities:
            yield step_log("Subscribing users to {}".format(community["url"]))

            succeeded = site.subscribe_users(**community)
            if not succeeded.get("error", False):
                yield success_log(succeeded["message"])
            else:
                yield error_log(succeeded["message"])