Exemple #1
0
def connection_string_to_sas_token(conn_str):
    """
    parse an IoTHub service connection string and return the host and a shared access
    signature that can be used to connect to the given hub
    """
    conn_str_obj = ConnectionString(conn_str)
    signing_mechanism = SymmetricKeySigningMechanism(conn_str_obj.get("SharedAccessKey"))
    sas_token = RenewableSasToken(
        uri=conn_str_obj.get("HostName"),
        signing_mechanism=signing_mechanism,
        key_name=conn_str_obj.get("SharedAccessKeyName"),
    )

    return {"host": conn_str_obj.get("HostName"), "sas": str(sas_token)}
Exemple #2
0
def connection_string_to_hostname(conn_str):
    """
    Retrieves only the hostname from connection string.
    This will eventually give us the Linked IoT Hub
    """
    conn_str_obj = ConnectionString(conn_str)
    return conn_str_obj.get("HostName")
 def test_calling_get_with_invalid_key_and_a_default_value_returns_default_value(
         self):
     cs = ConnectionString(
         "HostName=my.host.name;SharedAccessKeyName=mykeyname;SharedAccessKey=Zm9vYmFy"
     )
     assert cs.get("invalidkey", "defaultval") == "defaultval"
 def test_calling_get_with_key_returns_corresponding_value(self):
     cs = ConnectionString(
         "HostName=my.host.name;SharedAccessKeyName=mykeyname;SharedAccessKey=Zm9vYmFy"
     )
     assert cs.get("HostName") == "my.host.name"