Esempio n. 1
0
 def notify_g(cls, name, handlers = None, arguments = {}):
     logger = appier.get_logger()
     logger.debug("Triggering '%s' event ..." % name)
     kwargs = dict(name = name)
     if handlers: kwargs["handler"] = {"$in" : handlers}
     events = cls.find(**kwargs)
     for event in events: event.notify(arguments = arguments)
Esempio n. 2
0
    def setup(cls):
        super(Account, cls).setup()

        # tries to find the root account (default) in case it's not
        # found returns immediately nothing to be done
        root = cls.find(username="******")
        if root: return

        # retrieves the reference to the global logger that is going
        # to be used (should be initialized) and then prints the initial
        # information about the account to be generated
        logger = appier.get_logger()
        logger.info("Generating initial root account for %s model ..." %
                    cls.__name__)

        # creates the structure to be used as the root account description
        # using the default value and then stores the account as it's going
        # to be used as the default root entity (for administration)
        account = cls(enabled=True,
                      username=cls.ROOT_USERNAME,
                      email=cls.ROOT_EMAIL,
                      password=cls.generate(cls.ROOT_PASSWORD),
                      type=cls.ADMIN_TYPE)
        account.save(validate=False)

        # tries to retrieve the newly generated account with no rules and then
        # uses it to print information about the newly created account
        account = cls.get(id=account.id, rules=False)
        logger.info("Username: %s" % account.username)
        logger.info("Password: %s" % cls.ROOT_PASSWORD)
        logger.info("Secret Key: %s" % account.key)
Esempio n. 3
0
 def notify_http(self, arguments = {}):
     cls = self.__class__
     url = arguments.get("url", None)
     retries = arguments.get("retries", 3)
     logger = appier.get_logger()
     logger.debug("Running HTTP notification for '%s' ..." % url)
     return cls._retry(lambda: appier.post(url, data_j = arguments), count = retries)
Esempio n. 4
0
    def setup(cls):
        super(Account, cls).setup()

        # tries to find the root account (default) in case it's not
        # found returns immediately nothing to be done
        root = cls.find(username = "******")
        if root: return

        # retrieves the reference to the global logger that is going
        # to be used (should be initialized) and then prints the initial
        # information about the account to be generated
        logger = appier.get_logger()
        logger.info("Generating initial root account for %s model ..." % cls.__name__)

        # creates the structure to be used as the root account description
        # using the default value and then stores the account as it's going
        # to be used as the default root entity (for administration)
        account = cls(
            enabled = True,
            username = cls.ROOT_USERNAME,
            email = cls.ROOT_EMAIL,
            password = cls.generate(cls.ROOT_PASSWORD),
            type = cls.ADMIN_TYPE
        )
        account.save(validate = False)

        # tries to retrieve the newly generated account with no rules and then
        # uses it to print information about the newly created account
        account = cls.get(id = account.id, rules = False)
        logger.info("Username: %s" % account.username)
        logger.info("Password: %s" % cls.ROOT_PASSWORD)
        logger.info("Secret Key: %s" % account.key)
Esempio n. 5
0
 def notify_g(cls, name, handlers=None, arguments={}):
     logger = appier.get_logger()
     logger.debug("Triggering '%s' event ..." % name)
     kwargs = dict(name=name)
     if handlers: kwargs["handler"] = {"$in": handlers}
     events = cls.find_e(**kwargs)
     for event in events:
         event.notify(arguments=arguments)
Esempio n. 6
0
 def notify_http(self, arguments={}):
     cls = self.__class__
     url = arguments.get("url", None)
     retries = arguments.get("retries", 3)
     logger = appier.get_logger()
     logger.debug("Running HTTP notification for '%s' ..." % url)
     return cls._retry(lambda: appier.post(url, data_j=arguments),
                       count=retries)
Esempio n. 7
0
 def notify_mailme(self, arguments={}):
     cls = self.__class__
     appier.ensure_pip("mailme", package="mailme_api")
     import mailme
     retries = arguments.get("retries", 3)
     logger = appier.get_logger()
     logger.debug("Running Mailme notification ...")
     api = mailme.API()
     return cls._retry(lambda: api.send(arguments), count=retries)
Esempio n. 8
0
 def notify_mailme(self, arguments = {}):
     cls = self.__class__
     appier.ensure_pip("mailme", package = "mailme_api")
     import mailme
     retries = arguments.get("retries", 3)
     logger = appier.get_logger()
     logger.debug("Running Mailme notification ...")
     api = mailme.API()
     return cls._retry(lambda: api.send(arguments), count = retries)
Esempio n. 9
0
 def notify_g(cls, name, handlers=None, permutations=True, arguments={}):
     logger = appier.get_logger()
     logger.debug("Triggering '%s' event ..." % name)
     if permutations: names = cls._get_permutations(name)
     else: names = (name, )
     kwargs = dict()
     kwargs["name"] = {"$in": names}
     if handlers: kwargs["handler"] = {"$in": handlers}
     events = cls.find_e(**kwargs)
     for event in events:
         event.name = name
         event.notify(arguments=arguments)
Esempio n. 10
0
 def notify_nexmo(self, arguments = {}):
     cls = self.__class__
     appier.ensure_pip("nexmo", package = "nexmo_api")
     import nexmo
     sender = arguments["sender"]
     receiver = arguments["receiver"]
     text = arguments["text"]
     retries = arguments.get("retries", 3)
     logger = appier.get_logger()
     logger.debug("Running Nexmo notification for '%s' ..." % receiver)
     api = nexmo.API()
     return cls._retry(lambda: api.send_sms(sender, receiver, text), count = retries)
Esempio n. 11
0
 def notify_nexmo(self, arguments={}):
     cls = self.__class__
     appier.ensure_pip("nexmo", package="nexmo_api")
     import nexmo
     sender = arguments["sender"]
     receiver = arguments["receiver"]
     text = arguments["text"]
     retries = arguments.get("retries", 3)
     logger = appier.get_logger()
     logger.debug("Running Nexmo notification for '%s' ..." % receiver)
     api = nexmo.API()
     return cls._retry(lambda: api.send_sms(sender, receiver, text),
                       count=retries)
Esempio n. 12
0
 def notify(self, arguments = {}, delay = True, owner = None):
     delay_s = ("a delayed" if delay else "an immediate")
     logger = appier.get_logger()
     logger.debug(
         "Notifying handler '%s' for '%s' in %s fashion ..." %\
         (self.handler, self.name, delay_s)
     )
     owner = owner or appier.get_app()
     method = getattr(self, "notify_" + self.handler)
     arguments_m = dict(self.arguments)
     arguments_m.update(arguments)
     arguments_m.update(event = self.name, handler = self.handler)
     kwargs = dict(arguments = arguments_m)
     if delay: owner.delay(method, kwargs = kwargs)
     else: method(arguments, **kwargs)
Esempio n. 13
0
 def notify(self, arguments={}, delay=True):
     cls = self.__class__
     delay_s = "a delayed" if delay else "an immediate"
     logger = appier.get_logger()
     logger.debug(
         "Notifying handler '%s' for '%s' in %s fashion ..." %\
         (self.handler, self.name, delay_s)
     )
     method = getattr(self, "notify_" + self.handler)
     arguments_m = dict(self.arguments)
     arguments_m.update(arguments)
     arguments_m.update(event=self.name, handler=self.handler)
     arguments_m = cls.transform(arguments_m, self.handler + "_")
     arguments_m = cls.format(arguments_m)
     kwargs = dict(arguments=arguments_m)
     if delay: self.owner.delay(method, kwargs=kwargs)
     else: method(**kwargs)
Esempio n. 14
0
 def notify(self, arguments = {}, delay = True):
     cls = self.__class__
     delay_s = ("a delayed" if delay else "an immediate")
     logger = appier.get_logger()
     logger.debug(
         "Notifying handler '%s' for '%s' in %s fashion ..." %\
         (self.handler, self.name, delay_s)
     )
     method = getattr(self, "notify_" + self.handler)
     arguments_m = dict(self.arguments)
     arguments_m.update(arguments)
     arguments_m.update(event = self.name, handler = self.handler)
     arguments_m = cls.transform(arguments_m, self.handler + "_")
     arguments_m = cls.format(arguments_m)
     kwargs = dict(arguments = arguments_m)
     if delay: self.owner.delay(method, kwargs = kwargs)
     else: method(**kwargs)
Esempio n. 15
0
    def setup(cls):
        super(Role, cls).setup()

        # tries to find the owner role (default) in case it's not
        # found returns immediately nothing to be done
        owner = cls.find(name="owner")
        if owner: return

        # retrieves the reference to the global logger that is going
        # to be used (should be initialized) and then prints the initial
        # information about the role to be generated
        logger = appier.get_logger()
        logger.info("Generating initial owner role for %s model ..." %
                    cls.__name__)

        # creates the structure to be used as the owner role description
        # using the default value and then stores the role
        role = cls(name="owner",
                   description="Super administrator role",
                   tokens=["*"])
        role.save(validate=False)
Esempio n. 16
0
 def notify_mailme(self, arguments = {}):
     import mailme
     logger = appier.get_logger()
     logger.debug("Running Mailme notification ...")
     api = mailme.Api()
     return api.send(arguments)
Esempio n. 17
0
 def notify_http(self, arguments = {}):
     url = arguments.get("url", None)
     logger = appier.get_logger()
     logger.debug("Running HTTP notification for '%s' ..." % url)
     return appier.post(url, data_j = arguments)