2023-12-29 17:38:23 +01:00
|
|
|
import json
|
|
|
|
import requests
|
|
|
|
import argparse
|
2024-03-30 12:12:11 +01:00
|
|
|
import hashlib
|
2023-12-29 17:38:23 +01:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser("update_passkeys")
|
|
|
|
parser.add_argument("api_key", help="An API Key to access the https://passkeys.directory/ backend.", type=str)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
URL_PASSKEYS = "https://apecbgwekadegtkzpwyh.supabase.co/rest/v1/sites"
|
|
|
|
URL_APIKEY = args.api_key
|
|
|
|
|
|
|
|
response = requests.get(
|
|
|
|
URL_PASSKEYS,
|
|
|
|
params={
|
|
|
|
'select': '*',
|
|
|
|
'or': '(passkey_signin.eq.true,passkey_mfa.eq.true)',
|
|
|
|
},
|
|
|
|
headers={
|
|
|
|
'apikey': URL_APIKEY,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
aggr = []
|
|
|
|
|
|
|
|
for site in response.json():
|
2024-03-30 12:12:11 +01:00
|
|
|
# generate a unique id
|
|
|
|
id_str = site['name'] + '|' + site['domain'] + '|' + (site.get('created_at') or '')
|
|
|
|
id = hashlib\
|
|
|
|
.md5(id_str.encode('utf-8'))\
|
|
|
|
.hexdigest()
|
2023-12-29 17:38:23 +01:00
|
|
|
features = []
|
|
|
|
entry = {
|
2024-03-30 12:12:11 +01:00
|
|
|
'id': id,
|
2023-12-29 17:38:23 +01:00
|
|
|
'name': site['name'],
|
|
|
|
'domain': site['domain'],
|
|
|
|
'features': features,
|
|
|
|
}
|
|
|
|
|
|
|
|
def append_if_not_empty(src_key, dst_key):
|
|
|
|
if src_key in site and site[src_key]:
|
|
|
|
entry[dst_key] = site[src_key]
|
|
|
|
|
|
|
|
append_if_not_empty('documentation_link', 'documentation')
|
|
|
|
append_if_not_empty('setup_link', 'setup')
|
2024-03-30 12:12:11 +01:00
|
|
|
append_if_not_empty('category', 'category')
|
|
|
|
append_if_not_empty('created_at', 'created_at')
|
2023-12-29 17:38:23 +01:00
|
|
|
append_if_not_empty('notes', 'notes')
|
|
|
|
|
|
|
|
# convert features to a list
|
|
|
|
if site['passkey_mfa']:
|
|
|
|
features.append('mfa')
|
|
|
|
if site['passkey_signin']:
|
|
|
|
features.append('signin')
|
|
|
|
|
|
|
|
aggr.append(entry)
|
|
|
|
|
|
|
|
# Ensure the file is sorted for better
|
|
|
|
# git diff logs.
|
|
|
|
aggr.sort(key=lambda x: x['domain'])
|
|
|
|
|
|
|
|
aggr_text = json.dumps(aggr, indent=2)
|
|
|
|
|
|
|
|
with open('common/src/commonMain/resources/MR/files/passkeys.json', 'w') as f:
|
|
|
|
f.write(aggr_text)
|