from sfa.trust.credential import Credential
from sfa.util.sfaticket import SfaTicket
from sfa.util.record import SfaRecord, UserRecord, SliceRecord, NodeRecord, AuthorityRecord
-from sfa.util.namespace import get_leaf, get_authority, hrn_to_urn
+from sfa.util.xrn import Xrn, get_leaf, get_authority, hrn_to_urn
from sfa.util.xmlrpcprotocol import ServerException
import sfa.util.xmlrpcprotocol as xmlrpcprotocol
from sfa.util.config import Config
def get_key_file(self):
file = os.path.join(self.options.sfi_dir, self.user.replace(self.authority + '.', '') + ".pkey")
- #file = os.path.join(self.options.sfi_dir, get_leaf(self.user) + ".pkey")
if (os.path.isfile(file)):
return file
else:
def get_cert_file(self, key_file):
- #file = os.path.join(self.options.sfi_dir, get_leaf(self.user) + ".cert")
file = os.path.join(self.options.sfi_dir, self.user.replace(self.authority + '.', '') + ".cert")
if (os.path.isfile(file)):
return file
return None
def get_user_cred(self):
- #file = os.path.join(self.options.sfi_dir, get_leaf(self.user) + ".cred")
file = os.path.join(self.options.sfi_dir, self.user.replace(self.authority + '.', '') + ".cred")
return self.get_cred(file, 'user', self.user)
if not self.authority:
self.logger.critical("no authority specified. Use -a or set SF_AUTH")
sys.exit(-1)
- ### xxx get_leaf('authority') always returns 'authority'
- # are we not meaning get_leaf(self.authority) instead ?
- file = os.path.join(self.options.sfi_dir, get_leaf("authority") + ".cred")
+ file = os.path.join(self.options.sfi_dir, self.authority + ".cred")
return self.get_cred(file, 'authority', self.authority)
def get_slice_cred(self, name):
# - have to first retrieve the record to be removed
def remove(self, opts, args):
auth_cred = self.get_auth_cred().save_to_string(save_parents=True)
+ if len(args)!=1:
+ self.parser.print_help()
+ sys.exit(1)
hrn = args[0]
type = opts.type
if type in ['all']:
# add named registry record
def add(self, opts, args):
auth_cred = self.get_auth_cred().save_to_string(save_parents=True)
+ if len(args)!=1:
+ self.parser.print_help()
+ sys.exit(1)
record_filepath = args[0]
rec_file = self.get_record_file(record_filepath)
record = load_record_from_file(rec_file).as_dict()
# update named registry entry
def update(self, opts, args):
user_cred = self.get_user_cred()
+ if len(args)!=1:
+ self.parser.print_help()
+ sys.exit(1)
rec_file = self.get_record_file(args[0])
record = load_record_from_file(rec_file)
if record['type'] == "user":
from sqlobject import *
from sfa.util.faults import *
-from sfa.util.namespace import urn_to_hrn
+from sfa.util.xrn import urn_to_hrn
from sfa.util.rspec import RSpec
from sfa.server.registry import Registries
from sfa.util.rspec import RSpec
import sys
import pdb
-from sfa.util.namespace import hrn_to_pl_slicename, urn_to_hrn, get_authority
+from sfa.util.namespace import hrn_to_pl_slicename
+from sfa.util.xrn import urn_to_hrn, get_authority
from sfa.util.rspec import *
from sfa.util.specdict import *
from sfa.util.faults import *
import types
import time
+
+from sfa.util.faults import *
from sfa.util.prefixTree import prefixTree
from sfa.util.record import SfaRecord
from sfa.util.table import SfaTable
from sfa.util.record import SfaRecord
from sfa.trust.gid import GID
-from sfa.util.namespace import get_leaf, get_authority, hrn_to_urn, hrn_to_pl_login_base, urn_to_hrn
-from sfa.trust.credential import *
-from sfa.trust.certificate import *
-from sfa.util.faults import *
+from sfa.util.namespace import hrn_to_pl_login_base
+from sfa.util.xrn import Xrn, get_leaf, get_authority, hrn_to_urn, urn_to_hrn
+from sfa.trust.credential import Credential
+from sfa.trust.certificate import Certificate, Keypair
from sfa.trust.gid import create_uuid
def get_version(api):
return 1
-def remove(api, xrn, type, origin_hrn=None):
- # convert xrn to hrn
- if type:
- hrn = urn_to_hrn(xrn)[0]
- else:
- hrn, type = urn_to_hrn(xrn)
+# being PL specific it sounds right to expect a hrn+type (not a xrn)
+def remove(api, hrn, type, origin_hrn=None):
+# # convert xrn to hrn
+# if type:
+# hrn = urn_to_hrn(xrn)[0]
+# else:
+# hrn, type = urn_to_hrn(xrn)
table = SfaTable()
filter = {'hrn': hrn}
returns = Parameter(int, "1 if successful")
+# this does not sound quite right, but the best I could come up with is:
+# if type is not specified then we expect a URN
def call(self, xrn, creds, type):
- if not type:
- hrn = urn_to_hrn(xrn)[0]
- else:
- hrn, type = urn_to_hrn(xrn)
+ if type: hrn=xrn
+ else: (hrn,type) = urn_to_hrn(xrn)
# validate the cred
valid_creds = self.api.auth.checkCredentials(creds, "remove")
#log the call
origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
- self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
-
+ self.api.logger.info("interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-hrn: %s\ttype: %s"%(
+ self.api.interface, self.name, origin_hrn, hrn, type))
manager = self.api.get_interface_manager()
- return manager.remove(self.api, xrn, type)
+ return manager.remove(self.api, hrn, type)
# 3. replace ':' with '.' (':' is the urn hierarchy delimiter)
# 4. join list elements using '.'
#hrn = '.'.join([part.replace('.', '\\.').replace(':', '.') for part in hrn_parts if part])
- hrn = '.'.join([re.sub(r'([^a-zA-Z0-9\:])', r'\\\1', part).replace(':', '.') for part in urn_parts if part])
+# hrn = '.'.join([re.sub(r'([^a-zA-Z0-9\:])', r'\\\1', part).replace(':', '.') for part in urn_parts if part])
+ hrn = '.'.join([re.sub(r'\\.', r'\\.', part).replace(':', '.') for part in urn_parts if part])
return str(hrn), str(type)
from sfa.util.faults import *
from sfa.util.sfalogging import sfa_logger
+# for convenience and smoother translation
+def get_leaf(hrn): return Xrn(hrn=hrn,type='any').get_leaf()
+def get_authority(hrn): return Xrn(hrn=hrn,type='any').get_authority_hrn()
+def urn_to_hrn(urn): xrn=Xrn(urn=urn); return (xrn.hrn, xrn.type)
+def hrn_to_urn(hrn,type): return Xrn(hrn=hrn, type=type).urn
+
class Xrn:
########## basic tools on HRNs
self.type=type
self.hrn_to_urn()
else:
- raise SfaAPIError,"Xrn"
+ raise SfaAPIError,"Xrn.__init__"
def get_urn(self): return self.urn
def get_hrn(self): return (self.hrn, self.type)
def get_leaf(self):
- if not self.hrn: raise SfaAPIError, "Xrn"
+ if not self.hrn: raise SfaAPIError, "Xrn.get_leaf"
if not hasattr(self,'leaf'):
self.leaf=Xrn.hrn_split(self.hrn)[-1]
return self.leaf
def get_authority_hrn(self):
- if not self.hrn: raise SfaAPIError, "Xrn"
+ if not self.hrn: raise SfaAPIError, "Xrn.get_authority_hrn"
# self.authority keeps a list
if not hasattr(self,'authority'):
self.authority=Xrn.hrn_path_list(self.hrn)
return '.'.join( self.authority )
def get_authority_urn(self):
- if not self.hrn: raise SfaAPIError, "Xrn"
+ if not self.hrn: raise SfaAPIError, "Xrn.get_authority_urn"
# self.authority keeps a list
if not hasattr(self,'authority'):
self.authority=Xrn.hrn_path_list(self.hrn)
"""
if not self.urn or not self.urn.startswith(Xrn.URN_PREFIX):
- raise SfaAPIError, "Xrn"
+ raise SfaAPIError, "Xrn.urn_to_hrn"
parts = Xrn.urn_split(self.urn)
type=parts.pop(2)
"""
if not self.hrn or self.hrn.startswith(Xrn.URN_PREFIX):
- raise SfaAPIError, "Xrn"
+ raise SfaAPIError, "Xrn.hrn_to_urn"
if self.type == 'authority':
self.authority = Xrn.hrn_split(self.hrn)