Ejemplo n.º 1
0
def test_write_config(cleandir):
    config = TransistionDict()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    l = Loader()
    l.write_config_py(config)
    assert 'client_config.py' in os.listdir(os.getcwd())
Ejemplo n.º 2
0
def test_write_config(cleandir):
    config = TransistionDict()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    l = Loader()
    l.write_config_py(config)
    assert 'client_config.py' in os.listdir(os.getcwd())
Ejemplo n.º 3
0
 def test_process_packages(self, db):
     data_dir = os.getcwd()
     t_config = TConfig()
     t_config.DATA_DIR = data_dir
     t_config.UPDATE_PATCHES = False
     config = TransistionDict()
     config.from_object(t_config)
     p = PackageHandler(config, db)
     p.process_packages()
Ejemplo n.º 4
0
 def test_init(self, db):
     data_dir = os.getcwd()
     t_config = TConfig()
     t_config.DATA_DIR = data_dir
     config = TransistionDict()
     config.from_object(t_config)
     p = PackageHandler(config, db)
     assert p.files_dir == os.path.join(data_dir, s_dir, 'files')
     assert p.deploy_dir == os.path.join(data_dir, s_dir, 'deploy')
Ejemplo n.º 5
0
 def test_init(self, db):
     data_dir = os.getcwd()
     t_config = TConfig()
     t_config.DATA_DIR = data_dir
     config = TransistionDict()
     config.from_object(t_config)
     p = PackageHandler(config, db)
     assert p.files_dir == os.path.join(data_dir, s_dir, 'files')
     assert p.deploy_dir == os.path.join(data_dir, s_dir, 'deploy')
Ejemplo n.º 6
0
 def test_process_packages(self, db):
     data_dir = os.getcwd()
     t_config = TConfig()
     t_config.DATA_DIR = data_dir
     t_config.UPDATE_PATCHES = False
     config = TransistionDict()
     config.from_object(t_config)
     p = PackageHandler(config, db)
     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
        pyi_config = TransistionDict()
        pyi_config.from_object(obj)
        config = pyi_config.copy()

        self.FROZEN = jms_utils.app.FROZEN
        # Grabbing config information
        update_url = config.get('UPDATE_URL')
        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_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.public_keys = convert_to_list(config.get('PUBLIC_KEYS'),
                                           default=list())
        if len(self.public_keys) == 0:
            log.warning('May have passed an incorrect data type to '
                        'PUBLIC_KEYS or an empty list was passed')

        # Ensuring only one occurrence of a public key is present
        # Would be a waste to test a bad key twice
        self.public_keys = list(set(self.public_keys))
        # Config option to disable tls cert verification
        self.verify = config.get('VERIFY_SERVER_CERT', True)
        self.version_file = settings.VERSION_FILE

        self._setup()
        if refresh is True:
            self.refresh()
Ejemplo n.º 8
0
def test_prod_bad_atter():
    config = TransistionDict()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    assert config.get('DEBUG', None) is not None
Ejemplo n.º 9
0
def test_prod_config():
    config = TransistionDict()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    assert config['MORE_INFO'] == 'Yes Please'
Ejemplo n.º 10
0
def test_dev_config_bad_attr():
    config = TransistionDict()
    test_config = DevConfig()
    config.from_object(test_config)
    assert config.get('BAD_ATTR', None) is None
Ejemplo n.º 11
0
def test_dev_config():
    config = TransistionDict()
    test_config = DevConfig()
    config.from_object(test_config)
    assert config['TESTING'] is True
Ejemplo n.º 12
0
 def test_dev_dir_none(self):
     myconfig = TConfig()
     myconfig.APP_NAME = None
     updater = TransistionDict()
     updater.from_object(myconfig)
     assert updater['APP_NAME'] == 'PyUpdater App'
Ejemplo n.º 13
0
 def __init__(self, config=None, db=None):
     self.config = TransistionDict()
     # Important to keep this before updating config
     if config is not None:
         self.update_config(config, db)
Ejemplo n.º 14
0
class Core(object):
    """Processes, signs & uploads updates

        Kwargs:

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

    def update_config(self, config, db):
        """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()

        if db is None:
            self.db = Storage(config.DATA_DIR)
        else:
            self.db = db
        self.config.from_object(config)
        self._update(self.config, self.db)

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

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

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

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

        Args:

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

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

    def make_keys(self, count=3):
        "Creates signing keys"
        self.kh.make_keys(count)

    def revoke_key(self, count):
        self.kh.revoke_key(count)

    def get_recent_revoked_key(self):
        return self.kh.get_recent_revoked_key()

    def sign_update(self):
        "Signs version file with signing key"
        self.kh.sign_update()

    def get_public_keys(self):
        "Returns public key"
        return self.kh.get_public_keys()

    def print_public_key(self):
        "Prints public key to console"
        self.kh.print_public_key()
Ejemplo n.º 15
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
        pyi_config = TransistionDict()
        pyi_config.from_object(obj)
        config = pyi_config.copy()

        self.FROZEN = jms_utils.app.FROZEN
        # Grabbing config information
        update_url = config.get('UPDATE_URL')
        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_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.public_keys = convert_to_list(config.get('PUBLIC_KEYS'),
                                           default=list())
        if len(self.public_keys) == 0:
            log.warning('May have passed an incorrect data type to '
                        'PUBLIC_KEYS or an empty list was passed')

        # Ensuring only one occurrence of a public key is present
        # Would be a waste to test a bad key twice
        self.public_keys = list(set(self.public_keys))
        # Config option to disable tls cert verification
        self.verify = config.get('VERIFY_SERVER_CERT', True)
        self.version_file = settings.VERSION_FILE

        self._setup()
        if refresh is True:
            self.refresh()
Ejemplo n.º 16
0
def test_dev_config():
    config = TransistionDict()
    test_config = DevConfig()
    config.from_object(test_config)
    assert config['TESTING'] is True
Ejemplo n.º 17
0
def test_prod_bad_atter():
    config = TransistionDict()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    assert config.get('DEBUG', None) is not None
Ejemplo n.º 18
0
def test_prod_config():
    config = TransistionDict()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    assert config['MORE_INFO'] == 'Yes Please'
Ejemplo n.º 19
0
def test_dev_config_bad_attr():
    config = TransistionDict()
    test_config = DevConfig()
    config.from_object(test_config)
    assert config.get('BAD_ATTR', None) is None