You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by barrett <ba...@bossanova.com> on 2017/04/12 19:23:11 UTC

Azure Client with SAS Tokens

I am trying to replicate what is done by the Azure Java SKD  using Python

https://github.com/Azure/azure-event-hubs-java/blob/master/azure-eventhubs/src/main/java/com/microsoft/azure/servicebus/CBSChannel.java

Underneath the covers they are using proton so I feel it's relevant to point
that out.

I've boiled it down to what I think are the essential compoments

from proton import Message
from proton.handlers import MessagingHandler

from bnr_robot_cloud_common.azure_common.sas_tokens import
generate_sas_token
from proton.reactor import Container, DynamicNodeProperties

uri = "amqps://my-namespace.servicebus.windows.net/metrics"
sas_token = generate_sas_token(uri)

class Client(MessagingHandler):
    def __init__(self, url, requests):
        super(Client, self).__init__()
        self.url = url
        self.requests = requests

    def on_start(self, event):
        self.sender = event.container.create_sender(self.url)
        self.receiver =
event.container.create_receiver(self.sender.connection, None, dynamic=True)

    def next_request(self):
        if self.receiver.remote_source.address:
            req = Message(reply_to=self.receiver.remote_source.address,
body=self.requests[0])
            req.properties = {}
            req.properties['operation'] = 'put-token'
            req.properties['type'] = 'servicebus.windows.net:sastoken'
            req.properties['name'] = uri
            self.sender.send(req)

    def on_link_opened(self, event):
        if event.receiver == self.receiver:
            self.next_request()

    def on_message(self, event):
        print("%s => %s" % (self.requests.pop(0), event.message.body))
        if self.requests:
            self.next_request()
        else:
            event.connection.close()
            
client = Client(uri,[generate_sas_token(uri)])
container = Container(client)
container.allowed_mechs = "EXTERNAL"
container.run()


The line where I attempt to control the mechs is coming from this line in
docs :

It's important that theconnection is created with SASL authentication
mechanism set to EXTERNAL (and not the default
PLAIN with username and password used when you don't need to send theSAStok


https://opbuildstorageprod.blob.core.windows.net/output-pdf-files/en-us/Azure.azure-documents/live/event-hubs.pdf

Running the above snippet leads to

ERROR:root:proton:io: getaddrinfo(my-namespace.servicebus.windows.net,
amqps): Servname not supported for ai_socktype

Anythoughts on this? 

I am very new to QPID/Proton so I apologize if this is easily debugged.

Thanks!

-b




--
View this message in context: http://qpid.2158936.n2.nabble.com/Azure-Client-with-SAS-Tokens-tp7662225.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: Azure Client with SAS Tokens

Posted by Gordon Sim <gs...@redhat.com>.
On 12/04/17 20:23, barrett wrote:
> Running the above snippet leads to
>
> ERROR:root:proton:io: getaddrinfo(my-namespace.servicebus.windows.net,
> amqps): Servname not supported for ai_socktype
>
> Anythoughts on this?

Does specifying an explicit port in the url help?

What version of proton are you using and what platform are you running on?


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org