def delete_gateway( syndicate_user_id, syndicate_user_signingkey_str, syndicate_user_verifyingkey_str, ms_url, gateway_name ): log.info("Deleting gateway") ms_url_api = os.path.join( ms_url, "api" ) # store user data in a convenient place, so we can blow it away later tmpdir, syntool_conf = setup_syntool( syndicate_user_id, ms_url_api, syndicate_user_signingkey_str, syndicate_user_verifyingkey_str, "user", syndicate_user_id ) delete_result = None try: delete_result = syntool.client_call( syntool_conf, "delete_gateway", gateway_name ) assert delete_result except Exception, e: if "-32400" in e.message.lower() and "signature verification failure" in e.message.lower(): raise Exception("Invalid private key: signature verification failure") log.exception(e) log.error("Failed to delete gateway") return False
def make_gateway( pubkey_str, mail_password, syndicate_user_id, syndicate_user_signingkey_str, syndicate_user_verifyingkey_str, ms_url, volume_name, gateway_name, gateway_port, gateway_pkey_pem ): global CREATED, EXISTS if gateway_name is None: gateway_name = make_default_gateway_name() log.info("Check gateway for %s" % volume_name ) ms_url_api = os.path.join( ms_url, "api" ) # store user data in a convenient place, so we can blow it away later tmpdir, syntool_conf = setup_syntool( syndicate_user_id, ms_url_api, syndicate_user_signingkey_str, syndicate_user_verifyingkey_str, "user", syndicate_user_id ) expected_gateway_pkey_path = storage.path_join( tmpdir, Gateway.RUNTIME_KEY_TYPE, privkey_basename( gateway_name ) ) expected_gateway_signingkey_path = storage.path_join( tmpdir, Gateway.SIGNING_KEY_TYPE, privkey_basename( gateway_name ) ) # see if the gateway exists. If so, then get its key and be done with it gateway_exists = False gateway_info = None try: gateway_info = syntool.client_call( syntool_conf, "read_gateway", gateway_name ) gateway_exists = True readwrite_gateway_caps, _ = Gateway.parse_gateway_caps( "READWRITE" ) assert (gateway_info['caps'] & readwrite_gateway_caps) == readwrite_gateway_caps except Exception, e: # FIXME: use exception subclasses if is_signature_failure(e): raise Exception("Invalid private key: signature verification failure") if not gateway_exists: log.info("No gateway %s exists; will try to create one" % gateway_name) else: # assertion failed log.error("Gateway %s is not suitable for SyndicateMail") cleanup_syntool( [], tmpdir ) return False
if not gateway_exists: log.info("No gateway %s exists; will try to create one" % gateway_name) else: # assertion failed log.error("Gateway %s is not suitable for SyndicateMail") cleanup_syntool( [], tmpdir ) return False if not gateway_exists: log.info("Creating gateway for %s" % volume_name ) # make the gateway gateway_info = None try: gateway_info = syntool.client_call( syntool_conf, "create_gateway", volume_name, syndicate_user_id, "UG", gateway_name, "localhost", gateway_port ) except Exception, e: # FIXME: use exception subclasses if is_signature_failure(e): raise Exception("Invalid private key: signature verification failure") log.exception(e) log.error("Failed to set up Volume access") cleanup_syntool( [], tmpdir ) return False # give the gateway write permission try: setcaps_result = syntool.client_call( syntool_conf, "set_gateway_caps", gateway_name, "READWRITE" ) assert setcaps_result except Exception, e: