-
Notifications
You must be signed in to change notification settings - Fork 3k
Eh named key #18292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Eh named key #18292
Changes from 20 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
7f70520
Add AzureNamedKeyCredential
rakshith91 3db2ef2
lint
rakshith91 be51628
Merge branch 'master' into named_key
87530e9
Update sdk/core/azure-core/CHANGELOG.md
8be7ce5
some changes
rakshith91 8b21514
oops
rakshith91 75ecf46
Merge branch 'master' into named_key
05c4205
version
rakshith91 d8ba6de
mypy fix
rakshith91 1555f1d
lint
rakshith91 6ab090c
remove policy
rakshith91 6a98f0b
doc
rakshith91 5f94691
Update sdk/core/azure-core/azure/core/pipeline/policies/_authenticati…
53fab2e
Update sdk/core/azure-core/azure/core/pipeline/policies/__init__.py
0865f90
Update sdk/core/azure-core/azure/core/pipeline/policies/__init__.py
4a6736f
changelog
rakshith91 4c2143d
update tests
rakshith91 71f0b35
fix
rakshith91 845c6cb
base
rakshith91 574f3bc
add nk cred
rakshith91 4e2426a
Merge remote-tracking branch 'upstream/master' into eh_named_key
rakshith91 34a3a65
fix merge
rakshith91 8e559a5
Update sdk/eventhub/azure-eventhub/CHANGELOG.md
9ebe8b5
named key
rakshith91 e23f2d6
Apply suggestions from code review
27d80e2
update test
rakshith91 005af59
analyze
rakshith91 cd0cc62
lint
rakshith91 31b279d
lint
rakshith91 3c13677
mypy
rakshith91 c85e5c2
Update sdk/eventhub/azure-eventhub/tests/livetest/asynctests/test_aut…
9455bd2
Update sdk/eventhub/azure-eventhub/samples/async_samples/authenticate…
dd9ea6c
Apply suggestions from code review
b73b419
rename
rakshith91 77e90d9
Update sdk/eventhub/azure-eventhub/azure/eventhub/aio/_client_base_as…
ee9548d
ops
rakshith91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...thub/azure-eventhub/samples/async_samples/authenticate_with_named_key_credential_async.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python | ||
|
||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
""" | ||
Example to demonstrate utilizing AzureNamedKeyCredential to authenticate with Event Hubs. | ||
rakshith91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
|
||
# pylint: disable=C0111 | ||
|
||
import os | ||
import time | ||
from azure.core.credentials import AzureNamedKeyCredential | ||
swathipil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from azure.eventhub.aio import EventHubProducerClient | ||
from azure.eventhub import EventData | ||
|
||
# Target namespace and hub must also be specified. Consumer group is set to default unless required otherwise. | ||
rakshith91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FULLY_QUALIFIED_NAMESPACE = os.environ['EVENT_HUB_HOSTNAME'] | ||
EVENTHUB_NAME = os.environ['EVENT_HUB_NAME'] | ||
|
||
EVENTHUB_POLICY_NAME = os.environ['EVENT_HUB_POLICY_NAME'] | ||
EVENTHUB_KEY = os.environ['EVENT_HUB_KEY'] | ||
rakshith91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
credential = AzureNamedKeyCredential(EVENTHUB_POLICY_NAME, EVENTHUB_KEY) | ||
|
||
producer_client = EventHubProducerClient( | ||
fully_qualified_namespace=FULLY_QUALIFIED_NAMESPACE, | ||
eventhub_name=EVENTHUB_NAME, | ||
credential=credential, | ||
logging_enable=True | ||
) | ||
|
||
start_time = time.time() | ||
async def authenticate_with_named_key(): | ||
async with producer_client: | ||
event_data_batch = await producer_client.create_batch() | ||
event_data_batch.add(EventData('Single message')) | ||
await producer_client.send_batch(event_data_batch) | ||
|
||
loop = asyncio.get_event_loop() | ||
start_time = time.time() | ||
loop.run_until_complete(authenticate_with_named_key()) | ||
print("Send messages in {} seconds.".format(time.time() - start_time)) |
41 changes: 41 additions & 0 deletions
41
sdk/eventhub/azure-eventhub/samples/sync_samples/authenticate_with_named_key_credential.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env python | ||
|
||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
""" | ||
Example to demonstrate utilizing AzureNamedKeyCredential to authenticate with Event Hubs. | ||
""" | ||
|
||
# pylint: disable=C0111 | ||
|
||
import os | ||
import time | ||
from azure.core.credentials import AzureNamedKeyCredential | ||
swathipil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from azure.eventhub import EventHubProducerClient, EventData | ||
|
||
# Target namespace and hub must also be specified. Consumer group is set to default unless required otherwise. | ||
rakshith91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FULLY_QUALIFIED_NAMESPACE = os.environ['EVENT_HUB_HOSTNAME'] | ||
EVENTHUB_NAME = os.environ['EVENT_HUB_NAME'] | ||
|
||
EVENTHUB_POLICY_NAME = os.environ['EVENT_HUB_POLICY_NAME'] | ||
EVENTHUB_KEY = os.environ['EVENT_HUB_KEY'] | ||
rakshith91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
credential = AzureNamedKeyCredential(EVENTHUB_POLICY_NAME, EVENTHUB_KEY) | ||
|
||
producer_client = EventHubProducerClient( | ||
fully_qualified_namespace=FULLY_QUALIFIED_NAMESPACE, | ||
eventhub_name=EVENTHUB_NAME, | ||
credential=credential, | ||
logging_enable=True | ||
) | ||
|
||
start_time = time.time() | ||
with producer_client: | ||
event_data_batch = producer_client.create_batch() | ||
event_data_batch.add(EventData('Single message')) | ||
producer_client.send_batch(event_data_batch) | ||
|
||
print("Send messages in {} seconds.".format(time.time() - start_time)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.