@@ -235,11 +235,30 @@ It provides generators and library templates for supporting multiple languages a
235
235
236
236
The ** client-encryption-python** library provides a method you can use to integrate the OpenAPI generated client with this library:
237
237
``` python
238
- from client_encryption.field_level_encryption_config import FieldLevelEncryptionConfig
239
238
from client_encryption.api_encryption import add_encryption_layer
240
239
240
+ config = {
241
+ " paths" : {
242
+ " $" : {
243
+ ...
244
+ }
245
+ },
246
+ " ivFieldName" : " iv" ,
247
+ " encryptedKeyFieldName" : " encryptedKey" ,
248
+ ...
249
+ " oaepPaddingDigestAlgorithm" : " SHA256"
250
+ }
251
+
241
252
add_encryption_layer(api_client, config)
242
253
```
254
+
255
+ Alternatively you can pass the configuration by a json file:
256
+ ``` python
257
+ from client_encryption.api_encryption import add_encryption_layer
258
+
259
+ add_encryption_layer(api_client, " path/to/my/config.json" )
260
+ ```
261
+
243
262
This method will add the field level encryption in the generated OpenApi client, taking care of encrypting request and decrypting response payloads, but also of updating HTTP headers when needed, automatically, without manually calling ` encrypt_payload() ` /` decrypt_payload() ` functions for each API request or response.
244
263
245
264
##### OpenAPI Generator <a name =" openapi-generator " ></a >
@@ -265,21 +284,17 @@ To use it:
265
284
2 . Import the ** mastercard-client-encryption** module and the generated swagger ApiClient
266
285
267
286
``` python
268
- from client_encryption.field_level_encryption_config import FieldLevelEncryptionConfig
269
287
from client_encryption.api_encryption import add_encryption_layer
270
288
from swagger_client.api_client import ApiClient # import generated swagger ApiClient
271
289
```
272
290
273
291
3 . Add the field level encryption layer to the generated client:
274
292
275
293
``` python
276
- # Read the service configuration file
277
- config_file_path = " ./config.json"
278
- config = FieldLevelEncryptionConfig(config_file_path)
279
294
# Create a new instance of the generated client
280
295
api_client = ApiClient()
281
296
# Enable field level encryption
282
- add_encryption_layer(api_client, config)
297
+ add_encryption_layer(api_client, " path/to/my/ config.json " )
283
298
```
284
299
285
300
4 . Use the ` ApiClient ` instance with the Field Level Encryption enabled:
@@ -308,7 +323,6 @@ According to the above the signing layer must be applied first in order to work
308
323
309
324
``` python
310
325
from oauth1.signer_interceptor import add_signing_layer
311
- from client_encryption.field_level_encryption_config import FieldLevelEncryptionConfig
312
326
from client_encryption.api_encryption import add_encryption_layer
313
327
from swagger_client.api_client import ApiClient # import generated swagger ApiClient
314
328
```
@@ -324,12 +338,7 @@ According to the above the signing layer must be applied first in order to work
324
338
325
339
4 . Then add the field level encryption layer:
326
340
``` python
327
- # Read the service configuration file
328
- config_file_path = " ./config.json"
329
- config = FieldLevelEncryptionConfig(config_file_path)
330
-
331
- # Enable field level encryption
332
- add_encryption_layer(api_client, config)
341
+ add_encryption_layer(api_client, " path/to/my/config.json" )
333
342
```
334
343
335
344
5 . Use the ` ApiClient ` instance with Authentication and Field Level Encryption both enabled:
0 commit comments