Skip to content

Commit

Permalink
Update to version v1.7.3
Browse files Browse the repository at this point in the history
### Updated
- npm package security patching
  • Loading branch information
tabdunabi authored Apr 14, 2023
2 parents 23dd0b3 + 96e79d0 commit efa01cc
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 102 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.7.3] - 2023-04-13

### Updated

- npm package security patching

## [1.7.2] - 2023-01-10

### Updated
Expand Down
169 changes: 116 additions & 53 deletions source/lambda/msk-lambda-kdf/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion source/lambda/msk-lambda-kdf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
"chai": "4.3.4",
"jest": "^26.4.2",
"sinon": "12.0.1",
"aws-sdk-mock": "5.4.0"
"aws-sdk-mock": "5.8.0"
},
"overrides": {
"aws-sdk-mock": {
"aws-sdk": "^2.1354.0"
}
},
"jest": {
"testEnvironment": "node",
Expand Down
50 changes: 28 additions & 22 deletions source/lambda/solution-helper/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,56 @@
from datetime import datetime

logger = logging.getLogger(__name__)
helper = CfnResource(json_logging=True, log_level='INFO')
helper = CfnResource(json_logging=True, log_level="INFO")
REQUST_TIMEOUT = 10 # in seconds


def _sanitize_data(resource_properties):
# Remove ServiceToken (lambda arn) to avoid sending AccountId
resource_properties.pop('ServiceToken', None)
resource_properties.pop('Resource', None)
resource_properties.pop("ServiceToken", None)
resource_properties.pop("Resource", None)

# Solution ID and unique ID are sent separately
resource_properties.pop('SolutionId', None)
resource_properties.pop('UUID', None)
resource_properties.pop("SolutionId", None)
resource_properties.pop("UUID", None)

return resource_properties


@helper.create
@helper.update
@helper.delete
def custom_resource(event, _):
request_type = event['RequestType']
resource_properties = event['ResourceProperties']
resource = resource_properties['Resource']
request_type = event["RequestType"]
resource_properties = event["ResourceProperties"]
resource = resource_properties["Resource"]

if resource == 'UUID' and request_type == 'Create':
if resource == "UUID" and request_type == "Create":
random_id = str(uuid.uuid4())
helper.Data.update({ 'UUID': random_id })
elif resource == 'AnonymousMetric':
helper.Data.update({"UUID": random_id})
elif resource == "AnonymousMetric":
try:
metrics_data = _sanitize_data(copy(resource_properties))
metrics_data['RequestType'] = request_type
metrics_data["RequestType"] = request_type

headers = { 'Content-Type': 'application/json' }
headers = {"Content-Type": "application/json"}
payload = {
'Solution': resource_properties['SolutionId'],
'UUID': resource_properties['UUID'],
'TimeStamp': datetime.utcnow().isoformat(),
'Data': metrics_data
"Solution": resource_properties["SolutionId"],
"UUID": resource_properties["UUID"],
"TimeStamp": datetime.utcnow().isoformat(),
"Data": metrics_data,
}

logger.info(f'Sending payload: {payload}')
response = requests.post('https://metrics.awssolutionsbuilder.com/generic', json=payload, headers=headers)
logger.info(f'Response from metrics endpoint: {response.status_code} {response.reason}')
logger.info(f"Sending payload: {payload}")
response = requests.post(
"https://metrics.awssolutionsbuilder.com/generic", json=payload, headers=headers, timeout=REQUST_TIMEOUT
)
logger.info(f"Response from metrics endpoint: {response.status_code} {response.reason}")
except requests.exceptions.RequestException:
logger.exception('Could not send usage data')
logger.exception("Could not send usage data")
except Exception:
logger.exception('Unknown error when trying to send usage data')
logger.exception("Unknown error when trying to send usage data")


def handler(event, context):
helper(event, context)
Loading

0 comments on commit efa01cc

Please sign in to comment.