Skip to content

Commit aee3768

Browse files
authored
Merge pull request #11 from NehaDC-IMC/processor-template-with-openapi-cookiecutter
Filter by environment and Fix error updating the parameters.
2 parents 627143e + d0ffb93 commit aee3768

File tree

5 files changed

+23
-39
lines changed

5 files changed

+23
-39
lines changed

examples/connect_processor_example/connect_processor/app/utils/globals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Globals:
1111
"""
1212

1313
PRODUCTS = ['PRD-411-678-887']
14-
ENVIRONMENT = 'preview'
14+
ENVIRONMENT = ['preview']
1515
DAY_TO_REPORT_USAGE = 0
1616

1717
ACTIVATION_TEMPLATE_NAME = 'Default Activation Template'

examples/connect_processor_example/connect_processor/processor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def process_request():
6565
# Filter to fetch all the subscription Fulfillment requests from Connect that need to be processed by this Processor
6666
query = R()
6767
query &= R().asset.product.id.oneof(Globals.PRODUCTS)
68+
query &= R().asset.connection.type.oneof(Globals.ENVIRONMENT)
6869
query &= R().status.oneof(['pending'])
6970

7071
# Applying the filter

{{cookiecutter.project_slug}}/connect_processor/app/dynamic_validation.py

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# All rights reserved.
55
#
66

7-
from flask import Flask, request, json
7+
from flask import Flask, request
8+
from connect_processor.app.utils.utils import Utils
89

910
api = Flask(__name__)
1011

@@ -15,13 +16,6 @@
1516
"""
1617

1718

18-
def get_parameter_by_id(params, param_id):
19-
for param in params:
20-
if param['id'] == param_id:
21-
return param
22-
raise Exception('Parameter {id} not found.'.format(id=param_id))
23-
24-
2519
def set_parameter(params, param):
2620
ret = []
2721
for p in params:
@@ -32,36 +26,23 @@ def set_parameter(params, param):
3226
return ret
3327

3428

35-
def get_validation_request_data(request):
36-
data = request.data.decode("utf-8")
37-
json_data = json.loads(data)
38-
return json_data
39-
40-
4129
# The webhook configured in Connect will call the validate method to validate the value provided as ordering
4230
# parameter during order placement
4331
@api.route('/validate', methods=['POST', 'GET'])
4432
def do_validate():
45-
json_data = get_validation_request_data(request)
46-
params = json_data['asset']['params']
47-
# Customize: replace 'param_dynamic_validation' with Id of the parameter that requires to be validated
48-
param_1 = get_parameter_by_id(params, 'param_dynamic_validation')
33+
json_data = request.json
34+
# Customize: replace 'param_id_to_validate' with Id of the parameter that requires to be validated
35+
value = Utils.get_param_value(json_data, 'ordering', 'param_id_to_validate')
4936
# Customize: Implement the desired logic to validate the value provided as the parameter
50-
if param_1 and param_1['value'].isnumeric():
51-
return api.response_class(
52-
response=json.dumps(json_data),
53-
status=200,
54-
mimetype='application/json'
55-
)
56-
57-
else:
58-
# Customize: Provide proper error message
59-
param_1['value_error'] = "This error is from the validation script! Value should be numeric."
60-
params = set_parameter(params, param_1)
61-
json_data['asset']['params'] = params
62-
response = json.dumps(json_data)
63-
return api.response_class(
64-
response=response,
65-
status=400,
66-
mimetype='application/json'
67-
)
37+
# api_client = APIClient(api_url='',
38+
# api_key='')
39+
# error_message = api_client.validate_param(value)
40+
41+
# Customize: Provide proper error message
42+
error_message = "Param param_id_to_validate not valid "
43+
if len(error_message) > 0:
44+
params = json_data['asset']['params']
45+
validated_param = Utils.get_item_by_id(params, 'param_id_to_validate')
46+
validated_param['value_error'] = error_message
47+
set_parameter(params, validated_param)
48+
return json_data

{{cookiecutter.project_slug}}/connect_processor/app/purchase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ def _save_fulfillment_parameters(request, client):
5656
"id": "subscription_id",
5757
"value": "value for subscription ID in Vendor System",
5858
"value_error": "",
59-
"structured_value": ""
59+
"structured_value": {}
6060
},
6161
{
6262
# TODO: Change and/or add the fulfillment parameters id, as configured in product in Connect
6363
"id": "param_b",
6464
"value": "value for parameter b",
6565
"value_error": "",
66-
"structured_value": ""
66+
"structured_value": {}
6767
}
6868
]
6969
}

{{cookiecutter.project_slug}}/connect_processor/processor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
query_tcr = R()
3636
query_tcr &= R().configuration.product.id.oneof(Globals.PRODUCTS)
37+
query_tcr &= R().configuration.connection.type.oneof(Globals.ENVIRONMENT)
3738
query_tcr &= R().status.oneof(['pending'])
3839
tc_requests = client.ns('tier').collection('config-requests').filter(query_tcr)
3940
# Process each TCR
@@ -43,6 +44,7 @@
4344
# Filter to fetch all the subscription Fulfillment requests from Connect that need to be processed by this Processor
4445
query = R()
4546
query &= R().asset.product.id.oneof(Globals.PRODUCTS)
47+
query &= R().asset.connection.type.oneof(Globals.ENVIRONMENT)
4648
query &= R().status.oneof(['pending'])
4749

4850
# Applying the filter

0 commit comments

Comments
 (0)