Skip to content

Commit 479bf87

Browse files
committed
remove unneeded .. code-block:: python
1 parent 07508d9 commit 479bf87

File tree

2 files changed

+35
-82
lines changed

2 files changed

+35
-82
lines changed

docs/howto/queryable-encryption.rst

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,15 @@ Encryption in your Django project.
1515

1616
Queryable Encryption can be used with MongoDB replica sets or sharded
1717
clusters running version 8.0 or later. Standalone instances are not
18-
supported. The following table summarizes which MongoDB server products
19-
support each Queryable Encryption mechanism.
20-
21-
- :ref:`manual:qe-compatibility-reference`
18+
supported. The :ref:`manual:qe-compatibility-reference` table summarizes
19+
which MongoDB server products support Queryable Encryption.
2220

2321
Installation
2422
============
2523

26-
In addition to the :doc:`installation </intro/install>` and :doc:`configuration
27-
</intro/configure>` steps required to use Django MongoDB Backend, Queryable
28-
Encryption has additional dependencies. You can install these dependencies
29-
by using the ``encryption`` extra when installing ``django-mongodb-backend``:
24+
In addition to Django MongoDB Backend's regular :doc:`installation
25+
</intro/install>` and :doc:`configuration </intro/configure>` steps, Queryable
26+
Encryption has additional Python dependencies:
3027

3128
.. code-block:: console
3229
@@ -49,13 +46,8 @@ configure a separate encrypted database connection in your
4946
:class:`automatic encryption
5047
<pymongo.encryption_options.AutoEncryptionOpts>`.
5148

52-
The following example shows how to
53-
configure an encrypted database using the :class:`AutoEncryptionOpts
54-
<pymongo.encryption_options.AutoEncryptionOpts>` from the
55-
:mod:`encryption_options <pymongo.encryption_options>` module with a local KMS
56-
provider and encryption keys stored in the ``encryption.__keyVault`` collection.
57-
58-
.. code-block:: python
49+
Here's how to configure an encrypted database using a local KMS provider and
50+
encryption keys stored in the ``encryption.__keyVault`` collection::
5951

6052
import os
6153

@@ -104,10 +96,7 @@ route database operations to the encrypted database.
10496

10597
The following example shows how to configure a router for the "myapp"
10698
application that routes database operations to the encrypted database for all
107-
models in that application. The router also specifies the :ref:`KMS provider
108-
<qe-configuring-kms>` to use.
109-
110-
.. code-block:: python
99+
models in that application::
111100

112101
# myapp/routers.py
113102
class EncryptedRouter:
@@ -127,9 +116,7 @@ models in that application. The router also specifies the :ref:`KMS provider
127116
db_for_write = db_for_read
128117

129118
Then in your Django settings, add the custom database router to the
130-
:setting:`django:DATABASE_ROUTERS` setting:
131-
132-
.. code-block:: python
119+
:setting:`django:DATABASE_ROUTERS` setting::
133120

134121
# settings.py
135122
DATABASE_ROUTERS = ["myapp.routers.EncryptedRouter"]
@@ -162,9 +149,7 @@ options followed by an example of how to use them.
162149
+-------------------------------------------------------------------------+--------------------------------------------------------+
163150

164151
Example of KMS configuration with ``aws`` in your :class:`kms_providers
165-
<pymongo.encryption_options.AutoEncryptionOpts>` setting:
166-
167-
.. code-block:: python
152+
<pymongo.encryption_options.AutoEncryptionOpts>` setting::
168153

169154
from pymongo.encryption_options import AutoEncryptionOpts
170155

@@ -223,12 +208,10 @@ Django MongoDB Backend, along with the entire schema, you can run the
223208

224209
Use the output of :djadmin:`showencryptedfieldsmap` to set the
225210
``encrypted_fields_map`` in :class:`AutoEncryptionOpts
226-
<pymongo.encryption_options.AutoEncryptionOpts>` in your Django settings.
227-
228-
.. code-block:: python
211+
<pymongo.encryption_options.AutoEncryptionOpts>` in your Django settings::
229212

230-
from pymongo.encryption_options import AutoEncryptionOpts
231213
from bson import json_util
214+
from pymongo.encryption_options import AutoEncryptionOpts
232215

233216
DATABASES = {
234217
"encrypted": {
@@ -239,30 +222,28 @@ Use the output of :djadmin:`showencryptedfieldsmap` to set the
239222
encrypted_fields_map=json_util.loads(
240223
"""{
241224
"encrypt_patient": {
242-
"fields": [
243-
{
244-
"bsonType": "string",
245-
"path": "patient_record.ssn",
246-
"keyId": {
247-
"$binary": {
248-
"base64": "2MA29LaARIOqymYHGmi2mQ==",
249-
"subType": "04"
250-
}
251-
},
252-
"queries": {
253-
"queryType": "equality"
254-
}
255-
},
256-
]
257-
}
258-
}"""
225+
"fields": [
226+
{
227+
"bsonType": "string",
228+
"path": "patient_record.ssn",
229+
"keyId": {
230+
"$binary": {
231+
"base64": "2MA29LaARIOqymYHGmi2mQ==",
232+
"subType": "04"
233+
}
234+
},
235+
"queries": {
236+
"queryType": "equality"
237+
}
238+
},
239+
]
240+
}}"""
259241
),
260-
)
242+
),
261243
},
262244
},
263245
}
264246

265-
266247
.. admonition:: Security consideration
267248

268249
Supplying an encrypted fields map provides more security than relying on an
@@ -287,9 +268,7 @@ settings using the ``crypt_shared_lib_path`` option in
287268
:class:`AutoEncryptionOpts <pymongo.encryption_options.AutoEncryptionOpts>`.
288269

289270
The following example shows how to configure the shared library in your Django
290-
settings:
291-
292-
.. code-block:: python
271+
settings::
293272

294273
from pymongo.encryption_options import AutoEncryptionOpts
295274

docs/topics/queryable-encryption.rst

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ queries on certain encrypted fields. To use encrypted fields in your models,
2121
import the necessary field types from ``django_mongodb_backend.models`` and
2222
define your models as usual.
2323

24-
Here's the `Python Queryable Encryption Tutorial`_ example implemented in
25-
Django:
26-
27-
.. code-block:: python
24+
Here are models based on the `Python Queryable Encryption Tutorial`_::
2825

2926
# myapp/models.py
3027
from django.db import models
@@ -55,6 +52,8 @@ Django:
5552
cc_type = models.CharField(max_length=50)
5653
cc_number = models.CharField(max_length=20)
5754

55+
.. _Python Queryable Encryption Tutorial: https://github.com/mongodb/docs/tree/main/content/manual/manual/source/includes/qe-tutorials/python
56+
5857
.. _qe-migrations:
5958

6059
Migrations
@@ -84,25 +83,20 @@ The example above requires a :ref:`database router
8483
<qe-configuring-database-routers-setting>` to direct operations on models with
8584
encrypted fields to the appropriate database. It also requires the use of a
8685
:ref:`router for embedded models <configuring-database-routers-setting>`. Here
87-
is an example that includes both:
88-
89-
.. code-block:: python
86+
is an example that includes both::
9087

9188
# myproject/settings.py
9289
DATABASE_ROUTERS = [
9390
"django_mongodb_backend.routers.MongoRouter",
9491
"myproject.routers.EncryptedRouter",
9592
]
9693

97-
9894
Querying encrypted fields
9995
-------------------------
10096

10197
In order to query encrypted fields, you must define the queryable encryption
10298
query type in the model field definition. For example, if you want to query the
103-
``ssn`` field for equality, you can define it as follows:
104-
105-
.. code-block:: python
99+
``ssn`` field for equality, you can define it as follows::
106100

107101
class PatientRecord(EmbeddedModel):
108102
ssn = EncryptedCharField(max_length=11, queries={"queryType": "equality"})
@@ -137,30 +131,10 @@ supports:
137131
perform comparisons on encrypted fields, while Django's range lookups are
138132
used for filtering based on a range of values.
139133

140-
If you have an encrypted field that supports range queries like this:
141-
142-
.. code-block:: python
143-
144-
class PatientRecord(EmbeddedModel):
145-
ssn = EncryptedCharField(max_length=11, queries={"queryType": "range"})
146-
billing = EncryptedEmbeddedModelField("Billing")
147-
bill_amount = models.DecimalField(max_digits=10, decimal_places=2)
148-
149-
You can perform a query like this:
150-
151-
.. code-block:: console
152-
153-
>>> patients = Patient.objects.filter(patient_record__ssn__gte="123-45-0000",
154-
... patient_record__ssn__lte="123-45-9999")
155-
156-
This will return all patients whose SSN falls within the specified range.
157-
158134
QuerySet limitations
159135
~~~~~~~~~~~~~~~~~~~~
160136

161137
In addition to :ref:`Django MongoDB Backend's QuerySet limitations
162138
<known-issues-limitations-querying>`,
163139

164140
.. TODO
165-
166-
.. _Python Queryable Encryption Tutorial: https://github.com/mongodb/docs/tree/main/content/manual/manual/source/includes/qe-tutorials/python

0 commit comments

Comments
 (0)