Skip to content

Commit

Permalink
5.18 release
Browse files Browse the repository at this point in the history
  • Loading branch information
kbk-amzn committed Feb 7, 2022
1 parent d95dfdc commit 54ea710
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
8 changes: 6 additions & 2 deletions sam-app/lambda_functions/sfExecuteAWSService.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,13 @@ def retrieve_lambda_parameters(ConnectInstanceAlias):
connectReportingS3BucketName = connect_client.list_instance_storage_configs(
InstanceId=connectInstanceId, ResourceType="SCHEDULED_REPORTS"
)["StorageConfigs"][0]["S3Config"]["BucketName"]
ctrKinesisARN = connect_client.list_instance_storage_configs(
ctrKinesisConfig = connect_client.list_instance_storage_configs(
InstanceId=connectInstanceId, ResourceType="CONTACT_TRACE_RECORDS"
)["StorageConfigs"][0]["KinesisStreamConfig"]["StreamArn"]
)

ctrKinesisARN = ""
if ctrKinesisConfig["StorageConfigs"]:
ctrKinesisARN = ctrKinesisConfig["StorageConfigs"][0]["KinesisStreamConfig"]["StreamArn"]

result = {
"connectInstanceId": connectInstanceId,
Expand Down
40 changes: 27 additions & 13 deletions sam-app/lambda_functions/sfInvokeAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,24 @@ def delete(sf, sf_object, sf_id):
# ****WARNING**** -- this function will be deprecated in future versions of the integration; please use search/searchOne.
def lookup_all(sf, sf_object, sf_fields, **kwargs):
where = " AND ".join([where_parser(*item) for item in kwargs.items()])
query_filter = (" WHERE" + where) if kwargs.__len__() > 0 else ''
query_filter = (" WHERE " + where) if kwargs.__len__() > 0 else ''
query = "SELECT %s FROM %s %s" % (sf_fields, sf_object, query_filter)
records = sf.query(query=query)
return records

count = len(records)
result = {}

if count > 0:
recordArray = {}
for record in records:
recordArray[str(records.index(record))] = flatten_json(record)

result['sf_records'] = recordArray
else:
result['sf_records'] = {}

result['sf_count'] = count
return flatten_json(result, '_')

# ****WARNING**** -- this function will be deprecated in future versions of the integration; please use search/searchOne.
def query(sf, query, **kwargs):
Expand All @@ -164,16 +178,16 @@ def query(sf, query, **kwargs):
result = {}

if count > 0:
recordArray = []
for record in records :
recordArray.append(flatten_json(record))
recordArray = {}
for record in records:
recordArray[str(records.index(record))] = flatten_json(record)

result['sf_records'] = recordArray
else:
result['sf_records'] = []
result['sf_records'] = {}

result['sf_count'] = count
return result
return flatten_json(result, '_')

# ****WARNING**** -- this function will be deprecated in future versions of the integration; please use search/searchOne.
def queryOne(sf, query, **kwargs):
Expand Down Expand Up @@ -227,16 +241,16 @@ def search(sf, q, sf_fields, sf_object, where="", overallLimit=100, **kwargs):
result = {}

if count > 0:
recordArray = []
recordArray = {}
for record in records:
recordArray.append(flatten_json(record))
recordArray[str(records.index(record))] = flatten_json(record)

result['sf_records'] = recordArray
else:
result['sf_records'] = []
result['sf_records'] = {}

result['sf_count'] = count
return result
return flatten_json(result, '_')

def searchOne(sf, q, sf_fields, sf_object, where="", **kwargs):
obj = [ { 'name': sf_object } ]
Expand All @@ -254,13 +268,13 @@ def searchOne(sf, q, sf_fields, sf_object, where="", **kwargs):
result['sf_count'] = count
return result

def flatten_json(nested_json):
def flatten_json(nested_json, separator = '.'):
out = {}

def flatten(x, name=''):
if type(x) is dict:
for a in x:
flatten(x[a], name + a + '.')
flatten(x[a], name + a + separator)
elif type(x) is list:
i = 0
for a in x:
Expand Down

0 comments on commit 54ea710

Please sign in to comment.