Skip to content

Commit

Permalink
Simplify code around gRPC channel credentials (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnoczyns-volue authored Mar 14, 2024
1 parent ba8376f commit 7ccd627
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 30 deletions.
2 changes: 0 additions & 2 deletions src/volue/mesh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
XySet,
)
from ._connection import Connection
from ._credentials import Credentials

__title__ = "volue.mesh"
__author__ = "Volue AS"

__all__ = [
"Authentication",
"Credentials",
"Connection",
"AttributeBase",
"LinkRelationAttribute",
Expand Down
11 changes: 6 additions & 5 deletions src/volue/mesh/_base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from . import _authentication
from ._authentication import Authentication, ExternalAccessTokenPlugin
from ._credentials import Credentials

C = TypeVar("C", bound="Connection")

Expand Down Expand Up @@ -111,19 +110,21 @@ def __init__(
# insecure connection (without TLS)
channel = self._insecure_grpc_channel(target=target)
else:
credentials: Credentials = Credentials(root_pem_certificate)
channel_credentials = grpc.ssl_channel_credentials(
root_certificates=root_pem_certificate
)

# authentication requires TLS
if authentication_parameters:
self.auth_metadata_plugin = Authentication(
authentication_parameters, target, credentials.channel_creds
authentication_parameters, target, channel_credentials
)
call_credentials = grpc.metadata_call_credentials(
self.auth_metadata_plugin
)

composite_credentials = grpc.composite_channel_credentials(
credentials.channel_creds,
channel_credentials,
call_credentials,
)

Expand All @@ -134,7 +135,7 @@ def __init__(
else:
# connection using TLS (no Kerberos authentication)
channel = self._secure_grpc_channel(
target=target, credentials=credentials.channel_creds
target=target, credentials=channel_credentials
)

self.mesh_service = core.v1alpha.core_pb2_grpc.MeshServiceStub(channel)
Expand Down
21 changes: 0 additions & 21 deletions src/volue/mesh/_credentials.py

This file was deleted.

7 changes: 5 additions & 2 deletions src/volue/mesh/tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import sys

import grpc
import pytest
import pytest_asyncio

Expand All @@ -17,12 +18,14 @@ def auth_metadata_plugin(mesh_test_config):
Note: Depending on the test-case there will be some tokens left (not revoked) in Mesh server.
"""
assert mesh_test_config.creds_type == "kerberos"
credentials = mesh.Credentials(mesh_test_config.tls_root_certs)
channel_credentials = grpc.ssl_channel_credentials(
root_certificates=mesh_test_config.tls_root_certs
)
authentication_parameters = mesh.Authentication.Parameters(
mesh_test_config.krb5_svc, mesh_test_config.krb5_usr
)
return mesh.Authentication(
authentication_parameters, mesh_test_config.address, credentials.channel_creds
authentication_parameters, mesh_test_config.address, channel_credentials
)


Expand Down

0 comments on commit 7ccd627

Please sign in to comment.