github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/bddtests/steps/bdd_grpc_util.py (about)

     1  
     2  # Copyright IBM Corp. 2016 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  
    17  import grpc
    18  
    19  def getGRPCChannel(ipAddress, port, root_certificates, ssl_target_name_override):
    20      # channel = grpc.insecure_channel("{0}:{1}".format(ipAddress, 7051), options = [('grpc.max_message_length', 100*1024*1024)])
    21      # creds = grpc.ssl_channel_credentials(root_certificates=root_certificates, private_key=private_key, certificate_chain=certificate_chain)
    22      creds = grpc.ssl_channel_credentials(root_certificates=root_certificates)
    23      channel = grpc.secure_channel("{0}:{1}".format(ipAddress, port), creds,
    24                                    options=(('grpc.ssl_target_name_override', ssl_target_name_override,),('grpc.default_authority', ssl_target_name_override,),('grpc.max_receive_message_length', 100*1024*1024)))
    25  
    26      print("Returning GRPC for address: {0}".format(ipAddress))
    27      return channel
    28  
    29  def toStringArray(items):
    30      itemsAsStr = []
    31      for item in items:
    32          if type(item) == str:
    33              itemsAsStr.append(item)
    34          elif type(item) == unicode:
    35              itemsAsStr.append(str(item))
    36          else:
    37              raise Exception("Error tring to convert to string: unexpected type '{0}'".format(type(item)))
    38      return itemsAsStr
    39  
    40