Compare commits

..

No commits in common. "ripe_obj_creation" and "master" have entirely different histories.

2 changed files with 65 additions and 33 deletions

40
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "01bd2ed801b62b47100921e0ace284388d352ad9433e70331c082550bf830e03"
"sha256": "ca9c2522bf07f03d1588afe76e9f6fc73bc1efec20d4f155d82b709efaf14a56"
},
"pipfile-spec": 6,
"requires": {
@ -18,7 +18,43 @@
"default": {
"apixu": {
"git": "https://github.com/apixu/apixu-python.git",
"ref": "370216999346d5caf7f8dc6724b5766dcc6da25d"
"ref": "master"
},
"certifi": {
"hashes": [
"sha256:59b7658e26ca9c7339e00f8f4636cdfe59d34fa37b9b04f6f9e9926b3cece1a5",
"sha256:b26104d6835d1f5e49452a26eb2ff87fe7090b89dfcaee5ea2212697e1e1d7ae"
],
"version": "==2019.3.9"
},
"chardet": {
"hashes": [
"sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae",
"sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
],
"version": "==3.0.4"
},
"idna": {
"hashes": [
"sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407",
"sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c"
],
"version": "==2.8"
},
"requests": {
"hashes": [
"sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4",
"sha256:9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31"
],
"index": "pypi",
"version": "==2.22.0"
},
"urllib3": {
"hashes": [
"sha256:b246607a25ac80bedac05c6f282e3cdaf3afb65420fd024ac94435cabe6e18d1",
"sha256:dbe59173209418ae49d485b87d1681aefa36252ee85884c31346debd19463232"
],
"version": "==1.25.3"
}
},
"develop": {}

View file

@ -3,10 +3,9 @@ import ipaddress
import json
import urllib.request
import pprint
import requests
# RIPE_URL = "https://rest.db.ripe.net/{source}/{objecttype}/{key}"
# RIPE_URL = "https://rest.db.ripe.net/ripe"
RIPE_URL = "https://rest.db.ripe.net/ripe"
RIPE_URL = "https://rest-test.db.ripe.net/test"
class ungleichRIPE(object):
@ -34,21 +33,22 @@ class ungleichRIPE(object):
print("Sorry, {} does not look like an IPv6 network: {}".format(args.network, e))
raise
url = "{}/route6?password={}".format(RIPE_URL, args.password)
url = "{}/route6/?password={}".format(RIPE_URL, args.password)
ripe_object = {}
ripe_object['route6'] = args.network
ripe_object['origin'] = "AS209898"
ripe_object['descr'] = args.description
ripe_object['mnt-by'] = "mnt-ungleich"
ripe_object['source'] = "TEST"
ripe_attributes = [{ "name": key, "value": value } for key, value in ripe_object.items() ]
# Format according to API layout
ripe_element = {}
ripe_element['objects'] = {
"object": [
ripe_element['objects'] = []
ripe_element['objects'].append(
{ "object":
[
{
"attributes": {
"attribute": ripe_attributes
@ -56,28 +56,24 @@ class ungleichRIPE(object):
}
]
}
)
data = json.dumps(ripe_element).encode('utf-8')
# debug
# pprint.pprint(ripe_element)
pprint.pprint(ripe_element)
# method = 'POST'
# req = urllib.request.Request(url=url,
# data=data,
# method='POST',
# headers={
# "Content-Type": "application/json",
# "Accept": "application/json"
# })
# print("Adding a v6 route object at {} for {} with {} req={}".format(url, args.network, data, str(req)))
method = 'POST'
# with urllib.request.urlopen(req) as f:
# print(f.read().decode('utf-8'))
r = requests.post(url, data=data, headers={
req = urllib.request.Request(url=url,
data=data,
method='POST',
headers={
"Content-Type": "application/json",
"Accept": "application/json"
})
pprint.pprint(json.loads(r.content.decode("utf-8")))
# print(r.content.decode("utf-8"))
print("Adding a v6 route object at {} for {} with {} req={}".format(url, args.network, data, str(req)))
with urllib.request.urlopen(req) as f:
print(f.read().decode('utf-8'))