11from dataclasses import dataclass
22from datetime import datetime , timedelta
3+ import json
34import os .path
45import subprocess
56import time
67from typing import Optional
78
89import grpc
910import pytest
10- import requests
1111
1212
1313@dataclass (frozen = True )
@@ -22,7 +22,6 @@ class Service:
2222class Topaz :
2323 authorizer : Service
2424 directory_grpc : Service
25- directory_gw : Service
2625
2726 @staticmethod
2827 def start () -> None :
@@ -54,14 +53,14 @@ def import_data(path: str) -> None:
5453 @staticmethod
5554 def set_manifest (manifest_path : str ) -> None :
5655 subprocess .run (
57- f"topaz ds delete manifest --force" ,
56+ f"topaz ds delete manifest --force -i " ,
5857 shell = True ,
5958 capture_output = True ,
6059 check = True ,
6160 )
6261
6362 subprocess .run (
64- f"topaz ds set manifest { manifest_path } " ,
63+ f"topaz ds set manifest { manifest_path } -i " ,
6564 shell = True ,
6665 capture_output = True ,
6766 check = True ,
@@ -81,11 +80,6 @@ def wait_for_ready(self) -> None:
8180def topaz ():
8281 Topaz .stop ()
8382
84- topaz_db_dir = os .path .expanduser ("~/.config/topaz/db" )
85-
86- if os .path .exists (f"{ topaz_db_dir } /directory.db" ):
87- os .rename (f"{ topaz_db_dir } /directory.db" , f"{ topaz_db_dir } /directory.bak" )
88-
8983 svc = topaz_configure ()
9084 svc .start ()
9185 svc .wait_for_ready ()
@@ -99,9 +93,6 @@ def topaz():
9993
10094 time .sleep (1 )
10195
102- if os .path .exists (f"{ topaz_db_dir } /directory.bak" ):
103- os .rename (f"{ topaz_db_dir } /directory.bak" , f"{ topaz_db_dir } /directory.db" )
104-
10596
10697def topaz_configure () -> Topaz :
10798 subprocess .run (
@@ -111,25 +102,35 @@ def topaz_configure() -> Topaz:
111102 check = True ,
112103 )
113104
114- cert_path = topaz_cert_path ()
115- ca_cert_path_grpc = os .path .join (cert_path , "grpc-ca.crt" )
116- ca_cert_path_gw = os .path .join (cert_path , "gateway-ca.crt" )
105+ subprocess .run (
106+ "topaz config use todo" ,
107+ shell = True ,
108+ capture_output = True ,
109+ check = True ,
110+ )
117111
118- return Topaz (
119- authorizer = Service ("localhost:8282" , ca_cert_path = ca_cert_path_grpc ),
120- directory_grpc = Service ("localhost:9292" , ca_cert_path = ca_cert_path_grpc ),
121- directory_gw = Service ("localhost:9393" , ca_cert_path = ca_cert_path_gw ),
112+ config = json .loads (
113+ subprocess .run (
114+ "topaz config info" ,
115+ shell = True ,
116+ capture_output = True ,
117+ check = True ,
118+ )
119+ .stdout .decode ()
120+ .strip ()
122121 )
123122
123+ cert_path = config ["config" ]["topaz_certs_dir" ]
124+ ca_cert_path_grpc = os .path .join (cert_path , "grpc-ca.crt" )
124125
125- def topaz_cert_path () -> str :
126- proc = subprocess .run (
127- "topaz config info | jq .config.topaz_certs_dir -r" ,
128- shell = True ,
129- check = True ,
130- capture_output = True ,
126+ return Topaz (
127+ authorizer = Service (
128+ config ["authorizer" ]["topaz_authorizer_svc" ], ca_cert_path = ca_cert_path_grpc
129+ ),
130+ directory_grpc = Service (
131+ config ["directory" ]["topaz_directory_svc" ], ca_cert_path = ca_cert_path_grpc
132+ ),
131133 )
132- return proc .stdout .decode ().strip ()
133134
134135
135136def connect (svc : Service ) -> grpc .Channel :
0 commit comments