Ejemplo n.º 1
0
 def __init__(self, name=None, device=None):
     # The parent app constructor looks for a device configuration and returns that as a
     # dictionary called self.config
     App.__init__(self, name, device)
     self.introMessage = {"message": "Quote App"}
     self.baseUrl = "http://quotes.rest/qod.json?category=inspire"
     self.s = requests.Session()
Ejemplo n.º 2
0
 def __init__(self, name=None, device=None):
     App.__init__(self, name, device)  # Required to call superconstructor
     self.headers = {
         "Authorization":
         "Bearer {0}".format(self.get_device().get_password())
     }
     self.name = self.get_device().username
     self.base_url = 'https://api.lifx.com/v1/lights/'
Ejemplo n.º 3
0
 def __init__(self, name=None, device=None):
     App.__init__(self, name, device)
     self.device = self.get_device()
     self.service = client.connect(host=self.device.ip,
                                   port=self.device.port,
                                   username=self.device.username,
                                   password=self.device.get_password())
     self.kwargs_create = {}
     self.kwargs_results = {"output_mode": "json"}
Ejemplo n.º 4
0
 def __init__(self, name, device, context):
     App.__init__(self, name, device, context)
     self.base_url = 'https://%s:%s/api/v1/' % (
         self.device_fields['staxx_address'],
         self.device_fields['staxx_port'])
     self.headers = {'content-type': 'application/json'}
     self.staxx_username = self.device_fields['username']
     self.staxx_password = self.device.get_encrypted_field('password')
     self.verify_certificate = self.device_fields['verify_certificate']
Ejemplo n.º 5
0
 def __init__(self, name=None, device=None):
     App.__init__(self, name, device)
     self.service = client.connect(
         host=self.device_fields['ip'],
         port=self.device_fields['port'],
         username=self.device_fields['username'],
         password=self.device.get_encrypted_field('password'))
     self.kwargs_create = {}
     self.kwargs_results = {"output_mode": "json"}
Ejemplo n.º 6
0
    def __init__(self, name, device, context):
        App.__init__(self, name, device,
                     context)  # Required to call superconstructor
        self.headers = {
            "Authorization":
            "Bearer {0}".format(self.device.get_encrypted_field('token'))
        }
        self.name = device

        self.base_url = 'https://api.lifx.com/v1/lights'
Ejemplo n.º 7
0
    def __init__(self, name=None, device=None):
        App.__init__(self, name, device)

        self.connection = teslajson.Connection(self.device_fields['username'],
                                               self.device.get_encrypted_field('password'))

        try:
            self.vehicle = self.connection.vehicles[0]
        except IndexError:
            logger.error('This account has no tesla vehicles')
Ejemplo n.º 8
0
    def __init__(self, name=None, device=None):
        App.__init__(self, name, device)

        self.username = self.device_fields["username"]
        self.options = {}

        if self.device_fields["transport"] != "plaintext":
            self.options["transport"] = self.device_fields["transport"]

        if self.device_fields["server_cert_validation"] != "validate":
            self.options["server_cert_validation"] = self.device_fields["server_cert_validation"]

        if self.device_fields["message_encryption"] != "auto":
            self.options["message_encryption"] = self.device_fields["message_encryption"]

        if self.device_fields["read_timeout_sec"] not in (None, 30):
            self.options["read_timeout_sec"] = self.device_fields["read_timeout_sec"]

        if self.device_fields["operation_timeout_sec"] not in (None, 20):
            self.options["operation_timeout_sec"] = self.device_fields["operation_timeout_sec"]

        if self.options.get("read_timeout_sec", 30) <= self.options.get("operation_timeout_sec", 20):
            self.options["read_timeout_sec"] = self.options.get("operation_timeout_sec", 20) + 10

        if self.device_fields["keytab"] not in (None, ""):
            self.options["keytab"] = self.device_fields["keytab"]

        if self.device_fields["ca_trust_path"] not in (None, ""):
            self.options["ca_trust_path"] = self.device_fields["ca_trust_path"]

        if self.device_fields["cert_pem"] not in (None, ""):
            self.options["cert_pem"] = self.device_fields["cert_pem"]

        if self.device_fields["cert_key_pem"] not in (None, ""):
            self.options["cert_key_pem"] = self.device_fields["cert_key_pem"]

        if self.device_fields["kerberos_delegation"]:
            self.options["kerberos_delegation"] = True

        if self.device_fields["kerberos_hostname_override"] not in (None, ""):
            self.options["kerberos_hostname_override"] = self.device_fields["kerberos_hostname_override"]

        logger.info("Options: {}".format(self.options))

        self.timestamp = None

        if self.device_type == "Remote PowerShell Host":
            self.host = self.device_fields["host"]
            if self.device_fields["port"] is not None:
                self.host += ":" + str(self.device_fields["port"])

            self.winrm = winrm.Session(self.host,
                                       auth=(self.username,
                                             self.device.get_encrypted_field("password")),
                                       **self.options)
Ejemplo n.º 9
0
    def __init__(self, name=None, device=None):
        App.__init__(self, name, device)
        device = self.get_device()

        self.connection = teslajson.Connection(device.username,
                                               device.get_password())

        try:
            self.vehicle = self.connection.vehicles[0]
        except IndexError:
            logger.error('This account has no tesla vehicles')
Ejemplo n.º 10
0
 def __init__(self, name=None, device=None):
     App.__init__(self, name, device)
     self.is_connected = False
     self.headers = None
     self.refresh_token = None
     self.username = self.device_fields['username']
     self.walkoff_address = self.device_fields['ip']
     port = self.device_fields['port']
     if port:
         self.walkoff_address += ':{}'.format(port)
     self.is_https = self.walkoff_address.startswith('https')
Ejemplo n.º 11
0
 def __init__(self, name=None, device=None):
     App.__init__(self, name, device)
     device = self.get_device()
     if device is None:
         self.ip = ""
         self.username = ""
     else:
         self.ip = device.ip
         self.username = device.username
     self.baseURL = "http://" + self.ip + "/api/" + self.username
     self.headers = {'content-type': 'application/json'}
Ejemplo n.º 12
0
    def __init__(self, name, device, context):
        App.__init__(self, name, device, context)

        self.ssh = paramiko.SSHClient()
        self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        self.ip = self.device_fields['ip']
        self.port = self.device_fields['port']
        self.username = self.device_fields['username']

        self.ssh.connect(self.ip, self.port, self.username,
                         self.device.get_encrypted_field('password'))
Ejemplo n.º 13
0
 def __init__(self, name=None, device=None):
     App.__init__(self, name, device)
     self.is_connected = False
     self.headers = None
     self.refresh_token = None
     self.username = self.device_fields['username']
     self.is_https = self.device_fields['https']
     if self.is_https:
         self.walkoff_address = "https://"
     else:
         self.walkoff_address = "http://"
     self.walkoff_address += self.device_fields['ip']
     self.walkoff_address += ':{}'.format(self.device_fields['port'])
Ejemplo n.º 14
0
    def __init__(self, name=None, device=None):
        App.__init__(self, name, device)
        self.server = smtplib.SMTP('{0}:{1}'.format(self.device_fields['ip'], self.device_fields['port']))

        try:
            self.server.set_debuglevel(False)
            self.server.ehlo()
            if self.server.has_extn('STARTTLS'):
                self.server.starttls()
                self.server.ehlo()  # re-identify ourselves over TLS connection
            self.server.login(self.device_fields['username'], self.device.get_encrypted_field('password'))
        except Exception as e:
            self.shutdown()
Ejemplo n.º 15
0
 def __init__(self, name, device, context):
     App.__init__(self, name, device, context)
     self.is_connected = False
     self.headers = None
     self.refresh_token = None
     self.username = self.device_fields['username']
     self.is_https = self.device_fields['https']
     if self.is_https:
         self.walkoff_address = "https://"
     else:
         self.walkoff_address = "http://"
     self.walkoff_address += self.device_fields['ip']
     self.walkoff_address += ':{}'.format(self.device_fields['port'])
Ejemplo n.º 16
0
 def test_getattr_gets_from_cache(self):
     workflow_id = uuid4()
     context = {'workflow_execution_id': workflow_id}
     app = AppBase('Something', self.device2.id, context)
     app._cache = self.cache
     app.foo = 42
     app.bar = 23
     self.cache.set(app._format_cache_key('foo'), dill.dumps('a'))
     self.cache.set(app._format_cache_key('bar'), dill.dumps('b'))
     self.assertEqual(app.foo, 'a')
     self.assertEqual(app.bar, 'b')
     with self.assertRaises(AttributeError):
         y = app.baz
Ejemplo n.º 17
0
 def test_getattr_gets_from_cache(self):
     workflow_id = uuid4()
     context = {'workflow_execution_id': workflow_id}
     app = AppBase('Something', self.device2.id, context)
     app._cache = self.cache
     app.foo = 42
     app.bar = 23
     self.cache.set(app._format_cache_key('foo'), dill.dumps('a'))
     self.cache.set(app._format_cache_key('bar'), dill.dumps('b'))
     self.assertEqual(app.foo, 'a')
     self.assertEqual(app.bar, 'b')
     with self.assertRaises(AttributeError):
         y = app.baz
Ejemplo n.º 18
0
 def POST(self, auth_user=None, auth_app_id=None):
     '''
 Create a new app and return a JSON object containing the new
 app information.
 '''
     params = web.input(data=None)
     try:
         if params.data:
             data = decode_json(params.data)
         else:
             data = decode_json(web.ctx.data)
         App.validate(data)
     except Exception, e:
         logging.error(e)
         return error_response(400, 'Data did not pass validation')
Ejemplo n.º 19
0
 def POST(self, auth_user=None, auth_app_id=None):
   '''
   Create a new app and return a JSON object containing the new
   app information.
   '''
   params = web.input(data=None)
   try:
     if params.data:
       data = decode_json(params.data)
     else:
       data = decode_json(web.ctx.data)
     App.validate(data)
   except Exception, e:
     logging.error(e)
     return error_response(400, 'Data did not pass validation')
Ejemplo n.º 20
0
 def __init__(self, name, device, context):
     App.__init__(self, name, device, context)
     self.base_url = 'https://www.virustotal.com/vtapi/v2/'
     self.proxy = None
     if (self.device_fields['proxy_address']
             and self.device_fields['proxy_port']):
         self.proxy = {
             'http':
             'http://%s:%s' % (self.device_fields['proxy_address'],
                               self.device_fields['proxy_port']),
             'https':
             'https://%s:%s' % (self.device_fields['proxy_address'],
                                self.device_fields['proxy_port']),
         }
     self.api_key = self.device.get_encrypted_field('api_key')
Ejemplo n.º 21
0
 def test_reset_context(self):
     workflow_id1 = uuid4()
     context1 = {'workflow_execution_id': workflow_id1}
     app1 = AppBase('Something', self.device2.id, context1)
     app1._cache = self.cache
     workflow_id2 = uuid4()
     context2 = {'workflow_execution_id': workflow_id2}
     app2 = AppBase('Something', self.device2.id, context2)
     app2._cache = self.cache
     app1.foo = 42
     app1.bar = 'abc'
     app2.foo = 43
     app2.bar = 'def'
     app1._reset_context(context2)
     self.assertEqual(app1.foo, 43)
     self.assertEqual(app1.bar, 'def')
Ejemplo n.º 22
0
    def __init__(self, name=None, device=None):
        App.__init__(self, name, device)
        self._device = self.get_device()
        self.server = smtplib.SMTP('{0}:{1}'.format(self._device.ip,
                                                    self._device.port))

        try:
            self.server.set_debuglevel(False)
            self.server.ehlo()
            if self.server.has_extn('STARTTLS'):
                self.server.starttls()
                self.server.ehlo()  # re-identify ourselves over TLS connection
            self.server.login(self._device.username,
                              self._device.get_password())
        except Exception as e:
            self.shutdown()
Ejemplo n.º 23
0
 def test_reset_context(self):
     workflow_id1 = uuid4()
     context1 = {'workflow_execution_id': workflow_id1}
     app1 = AppBase('Something', self.device2.id, context1)
     app1._cache = self.cache
     workflow_id2 = uuid4()
     context2 = {'workflow_execution_id': workflow_id2}
     app2 = AppBase('Something', self.device2.id, context2)
     app2._cache = self.cache
     app1.foo = 42
     app1.bar = 'abc'
     app2.foo = 43
     app2.bar = 'def'
     app1._reset_context(context2)
     self.assertEqual(app1.foo, 43)
     self.assertEqual(app1.bar, 'def')
Ejemplo n.º 24
0
    def __init__(self, name=None, device=None):
        # The parent app constructor looks for a device configuration and returns that as a dict called self.config
        App.__init__(self, name, device)

        device = self.get_device()
        if device is None:
            self.ip = "127.0.0.1"
            self.port = 22
            self.username = ""
            password = ""

        else:
            self.ip = device.ip
            self.port = device.port
            self.username = device.username
            password = device.password
Ejemplo n.º 25
0
 def __init__(self, name=None, device=None):
     App.__init__(self, name, device)
     self.host = "{}:{}".format(self.device_fields["host"],
                                self.device_fields["port"])
     if self.device_fields["https"]:
         self.host = "https://" + self.host
     self.username = self.device_fields["username"]
     self.insecure_mode = {}
     if self.device_fields["very_insecure_mode_testing_only"]:
         self.insecure_mode = {
             "transport": "ntlm",
             "server_cert_validation": "ignore"
         }
     self.winrm = winrm.Session(
         self.host,
         auth=(self.username, self.device.get_encrypted_field("password")),
         **self.insecure_mode)
Ejemplo n.º 26
0
    def __init__(self, name='', device=''):
        App.__init__(self, name, device)

        self.ssh = paramiko.SSHClient()
        self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        device = self.get_device()
        if device is None:
            self.ip = ""
            self.port = 22
            self.username = ""
            password = ""
        else:
            self.ip = device.ip
            self.port = device.port
            self.username = device.username
            password = device.password

        self.ssh.connect(self.ip, self.port, self.username, password)
Ejemplo n.º 27
0
 def create_device(self, workflow_context, device_id):
     workflow_exec_id = workflow_context['workflow_execution_id']
     logger.info('Creating app instance for workflow {}, device {}'.format(workflow_exec_id, device_id))
     redis_key = ActionExecution.format_app_instance_key(workflow_exec_id, device_id)
     app_class = get_app(app_name)
     if not redis_cache.cache.sismember(app_instance_set_name, redis_key):
         # If workflows become parallelized, this will need to be locked
         logger.info('Creating new app instance')
         app_instance = app_class(app_name, device_id, workflow_context)
         redis_cache.cache.sadd(app_instance_set_name, redis_key)
         return app_instance
     else:
         logger.debug('Using existing app instance')
         return App.from_cache(app_name, device_id, workflow_context)
Ejemplo n.º 28
0
 def test_setattr_syncs_to_cache(self):
     workflow_id = uuid4()
     context = {'workflow_execution_id': workflow_id}
     app = AppBase('Something', self.device2.id, context)
     app._cache = self.cache
     app.foo = 42
     app.bar = 23
     self.assertSetEqual(
         set(self.cache.scan()),
         {app._format_cache_key('foo'), app._format_cache_key('bar')}
     )
     for field, expected in (('foo', 42), ('bar', 23)):
         self.assertEqual(dill.loads(self.cache.get(app._format_cache_key(field))), expected)
Ejemplo n.º 29
0
 def test_setattr_syncs_to_cache(self):
     workflow_id = uuid4()
     context = {'workflow_execution_id': workflow_id}
     app = AppBase('Something', self.device2.id, context)
     app._cache = self.cache
     app.foo = 42
     app.bar = 23
     self.assertSetEqual(
         set(self.cache.scan()),
         {app._format_cache_key('foo'),
          app._format_cache_key('bar')})
     for field, expected in (('foo', 42), ('bar', 23)):
         self.assertEqual(
             dill.loads(self.cache.get(app._format_cache_key(field))),
             expected)
Ejemplo n.º 30
0
 def test_get_all_devices(self):
     app = AppBase(self.test_app_name, self.device2.id, {})
     devices = app.get_all_devices()
     self.assertIn(self.device1, devices)
     self.assertIn(self.device2, devices)
Ejemplo n.º 31
0
 def __init__(self, app_name, device, context):
     App.__init__(self, app_name, device, context)  # Required to call superconstructor
Ejemplo n.º 32
0
 def __init__(self, name=None, device=None):
     self.is_running = False
     App.__init__(self, name, device)
Ejemplo n.º 33
0
 def __init__(self, app_name, device, context):
     App.__init__(self, app_name, device, context)
     self.introMessage = {"message": "Quote App"}
     self.baseUrl = "http://quotes.rest/qod.json?category=inspire"
     self.s = requests.Session()
Ejemplo n.º 34
0
 def test_get_all_devices_invalid_app(self):
     app = AppBase('Invalid', self.device2.id)
     self.assertListEqual(app.get_all_devices(), [])
Ejemplo n.º 35
0
Archivo: demo.py Proyecto: a1eko/lampy
#!/usr/bin/python

from apps import App
import physics
import scene

app = App("demo", scene.Demo(), physics.Demo())
app.run()

Ejemplo n.º 36
0
 def __init__(self, name=None, device=None):
     App.__init__(self, name, device)
     self.h = self.device_fields['host']
     self.u = self.device_fields['username']
     self.p = self.device_fields['port']
Ejemplo n.º 37
0
    Create a new app and return a JSON object containing the new
    app information.
    '''
    params = web.input(data=None)
    try:
      if params.data:
        data = decode_json(params.data)
      else:
        data = decode_json(web.ctx.data)
      App.validate(data)
    except Exception, e:
      logging.error(e)
      return error_response(400, 'Data did not pass validation')

    try:
      app = App(data)
      app.set_creator(auth_user)
      app.save()
      formatted_dict = app.formatted_dict()
      return encode_json(formatted_dict)
    except Exception, e:
      logging.error(e)
      return error_response(500)


class AppHandler(object):
  '''
  Handler for retrieving information about a specific app. Also
  allows app information to be updated, or for an app to be deleted. Only
  the creator can access and modify the app information.
  '''
Ejemplo n.º 38
0
 def __init__(self, name=None, device=None):
     App.__init__(self, name, device)
     self.whitelist = []
     self.blacklist = []
Ejemplo n.º 39
0
 def __init__(self, name, device, context):
     App.__init__(self, name, device, context)
     self.introMessage = {"message": "HELLO WORLD"}
Ejemplo n.º 40
0
 def __init__(self, name=None, device=None):
     self.curDirPath = os.path.dirname(os.path.realpath(__file__))
     self.greeting = "No greeting provided"
     self.totalNodes = "2"
     App.__init__(self, name, device)
Ejemplo n.º 41
0
 def test_get_all_devices_invalid_app(self):
     app = AppBase('Invalid', self.device2.id, {})
     self.assertListEqual(app.get_all_devices(), [])
Ejemplo n.º 42
0
 def __init__(self, app_name, device, context):
     App.__init__(self, app_name, device,
                  context)  # Required to call superconstructor
Ejemplo n.º 43
0
 def test_get_all_devices(self):
     app = AppBase(self.test_app_name, self.device2.id)
     devices = app.get_all_devices()
     self.assertIn(self.device1, devices)
     self.assertIn(self.device2, devices)