def _fn_create_zoom_meeting_function(self, event, *args, **kwargs):
        """Function: This will return a meeting URL to connect to a zoom meeting"""
        try:
            log = logging.getLogger(__name__)

            # Get the function parameters:
            zoom_host_email = kwargs.get("zoom_host_email")  # text
            zoom_topic = kwargs.get("zoom_topic")  # text
            zoom_password = kwargs.get("zoom_password")  # text
            zoom_record_meeting = kwargs.get("zoom_record_meeting")  # boolean

            # Remove the HTML tags
            zoom_agenda = self._clean_html(kwargs.get("zoom_agenda"))  # text

            if type(zoom_record_meeting) is not bool:
                zoom_record_meeting = False

            zoom_api_url = self.options.get("zoom_api_url")
            zoom_api_key = self.options.get("zoom_api_key")
            zoom_api_secret = self.options.get("zoom_api_secret")
            zoom_api_timezone = self.options.get("zoom_api_timezone")

            if zoom_api_timezone is None:
                yield FunctionError(
                    "zoom_api_timezone is not defined in app.config")

            try:
                pytz.timezone(str(zoom_api_timezone))
            except pytz.exceptions.UnknownTimeZoneError:
                yield FunctionError("Invalid timezone provided in app.config")

            if zoom_api_url is None:
                yield FunctionError(
                    "zoom_api_url is not defined in app.config")

            if zoom_api_key is None:
                yield FunctionError(
                    "zoom_api_key is not defined in app.config")

            if zoom_api_secret is None:
                yield FunctionError(
                    "zoom_api_secret is not defined in app.config")

            if zoom_topic is None:
                zoom_topic = ""

            if zoom_password is None:
                zoom_password = ""

            self.common = ZoomCommon(zoom_api_url, zoom_api_key,
                                     zoom_api_secret)

            r = self.common.create_meeting(zoom_host_email, zoom_agenda,
                                           zoom_record_meeting, zoom_topic,
                                           zoom_password, zoom_api_timezone)

            yield FunctionResult(r)
        except Exception as e:
            log.error(e)
            yield FunctionError(e)
示例#2
0
def selftest_function(opts):
    """
    Placeholder for selftest function. An example use would be to test package api connectivity.
    Suggested return values are be unimplemented, success, or failure.
    """
    app_configs = opts.get("fn_create_zoom_meeting", {})

    zoom = ZoomCommon(opts, app_configs)
    request = zoom.zoom_request(
        "/users?status=active&page_size=30&page_number=", "GET")
    if request.status_code == 200:
        return {"state": "success"}
    else:
        return {"state": "failure", "reason": "Get request failed"}
    def test_strip_password_from_join_url(self):
        print("Testing striping password from url....")

        url = "https://zoom.us/j/759429847?pwd=L3RMeXFXaHVxT3U5NmlJM1I1UEtLdz09"
        result = ZoomCommon.strip_password_from_join_url(url)
        assert result == "https://zoom.us/j/759429847"

        url = "https://zoom.us/j/759429847?pwd=L3RMeXFXaHVxT3U5NmlJM1I1UEtLdz09&sthelsehere=1111"
        result = ZoomCommon.strip_password_from_join_url(url)
        assert result == "https://zoom.us/j/759429847?sthelsehere=1111"

        url = "https://zoom.us/j/759429847"
        result = ZoomCommon.strip_password_from_join_url(url)
        assert result == "https://zoom.us/j/759429847"

        url = "https://zoom.us/j/759429847?sthelsehere=1111&pwd=L3RMeXFXaHVxT3U5NmlJM1I1UEtLdz09"
        result = ZoomCommon.strip_password_from_join_url(url)
        assert result == "https://zoom.us/j/759429847?sthelsehere=1111"
def run_zoom_common_create_meeting():
    zoom_api_url = "https://api.zoom.us/v2"
    zoom_api_key = ""  # Fill with zoom api key
    zoom_api_secret = ""  # Fill with zoom api secret

    zoom_host_email = "x"
    zoom_agenda = "test"
    zoom_record_meeting = False
    zoom_topic = "test"
    zoom_password = ""
    zoom_timezone = "America/New_York"

    common = ZoomCommon(zoom_api_url, zoom_api_key, zoom_api_secret)

    result = common.create_meeting(zoom_host_email, zoom_agenda,
                                   zoom_record_meeting, zoom_topic,
                                   zoom_password, zoom_timezone)

    return result
def run_zoom_common_create_meeting():
    zoom_api_url = "https://api.zoom.us/v2"
    zoom_api_key = ""  # Fill with zoom api key
    zoom_api_secret = ""  # Fill with zoom api secret

    zoom_host_email = "" # Add associated email
    zoom_agenda = "test"
    zoom_record_meeting = False
    zoom_topic = "test"
    zoom_password = ""
    zoom_timezone = "America/New_York"

    opts = {}
    options = {
        "zoom_api_key": zoom_api_key, 
        "zoom_api_secret": zoom_api_secret, 
        "zoom_api_url": zoom_api_url
        }

    common = ZoomCommon(opts, options)

    result = common.create_meeting(zoom_host_email, zoom_agenda, zoom_record_meeting, zoom_topic, zoom_password, zoom_timezone)

    return result
class FunctionComponent(ResilientComponent):
    """Component that implements Resilient function 'fn_create_zoom_meeting"""
    def __init__(self, opts):
        """constructor provides access to the configuration options"""
        super(FunctionComponent, self).__init__(opts)
        self.options = opts.get("create_zoom_meeting", {})

    @handler("reload")
    def _reload(self, event, opts):
        """Configuration options have changed, save new values"""
        self.options = opts.get("create_zoom_meeting", {})

    @function("fn_create_zoom_meeting")
    def _fn_create_zoom_meeting_function(self, event, *args, **kwargs):
        """Function: This will return a meeting URL to connect to a zoom meeting"""
        try:
            log = logging.getLogger(__name__)

            # Get the function parameters:
            zoom_host_email = kwargs.get("zoom_host_email")  # text
            zoom_topic = kwargs.get("zoom_topic")  # text
            zoom_password = kwargs.get("zoom_password")  # text
            zoom_record_meeting = kwargs.get("zoom_record_meeting")  # boolean

            # Remove the HTML tags
            zoom_agenda = self._clean_html(kwargs.get("zoom_agenda"))  # text

            if type(zoom_record_meeting) is not bool:
                zoom_record_meeting = False

            zoom_api_url = self.options.get("zoom_api_url")
            zoom_api_key = self.options.get("zoom_api_key")
            zoom_api_secret = self.options.get("zoom_api_secret")
            zoom_api_timezone = self.options.get("zoom_api_timezone")

            if zoom_api_timezone is None:
                yield FunctionError(
                    "zoom_api_timezone is not defined in app.config")

            try:
                pytz.timezone(str(zoom_api_timezone))
            except pytz.exceptions.UnknownTimeZoneError:
                yield FunctionError("Invalid timezone provided in app.config")

            if zoom_api_url is None:
                yield FunctionError(
                    "zoom_api_url is not defined in app.config")

            if zoom_api_key is None:
                yield FunctionError(
                    "zoom_api_key is not defined in app.config")

            if zoom_api_secret is None:
                yield FunctionError(
                    "zoom_api_secret is not defined in app.config")

            if zoom_topic is None:
                zoom_topic = ""

            if zoom_password is None:
                zoom_password = ""

            self.common = ZoomCommon(zoom_api_url, zoom_api_key,
                                     zoom_api_secret)

            r = self.common.create_meeting(zoom_host_email, zoom_agenda,
                                           zoom_record_meeting, zoom_topic,
                                           zoom_password, zoom_api_timezone)

            yield FunctionResult(r)
        except Exception as e:
            log.error(e)
            yield FunctionError(e)

    def _clean_html(self, html_fragment):
        """
        Resilient textarea fields return html fragments. This routine will remove the html and insert any
        code within <div></div> with a linefeed
        :param html_fragment:
        :return: cleaned up code
        """

        if not html_fragment or not isinstance(html_fragment, string_types):
            return html_fragment

        return BeautifulSoup(self._unescape(html_fragment), "html.parser").text

    @staticmethod
    def _unescape(data):
        """ Return unescaped data such as &gt; -> >, &quot -> ', etc. """
        try:
            return htmlparser.unescape(data)
        except:
            return data