kopia lustrzana https://github.com/snarfed/bridgy-fed
Protocol.send: drop log_data kwarg
protocols are responsible for logging objects themselvespull/663/head
rodzic
7e7962fe45
commit
59abcb00bc
|
@ -186,7 +186,7 @@ class ActivityPub(User, Protocol):
|
|||
return actor.get('publicInbox') or actor.get('inbox')
|
||||
|
||||
@classmethod
|
||||
def send(to_cls, obj, url, orig_obj=None, log_data=True):
|
||||
def send(to_cls, obj, url, orig_obj=None):
|
||||
"""Delivers an activity to an inbox URL.
|
||||
|
||||
If ``obj.recipient_obj`` is set, it's interpreted as the receiving actor
|
||||
|
@ -205,7 +205,7 @@ class ActivityPub(User, Protocol):
|
|||
elif not activity.get('actor'):
|
||||
logger.warning('Outgoing AP activity has no actor!')
|
||||
|
||||
return signed_post(url, log_data=True, data=activity).ok
|
||||
return signed_post(url, data=activity).ok
|
||||
|
||||
@classmethod
|
||||
def fetch(cls, obj, **kwargs):
|
||||
|
@ -417,7 +417,7 @@ def signed_post(url, **kwargs):
|
|||
return signed_request(util.requests_post, url, **kwargs)
|
||||
|
||||
|
||||
def signed_request(fn, url, data=None, log_data=True, headers=None, **kwargs):
|
||||
def signed_request(fn, url, data=None, headers=None, **kwargs):
|
||||
"""Wraps ``requests.*`` and adds HTTP Signature.
|
||||
|
||||
If the current session has a user (ie in ``g.user``), signs with that user's
|
||||
|
@ -427,7 +427,6 @@ def signed_request(fn, url, data=None, log_data=True, headers=None, **kwargs):
|
|||
fn (callable): :func:`util.requests_get` or :func:`util.requests_post`
|
||||
url (str):
|
||||
data (dict): optional AS2 object
|
||||
log_data (bool): whether to log full data object
|
||||
kwargs: passed through to requests
|
||||
|
||||
Returns:
|
||||
|
@ -440,8 +439,6 @@ def signed_request(fn, url, data=None, log_data=True, headers=None, **kwargs):
|
|||
user = g.user or default_signature_user()
|
||||
|
||||
if data:
|
||||
if log_data:
|
||||
logger.info(f'Sending AS2 object: {json_dumps(data, indent=2)}')
|
||||
data = json_dumps(data).encode()
|
||||
|
||||
headers = {
|
||||
|
@ -477,8 +474,7 @@ def signed_request(fn, url, data=None, log_data=True, headers=None, **kwargs):
|
|||
# handle GET redirects manually so that we generate a new HTTP signature
|
||||
if resp.is_redirect and fn == util.requests_get:
|
||||
new_url = urljoin(url, resp.headers['Location'])
|
||||
return signed_request(fn, new_url, data=data, headers=headers,
|
||||
log_data=log_data, **kwargs)
|
||||
return signed_request(fn, new_url, data=data, headers=headers, **kwargs)
|
||||
|
||||
type = common.content_type(resp)
|
||||
if (type and type != 'text/html' and
|
||||
|
|
|
@ -251,7 +251,7 @@ class ATProto(User, Protocol):
|
|||
user.put()
|
||||
|
||||
@classmethod
|
||||
def send(to_cls, obj, url, orig_obj=None, log_data=True):
|
||||
def send(to_cls, obj, url, orig_obj=None):
|
||||
"""Creates a record if we own its repo.
|
||||
|
||||
Creates the repo first if it doesn't exist.
|
||||
|
|
|
@ -357,7 +357,7 @@ class Protocol:
|
|||
return g.user.key
|
||||
|
||||
@classmethod
|
||||
def send(to_cls, obj, url, orig_obj=None, log_data=True):
|
||||
def send(to_cls, obj, url, orig_obj=None):
|
||||
"""Sends an outgoing activity.
|
||||
|
||||
To be implemented by subclasses.
|
||||
|
@ -367,7 +367,6 @@ class Protocol:
|
|||
url (str): destination URL to send to
|
||||
orig_obj (models.Object): the "original object" that this object
|
||||
refers to, eg replies to or reposts or likes
|
||||
log_data (bool): whether to log full data object
|
||||
|
||||
Returns:
|
||||
bool: True if the activity is sent successfully, False if it is
|
||||
|
@ -816,7 +815,6 @@ class Protocol:
|
|||
)
|
||||
logger.info(f'Delivering to: {obj.undelivered}')
|
||||
|
||||
log_data = True
|
||||
errors = [] # stores (target URL, code, body) tuples
|
||||
|
||||
# deliver!
|
||||
|
@ -825,8 +823,7 @@ class Protocol:
|
|||
protocol = PROTOCOLS[target.protocol]
|
||||
|
||||
try:
|
||||
sent = protocol.send(obj, target.uri, orig_obj=orig_obj,
|
||||
log_data=log_data)
|
||||
sent = protocol.send(obj, target.uri, orig_obj=orig_obj)
|
||||
if sent:
|
||||
add(obj.delivered, target)
|
||||
obj.undelivered.remove(target)
|
||||
|
@ -837,8 +834,6 @@ class Protocol:
|
|||
add(obj.failed, target)
|
||||
obj.undelivered.remove(target)
|
||||
errors.append((target.uri, code, body))
|
||||
finally:
|
||||
log_data = False
|
||||
|
||||
obj.put()
|
||||
|
||||
|
|
|
@ -947,7 +947,7 @@ class ProtocolReceiveTest(TestCase):
|
|||
}
|
||||
|
||||
sent = []
|
||||
def send(obj, url, orig_obj=None, log_data=True):
|
||||
def send(obj, url, orig_obj=None):
|
||||
self.assertEqual(create_as1, obj.as1)
|
||||
if not sent:
|
||||
self.assertEqual('target:1', url)
|
||||
|
|
|
@ -100,7 +100,7 @@ class Fake(User, protocol.Protocol):
|
|||
return url.startswith('fake:blocklisted')
|
||||
|
||||
@classmethod
|
||||
def send(cls, obj, url, orig_obj=None, log_data=True):
|
||||
def send(cls, obj, url, orig_obj=None):
|
||||
logger.info(f'Fake.send {url}')
|
||||
cls.sent.append((obj, url))
|
||||
return True
|
||||
|
|
Ładowanie…
Reference in New Issue