Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 1a62321

Browse files
Abeer UpadhyaySanket Saurav
Abeer Upadhyay
authored and
Sanket Saurav
committed
[Fix issue#14] -- Set gRPC Channel based on DSN scheme
During Agent initialization, the gRPC Channel is created based on the DSN scheme. For secure scheme, `grpc.secure_channel` and `grpc.insecure_channel` otherwise. Signed-off-by: Abeer Upadhyay <[email protected]>
1 parent 9e32331 commit 1a62321

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

beacon/agent.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __init__(self, dsn=None, **options):
8686
self.tracer = Tracer(buffer=self.buffers['function'], **options)
8787

8888
# create a stub for this agent
89-
channel = grpc.insecure_channel(self.dsn.host)
89+
channel = self._get_grpc_channel()
9090
self.stub = pb2_grpc.BeaconStub(channel)
9191

9292
# set the logger
@@ -147,3 +147,13 @@ def _set_project_root(self, project_root):
147147

148148
def _set_source_version(self, source_version):
149149
self.source_version = source_version
150+
151+
def _get_grpc_channel(self):
152+
"""Returns a secure/insecure gRPC Channel instance"""
153+
if self.dsn.has_secure_scheme():
154+
ssl_credentials = grpc.ssl_channel_credentials()
155+
channel = grpc.secure_channel(self.dsn.host, ssl_credentials)
156+
else:
157+
channel = grpc.insecure_channel(self.dsn.host)
158+
159+
return channel

beacon/utils.py

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# -*- coding: utf-8 -*-
33

44
"""Utilities for Beacon."""
5+
from __future__ import unicode_literals
6+
57
import re
68
import threading
79
import time
@@ -153,3 +155,6 @@ def ERROR_MESSAGE(self):
153155
"<scheme>://<api-key>@<beacon-server-hostname>/<repository-id>"
154156
.format(self.input_dsn_string)
155157
)
158+
159+
def has_secure_scheme(self):
160+
return self.scheme.lower() == 'https'

0 commit comments

Comments
 (0)