Skip to content

Commit

Permalink
Add .from_jwk examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mccoyp committed Mar 5, 2021
1 parent 0d2519f commit 219f32f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ def from_jwk(cls, jwk):
:param jwk: the key's cryptographic material, as a JsonWebKey or dictionary.
:type jwk: JsonWebKey or dict
:rtype: CryptographyClient
.. literalinclude:: ../tests/test_examples_crypto.py
:start-after: [START from_jwk]
:end-before: [END from_jwk]
:caption: Create a CryptographyClient from a JsonWebKey
:language: python
:dedent: 8
"""
if isinstance(jwk, JsonWebKey):
key = vars(jwk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ def from_jwk(cls, jwk: "Union[JsonWebKey, dict]") -> "CryptographyClient":
:param jwk: the key's cryptographic material, as a JsonWebKey or dictionary.
:type jwk: JsonWebKey or dict
:rtype: CryptographyClient
.. literalinclude:: ../tests/test_examples_crypto_async.py
:start-after: [START from_jwk]
:end-before: [END from_jwk]
:caption: Create a CryptographyClient from a JsonWebKey
:language: python
:dedent: 8
"""
if isinstance(jwk, JsonWebKey):
key = vars(jwk)
Expand Down
14 changes: 13 additions & 1 deletion sdk/keyvault/azure-keyvault-keys/tests/test_examples_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ------------------------------------
import functools

from azure.keyvault.keys import KeyClient
from azure.keyvault.keys import JsonWebKey, KeyClient
from azure.keyvault.keys.crypto import CryptographyClient
from azure.keyvault.keys._shared import HttpChallengeCache
from devtools_testutils import PowerShellPreparer
Expand All @@ -18,6 +18,18 @@
)


def test_create_client_from_jwk():
# [START from_jwk]
# create a CryptographyClient using a JsonWebKey instance
key = JsonWebKey(kty="RSA")
crypto_client = CryptographyClient.from_jwk(jwk=key)

# or a dictionary with JsonWebKey properties
key_dict = {"kty":"RSA"}
crypto_client = CryptographyClient.from_jwk(jwk=key_dict)
# [END from_jwk]


class TestCryptoExamples(KeyVaultTestCase):
def __init__(self, *args, **kwargs):
kwargs["match_body"] = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# ------------------------------------
import functools

from azure.keyvault.keys import JsonWebKey
from azure.keyvault.keys.aio import KeyClient
from azure.keyvault.keys.crypto.aio import CryptographyClient
from azure.keyvault.keys._shared import HttpChallengeCache
Expand All @@ -17,6 +18,18 @@
)


def test_create_client_from_jwk():
# [START from_jwk]
# create a CryptographyClient using a JsonWebKey instance
key = JsonWebKey(kty="RSA")
crypto_client = CryptographyClient.from_jwk(jwk=key)

# or a dictionary with JsonWebKey properties
key_dict = {"kty":"RSA"}
crypto_client = CryptographyClient.from_jwk(jwk=key_dict)
# [END from_jwk]


class TestCryptoExamples(KeyVaultTestCase):
def __init__(self, *args, **kwargs):
kwargs["match_body"] = False
Expand Down

0 comments on commit 219f32f

Please sign in to comment.