Skip to content

Commit

Permalink
Fix cosmos spec updating script
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrod-teich committed Mar 10, 2024
1 parent b667add commit 771d6e8
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import re

LAVA_PUBLIC_RPC = ""
LAVA_PUBLIC_RPC = "grpcbin.pulsar.scrttestnet.com:9099"


def parse_endpoints_from_spec(lava_spec_file: str) -> dict[str, list[str]]:
Expand Down Expand Up @@ -35,11 +35,11 @@ def parse_endpoints_from_spec(lava_spec_file: str) -> dict[str, list[str]]:
return endpoints


def parse_endpoints_from_grpcurl() -> dict[str, list[str]]:
def parse_endpoints_from_grpcurl(grpc_url: str) -> dict[str, list[str]]:
print("### Parsing endpoints from gRPC service")

endpoints: dict[str, list[str]] = {"grpc": [], "rest": []}
content = os.popen(f"grpcurl -plaintext {LAVA_PUBLIC_RPC} describe").read()
content = os.popen(f"grpcurl -plaintext {grpc_url} describe").read()

# Regex pattern to find services starting with their corresponding rpc and rest paths
grpc_pattern = re.compile(
Expand All @@ -54,7 +54,7 @@ def parse_endpoints_from_grpcurl() -> dict[str, list[str]]:
for service_match in grpc_pattern.finditer(content):
service_name, service_content = service_match.groups()

if "cosmos" in service_content or "cosmwasm" in service_content or "ibc" in service_content:
if "cosmos" in service_content or "cosmwasm" in service_content or "ibc" in service_content or "grpc.reflection.v1alpha" in service_content:
continue

# Extracting all grpc paths
Expand Down Expand Up @@ -120,18 +120,18 @@ def create_api_entry(endpoint: str) -> dict:


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Update Lava's spec file")
parser.add_argument("lava_spec_file", help="Path to the Lava spec file.")
parser = argparse.ArgumentParser(description="Update Cosmos-based spec file")
parser.add_argument("spec_file", help="Path to the spec file to update")
parser.add_argument("grpc_url", help="GRPC URL to fetch the endpoints from")
parser.add_argument(
"--dry-run",
action="store_true",
help="Perform a dry run without making any changes.",
)
args = parser.parse_args()

try:
grpcurl_endpoints = parse_endpoints_from_grpcurl()
spec_endpoints = parse_endpoints_from_spec(args.lava_spec_file)
grpcurl_endpoints = parse_endpoints_from_grpcurl(args.grpc_url)
spec_endpoints = parse_endpoints_from_spec(args.spec_file)

grpc_endpoints_to_update = set(grpcurl_endpoints["grpc"]) - set(
spec_endpoints["grpc"]
Expand All @@ -146,7 +146,7 @@ def create_api_entry(endpoint: str) -> dict:
exit(1)
else:
update_spec_file(
args.lava_spec_file, grpc_endpoints_to_update, rest_endpoints_to_update
args.spec_file, grpc_endpoints_to_update, rest_endpoints_to_update
)

print("### Done")
Expand Down

0 comments on commit 771d6e8

Please sign in to comment.