Source code for latch_cli.services.cp.utils
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
@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
[docs]class UserInfoByAccountId(TypedDict):
defaultAccount: str
teamMembersByUserId: TeamMembersByUserId
teamInfosByOwnerId: TeamInfosByOwnerId
[docs]class LdataS3MountConfiguratorRolesByAccountIdNode(TypedDict):
ldataS3MountAccessProvensByGeneratedUsing: LdataS3MountAccessProvensByGeneratedUsing
[docs]class LdataS3MountConfiguratorRolesByAccountId(TypedDict):
nodes: List[LdataS3MountConfiguratorRolesByAccountIdNode]
[docs]class AccountInfoCurrent(TypedDict):
userInfoByAccountId: UserInfoByAccountId
ldataS3MountConfiguratorRolesByAccountId: LdataS3MountConfiguratorRolesByAccountId
@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