From 6d32570ac8dff9a4ef424a2ac3abde4bf4d9cce2 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Mon, 27 Sep 2010 14:42:40 -0400 Subject: [PATCH] ProtoGeni slices may have special characters that need to be filtered out --- sfa/managers/aggregate_manager_pl.py | 12 ++++++++---- sfa/util/namespace.py | 13 ++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/sfa/managers/aggregate_manager_pl.py b/sfa/managers/aggregate_manager_pl.py index 05beae9a..fe4e53d1 100644 --- a/sfa/managers/aggregate_manager_pl.py +++ b/sfa/managers/aggregate_manager_pl.py @@ -5,7 +5,7 @@ import datetime import time import traceback import sys - +import re from types import StringTypes from sfa.util.namespace import * from sfa.util.rspec import * @@ -37,19 +37,23 @@ def __get_registry_objects(slice_xrn, creds, users): reg_objects = None if users: + # dont allow special characters in the site login base + only_alphanumeric = re.compile('[^a-zA-Z0-9]+') + login_base = only_alphanumeric.sub('', hrn_auth[:20]).lower() + reg_objects = {} site = {} site['site_id'] = 0 - site['name'] = 'geni.%s' % hrn_auth[:20] + site['name'] = 'geni.%s' % login_base site['enabled'] = True site['max_slices'] = 100 # Note: # Is it okay if this login base is the same as one already at this myplc site? # Do we need uniqueness? Should use hrn_auth instead of just the leaf perhaps? - site['login_base'] = hrn_auth[:20] - site['abbreviated_name'] = hrn_auth[:20] + site['login_base'] = login_base + site['abbreviated_name'] = login_base site['max_slivers'] = 1000 reg_objects['site'] = site diff --git a/sfa/util/namespace.py b/sfa/util/namespace.py index f53808cb..512f398a 100644 --- a/sfa/util/namespace.py +++ b/sfa/util/namespace.py @@ -1,6 +1,6 @@ ### $Id$ ### $URL$ - +import re from sfa.util.faults import * URN_PREFIX = "urn:publicid:IDN" @@ -57,6 +57,9 @@ def urn_to_hrn(urn): """ convert a urn to hrn return a tuple (hrn, type) + Warning: urn_to_hrn() replces some special characters that + are not replaced in hrn_to_urn(). Due to this, + urn_to_hrn() -> hrn_to_urn() may not return the original urn """ # if this is already a hrn dont do anything @@ -66,16 +69,20 @@ def urn_to_hrn(urn): name = urn[len(URN_PREFIX):] hrn_parts = name.split("+") type = hrn_parts.pop(2) - + + # Remove the authority name (e.g. '.sa') if type == 'authority': hrn_parts = hrn_parts[:-1] # convert hrn_parts (list) into hrn (str) by doing the following + # dont allow special characters (except ':') in the site login base # remove blank elements # replace ':' with '.' # join list elements using '.' - hrn = '.'.join([part.replace(':', '.') for part in hrn_parts if part]) + only_alphanum = re.compile('[^a-zA-Z0-9:]+') + valid_chars = lambda x: only_alphanum.sub('', x).replace(':', '.') + hrn = '.'.join([valid_chars(part) for part in hrn_parts if part]) return str(hrn), str(type) -- 2.43.0