-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_public.py
106 lines (84 loc) · 2.98 KB
/
make_public.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from logging import warn
from google.cloud import bigquery
from tqdm import tqdm
import yaml
import synapseclient
# Initialize the Synapse client and log in
syn = synapseclient.Synapse()
syn.login()
# Construct a BigQuery client object.
client = bigquery.Client(project="htan-dcc")
def make_public(synid):
registered = syn.getPermissions(synid, "273948") == ["DOWNLOAD", "READ"]
if registered:
pass
else:
syn.setPermissions(
synid, "273948", ["DOWNLOAD", "READ"], warn_if_inherits=False
)
public = syn.getPermissions(synid, "PUBLIC") == ["READ"]
if public:
pass
else:
syn.setPermissions(
synid, principalId="PUBLIC", accessType=["READ"], warn_if_inherits=False
)
# Load configuration from the external YAML file
config_file_path = "config.yaml"
with open(config_file_path, "r") as file:
config = yaml.safe_load(file)
# Assign values from the YAML config
users = config["users"]
permission_levels = config["permission_levels"]
# Append specific ids to make public from the config file
public_dirs = config["public_dirs"]
# Define public view and registered user download permission RAs
public_view_access = {
"principalId": users["anyone_on_the_web"],
"accessType": permission_levels["view"],
}
registered_user_download_access = {
"principalId": users["all_registered_synapse_users"],
"accessType": permission_levels["download"],
}
# Define the query to fetch releasable entity IDs
query = """
WITH released AS (
SELECT entityId, Component, channel_metadata_synapseId
FROM `htan-dcc.released.entities`
)
SELECT entityId AS syn_public FROM released
WHERE REGEXP_CONTAINS(Component,
r'Level[34]|Auxiliary|Accessory|Other|MassSpectrometry|RPPA')
UNION ALL
SELECT DISTINCT channel_metadata_synapseId AS syn_public FROM released
WHERE channel_metadata_synapseId IS NOT NULL
"""
print("Listing releasable entities...")
# Execute the query and fetch the results
results = client.query(query).result()
# Extract the entity IDs from the results
entity_ids = [row["syn_public"] for row in results]
# entity_ids.append(public_dirs)
# Subset for testing
# entity_ids = entity_ids[:50]
print(f"Ready to make {len(entity_ids)} entities public...")
proceed = input("Do you want to proceed? (y/n): ")
if proceed.lower() == "y":
print(f"Making {len(entity_ids)} entities public...")
else:
print("Exiting...")
exit()
for entity_id in (pbar := tqdm(entity_ids)):
try:
pbar.set_description(f"{entity_id}")
syn.setPermissions(entity_id, "273949", ["READ"], warn_if_inherits=False)
syn.setPermissions(
entity_id, "273948", ["DOWNLOAD", "READ"], warn_if_inherits=False
)
with open("entity_ids.txt", "a") as file:
file.write(entity_id + "\n")
except Exception as e:
print(f"Error setting permissions for entity {entity_id}: {e}")
raise
print("Done!")