Skip to content

Instantly share code, notes, and snippets.

@kylegallatin
Last active March 7, 2023 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylegallatin/cb6212b669fbc19a05cb45351fbc68a4 to your computer and use it in GitHub Desktop.
Save kylegallatin/cb6212b669fbc19a05cb45351fbc68a4 to your computer and use it in GitHub Desktop.
import sys
import grpc
def get_grpc_connection(host_port: str, secure: bool):
if secure:
credentials = grpc.ssl_channel_credentials()
channel = grpc.secure_channel(host_port, credentials)
else:
channel = grpc.insecure_channel(host_port)
return channel
def check_grpc_connection(host_port: str, secure: bool):
channel = get_grpc_connection(host_port, secure)
try:
grpc.channel_ready_future(channel).result(timeout=5)
return f"Successfully established secure:{secure} channel to {host_port}"
except:
return f"Timeout. Failed to establish secure:{secure} channel to {host_port}. Check your ingress/proxy configuration."
print(check_grpc_connection(sys.argv[1], True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment