-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathutils.py
164 lines (122 loc) · 4.3 KB
/
utils.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
from typing import List, TypedDict
try:
from functools import cache
except ImportError:
from functools import lru_cache as cache
import gql
from latch_sdk_gql.execute import execute
class Child(TypedDict):
name: str
class ChildLdataTreeEdgesNode(TypedDict):
child: Child
class ChildLdataTreeEdges(TypedDict):
nodes: List[ChildLdataTreeEdgesNode]
class LdataResolvePathData(TypedDict):
childLdataTreeEdges: ChildLdataTreeEdges
@cache
def _get_immediate_children_of_node(path: str) -> List[str]:
lrpd: LdataResolvePathData = execute(
gql.gql("""
query MyQuery($argPath: String!) {
ldataResolvePathData(argPath: $argPath) {
childLdataTreeEdges(
filter: {child: {removed: {equalTo: false}}}
) {
nodes {
child {
name
}
}
}
}
}
"""),
{"argPath": path},
)["ldataResolvePathData"]
if lrpd is None:
return []
res: List[str] = []
for node in lrpd["childLdataTreeEdges"]["nodes"]:
res.append(node["child"]["name"])
return res
class Team(TypedDict):
accountId: str
class TeamMembersByUserIdNode(TypedDict):
team: Team
class TeamMembersByUserId(TypedDict):
nodes: List[TeamMembersByUserIdNode]
class TeamInfosByOwnerId(TypedDict):
nodes: List[Team]
class UserInfoByAccountId(TypedDict):
defaultAccount: str
teamMembersByUserId: TeamMembersByUserId
teamInfosByOwnerId: TeamInfosByOwnerId
class Bucket(TypedDict):
bucketName: str
class LdataS3MountAccessProvensByGeneratedUsing(TypedDict):
nodes: List[Bucket]
class LdataS3MountConfiguratorRolesByAccountIdNode(TypedDict):
ldataS3MountAccessProvensByGeneratedUsing: LdataS3MountAccessProvensByGeneratedUsing
class LdataS3MountConfiguratorRolesByAccountId(TypedDict):
nodes: List[LdataS3MountConfiguratorRolesByAccountIdNode]
class AccountInfoCurrent(TypedDict):
userInfoByAccountId: UserInfoByAccountId
ldataS3MountConfiguratorRolesByAccountId: LdataS3MountConfiguratorRolesByAccountId
# todo(taras): support for gcp and azure mounts
# skipping now due to time. This decision does not
# influence correcetness of the CLI and only
# reduces the set of returned autocomplete
# suggestions
@cache
def _get_known_domains_for_account() -> List[str]:
aic: AccountInfoCurrent = execute(gql.gql("""
query DomainCompletionQuery {
accountInfoCurrent {
userInfoByAccountId {
defaultAccount
teamMembersByUserId(
filter: { team: { account: { removed: { equalTo: false } } } }
) {
nodes {
team {
accountId
}
}
}
teamInfosByOwnerId(filter: { account: { removed: { equalTo: false } } }) {
nodes {
accountId
}
}
}
ldataS3MountConfiguratorRolesByAccountId {
nodes {
ldataS3MountAccessProvensByGeneratedUsing {
nodes {
bucketName
}
}
}
}
}
}
"""))["accountInfoCurrent"]
ui = aic["userInfoByAccountId"]
res: List[str] = [""] # "" is for latch:///
accs: List[int] = [int(ui["defaultAccount"])]
accs.extend(
int(tm["team"]["accountId"]) for tm in ui["teamMembersByUserId"]["nodes"]
)
accs.extend(int(ti["accountId"]) for ti in ui["teamInfosByOwnerId"]["nodes"])
accs.sort()
for x in accs:
res.append(f"{x}.account")
res.append(f"shared.{x}.account")
buckets = [
map["bucketName"]
for role in aic["ldataS3MountConfiguratorRolesByAccountId"]["nodes"]
for map in role["ldataS3MountAccessProvensByGeneratedUsing"]["nodes"]
]
buckets.sort()
res.extend(f"{x}.mount" for x in buckets)
return res