Ejemplo n.º 1
0
 def __call__(self, *args, **kw):
    # parse arguments.
    # use lib to load and store temporary data for the argument parsers.
    lib = conf.ArgLib()
    lib.config = self.config
    lib.storage = storage
    lib.user_id = self.config['user_id']
    
    args, kw, extras = conf.parse_args( self.method_name, args, kw, lib )
    
    # validate arguments
    valid = conf.validate_args( self.method_name, args, kw )
    if not valid:
       raise Exception("Invalid arguments for %s" % self.method_name)
    
    return call_method( self.config, self.client, self.method_name, args, kw )
Ejemplo n.º 2
0
    def __call__(self, *args, **kw):
        # parse arguments.
        # use lib to load and store temporary data for the argument parsers.
        lib = conf.ArgLib()
        lib.config = self.config
        lib.storage = storage
        lib.user_id = self.config['user_id']

        args, kw, extras = conf.parse_args(self.method_name, args, kw, lib)

        # validate arguments
        valid = conf.validate_args(self.method_name, args, kw)
        if not valid:
            raise Exception("Invalid arguments for %s" % self.method_name)

        return call_method(self.config, self.client, self.method_name, args,
                           kw)
Ejemplo n.º 3
0
def client_call( CONFIG, method_name, *args, **kw ):
   # call a method, with the given args and kw.
   
   called_from_main = False 
   if CONFIG.has_key('__from_main__'):
      # we were called from the main method (not from a client program).
      # This should be remembered, since it determines whether or not we use
      # the CONFIG-given user_id if no user_id can be found.
      called_from_main = CONFIG['__from_main__']
      
   verify_reply = True
   if CONFIG.has_key('verify_reply'):
      # do not verify the reply (i.e. we might not know the Syndicate public key)
      verify_reply = CONFIG['verify_reply']
   
   user_id = CONFIG.get('user_id', None)
   if user_id is None:
      raise Exception("Invalid config: no user_id")
   
   # parse arguments.
   # use lib to load and store temporary data for the argument parsers.
   lib = conf.ArgLib()
   lib.config = CONFIG
   lib.storage = storage
   lib.user_id = user_id
   
   args, kw, extras = conf.parse_args( method_name, args, kw, lib )
   
   # validate arguments
   valid = conf.validate_args( method_name, args, kw )
   if not valid:
      raise Exception("Invalid arguments for %s" % method_name)
   
   # determine the user_id, if needed
   force_user_name = None 
   
   if "user_id" in CONFIG['_in_argv']:
      # override user_id with argv
      force_user_name = user_id
   
   if CONFIG.has_key('force_user_name'):
      # override user_id with a value set in make_conf()?
      force_user_name = CONFIG['force_user_name']
      
   if called_from_main and force_user_name is None:
      # use CONFIG-given user_id if called from the command-line (main()), but we don't yet know the user_id from above.
      force_user_name = user_id
      
      
   # attempt to read the public key from disk   
   syndicate_public_key = load_syndicate_public_key( CONFIG )
   
   # will we trust a downloaded public key, if one is not known?
   trust_public_key = False
   if syndicate_public_key is None:
      trust_public_key = CONFIG.get('trust_public_key', False)
   
   # will we verify the result of our method?
   no_verify_result = CONFIG.get('no_verify_result', False)
   
   if syndicate_public_key is None:
      # get the public key from the MS
      syndicate_public_key_str = download_syndicate_public_key( CONFIG )
      if syndicate_public_key_str is not None:
         if not trust_public_key:
            do_trust = ask_trust_public_key( CONFIG, syndicate_public_key_str )
            if do_trust:
               store_syndicate_public_key( CONFIG, syndicate_public_key_str )
   
         elif not no_verify_result:
            log.error("Could not obtain Syndicate public key.  Cannot continue.")
            return None
         
         else:
            log.warning("INSECURE: will not verify result!")
            
         try:
            syndicate_public_key = CryptoKey.importKey( syndicate_public_key_str )
         except:
            log.error("Failed to parse public key")
            return None
            
   
   # create the RPC client
   client = make_rpc_client( CONFIG, username=CONFIG['user_id'], password=CONFIG.get('password',None), user_private_key=CONFIG.get('user_pkey',None),
                             syndicate_public_key=syndicate_public_key, no_verify_result=no_verify_result )
   
   # call the method
   ret = call_method( CONFIG, client, method_name, args, kw ) 
   
   # failure? 
   if ret is None:
      raise Exception("No data returned from server")
   
   # process object-specific extra information
   for object_cls in object_stub.object_classes:
      object_cls.ProcessExtras( extras, CONFIG, method_name, args, kw, ret, storage )

   return ret
Ejemplo n.º 4
0
def client_call(CONFIG, method_name, *args, **kw):
    # call a method, with the given args and kw.

    called_from_main = False
    if CONFIG.has_key('__from_main__'):
        # we were called from the main method (not from a client program).
        # This should be remembered, since it determines whether or not we use
        # the CONFIG-given user_id if no user_id can be found.
        called_from_main = CONFIG['__from_main__']

    verify_reply = True
    if CONFIG.has_key('verify_reply'):
        # do not verify the reply (i.e. we might not know the Syndicate public key)
        verify_reply = CONFIG['verify_reply']

    user_id = CONFIG.get('user_id', None)
    if user_id is None:
        raise Exception("Invalid config: no user_id")

    # parse arguments.
    # use lib to load and store temporary data for the argument parsers.
    lib = conf.ArgLib()
    lib.config = CONFIG
    lib.storage = storage
    lib.user_id = user_id

    args, kw, extras = conf.parse_args(method_name, args, kw, lib)

    # validate arguments
    valid = conf.validate_args(method_name, args, kw)
    if not valid:
        raise Exception("Invalid arguments for %s" % method_name)

    # determine the user_id, if needed
    force_user_name = None

    if "user_id" in CONFIG['_in_argv']:
        # override user_id with argv
        force_user_name = user_id

    if CONFIG.has_key('force_user_name'):
        # override user_id with a value set in make_conf()?
        force_user_name = CONFIG['force_user_name']

    if called_from_main and force_user_name is None:
        # use CONFIG-given user_id if called from the command-line (main()), but we don't yet know the user_id from above.
        force_user_name = user_id

    # attempt to read the public key from disk
    syndicate_public_key = load_syndicate_public_key(CONFIG)

    # will we trust a downloaded public key, if one is not known?
    trust_public_key = False
    if syndicate_public_key is None:
        trust_public_key = CONFIG.get('trust_public_key', False)

    # will we verify the result of our method?
    no_verify_result = CONFIG.get('no_verify_result', False)

    if syndicate_public_key is None:
        # get the public key from the MS
        syndicate_public_key_str = download_syndicate_public_key(CONFIG)
        if syndicate_public_key_str is not None:
            if not trust_public_key:
                do_trust = ask_trust_public_key(CONFIG,
                                                syndicate_public_key_str)
                if do_trust:
                    store_syndicate_public_key(CONFIG,
                                               syndicate_public_key_str)

            elif not no_verify_result:
                log.error(
                    "Could not obtain Syndicate public key.  Cannot continue.")
                return None

            else:
                log.warning("INSECURE: will not verify result!")

            try:
                syndicate_public_key = CryptoKey.importKey(
                    syndicate_public_key_str)
            except:
                log.error("Failed to parse public key")
                return None

    # create the RPC client
    client = make_rpc_client(CONFIG,
                             username=CONFIG['user_id'],
                             password=CONFIG.get('password', None),
                             user_private_key=CONFIG.get('user_pkey', None),
                             syndicate_public_key=syndicate_public_key,
                             no_verify_result=no_verify_result)

    # call the method
    ret = call_method(CONFIG, client, method_name, args, kw)

    # failure?
    if ret is None:
        raise Exception("No data returned from server")

    # process object-specific extra information
    for object_cls in object_stub.object_classes:
        object_cls.ProcessExtras(extras, CONFIG, method_name, args, kw, ret,
                                 storage)

    return ret