diff --git a/.gitignore b/.gitignore index 6c52410..65728b0 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,9 @@ log/ # localstack localstack/.localstack/ + +# VS Code +.vscode/ + +# Results +results/ \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index e28d6a1..5210ef6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ robotframework>=6.1.1 -boto3>=1.34.125 +boto3>=1.40.30 robotframework-pythonlibcore>=4.4.1 \ No newline at end of file diff --git a/setup.py b/setup.py index 1773950..ac2d677 100644 --- a/setup.py +++ b/setup.py @@ -25,5 +25,5 @@ def readme(): ], packages=find_packages('src'), package_dir={'': 'src'}, - install_requires=['boto3 >= 1.34.125', 'robotframework >= 6.1.1', 'robotframework-pythonlibcore>=4.4.1'] + install_requires=['boto3 >= 1.40.30', 'robotframework >= 6.1.1', 'robotframework-pythonlibcore>=4.4.1'] ) diff --git a/src/AWSLibrary/keywords/s3.py b/src/AWSLibrary/keywords/s3.py index fa824e6..781cb82 100644 --- a/src/AWSLibrary/keywords/s3.py +++ b/src/AWSLibrary/keywords/s3.py @@ -333,6 +333,32 @@ def s3_upload_file(self, bucket, key, local_path): except botocore.exceptions.ClientError as e: raise Exception(e) + @keyword('S3 Put Object With Checksum') + def s3_put_object_with_checksum(self, bucket, key, body, checksum_algorithm='SHA256'): + """ Put an object to the bucket with checksum validation for integrity. + + | =Arguments= | =Description= | + | ``bucket`` | The bucket name. | + | ``key`` | Complete s3 filepath. | + | ``body`` | The object data. | + | ``checksum_algorithm`` | The checksum algorithm (SHA256, SHA1, CRC32, CRC32C). Default: SHA256. | + + *Examples:* + | S3 Put Object With Checksum | bucket_name | s3_file.txt | ${data} | + | S3 Put Object With Checksum | bucket_name | s3_file.txt | ${data} | CRC32 | + """ + client = self.library.session.client('s3', endpoint_url=self.endpoint_url) + try: + response = client.put_object( + Bucket=bucket, + Key=key, + Body=body, + ChecksumAlgorithm=checksum_algorithm + ) + logger.info(response) + except botocore.exceptions.ClientError as e: + raise Exception(e) + @keyword('S3 Key Should Exist') def s3_key_should_exist(self, bucket, key): """ Check if the s3 object exist inside the bucket diff --git a/tests/robot/s3.robot b/tests/robot/s3.robot index eab0228..d62553f 100644 --- a/tests/robot/s3.robot +++ b/tests/robot/s3.robot @@ -76,3 +76,10 @@ Test Metadata Dictionary Should Contain Key ${metadata}[ResponseMetadata] RequestId Dictionary Should Contain Key ${metadata}[ResponseMetadata][HTTPHeaders] last-modified [Teardown] S3 Delete File ${BUCKET_NAME} s3_file_metadata.txt + +Test Put Object With Checksum + [Tags] s3 + ${data}= Get File ${CURDIR}/data/local_file.txt + S3 Put Object With Checksum ${BUCKET_NAME} s3_file_checksum.txt ${data} SHA256 + S3 Key Should Exist ${BUCKET_NAME} s3_file_checksum.txt + [Teardown] S3 Delete File ${BUCKET_NAME} s3_file_checksum.txt