(как) это возможно?
два подхода:
1.
uri = 'https://management.azure.com/subscriptions/%s/resourceGroups/%s/providers/Microsoft.EventHub/namespaces/%s/eventhubs/%s/consumergroups/%s?api-version=%s' % (subscriptionId,resourceGroupName,namespaceName,eventHubName,consumerGroupName,apiVersion)
-> Я не могу создать заголовок (аутентификация длядоступ) с:
def get_auth_token(sb_name, eh_name, sas_name, sas_value): # Returns an authorization token dictionary for making calls to Event Hubs REST API.
uri = quote_plus("https://{}.servicebus.windows.net/{}".format(sb_name, eh_name))
sas = sas_value.encode('utf-8')
expiry = str(int(time() + 10000))
string_to_sign = (uri + '\n' + expiry).encode('utf-8')
signed_hmac_sha256 = HMAC(sas, string_to_sign, sha256)
signature = quote(b64encode(signed_hmac_sha256.digest()))
return 'SharedAccessSignature sr={}&sig={}&se={}&skn={}'.format(uri, signature, expiry, sas_name)
header = { 'Authorization':get_auth_token(sb_name, eh_name, 'iothubowner', sas_value), 'Content-Type':'application/json' }
2.
uri = '{sb_name}.servicebus.windows.net/{eh_name}/consumergroups'
header = { 'Authorization':get_auth_token(sb_name, eh_name, 'iothubowner', sas_value), 'Content-Type':'application/json' }
res = get(uri, headers=header) # this works (list of consumerGroups)
, но:
uri = '{sb_name}.servicebus.windows.net/{eh_name}/consumergroups/newConsumerGroup'
res = put(uri, headers=header)
не работает:
401 40100: Unauthorized : Unauthorized access for 'CreateOrUpdateConsumerGroup' operation on endpoint 'sb://{sb_name}.servicebus.windows.net/{eh_name}/consumergroups/newConsumerGroup'.