aboutsummaryrefslogtreecommitdiff
path: root/portal-gui
diff options
context:
space:
mode:
authorMichael Elkins <melkins@tislabs.com>2010-11-07 05:48:48 +0000
committerMichael Elkins <melkins@tislabs.com>2010-11-07 05:48:48 +0000
commit239f649e65e8daff20c87c4184ae8f12e8b48598 (patch)
treec2a98725b6c1bccb44fa8bc8d843d6a951024263 /portal-gui
parent6a5dd269c262b086729cb619c81824fb522bf9a8 (diff)
updates to portal-giu to better support hosted handles
svn path=/portal-gui/rpkigui/myrpki/glue.py; revision=3538
Diffstat (limited to 'portal-gui')
-rw-r--r--portal-gui/rpkigui/myrpki/glue.py29
-rw-r--r--portal-gui/rpkigui/myrpki/models.py3
-rw-r--r--portal-gui/rpkigui/myrpki/views.py15
-rwxr-xr-xportal-gui/scripts/adduser.py21
4 files changed, 36 insertions, 32 deletions
diff --git a/portal-gui/rpkigui/myrpki/glue.py b/portal-gui/rpkigui/myrpki/glue.py
index 959a8da6..bca536df 100644
--- a/portal-gui/rpkigui/myrpki/glue.py
+++ b/portal-gui/rpkigui/myrpki/glue.py
@@ -49,11 +49,11 @@ from rpkigui.myrpki import models
def invoke_rpki(handle, args):
"""Invoke the myrpki cli for the specified configuration."""
config = settings.MYRPKI_DATA_DIR + '/' + handle + '/myrpki.conf'
+ myrpki_dir = settings.MYRPKI_DATA_DIR + '/' + handle
# default myrpki.conf uses relative paths, so chdir() to the repo first
- os.chdir(settings.MYRPKI_DATA_DIR + '/' + handle)
- cmd = '%s %s %s' % (sys.executable, settings.MYRPKI_PATH,
+ cmd = 'cd %s && %s %s %s' % (myrpki_dir, sys.executable, settings.MYRPKI_PATH,
' '.join(['--config=' + config] + args))
- print 'invoking', cmd
+ print >>sys.stderr, 'invoking', cmd
os.system(cmd)
def read_file_from_handle(handle, fname):
@@ -104,6 +104,12 @@ def output_roas(path, handle):
w.writerows([req.as_roa_prefix(), req.roa.asn,
'%s-group-%d' % (handle.handle, req.roa.pk)] for req in qs)
+def configure_daemons(handle):
+ args = ['configure_daemons']
+ for hosted in handle.hosting.all():
+ args.append(settings.MYRPKI_DATA_DIR + '/' + hosted.handle + '/myrpki.xml')
+ invoke_rpki(handle.handle, args)
+
def configure_resources(handle):
'''Write out the csv files and invoke the myrpki.py command line tool.'''
# chdir to the repo dir since the default myrpki.conf uses relative
@@ -116,17 +122,14 @@ def configure_resources(handle):
run_rpkidemo = cfg.getboolean('run_rpkidemo', False)
if not run_rpkidemo:
run_rpkid = cfg.getboolean('run_rpkid')
- cmd = 'daemons' if run_rpkid else 'resources'
- invoke_rpki(handle.handle, ['configure_' + cmd])
- # handle the hosted case where some communication between rpkid operator
- # and resource holder is required
- if not run_rpkid:
- xml_path = cfg.get('xml_filename')
- if xml_path[0] != '/':
- # convert to full path
- xml_path = '%s/%s/%s' % (settings.MYRPKI_DATA_DIR, handle.handle, xml_path)
+ if run_rpkid:
+ configure_daemons(handle)
+ else:
+ invoke_rpki(handle.handle, ['configure_resources'])
+
# send the myrpki.xml to the rpkid hosting me
- invoke_rpki(handle.parents.all()[0].handle, ['configure_daemons', xml_path])
+ configure_daemons(handle.host)
+
# process the response
invoke_rpki(handle.handle, ['configure_resources'])
diff --git a/portal-gui/rpkigui/myrpki/models.py b/portal-gui/rpkigui/myrpki/models.py
index dfa4db04..c78e9792 100644
--- a/portal-gui/rpkigui/myrpki/models.py
+++ b/portal-gui/rpkigui/myrpki/models.py
@@ -40,6 +40,9 @@ class Conf(models.Model):
handle = HandleField(unique=True, db_index=True)
owner = models.ManyToManyField(User)
+ # NULL if self-hosted, otherwise the conf that is hosting us
+ host = models.ForeignKey('Conf', related_name='hosting', null=True)
+
def __unicode__(self):
return self.handle
diff --git a/portal-gui/rpkigui/myrpki/views.py b/portal-gui/rpkigui/myrpki/views.py
index 674d5af1..b3c69013 100644
--- a/portal-gui/rpkigui/myrpki/views.py
+++ b/portal-gui/rpkigui/myrpki/views.py
@@ -539,19 +539,18 @@ def upload_repository_request(request, self_handle):
def upload_myrpki_xml(request, self_handle):
"handles POST of the myrpki.xml file for a given resource handle."
conf = handle_or_404(request, self_handle)
- parent_handle = get_parent_handle(conf)
if request.method == 'POST':
try:
- fname = '%s/%s/myrpki.xml' % (settings.MYRPKI_DATA_DIR, self_handle,)
- print >>sys.stderr, 'writing ', fname
- myrpki_xml = open(fname, 'w')
- myrpki_xml.write(request.raw_post_data)
- myrpki_xml.close()
+ fname = '%s/%s/myrpki.xml' % (settings.MYRPKI_DATA_DIR, self_handle,)
+ print >>sys.stderr, 'writing ', fname
+ myrpki_xml = open(fname, 'w')
+ myrpki_xml.write(request.raw_post_data)
+ myrpki_xml.close()
- glue.invoke_rpki(parent_handle, [ 'configure_daemons', myrpki_xml.name ])
+ glue.configure_daemons(conf.host)
except:
- print >>sys.stderr, ''.join(sys.exc_info())
+ print >>sys.stderr, ''.join(sys.exc_info())
return serve_file(self_handle, 'myrpki.xml', 'application/xml')
diff --git a/portal-gui/scripts/adduser.py b/portal-gui/scripts/adduser.py
index f5740ba9..c7fc2a55 100755
--- a/portal-gui/scripts/adduser.py
+++ b/portal-gui/scripts/adduser.py
@@ -20,7 +20,7 @@
from django.contrib.auth.models import User
from django.conf import settings
-from rpkigui.myrpki.models import Conf, Parent
+from rpkigui.myrpki.models import Conf
import os
import sys
@@ -45,13 +45,13 @@ def update_apache_auth_file(passfile, username, realm, password):
if __name__ == '__main__':
if len(sys.argv) < 3:
- print >>sys.stderr, 'usage: adduser <name> <email> <parent>'
+ print >>sys.stderr, 'usage: adduser <username> <user\'s email> <host handle>'
sys.exit(1)
username = sys.argv[1]
email = sys.argv[2]
- parent = sys.argv[3]
- print 'username=', username, 'email=', email, 'parent=', parent
+ host = sys.argv[3]
+ print 'username=', username, 'email=', email, 'host=', host
user_set = User.objects.filter(username=username)
if user_set:
@@ -69,15 +69,14 @@ if __name__ == '__main__':
print >>sys.stderr, 'creating conf'
conf = Conf.objects.create(handle=username)
conf.owner.add(user)
- conf.save()
- parent_set = conf.parents.filter(handle=parent)
- if parent_set:
- print 'parent %s is already present' % parent
- else:
- print "creating %s' parent %s" % (username, parent)
- parent = Parent.objects.create(handle=parent, conf=conf)
+ host_set = Conf.objects.filter(handle=host)
+ if not host_set:
+ print >>sys.stderr, 'error: Conf object for host %s does not exist!' % host
+ conf.host = host_set[0]
+ conf.save()
+
myrpki_dir = '%s/%s' % (settings.MYRPKI_DATA_DIR, username)
print 'myrpki_dir=', myrpki_dir
if not os.path.exists(myrpki_dir):