2020-12-24 16:48:03 +00:00
|
|
|
__filename__ = "briar.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
2022-02-03 13:58:20 +00:00
|
|
|
__version__ = "1.3.0"
|
2020-12-24 16:48:03 +00:00
|
|
|
__maintainer__ = "Bob Mottram"
|
2021-09-10 16:14:50 +00:00
|
|
|
__email__ = "bob@libreserver.org"
|
2020-12-24 16:48:03 +00:00
|
|
|
__status__ = "Production"
|
2021-06-15 15:08:12 +00:00
|
|
|
__module_group__ = "Profile Metadata"
|
2020-12-24 16:48:03 +00:00
|
|
|
|
|
|
|
|
2021-12-28 17:33:54 +00:00
|
|
|
def get_briar_address(actor_json: {}) -> str:
|
2020-12-24 16:48:03 +00:00
|
|
|
"""Returns briar address for the given actor
|
|
|
|
"""
|
2021-12-26 10:29:52 +00:00
|
|
|
if not actor_json.get('attachment'):
|
2020-12-24 16:48:03 +00:00
|
|
|
return ''
|
2021-12-26 10:32:45 +00:00
|
|
|
for property_value in actor_json['attachment']:
|
2022-05-11 16:10:38 +00:00
|
|
|
name_value = None
|
|
|
|
if property_value.get('name'):
|
|
|
|
name_value = property_value['name']
|
|
|
|
elif property_value.get('schema:name'):
|
|
|
|
name_value = property_value['schema:name']
|
|
|
|
if not name_value:
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2022-05-11 16:10:38 +00:00
|
|
|
if not name_value.lower().startswith('briar'):
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-26 10:32:45 +00:00
|
|
|
if not property_value.get('type'):
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-26 10:32:45 +00:00
|
|
|
if not property_value.get('value'):
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-26 10:32:45 +00:00
|
|
|
if property_value['type'] != 'PropertyValue':
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-26 10:32:45 +00:00
|
|
|
property_value['value'] = property_value['value'].strip()
|
|
|
|
if len(property_value['value']) < 50:
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-26 10:32:45 +00:00
|
|
|
if not property_value['value'].startswith('briar://'):
|
2020-12-24 16:55:06 +00:00
|
|
|
continue
|
2021-12-26 10:32:45 +00:00
|
|
|
if property_value['value'].lower() != property_value['value']:
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-26 10:32:45 +00:00
|
|
|
if '"' in property_value['value']:
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-26 10:32:45 +00:00
|
|
|
if ' ' in property_value['value']:
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-26 10:32:45 +00:00
|
|
|
if ',' in property_value['value']:
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-26 10:32:45 +00:00
|
|
|
if '.' in property_value['value']:
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-26 10:32:45 +00:00
|
|
|
return property_value['value']
|
2020-12-24 16:48:03 +00:00
|
|
|
return ''
|
|
|
|
|
|
|
|
|
2021-12-30 18:38:36 +00:00
|
|
|
def set_briar_address(actor_json: {}, briar_address: str) -> None:
|
2020-12-24 16:48:03 +00:00
|
|
|
"""Sets an briar address for the given actor
|
|
|
|
"""
|
2021-12-30 18:38:36 +00:00
|
|
|
not_briar_address = False
|
2020-12-24 16:48:03 +00:00
|
|
|
|
2021-12-30 18:38:36 +00:00
|
|
|
if len(briar_address) < 50:
|
|
|
|
not_briar_address = True
|
|
|
|
if not briar_address.startswith('briar://'):
|
|
|
|
not_briar_address = True
|
|
|
|
if briar_address.lower() != briar_address:
|
|
|
|
not_briar_address = True
|
|
|
|
if '"' in briar_address:
|
|
|
|
not_briar_address = True
|
|
|
|
if ' ' in briar_address:
|
|
|
|
not_briar_address = True
|
|
|
|
if '.' in briar_address:
|
|
|
|
not_briar_address = True
|
|
|
|
if ',' in briar_address:
|
|
|
|
not_briar_address = True
|
|
|
|
if '<' in briar_address:
|
|
|
|
not_briar_address = True
|
2020-12-24 16:48:03 +00:00
|
|
|
|
2021-12-26 10:29:52 +00:00
|
|
|
if not actor_json.get('attachment'):
|
|
|
|
actor_json['attachment'] = []
|
2020-12-24 16:48:03 +00:00
|
|
|
|
|
|
|
# remove any existing value
|
2021-12-30 18:38:36 +00:00
|
|
|
property_found = None
|
2021-12-26 10:32:45 +00:00
|
|
|
for property_value in actor_json['attachment']:
|
2022-05-11 16:10:38 +00:00
|
|
|
name_value = None
|
|
|
|
if property_value.get('name'):
|
|
|
|
name_value = property_value['name']
|
|
|
|
elif property_value.get('schema:name'):
|
|
|
|
name_value = property_value['schema:name']
|
|
|
|
if not name_value:
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-26 10:32:45 +00:00
|
|
|
if not property_value.get('type'):
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2022-05-11 16:10:38 +00:00
|
|
|
if not name_value.lower().startswith('briar'):
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-30 18:38:36 +00:00
|
|
|
property_found = property_value
|
2020-12-24 16:48:03 +00:00
|
|
|
break
|
2021-12-30 18:38:36 +00:00
|
|
|
if property_found:
|
|
|
|
actor_json['attachment'].remove(property_found)
|
|
|
|
if not_briar_address:
|
2020-12-24 16:48:03 +00:00
|
|
|
return
|
|
|
|
|
2021-12-26 10:32:45 +00:00
|
|
|
for property_value in actor_json['attachment']:
|
2022-05-11 16:10:38 +00:00
|
|
|
name_value = None
|
|
|
|
if property_value.get('name'):
|
|
|
|
name_value = property_value['name']
|
|
|
|
elif property_value.get('schema:name'):
|
|
|
|
name_value = property_value['schema:name']
|
|
|
|
if not name_value:
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-26 10:32:45 +00:00
|
|
|
if not property_value.get('type'):
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2022-05-11 16:10:38 +00:00
|
|
|
if not name_value.lower().startswith('briar'):
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-26 10:32:45 +00:00
|
|
|
if property_value['type'] != 'PropertyValue':
|
2020-12-24 16:48:03 +00:00
|
|
|
continue
|
2021-12-30 18:38:36 +00:00
|
|
|
property_value['value'] = briar_address
|
2020-12-24 16:48:03 +00:00
|
|
|
return
|
|
|
|
|
2021-12-30 18:38:36 +00:00
|
|
|
new_briar_address = {
|
2020-12-24 16:48:03 +00:00
|
|
|
"name": "Briar",
|
|
|
|
"type": "PropertyValue",
|
2021-12-30 18:38:36 +00:00
|
|
|
"value": briar_address
|
2020-12-24 16:48:03 +00:00
|
|
|
}
|
2021-12-30 18:38:36 +00:00
|
|
|
actor_json['attachment'].append(new_briar_address)
|