Browse Source

added git releases transport

pull/3/head
R4SAS 8 years ago
parent
commit
50c3b64cd8
  1. 4
      pyseeder/crypto.py
  2. 1
      pyseeder/transport.py
  3. 59
      pyseeder/transports/git_publish.py
  4. 3
      requirements.txt
  5. 10
      transports.ini.example

4
pyseeder/crypto.py

@ -33,8 +33,8 @@ def keygen(pub_key, priv_key, priv_key_password, user_id):
subject = issuer = x509.Name([ subject = issuer = x509.Name([
x509.NameAttribute(NameOID.COUNTRY_NAME, "XX"), x509.NameAttribute(NameOID.COUNTRY_NAME, "XX"),
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "XX"), x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "XX"),
x509.NameAttribute(NameOID.LOCALITY_NAME, "XX"), x509.NameAttribute(NameOID.LOCALITY_NAME, "I2P Anonymous Network"),
x509.NameAttribute(NameOID.ORGANIZATION_NAME, "I2P Anonymous Network"), x509.NameAttribute(NameOID.ORGANIZATION_NAME, "XX"),
x509.NameAttribute(NameOID.ORGANIZATIONAL_UNIT_NAME, "I2P"), x509.NameAttribute(NameOID.ORGANIZATIONAL_UNIT_NAME, "I2P"),
x509.NameAttribute(NameOID.COMMON_NAME, user_id), x509.NameAttribute(NameOID.COMMON_NAME, user_id),
]) ])

1
pyseeder/transport.py

@ -55,4 +55,3 @@ def upload(filename, config):
except ImportError: except ImportError:
raise PyseederException( raise PyseederException(
"{} transport can't be loaded".format(t)) "{} transport can't be loaded".format(t))

59
pyseeder/transports/git_publish.py

@ -0,0 +1,59 @@
#!/usr/bin/env python3
# unpythonic script to (re)upload asset to github release
# used for stealthy I2P reseeding
# GENERATE TOKEN for this script here --> https://github.com/settings/tokens
# Check scope: public_repo (shall be enough)
from urllib.parse import urljoin
from mimetypes import guess_type
from pyseeder.utils import TransportException
import requests
import os
TRANSPORT_NAME = "git"
def run(filename, config):
if "GH_USERNAME" not in config:
raise TransportException("git: No username specified in config")
else:
REPO_USERNAME = config["GH_USERNAME"]
if "GH_TOKEN" not in config:
raise TransportException("git: No token specified in config")
else:
REPO_TOKEN = config["GH_TOKEN"]
if "GH_REPO" not in config:
raise TransportException("git: No repository specified in config")
else:
REPO_PATH = config["GH_REPO"]
if "GH_TAG" not in config:
raise TransportException("git: No tag specified in config")
else:
REPO_TAG = config["GH_TAG"]
API_URL = "https://api.github.com/"
asset_name = os.path.split(filename)[1]
content_type = guess_type(asset_name)[0] or "application/zip"
creds = (REPO_USERNAME, REPO_TOKEN)
release_info_url = urljoin(API_URL, "/repos/{}/releases/tags/{}".format(
REPO_PATH, REPO_TAG))
# get release info
resp = requests.get(release_info_url, auth=creds)
assert resp.status_code is 200, "Successfull auth must return 200"
# delete old asset
for x in resp.json()["assets"]:
if x["name"] == asset_name:
r = requests.delete(x["url"], auth=creds)
assert r.status_code is 204, "Deletion must return 204"
# upload new asset
# im super lazy
upload_url = resp.json()["upload_url"].split("{")[0]
headers = {'Content-Type': content_type}
params = {'name': asset_name}
data = open(filename, 'rb').read()
r = requests.post(upload_url, headers=headers, params=params, auth=creds,
data=data)
assert r.status_code is 201, "Upload must return 201"

3
requirements.txt

@ -1 +1,2 @@
cryptography>=1.4 cryptography==1.4
requests

10
transports.ini.example

@ -1,10 +1,18 @@
[transports] [transports]
; enabled transports separated by space ; enabled transports separated by space
enabled=git enabled=git_publish
[git] [git]
; Folder with git repository to use ; Folder with git repository to use
folder=/home/user/reseed-data-repo folder=/home/user/reseed-data-repo
[git_publish]
; GENERATE TOKEN for this script here --> https://github.com/settings/tokens
; Check scope: public_repo (shall be enough)
GH_USERNAME=user
GH_TOKEN=your token here
GH_REPO=user/i2pd-reseed
GH_TAG=1.0
[dropbox] [dropbox]
; todo ; todo

Loading…
Cancel
Save