Пример #1
0
    def run(self, params={}):
        """ Get the user by email """
        email = params.get(Input.EMAIL)
        user_id = helpers.get_user_id(email, self.connection, self.logger)

        if user_id is None:
            return {Output.SUCCESS: False}
        """ Deactivate the user by id """
        url = requests.compat.urljoin(
            self.connection.okta_url,
            f'/api/v1/users/{user_id}/lifecycle/deactivate')
        response = self.connection.session.post(url)

        if response.status_code == 401:
            raise PluginException(PluginException.Preset.API_KEY)

        if response.status_code != 200:
            raise PluginException(
                cause='Okta Deactivate User failed',
                assistance=
                f'Okta Deactivate User failed with status code: {response.status_code}'
            )

        return {
            Output.EMAIL: email,
            Output.USER_ID: user_id,
            Output.SUCCESS: True
        }
Пример #2
0
    def run(self, params={}):
        """Get the user by email"""
        email = params.get(Input.EMAIL)
        user_id = helpers.get_user_id(email, self.connection, self.logger)

        if user_id is None:
            return {Output.SUCCESS: False}
        """ Deactivate the user by id """
        url = requests.compat.urljoin(
            self.connection.okta_url,
            f"/api/v1/users/{user_id}/lifecycle/suspend")
        response = self.connection.session.post(url)

        if response.status_code == 404:
            raise PluginException(
                cause="Suspend User failed",
                assistance=
                "Okta: Suspend User failed with status code 404: User not found by ID after retrieving ID via email",
            )
        elif response.status_code == 400:
            raise PluginException(
                cause="Suspend User failed",
                assistance=
                "Okta: Suspend User failed with status code 400: User was already suspended or in a state where they could not be suspended",
            )
        elif response.status_code == 401:
            raise PluginException(PluginException.Preset.API_KEY)

        return {
            Output.EMAIL: email,
            Output.USER_ID: user_id,
            Output.SUCCESS: True
        }
Пример #3
0
    def run(self, params={}):
        """Get the user by email"""
        email = params.get(Input.EMAIL)
        okta_url = self.connection.okta_url
        user_id = helpers.get_user_id(email, self.connection, self.logger)

        if user_id is None:
            return {Output.SUCCESS: False}
        """ Get enrolled factors by user id """
        url = requests.compat.urljoin(okta_url,
                                      f"/api/v1/users/{user_id}/factors")
        response = self.connection.session.get(url)
        data = response.json()
        """ Reset all factors """
        for factor in data:
            factor_id = factor["id"]
            url = requests.compat.urljoin(
                okta_url, f"/api/v1/users/{user_id}/factors/{factor_id}")
            response = self.connection.session.delete(url)

            if response.status_code != 204:
                data = response.json()
                error_code = data["errorCode"]
                error_summary = data["errorSummary"]
                self.logger.error(
                    f"Okta: {response.status_code} error. Error code: {error_code}. {error_summary}"
                )
                raise PluginException(cause="Reset factors error",
                                      assistance=data["errorSummary"])

        return {
            Output.EMAIL: email,
            Output.USER_ID: user_id,
            Output.SUCCESS: True
        }
Пример #4
0
    def run(self, params={}):
        """Get the user by email"""
        group_id = params.get(Input.GROUP_ID)
        email = params.get(Input.EMAIL)
        user_id = helpers.get_user_id(email, self.connection, self.logger)

        if user_id is None:
            return {Output.SUCCESS: False}
        """ Remove user from group by id"""
        url = requests.compat.urljoin(
            self.connection.okta_url,
            f"/api/v1/groups/{group_id}/users/{user_id}")
        response = self.connection.session.delete(url)

        return helpers.group_response(response, user_id)