Ejemplo n.º 1
0
def test_write_config(cleandir):
    config = Config()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    cm = ConfigManager()
    cm._write_config_py(config)
    assert 'client_config.py' in os.listdir(os.getcwd())
Ejemplo n.º 2
0
def test_write_config(cleandir):
    config = Config()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    cm = ConfigManager()
    cm.write_config_py(config)
    assert 'client_config.py' in os.listdir(os.getcwd())
Ejemplo n.º 3
0
 def test_init(self):
     data_dir = os.getcwd()
     t_config = TConfig()
     t_config.DATA_DIR = data_dir
     config = Config()
     config.from_object(t_config)
     p = PackageHandler(config)
     assert p.files_dir == os.path.join(data_dir, user_data_dir, "files")
     assert p.deploy_dir == os.path.join(data_dir, user_data_dir, "deploy")
Ejemplo n.º 4
0
 def test_process_packages(self):
     data_dir = os.getcwd()
     t_config = TConfig()
     t_config.DATA_DIR = data_dir
     t_config.UPDATE_PATCHES = False
     config = Config()
     config.from_object(t_config)
     p = PackageHandler(config)
     p.process_packages()
 def test_init(self):
     data_dir = os.getcwd()
     t_config = TConfig()
     t_config.DATA_DIR = data_dir
     config = Config()
     config.from_object(t_config)
     p = PackageHandler(config)
     assert p.files_dir == os.path.join(data_dir, s_dir, 'files')
     assert p.deploy_dir == os.path.join(data_dir, s_dir, 'deploy')
 def test_process_packages(self):
     data_dir = os.getcwd()
     t_config = TConfig()
     t_config.DATA_DIR = data_dir
     t_config.UPDATE_PATCHES = False
     config = Config()
     config.from_object(t_config)
     p = PackageHandler(config)
     p.process_packages()
Ejemplo n.º 7
0
    def init_app(self, obj, refresh=False, test=False):
        """Sets up client with config values from obj

        Args:

            obj (instance): config object

        Kwargs:

            refresh (bool) Meaning:

            True: Refresh update manifest on object initialization

            False: Don't refresh update manifest on object initialization

        """
        # Used to add missing required information
        # i.e. APP_NAME
        config = Config()
        config.from_object(obj)

        self.FROZEN = jms_utils.app.FROZEN
        # Grabbing config information
        update_urls = config.get('UPDATE_URLS')
        # Here we combine all urls & add trailing / if one isn't present
        self.update_urls = self._sanatize_update_url(update_urls)
        self.app_name = config.get('APP_NAME', 'PyUpdater')
        self.company_name = config.get('COMPANY_NAME', 'Digital Sapphire')
        if test:
            # Making platform deterministic for tests.
            # No need to test for other platforms at the moment
            self.data_dir = obj.DATA_DIR
            self.platform = 'mac'
        else:  # pragma: no cover
            # Getting platform specific application directory
            self.data_dir = appdirs.user_data_dir(self.app_name,
                                                  self.company_name,
                                                  roaming=True)
            # Setting the platform to pass when requesting updates
            self.platform = jms_utils.system.get_system()
        # Creating update folder. Using settings to ease change in future
        self.update_folder = os.path.join(self.data_dir,
                                          settings.UPDATE_FOLDER)
        # Attempting to sanitize incorrect inputs types
        self.root_key = config.get('PUBLIC_KEY', '')
        self.app_key = None

        # Config option to disable tls cert verification
        self.verify = config.get('VERIFY_SERVER_CERT', True)
        self.version_file = settings.VERSION_FILE
        self.key_file = settings.KEY_FILE

        self._setup()
        if refresh is True:
            self.refresh()
Ejemplo n.º 8
0
    def test_plugin_config(self):

        class TPlugin(object):
            name = 'test'
            author = 'test1'
            bucket = ''

            def init_config(self, config):
                self.bucket = config.get("bucket", "bad")

        master_config = Config()

        master_config['PLUGIN_CONFIGS'] = {
            "test-test1": {
                "bucket": "test_bucket"
            }
        }

        pm = PluginManager(master_config, plugins=[TPlugin()])

        p = pm.get_plugin('test', False)
        assert p.bucket == ''

        p = pm.get_plugin('test', True)
        assert p.bucket == 'test_bucket'
Ejemplo n.º 9
0
    def test_uploader(self, cleandir, shared_datadir, upload_plugin_type):

        uploaders = [
            TestUploaderPass(),
            TestUploaderFail(),
            TestUploaderRetryPass(),
            TestUploaderRetryFail(),
        ]

        # Don't mind the name, should only contain 1 plugin
        upload_plugins = [u for u in uploaders if u.name == upload_plugin_type]

        if sys.version_info[1] == 5:
            data_dir = str(shared_datadir)
        else:
            data_dir = shared_datadir

        if not os.path.exists(data_dir):
            os.makedirs(data_dir)

        with ChDir(data_dir):
            uploader = Uploader(config=Config(), plugins=upload_plugins)

            upload_plugin = upload_plugins[0]

            uploader.set_uploader(upload_plugin_type)
            assert uploader.uploader.name == upload_plugin_type

            if "success" in upload_plugin.name:
                assert uploader.upload(["/file1"]) is True
            elif "fail" in upload_plugin.name:
                assert uploader.upload(["/file2"]) is False
Ejemplo n.º 10
0
    def test_plugin_manager_load(self, n, a):
        class Plugin(object):
            name = n
            author = a

        pm = PluginManager(Config(), plugins=[Plugin()])

        if isinstance(n, six.string_types) and isinstance(a, six.string_types):
            assert len(pm.plugins) == 1
        else:
            assert len(pm.plugins) == 0
Ejemplo n.º 11
0
def init():  # pragma: no cover
    if not os.path.exists(os.path.join(settings.CONFIG_DATA_FOLDER,
                          settings.CONFIG_FILE_USER)):
        config = Config()
        config = initial_setup(config)
        log.info('Creating pyu-data dir...')
        pyu = PyUpdater(config)
        pyu.setup()
        loader = Loader()
        loader.save_config(config)
        log.info('Setup complete')
    else:
        sys.exit('Not an empty PyUpdater repository')
Ejemplo n.º 12
0
    def test_plugin_unique_names(self):
        class Plugin1(object):
            name = "test"
            author = "test1"

        class Plugin2(object):
            name = "test"
            author = "test2"

        pm = PluginManager(Config(), plugins=[Plugin1(), Plugin2()])

        plugin_names = [n["name"] for n in pm.plugins]

        assert "test" in plugin_names
        assert "test2" in plugin_names
Ejemplo n.º 13
0
    def test_plugin_unique_names(self):

        class Plugin1(object):
            name = 'test'
            author = 'test1'

        class Plugin2(object):
            name = 'test'
            author = 'test2'

        pm = PluginManager(Config(), plugins=[Plugin1(), Plugin2()])

        plugin_names = [n['name'] for n in pm.plugins]

        assert 'test' in plugin_names
        assert 'test2' in plugin_names
Ejemplo n.º 14
0
def _cmd_init(*args):  # pragma: no cover
    if not os.path.exists(
            os.path.join(settings.CONFIG_DATA_FOLDER,
                         settings.CONFIG_FILE_USER)):
        # Load a basic config.
        config = Config()

        # Run config through all of the setup functions
        config = initial_setup(config)
        log.info('Creating pyu-data dir...')

        # Initialize PyUpdater with newly created config
        pyu = PyUpdater(config)

        # Setup repository
        pyu.setup()

        # Load config manager & save config to disk
        cm = ConfigManager()
        cm.save_config(config)
        log.info('Setup complete')
    else:
        log.error('Not an empty PyUpdater repository')
Ejemplo n.º 15
0
    def test_plugin_config(self):
        class TPlugin(object):
            name = "test"
            author = "test1"
            bucket = ""

            def init_config(self, config):
                self.bucket = config.get("bucket", "bad")

        master_config = Config()

        master_config["PLUGIN_CONFIGS"] = {
            "test-test1": {
                "bucket": "test_bucket"
            }
        }

        pm = PluginManager(master_config, plugins=[TPlugin()])

        p = pm.get_plugin("test", False)
        assert p.bucket == ""

        p = pm.get_plugin("test", True)
        assert p.bucket == "test_bucket"
Ejemplo n.º 16
0
class PyUpdater(object):
    """Processes, signs & uploads updates

        Kwargs:

            config (obj): config object
    """
    def __init__(self, config=None):
        self.config = Config()
        # Important to keep this before updating config
        if config is not None:
            self.update_config(config)

    def update_config(self, config):
        """Updates internal config

        Args:

            config (obj): config object
        """
        if not hasattr(config, "DATA_DIR"):
            config.DATA_DIR = None
        if config.DATA_DIR is None:
            config.DATA_DIR = os.getcwd()
        self.config.from_object(config)
        self._update(self.config)

    def _update(self, config):
        self.kh = KeyHandler()
        self.key_importer = KeyImporter()
        self.ph = PackageHandler(config)
        self.up = Uploader(config)

    def setup(self):
        """Sets up root dir with required PyUpdater folders"""
        self.ph.setup()

    def process_packages(self, report_errors=False):
        """Creates hash for updates & adds information about update to
        version file
        """
        self.ph.process_packages(report_errors)

    def set_uploader(self, requested_uploader, keep=False):
        """Sets upload destination

        Args:

            requested_uploader (str): upload service. i.e. s3, scp

            keep (bool): False to delete files after upload.
                         True to keep files. Default False.

        """
        self.up.set_uploader(requested_uploader, keep)

    def upload(self):
        """Uploads files in deploy folder"""
        return self.up.upload()

    def get_plugin_names(self):
        return self.up.get_plugin_names()

    def import_keypack(self):
        """Creates signing keys"""
        return self.key_importer.start()

    def sign_update(self, split_version):
        """Signs version file with signing key"""
        self.kh.sign_update(split_version)
Ejemplo n.º 17
0
def test_dev_config():
    config = Config()
    test_config = DevConfig()
    config.from_object(test_config)
    assert config['TESTING'] is True
Ejemplo n.º 18
0
def test_prod_bad_atter():
    config = Config()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    assert config.get('DEBUG', None) is not None
Ejemplo n.º 19
0
def test_prod_config():
    config = Config()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    assert config['MORE_INFO'] == 'Yes Please'
Ejemplo n.º 20
0
def test_dev_config_bad_attr():
    config = Config()
    test_config = DevConfig()
    config.from_object(test_config)
    assert config.get('BAD_ATTR', None) is None
Ejemplo n.º 21
0
def test_prod_config():
    config = Config()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    assert config['MORE_INFO'] == 'Yes Please'
Ejemplo n.º 22
0
 def __init__(self, config=None):
     self.config = Config()
     # Important to keep this before updating config
     if config is not None:
         self.update_config(config)
Ejemplo n.º 23
0
class PyUpdater(object):
    """Processes, signs & uploads updates

        Kwargs:

            config (obj): config object
    """
    def __init__(self, config=None):
        self.config = Config()
        # Important to keep this before updating config
        if config is not None:
            self.update_config(config)

    def update_config(self, config):
        """Updates internal config

        Args:

            config (obj): config object
        """
        if not hasattr(config, 'DATA_DIR'):
            config.DATA_DIR = None
        if config.DATA_DIR is None:
            config.DATA_DIR = os.getcwd()
        self.config.from_object(config)
        self._update(self.config)

    def _update(self, config):
        self.kh = KeyHandler()
        self.key_importer = KeyImporter()
        self.ph = PackageHandler(config)
        self.up = Uploader(config)

    def setup(self):
        "Sets up root dir with required PyUpdater folders"
        self.ph.setup()

    def process_packages(self, report_errors=False):
        """Creates hash for updates & adds information about update to
        version file
        """
        self.ph.process_packages(report_errors)

    def set_uploader(self, requested_uploader, keep=False):
        """Sets upload destination

        Args:

            requested_uploader (str): upload service. i.e. s3, scp
        """
        self.up.set_uploader(requested_uploader, keep)

    def upload(self):
        "Uploads files in deploy folder"
        self.up.upload()

    def get_plugin_names(self):
        return self.up.get_plugin_names()

    def import_keypack(self):
        "Creates signing keys"
        self.key_importer.start()

    def sign_update(self):
        "Signs version file with signing key"
        self.kh.sign_update()
Ejemplo n.º 24
0
    def test_default_plugin_detection_scp(self):
        pm = PluginManager(Config())

        plugin_names = [n["name"] for n in pm.plugins]
        assert "scp" in plugin_names
Ejemplo n.º 25
0
def test_prod_bad_atter():
    config = Config()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    assert config.get('DEBUG', None) is not None
Ejemplo n.º 26
0
def test_prod_config():
    config = Config()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    assert config["MORE_INFO"] == "Yes Please"
Ejemplo n.º 27
0
 def __init__(self, config=None):
     self.config = Config()
     # Important to keep this before updating config
     if config is not None:
         self.update_config(config)
Ejemplo n.º 28
0
def test_dev_config():
    config = Config()
    test_config = DevConfig()
    config.from_object(test_config)
    assert config['TESTING'] is True
Ejemplo n.º 29
0
def test_dev_config_bad_attr():
    config = Config()
    test_config = DevConfig()
    config.from_object(test_config)
    assert config.get('BAD_ATTR', None) is None
Ejemplo n.º 30
0
    def init_app(self, obj, refresh=False, test=False):
        """Sets up client with config values from obj

        Args:

            obj (instance): config object

        Kwargs:

            refresh (bool) Meaning:

            True: Refresh update manifest on object initialization

            False: Don't refresh update manifest on object initialization

        """

        # A super dict used to save config info & be dot accessed
        config = Config()
        config.from_object(obj)

        # Boolean: If executing frozen
        self.FROZEN = dsdev_utils.app.FROZEN

        # Grabbing config information
        update_urls = config.get('UPDATE_URLS', [])

        # List of URL to check for update data
        self.update_urls = self._sanatize_update_url(update_urls)

        # Name of the running application
        self.app_name = config.get('APP_NAME', 'PyUpdater')

        # Name of the app author
        self.company_name = config.get('COMPANY_NAME', 'Digital Sapphire')

        # Used in testing to force use of the mac archive
        if test:
            # Making platform deterministic for tests.
            self.data_dir = obj.DATA_DIR
            self.platform = 'mac'
        else:  # pragma: no cover
            # Getting platform specific user data directory
            self.data_dir = appdirs.user_data_dir(self.app_name,
                                                  self.company_name)

            # Used when parsing the update manifest
            self.platform = dsdev_utils.system.get_system()

        # Folder to house update archives
        self.update_folder = os.path.join(self.data_dir,
                                          settings.UPDATE_FOLDER)

        # The root public key to verify the app signing private key
        self.root_key = config.get('PUBLIC_KEY', '')

        # We'll get the app_key later in _get_signing_key
        # That's if we verify the keys manifest
        self.app_key = None

        # Used to disable TLS cert verification
        self.verify = config.get('VERIFY_SERVER_CERT', True)

        # The name of the version file to download
        self.version_file = settings.VERSION_FILE_FILENAME

        # The name of the key file to download
        self.key_file = settings.KEY_FILE_FILENAME

        # Creating data & update directories
        self._setup()

        if refresh is True:
            self.refresh()
Ejemplo n.º 31
0
    def test_default_plugin_detection_scp(self):
        pm = PluginManager(Config())

        plugin_names = [n['name'] for n in pm.plugins]
        assert 'scp' in plugin_names