Esempio n. 1
0
def add_storage_provider(introducer_furl, name=None, description=None):
    providers_db = os.path.join(Config().config_dir, 'storage-providers.yml')
    storage_providers = get_storage_providers()
    if not name:
        _, connection_hints = decode_introducer_furl(introducer_furl)
        name = connection_hints.split(',')[0].split(':')[0]
    new_provider = {}
    new_provider[name] = {
        'introducer.furl': introducer_furl,
        'description': description
    }
    storage_providers.update(new_provider)
    with open(providers_db, 'w') as f:
        try:
            os.chmod(providers_db, 0o600)
        except OSError:
            pass
        yaml.safe_dump(storage_providers, f, encoding='utf-8',
                       allow_unicode=True, width=68, default_flow_style=False)
Esempio n. 2
0
 def on_save(self):
     introducer_furl = self.grid_form.introducer_text_edit.toPlainText()
     name = self.grid_form.name_line_edit.text()
     if not introducer_furl:
         msg = QMessageBox()
         msg.setIcon(QMessageBox.Warning)
         msg.setWindowTitle("Gridsync")
         msg.setText("Please enter an Introducer fURL.")
         msg.setStandardButtons(QMessageBox.Ok)
         msg.exec_()
     else:
         try:
             _, connection_hints = decode_introducer_furl(introducer_furl)
             logging.debug("connection_hints = %s", connection_hints)
         except AttributeError:
             msg = QMessageBox()
             msg.setIcon(QMessageBox.Warning)
             msg.setWindowTitle("Gridsync")
             msg.setText("Please enter a valid Introducer fURL.")
             msg.setStandardButtons(QMessageBox.Ok)
             msg.exec_()
         add_storage_provider(introducer_furl, name)
Esempio n. 3
0
 def on_save(self):
     introducer_furl = self.grid_form.introducer_text_edit.toPlainText()
     name = self.grid_form.name_line_edit.text()
     if not introducer_furl:
         msg = QMessageBox()
         msg.setIcon(QMessageBox.Warning)
         msg.setWindowTitle("Gridsync")
         msg.setText("Please enter an Introducer fURL.")
         msg.setStandardButtons(QMessageBox.Ok)
         msg.exec_()
     else:
         try:
             _, connection_hints = decode_introducer_furl(introducer_furl)
             logging.debug("connection_hints = %s", connection_hints)
         except AttributeError:
             msg = QMessageBox()
             msg.setIcon(QMessageBox.Warning)
             msg.setWindowTitle("Gridsync")
             msg.setText("Please enter a valid Introducer fURL.")
             msg.setStandardButtons(QMessageBox.Ok)
             msg.exec_()
         add_storage_provider(introducer_furl, name)
Esempio n. 4
0
def add_storage_provider(introducer_furl, name=None, description=None):
    providers_db = os.path.join(Config().config_dir, 'storage-providers.yml')
    storage_providers = get_storage_providers()
    if not name:
        _, connection_hints = decode_introducer_furl(introducer_furl)
        name = connection_hints.split(',')[0].split(':')[0]
    new_provider = {}
    new_provider[name] = {
        'introducer.furl': introducer_furl,
        'description': description
    }
    storage_providers.update(new_provider)
    with open(providers_db, 'w') as f:
        try:
            os.chmod(providers_db, 0o600)
        except OSError:
            pass
        yaml.safe_dump(storage_providers,
                       f,
                       encoding='utf-8',
                       allow_unicode=True,
                       width=68,
                       default_flow_style=False)
Esempio n. 5
0
def test_decode_introducer_furl_tub_id_not_base32():
    furl = 'pb://[email protected]:12345/introducer'
    with pytest.raises(AttributeError):
        assert decode_introducer_furl(furl)
Esempio n. 6
0
def test_decode_introducer_furl_invalid_char_in_connection_hint():
    furl = 'pb://abc234@exam/ple.org:12345/introducer'
    with pytest.raises(AttributeError):
        assert decode_introducer_furl(furl)
Esempio n. 7
0
def test_decode_introducer_furl_no_port_separator():
    furl = 'pb://[email protected]/introducer'
    with pytest.raises(AttributeError):
        assert decode_introducer_furl(furl)
Esempio n. 8
0
def test_decode_introducer_furl():
    furl = 'pb://[email protected]:12345/introducer'
    assert decode_introducer_furl(furl) == ('abc234', 'example.org:12345')