Exemplo n.º 1
0
    def run(self, params={}):
        # Import variables from connection
        url = self.connection.url
        access_key = self.connection.access_key
        secret_key = self.connection.secret_key
        app_id = self.connection.app_id
        app_key = self.connection.app_key

        # Generate payload dictionary
        data = {}
        for key, value in params.items():
            temp = util.normalize(key, value)
            data.update(temp)

        # Mimecast request
        mimecast_request = util.MimecastRequests()
        response = mimecast_request.mimecast_post(
            url=url,
            uri=CreateManagedUrl._URI,
            access_key=access_key,
            secret_key=secret_key,
            app_id=app_id,
            app_key=app_key,
            data=data,
        )

        return {"response": response["data"]}
Exemplo n.º 2
0
    def run(self, params={}):
        # Import variables from connection
        url = self.connection.url
        access_key = self.connection.access_key
        secret_key = self.connection.secret_key
        app_id = self.connection.app_id
        app_key = self.connection.app_key

        # Generate payload dictionary
        data = {}
        for key, value in params.items():
            temp = util.normalize(key, value)
            data.update(temp)

        # Mimecast request
        mimecast_request = util.MimecastRequests()
        response = mimecast_request.mimecast_post(url=url,
                                                  uri=PermitOrBlockSender._URI,
                                                  access_key=access_key,
                                                  secret_key=secret_key,
                                                  app_id=app_id,
                                                  app_key=app_key,
                                                  data=data)

        return {Output.RESPONSE: response['data']}
Exemplo n.º 3
0
    def run(self, params={}):
        # Import variables from connection
        url = self.connection.url
        access_key = self.connection.access_key
        secret_key = self.connection.secret_key
        app_id = self.connection.app_id
        app_key = self.connection.app_key

        # Mimecast request
        mimecast_request = util.MimecastRequests()
        response = mimecast_request.mimecast_post(
            url=url,
            uri=GetManagedUrl._URI,
            access_key=access_key,
            secret_key=secret_key,
            app_id=app_id,
            app_key=app_key,
            data=None,
        )

        # Create filter dictionary
        filter_ = {}
        for key, value in params.items():
            temp = util.normalize(key, value)
            filter_.update(temp)

        data = response["data"]
        # Create filtered list
        for item in filter_:
            data[:] = [d for d in data if d.get(item) == filter_[item]]

        return {"response": data}
Exemplo n.º 4
0
    def run(self, params={}):
        # Import variables from connection
        url = self.connection.url
        access_key = self.connection.access_key
        secret_key = self.connection.secret_key
        app_id = self.connection.app_id
        app_key = self.connection.app_key

        source_ips = params.get(Input.SOURCE_IPS)
        option = params.get(Input.OPTION)

        data = {"option": option}

        # Generate policy dictionary
        policy = {}
        for key, value in params.items():
            temp = util.normalize(key, value)
            policy.update(temp)

        # Remove source_ips and option from policy as they should not be directly in that dictionary
        if params.get(Input.SOURCE_IPS):
            del policy["sourceIps"]
        del policy["option"]

        # Transform source_ips from comma delimited string to list
        if params.get(Input.SOURCE_IPS):
            source_ips = source_ips.split(",")

        # Add conditions dic to policy
        if source_ips:
            policy["conditions"] = {"sourceIPs": source_ips}

        # Add policy to data
        data["policy"] = policy

        # Mimecast request
        mimecast_request = util.MimecastRequests()
        response = mimecast_request.mimecast_post(
            url=url,
            uri=CreateBlockedSenderPolicy._URI,
            access_key=access_key,
            secret_key=secret_key,
            app_id=app_id,
            app_key=app_key,
            data=data,
        )

        return {Output.SENDER_POLICY: response["data"]}
Exemplo n.º 5
0
    def run(self, params={}):
        # Import variables from connection
        url = self.connection.url
        username = self.connection.username
        password = self.connection.password
        access_key = self.connection.access_key
        secret_key = self.connection.secret_key
        app_id = self.connection.app_id
        app_key = self.connection.app_key
        auth_type = self.connection.auth_type

        # Mimecast request
        mimecast_request = util.MimecastRequests()
        response = mimecast_request.mimecast_post(url=url,
                                                  uri=GetManagedUrl._URI,
                                                  username=username,
                                                  password=password,
                                                  auth_type=auth_type,
                                                  access_key=access_key,
                                                  secret_key=secret_key,
                                                  app_id=app_id,
                                                  app_key=app_key,
                                                  data=None)

        # Logout
        logout = util.Authentication()
        logout_result = logout.logout(url=url,
                                      username=username,
                                      password=password,
                                      auth_type=auth_type,
                                      access_key=access_key,
                                      secret_key=secret_key,
                                      app_id=app_id,
                                      app_key=app_key)

        try:
            # Test for logout fail
            if logout_result['fail']:
                self.logger.error(logout_result['fail'])
                try:
                    raise Exception(
                        'Could not log out. Contact support for help. Status code is {}, see log for details'
                        .format(response['meta']['status']))
                except KeyError:
                    self.logger.error(response)
                    raise Exception(
                        'Unknown error. The Mimecast server did not respond correctly, see log for details.'
                    )

        except KeyError:
            # Unknown key error
            self.logger.error(logout_result)
            raise Exception(
                'An unhandled error response was received from the Mimecast server. Response: {}'
                .format(logout_result))

        # Create filter dictionary
        filter_ = {}
        for key, value in params.items():
            temp = util.normalize(key, value)
            filter_.update(temp)

        data = response['data']
        # Create filtered list
        for item in filter_:
            data[:] = [d for d in data if d.get(item) == filter_[item]]

        return {'response': data}
Exemplo n.º 6
0
    def run(self, params={}):
        # Import variables from connection
        url = self.connection.url
        username = self.connection.username
        password = self.connection.password
        access_key = self.connection.access_key
        secret_key = self.connection.secret_key
        app_id = self.connection.app_id
        app_key = self.connection.app_key
        auth_type = self.connection.auth_type

        # Generate payload dictionary
        data = {}
        for key, value in params.items():
            temp = util.normalize(key, value)
            data.update(temp)

        # Mimecast request
        mimecast_request = util.MimecastRequests()
        response = mimecast_request.mimecast_post(url=url,
                                                  uri=PermitOrBlockSender._URI,
                                                  username=username,
                                                  password=password,
                                                  auth_type=auth_type,
                                                  access_key=access_key,
                                                  secret_key=secret_key,
                                                  app_id=app_id,
                                                  app_key=app_key,
                                                  data=data)

        # Logout
        logout = util.Authentication()
        logout_result = logout.logout(url=url,
                                      username=username,
                                      password=password,
                                      auth_type=auth_type,
                                      access_key=access_key,
                                      secret_key=secret_key,
                                      app_id=app_id,
                                      app_key=app_key)

        try:
            # Test for logout fail
            if logout_result['fail']:
                self.logger.error(logout_result['fail'])
                try:
                    raise Exception(
                        'Could not log out. Contact support for help. Status code is {}, see log for details'
                        .format(response['meta']['status']))
                except KeyError:
                    self.logger.error(response)
                    raise Exception(
                        'Unknown error. The Mimecast server did not respond correctly, see log for details.'
                    )

        except KeyError:
            # Unknown key error
            self.logger.error(logout_result)
            raise Exception(
                'Unknown error. The Mimecast server did not respond correctly, see log for details.'
            )

        return {Output.RESPONSE: response['data']}
Exemplo n.º 7
0
    def run(self, params={}):
        # Import variables from connection
        url = self.connection.url
        username = self.connection.username
        password = self.connection.password
        access_key = self.connection.access_key
        secret_key = self.connection.secret_key
        app_id = self.connection.app_id
        app_key = self.connection.app_key
        auth_type = self.connection.auth_type

        source_ips = params.get(Input.SOURCE_IPS)
        option = params.get(Input.OPTION)

        data = {'option': option}

        # Generate policy dictionary
        policy = {}
        for key, value in params.items():
            temp = util.normalize(key, value)
            policy.update(temp)

        # Remove source_ips and option from policy as they should not be directly in that dictionary
        if params.get(Input.SOURCE_IPS):
            del policy['sourceIps']
        del policy['option']

        # Transform source_ips from comma delimited string to list
        if params.get(Input.SOURCE_IPS):
            source_ips = source_ips.split(',')

        # Add conditions dic to policy
        if source_ips:
            policy['conditions'] = {'sourceIPs': source_ips}

        # Add policy to data
        data['policy'] = policy

        # Mimecast request
        mimecast_request = util.MimecastRequests()
        response = mimecast_request.mimecast_post(
            url=url,
            uri=CreateBlockedSenderPolicy._URI,
            username=username,
            password=password,
            auth_type=auth_type,
            access_key=access_key,
            secret_key=secret_key,
            app_id=app_id,
            app_key=app_key,
            data=data)

        # Logout
        logout = util.Authentication()
        logout_result = logout.logout(url=url,
                                      username=username,
                                      password=password,
                                      auth_type=auth_type,
                                      access_key=access_key,
                                      secret_key=secret_key,
                                      app_id=app_id,
                                      app_key=app_key)

        try:
            # Test for logout fail
            if logout_result['fail']:
                self.logger.error(logout_result['fail'])
                try:
                    raise Exception(
                        'Could not log out. Contact support for help. Status code is {}, see log for details'
                        .format(response['meta']['status']))
                except KeyError:
                    self.logger.error(response)
                    raise Exception(
                        'Unknown error. The Mimecast server did not respond correctly, see log for details.'
                    )

        except KeyError:
            # Unknown key error
            self.logger.error(logout_result)
            raise Exception(
                'Unknown error. The Mimecast server did not respond correctly, see log for details.'
            )

        return {Output.SENDER_POLICY: response['data']}