def make_authorization(self, username, auth_text): """ Expects an authorization json object as follows: { "publish": ["example/weather-stations/F83A5D/#", ...], "subscribe": ["example/weather-server/status", ...] } Strings in publish and subscribe arrays can and should follow MQTT's topic specification. Wildcards are allowed. The value of `publish` and `subscribe` fields can also be `"*"`, meaning full authorization. If an empty list is passed, no authorization is granted. :param string auth_text: :return: an Authorization object :rtype: Authorization """ try: if isinstance(auth_text, bytes): auth_text = auth_text.decode('utf-8') assert isinstance(auth_text, str) return Authorization.from_dict(json.loads(auth_text)) except: self.logger.error('error parsing authorizations for user:%s' % username, exc_info=True) return None
def from_dict(cls, item, pwcheck=None): assert 'username' in item assert 'password' in item authorization = Authorization.from_dict(item) return cls(item['username'], item['password'], authorization, pwcheck)