Browse Source

add support for configuring IPFS via the config file...

main
John-Mark Gurney 1 year ago
parent
commit
47609472a6
1 changed files with 16 additions and 5 deletions
  1. +16
    -5
      casimport/__init__.py

+ 16
- 5
casimport/__init__.py View File

@@ -141,16 +141,19 @@ class HTTPSCAS(object):
return urlfetch(url)

class IPFSCAS(object):
gwhost = 'gateway.ipfs.io'
gwhost = 'cloudflare-ipfs.com'
gwurl = 'https://gateway.ipfs.io/ipfs/'
gwurl = 'https://cloudflare-ipfs.com/ipfs/'

def __init__(self, gw=None):
if gw is not None:
self.gwurl = gw

@classmethod
def fromconfig(cls, conf):
return cls()
return cls(conf.get('gateway', None))

def make_url(self, url):
return urllib.parse.urlunparse(('https', self.gwhost,
'/ipfs/' + url.netloc) + ('', ) * 3)
return urllib.parse.urljoin(self.gwurl, url.netloc)

def fetch_data(self, url):
if url.scheme != 'ipfs':
@@ -536,6 +539,14 @@ class Test(unittest.TestCase):
# and that the second loader is the IPFSCAS
self.assertIsInstance(f._loaders[1], IPFSCAS)

def test_ipfsgwfromconfig(self):
gwurl = 'https://www.example.com/somepath/'
ipfsconf = dict(gateway=gwurl)
ipfsobj = IPFSCAS.fromconfig(ipfsconf)

self.assertEqual(ipfsobj.make_url(urllib.parse.urlparse('ipfs://someobj')),
'https://www.example.com/somepath/someobj')

def test_defaultinit(self):
temphome = self.tempdir / 'home'
temphome.mkdir()


Loading…
Cancel
Save