How to use secretsmanager_http_list_secret_version_ids method in localstack

Best Python code snippet using localstack_python

test_secretsmanager.py

Source:test_secretsmanager.py Github

copy

Full Screen

...278 res, secret_name, secret_string, version_id279 )280 assert res_json["VersionStages"] == [version_stage]281 return res_json282 def secretsmanager_http_list_secret_version_ids(self, secret_id: str) -> requests.Response:283 http_body: json = {"SecretId": secret_id}284 return self.secretsmanager_http_json_post("secretsmanager.ListSecretVersionIds", http_body)285 @staticmethod286 def secretsmanager_http_list_secret_version_ids_val_res(287 res: requests.Response, secret_name: str, versions: json288 ) -> json:289 assert res.status_code == 200290 res_json: json = res.json()291 assert res_json["Name"] == secret_name292 res_versions: [json] = res_json["Versions"]293 assert len(res_versions) == len(versions)294 assert len(set([rv["VersionId"] for rv in res_versions])) == len(res_versions)295 assert len(set([v["VersionId"] for v in versions])) == len(versions)296 for version in versions:297 vs_in_res: [json] = list(298 filter(lambda rv: rv["VersionId"] == version["VersionId"], res_versions)299 )300 assert len(vs_in_res) == 1301 v_in_res = vs_in_res[0]302 assert v_in_res["VersionStages"] == version["VersionStages"]303 return res_json304 def secretsmanager_http_put_secret_value(305 self, secret_id: str, secret_string: str306 ) -> requests.Response:307 http_body: json = {308 "SecretId": secret_id,309 "SecretString": secret_string,310 }311 return self.secretsmanager_http_json_post("secretsmanager.PutSecretValue", http_body)312 @staticmethod313 def secretsmanager_http_put_secret_value_val_res(314 res: requests.Response, secret_name: str315 ) -> json:316 assert res.status_code == 200317 res_json: json = res.json()318 assert res_json["Name"] == secret_name319 return res_json320 def secretsmanager_http_put_pending_secret_value(321 self, secret_id: str, secret_string: str322 ) -> requests.Response:323 http_body: json = {324 "SecretId": secret_id,325 "SecretString": secret_string,326 "VersionStages": ["AWSPENDING"],327 }328 return self.secretsmanager_http_json_post("secretsmanager.PutSecretValue", http_body)329 @staticmethod330 def secretsmanager_http_put_pending_secret_value_val_res(331 res: requests.Response, secret_name: str332 ) -> json:333 return TestSecretsManager.secretsmanager_http_put_secret_value_val_res(res, secret_name)334 def secretsmanager_http_put_secret_value_with(335 self, secret_id: str, secret_string: str, client_request_token: Optional[str]336 ) -> requests.Response:337 http_body: json = {338 "SecretId": secret_id,339 "SecretString": secret_string,340 "ClientRequestToken": client_request_token,341 }342 return self.secretsmanager_http_json_post("secretsmanager.PutSecretValue", http_body)343 @staticmethod344 def secretsmanager_http_put_secret_value_with_val_res(345 res: requests.Response, secret_name: str, client_request_token: str346 ) -> json:347 assert res.status_code == 200348 res_json: json = res.json()349 assert res_json["Name"] == secret_name350 assert res_json["VersionId"] == client_request_token351 return res_json352 def secretsmanager_http_put_secret_value_with_version(353 self,354 secret_id: str,355 secret_string: str,356 client_request_token: Optional[str],357 version_stages: [str],358 ) -> requests.Response:359 http_body: json = {360 "SecretId": secret_id,361 "SecretString": secret_string,362 "ClientRequestToken": client_request_token,363 "VersionStages": version_stages,364 }365 return self.secretsmanager_http_json_post("secretsmanager.PutSecretValue", http_body)366 @staticmethod367 def secretsmanager_http_put_secret_value_with_version_val_res(368 res: requests.Response,369 secret_name: str,370 client_request_token: Optional[str],371 version_stages: [str],372 ) -> json:373 req_version_id: str374 if client_request_token is None:375 assert res.status_code == 200376 req_version_id = res.json()["VersionId"]377 else:378 req_version_id = client_request_token379 res_json = TestSecretsManager.secretsmanager_http_put_secret_value_with_val_res(380 res, secret_name, req_version_id381 )382 assert res_json["VersionStages"] == version_stages383 return res_json384 def test_http_put_secret_value_with_new_custom_client_request_token(self):385 secret_name: str = "test_http_put_secret_value_with_new_custom_client_request_token"386 # Create v0.387 secret_string_v0: str = "MySecretString"388 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(389 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),390 secret_name,391 )392 #393 # Check v0 base consistency.394 self.secretsmanager_http_get_secret_value_val_res(395 self.secretsmanager_http_get_secret_value(secret_name),396 secret_name,397 secret_string_v0,398 cr_v0_res_json["VersionId"],399 )400 # Update v0 with predefined ClientRequestToken.401 secret_string_v1: str = "MyNewSecretString"402 #403 crt_v1: str = str(uuid.uuid4())404 while crt_v1 == cr_v0_res_json["VersionId"]:405 crt_v1 = str(uuid.uuid4())406 #407 self.secretsmanager_http_put_secret_value_val_res(408 self.secretsmanager_http_put_secret_value_with(secret_name, secret_string_v1, crt_v1),409 secret_name,410 )411 #412 # Check v1 base consistency.413 self.secretsmanager_http_get_secret_value_val_res(414 self.secretsmanager_http_get_secret_value(secret_name),415 secret_name,416 secret_string_v1,417 crt_v1,418 )419 #420 # Check versioning base consistency.421 versions_v0_v1: json = [422 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSPREVIOUS"]},423 {"VersionId": crt_v1, "VersionStages": ["AWSCURRENT"]},424 ]425 self.secretsmanager_http_list_secret_version_ids_val_res(426 self.secretsmanager_http_list_secret_version_ids(secret_name),427 secret_name,428 versions_v0_v1,429 )430 self.secretsmanager_http_delete_secret_val_res(431 self.secretsmanager_http_delete_secret(secret_name), secret_name432 )433 def test_http_put_secret_value_with_duplicate_client_request_token(self):434 secret_name: str = "test_http_put_secret_value_with_duplicate_client_request_token"435 # Create v0.436 secret_string_v0: str = "MySecretString"437 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(438 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),439 secret_name,440 )441 #442 # Check v0 base consistency.443 self.secretsmanager_http_get_secret_value_val_res(444 self.secretsmanager_http_get_secret_value(secret_name),445 secret_name,446 secret_string_v0,447 cr_v0_res_json["VersionId"],448 )449 # Update v0 with duplicate ClientRequestToken.450 secret_string_v1: str = "MyNewSecretString"451 #452 crt_v1: str = cr_v0_res_json["VersionId"]453 #454 self.secretsmanager_http_put_secret_value_val_res(455 self.secretsmanager_http_put_secret_value_with(secret_name, secret_string_v1, crt_v1),456 secret_name,457 )458 #459 # Check v1 base consistency.460 self.secretsmanager_http_get_secret_value_val_res(461 self.secretsmanager_http_get_secret_value(secret_name),462 secret_name,463 secret_string_v1,464 crt_v1,465 )466 #467 # Check versioning base consistency.468 versions_v0_v1: json = [{"VersionId": crt_v1, "VersionStages": ["AWSCURRENT"]}]469 self.secretsmanager_http_list_secret_version_ids_val_res(470 self.secretsmanager_http_list_secret_version_ids(secret_name),471 secret_name,472 versions_v0_v1,473 )474 self.secretsmanager_http_delete_secret_val_res(475 self.secretsmanager_http_delete_secret(secret_name), secret_name476 )477 def test_http_put_secret_value_with_null_client_request_token(self):478 secret_name: str = "test_http_put_secret_value_with_null_client_request_token"479 # Create v0.480 secret_string_v0: str = "MySecretString"481 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(482 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),483 secret_name,484 )485 #486 # Check v0 base consistency.487 self.secretsmanager_http_get_secret_value_val_res(488 self.secretsmanager_http_get_secret_value(secret_name),489 secret_name,490 secret_string_v0,491 cr_v0_res_json["VersionId"],492 )493 # Update v0 with null ClientRequestToken.494 secret_string_v1: str = "MyNewSecretString"495 #496 pv_v1_res_json = self.secretsmanager_http_put_secret_value_val_res(497 self.secretsmanager_http_put_secret_value_with(secret_name, secret_string_v1, None),498 secret_name,499 )500 #501 # Check v1 base consistency.502 self.secretsmanager_http_get_secret_value_val_res(503 self.secretsmanager_http_get_secret_value(secret_name),504 secret_name,505 secret_string_v1,506 pv_v1_res_json["VersionId"],507 )508 #509 # Check versioning base consistency.510 versions_v0_v1: json = [511 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSPREVIOUS"]},512 {"VersionId": pv_v1_res_json["VersionId"], "VersionStages": ["AWSCURRENT"]},513 ]514 self.secretsmanager_http_list_secret_version_ids_val_res(515 self.secretsmanager_http_list_secret_version_ids(secret_name),516 secret_name,517 versions_v0_v1,518 )519 self.secretsmanager_http_delete_secret_val_res(520 self.secretsmanager_http_delete_secret(secret_name), secret_name521 )522 def test_http_put_secret_value_with_undefined_client_request_token(self):523 secret_name: str = "test_http_put_secret_value_with_undefined_client_request_token"524 # Create v0.525 secret_string_v0: str = "MySecretString"526 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(527 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),528 secret_name,529 )530 #531 # Check v0 base consistency.532 self.secretsmanager_http_get_secret_value_val_res(533 self.secretsmanager_http_get_secret_value(secret_name),534 secret_name,535 secret_string_v0,536 cr_v0_res_json["VersionId"],537 )538 # Update v0 with undefined ClientRequestToken.539 secret_string_v1: str = "MyNewSecretString"540 #541 pv_v1_res_json = self.secretsmanager_http_put_secret_value_val_res(542 self.secretsmanager_http_put_secret_value(secret_name, secret_string_v1), secret_name543 )544 #545 # Check v1 base consistency.546 self.secretsmanager_http_get_secret_value_val_res(547 self.secretsmanager_http_get_secret_value(secret_name),548 secret_name,549 secret_string_v1,550 pv_v1_res_json["VersionId"],551 )552 #553 # Check versioning base consistency.554 versions_v0_v1: json = [555 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSPREVIOUS"]},556 {"VersionId": pv_v1_res_json["VersionId"], "VersionStages": ["AWSCURRENT"]},557 ]558 self.secretsmanager_http_list_secret_version_ids_val_res(559 self.secretsmanager_http_list_secret_version_ids(secret_name),560 secret_name,561 versions_v0_v1,562 )563 self.secretsmanager_http_delete_secret_val_res(564 self.secretsmanager_http_delete_secret(secret_name), secret_name565 )566 def test_http_put_secret_value_duplicate_req(self):567 secret_name: str = "test_http_put_secret_value_duplicate_req"568 # Create v0.569 secret_string_v0: str = "MySecretString"570 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(571 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),572 secret_name,573 )574 #575 # Check v0 base consistency.576 self.secretsmanager_http_get_secret_value_val_res(577 self.secretsmanager_http_get_secret_value(secret_name),578 secret_name,579 secret_string_v0,580 cr_v0_res_json["VersionId"],581 )582 # Duplicate update.583 self.secretsmanager_http_put_secret_value_val_res(584 self.secretsmanager_http_put_secret_value_with(585 secret_name, secret_string_v0, cr_v0_res_json["VersionId"]586 ),587 secret_name,588 )589 #590 # Check v1 base consistency.591 self.secretsmanager_http_get_secret_value_val_res(592 self.secretsmanager_http_get_secret_value(secret_name),593 secret_name,594 secret_string_v0,595 cr_v0_res_json["VersionId"],596 )597 #598 # Check versioning base consistency.599 versions_v0_v1: json = [600 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSCURRENT"]},601 ]602 self.secretsmanager_http_list_secret_version_ids_val_res(603 self.secretsmanager_http_list_secret_version_ids(secret_name),604 secret_name,605 versions_v0_v1,606 )607 self.secretsmanager_http_delete_secret_val_res(608 self.secretsmanager_http_delete_secret(secret_name), secret_name609 )610 def test_http_put_secret_value_null_client_request_token_new_version_stages(self):611 secret_name: str = "test_http_put_secret_value_null_client_request_token_new_version_stages"612 # Create v0.613 secret_string_v0: str = "MySecretString"614 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(615 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),616 secret_name,617 )618 #619 # Check v0 base consistency.620 self.secretsmanager_http_get_secret_value_val_res(621 self.secretsmanager_http_get_secret_value(secret_name),622 secret_name,623 secret_string_v0,624 cr_v0_res_json["VersionId"],625 )626 # Update v0 with null ClientRequestToken.627 secret_string_v1: str = "MyNewSecretString"628 version_stages_v1: [str] = ["AWSPENDING"]629 #630 pv_v1_res_json = self.secretsmanager_http_put_secret_value_with_version_val_res(631 self.secretsmanager_http_put_secret_value_with_version(632 secret_name, secret_string_v1, None, version_stages_v1633 ),634 secret_name,635 None,636 version_stages_v1,637 )638 #639 assert pv_v1_res_json["VersionId"] != cr_v0_res_json["VersionId"]640 #641 # Check v1 base consistency.642 self.secretsmanager_http_get_secret_value_with_val_res(643 self.secretsmanager_http_get_secret_value_with(secret_name, "AWSPENDING"),644 secret_name,645 secret_string_v1,646 pv_v1_res_json["VersionId"],647 "AWSPENDING",648 )649 #650 # Check v0 base consistency.651 self.secretsmanager_http_get_secret_value_val_res(652 self.secretsmanager_http_get_secret_value(secret_name),653 secret_name,654 secret_string_v0,655 cr_v0_res_json["VersionId"],656 )657 #658 # Check versioning base consistency.659 versions_v0_v1: json = [660 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSCURRENT"]},661 {"VersionId": pv_v1_res_json["VersionId"], "VersionStages": ["AWSPENDING"]},662 ]663 self.secretsmanager_http_list_secret_version_ids_val_res(664 self.secretsmanager_http_list_secret_version_ids(secret_name),665 secret_name,666 versions_v0_v1,667 )668 self.secretsmanager_http_delete_secret_val_res(669 self.secretsmanager_http_delete_secret(secret_name), secret_name670 )671 def test_http_put_secret_value_custom_client_request_token_new_version_stages(self):672 secret_name: str = (673 "test_http_put_secret_value_custom_client_request_token_new_version_stages"674 )675 # Create v0.676 secret_string_v0: str = "MySecretString"677 cr_v0_res_json: json = self.secretsmanager_http_create_secret_string_val_res(678 self.secretsmanager_http_create_secret_string(secret_name, secret_string_v0),679 secret_name,680 )681 #682 # Check v0 base consistency.683 self.secretsmanager_http_get_secret_value_val_res(684 self.secretsmanager_http_get_secret_value(secret_name),685 secret_name,686 secret_string_v0,687 cr_v0_res_json["VersionId"],688 )689 # Update v0 with null ClientRequestToken.690 secret_string_v1: str = "MyNewSecretString"691 version_stages_v1: [str] = ["AWSPENDING"]692 crt_v1: str = str(uuid.uuid4())693 while crt_v1 == cr_v0_res_json["VersionId"]:694 crt_v1 = str(uuid.uuid4())695 #696 self.secretsmanager_http_put_secret_value_with_version_val_res(697 self.secretsmanager_http_put_secret_value_with_version(698 secret_name, secret_string_v1, crt_v1, version_stages_v1699 ),700 secret_name,701 crt_v1,702 version_stages_v1,703 )704 #705 # Check v1 base consistency.706 self.secretsmanager_http_get_secret_value_with_val_res(707 self.secretsmanager_http_get_secret_value_with(secret_name, "AWSPENDING"),708 secret_name,709 secret_string_v1,710 crt_v1,711 "AWSPENDING",712 )713 #714 # Check v0 base consistency.715 self.secretsmanager_http_get_secret_value_val_res(716 self.secretsmanager_http_get_secret_value(secret_name),717 secret_name,718 secret_string_v0,719 cr_v0_res_json["VersionId"],720 )721 #722 # Check versioning base consistency.723 versions_v0_v1: json = [724 {"VersionId": cr_v0_res_json["VersionId"], "VersionStages": ["AWSCURRENT"]},725 {"VersionId": crt_v1, "VersionStages": ["AWSPENDING"]},726 ]727 self.secretsmanager_http_list_secret_version_ids_val_res(728 self.secretsmanager_http_list_secret_version_ids(secret_name),729 secret_name,730 versions_v0_v1,731 )732 self.secretsmanager_http_delete_secret_val_res(733 self.secretsmanager_http_delete_secret(secret_name), secret_name...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful