part of 'repositories.dart'; class GRPCCredentialsClient implements CredentialsRepo { static GRPCCredentialsClient _instance; grpc.CredentialsClient _client; GRPCCredentialsClient(ConnectionConfig config) { final caCert = utf8.encode(config.caCertificate); final cert = utf8.encode(config.certificate); final privateCert = utf8.encode(config.privateCertificate); final splitHost = config.host.split(':'); final hostname = splitHost[0]; final port = int.parse(splitHost[1]); _client = grpc.CredentialsClient(ClientChannel( hostname, port: port, options: ChannelOptions( credentials: _ChannelCredentials(caCert, cert, privateCert), ), )); } factory GRPCCredentialsClient.getInstance({ConnectionConfig config}) => config == null ? _instance : _instance = GRPCCredentialsClient(config); Stream getAllMetadata(String sourceHost) { final request = grpc.SourceHostRequest(); request.sourceHost = sourceHost; return _client.getAllMetadata(request).map( (protobuf.Metadata pbMetadata) => Metadata.fromProtobuf(pbMetadata)); } Future get(String id) async { final request = grpc.IdRequest(); request.id = id; return Credential.fromProtobuf(await _client.get(request)); } Future create(CredentialInput input) async { return Credential(); } Future update(String id, CredentialInput input) async { return Credential(); } Future delete(String id) { final request = grpc.IdRequest(); request.id = id; return _client.delete(request); } } class _ChannelCredentials extends ChannelCredentials { final List _key; final List _cert; const _ChannelCredentials(List caCert, this._cert, this._key) : super.secure(certificates: caCert); @override SecurityContext get securityContext { return super.securityContext ..usePrivateKeyBytes(_key) ..useCertificateChainBytes(_cert); } }