InteroperabilityTestClientConnection.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2019, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import Foundation
  17. import GRPC
  18. import NIO
  19. import NIOSSL
  20. public func makeInteroperabilityTestClientConfiguration(
  21. host: String,
  22. port: Int,
  23. eventLoopGroup: EventLoopGroup,
  24. useTLS: Bool
  25. ) -> ClientConnection.Configuration {
  26. var configuration = ClientConnection.Configuration(
  27. target: .hostAndPort(host, port),
  28. eventLoopGroup: eventLoopGroup
  29. )
  30. if useTLS {
  31. // The CA certificate has a common name of "*.test.google.fr", use the following host override
  32. // so we can do full certificate verification.
  33. configuration.tls = .init(
  34. trustRoots: .certificates([InteroperabilityTestCredentials.caCertificate]),
  35. hostnameOverride: "foo.test.google.fr"
  36. )
  37. }
  38. return configuration
  39. }
  40. /// Makes a client connections for gRPC interoperability testing.
  41. ///
  42. /// - Parameters:
  43. /// - host: The host to connect to.
  44. /// - port: The port to connect to.
  45. /// - eventLoopGroup: Event loop group to run client connection on.
  46. /// - useTLS: Whether to use TLS or not.
  47. /// - Returns: A future of a `ClientConnection`.
  48. public func makeInteroperabilityTestClientConnection(
  49. host: String,
  50. port: Int,
  51. eventLoopGroup: EventLoopGroup,
  52. useTLS: Bool
  53. ) -> ClientConnection {
  54. let configuration = makeInteroperabilityTestClientConfiguration(
  55. host: host,
  56. port: port,
  57. eventLoopGroup: eventLoopGroup,
  58. useTLS: useTLS
  59. )
  60. return ClientConnection(configuration: configuration)
  61. }