How to use describe_parameters method in localstack

Best Python code snippet using localstack_python

test_ssm_boto3.py

Source:test_ssm_boto3.py Github

copy

Full Screen

...392 err.response["Error"]["Message"].should.equal(393 "Parameter test_noexist not found."394 )395@mock_ssm396def test_describe_parameters():397 client = boto3.client("ssm", region_name="us-east-1")398 client.put_parameter(399 Name="test",400 Description="A test parameter",401 Value="value",402 Type="String",403 AllowedPattern=r".*",404 )405 response = client.describe_parameters()406 parameters = response["Parameters"]407 parameters.should.have.length_of(1)408 parameters[0]["Name"].should.equal("test")409 parameters[0]["Type"].should.equal("String")410 parameters[0]["AllowedPattern"].should.equal(r".*")411@mock_ssm412def test_describe_parameters_paging():413 client = boto3.client("ssm", region_name="us-east-1")414 for i in range(50):415 client.put_parameter(Name="param-%d" % i, Value="value-%d" % i, Type="String")416 response = client.describe_parameters()417 response["Parameters"].should.have.length_of(10)418 response["NextToken"].should.equal("10")419 response = client.describe_parameters(NextToken=response["NextToken"])420 response["Parameters"].should.have.length_of(10)421 response["NextToken"].should.equal("20")422 response = client.describe_parameters(NextToken=response["NextToken"])423 response["Parameters"].should.have.length_of(10)424 response["NextToken"].should.equal("30")425 response = client.describe_parameters(NextToken=response["NextToken"])426 response["Parameters"].should.have.length_of(10)427 response["NextToken"].should.equal("40")428 response = client.describe_parameters(NextToken=response["NextToken"])429 response["Parameters"].should.have.length_of(10)430 response["NextToken"].should.equal("50")431 response = client.describe_parameters(NextToken=response["NextToken"])432 response["Parameters"].should.have.length_of(0)433 response.should_not.have.key("NextToken")434@mock_ssm435def test_describe_parameters_filter_names():436 client = boto3.client("ssm", region_name="us-east-1")437 for i in range(50):438 p = {"Name": "param-%d" % i, "Value": "value-%d" % i, "Type": "String"}439 if i % 5 == 0:440 p["Type"] = "SecureString"441 p["KeyId"] = "a key"442 client.put_parameter(**p)443 response = client.describe_parameters(444 Filters=[{"Key": "Name", "Values": ["param-22"]}]445 )446 parameters = response["Parameters"]447 parameters.should.have.length_of(1)448 parameters[0]["Name"].should.equal("param-22")449 parameters[0]["Type"].should.equal("String")450 response.should_not.have.key("NextToken")451@mock_ssm452def test_describe_parameters_filter_type():453 client = boto3.client("ssm", region_name="us-east-1")454 for i in range(50):455 p = {"Name": "param-%d" % i, "Value": "value-%d" % i, "Type": "String"}456 if i % 5 == 0:457 p["Type"] = "SecureString"458 p["KeyId"] = "a key"459 client.put_parameter(**p)460 response = client.describe_parameters(461 Filters=[{"Key": "Type", "Values": ["SecureString"]}]462 )463 parameters = response["Parameters"]464 parameters.should.have.length_of(10)465 parameters[0]["Type"].should.equal("SecureString")466 response.should.have.key("NextToken").which.should.equal("10")467@mock_ssm468def test_describe_parameters_filter_keyid():469 client = boto3.client("ssm", region_name="us-east-1")470 for i in range(50):471 p = {"Name": "param-%d" % i, "Value": "value-%d" % i, "Type": "String"}472 if i % 5 == 0:473 p["Type"] = "SecureString"474 p["KeyId"] = "key:%d" % i475 client.put_parameter(**p)476 response = client.describe_parameters(477 Filters=[{"Key": "KeyId", "Values": ["key:10"]}]478 )479 parameters = response["Parameters"]480 parameters.should.have.length_of(1)481 parameters[0]["Name"].should.equal("param-10")482 parameters[0]["Type"].should.equal("SecureString")483 response.should_not.have.key("NextToken")484@mock_ssm485def test_describe_parameters_with_parameter_filters_keyid():486 client = boto3.client("ssm", region_name="us-east-1")487 client.put_parameter(Name="secure-param", Value="secure-value", Type="SecureString")488 client.put_parameter(489 Name="custom-secure-param",490 Value="custom-secure-value",491 Type="SecureString",492 KeyId="alias/custom",493 )494 client.put_parameter(Name="param", Value="value", Type="String")495 response = client.describe_parameters(496 ParameterFilters=[{"Key": "KeyId", "Values": ["alias/aws/ssm"]}]497 )498 parameters = response["Parameters"]499 parameters.should.have.length_of(1)500 parameters[0]["Name"].should.equal("secure-param")501 parameters[0]["Type"].should.equal("SecureString")502 response.should_not.have.key("NextToken")503 response = client.describe_parameters(504 ParameterFilters=[{"Key": "KeyId", "Values": ["alias/custom"]}]505 )506 parameters = response["Parameters"]507 parameters.should.have.length_of(1)508 parameters[0]["Name"].should.equal("custom-secure-param")509 parameters[0]["Type"].should.equal("SecureString")510 response.should_not.have.key("NextToken")511 response = client.describe_parameters(512 ParameterFilters=[{"Key": "KeyId", "Option": "BeginsWith", "Values": ["alias"]}]513 )514 parameters = response["Parameters"]515 parameters.should.have.length_of(2)516 response.should_not.have.key("NextToken")517@mock_ssm518def test_describe_parameters_with_parameter_filters_name():519 client = boto3.client("ssm", region_name="us-east-1")520 client.put_parameter(Name="param", Value="value", Type="String")521 client.put_parameter(Name="/param-2", Value="value-2", Type="String")522 client.put_parameter(Name="/tangent-3", Value="value-3", Type="String")523 client.put_parameter(Name="tangram-4", Value="value-4", Type="String")524 client.put_parameter(Name="standby-5", Value="value-5", Type="String")525 response = client.describe_parameters(526 ParameterFilters=[{"Key": "Name", "Values": ["param"]}]527 )528 parameters = response["Parameters"]529 parameters.should.have.length_of(1)530 parameters[0]["Name"].should.equal("param")531 parameters[0]["Type"].should.equal("String")532 response.should_not.have.key("NextToken")533 response = client.describe_parameters(534 ParameterFilters=[{"Key": "Name", "Values": ["/param"]}]535 )536 parameters = response["Parameters"]537 parameters.should.have.length_of(1)538 parameters[0]["Name"].should.equal("param")539 parameters[0]["Type"].should.equal("String")540 response.should_not.have.key("NextToken")541 response = client.describe_parameters(542 ParameterFilters=[{"Key": "Name", "Values": ["param-2"]}]543 )544 parameters = response["Parameters"]545 parameters.should.have.length_of(1)546 parameters[0]["Name"].should.equal("/param-2")547 parameters[0]["Type"].should.equal("String")548 response.should_not.have.key("NextToken")549 response = client.describe_parameters(550 ParameterFilters=[{"Key": "Name", "Option": "BeginsWith", "Values": ["param"]}]551 )552 parameters = response["Parameters"]553 parameters.should.have.length_of(2)554 response.should_not.have.key("NextToken")555 response = client.describe_parameters(556 ParameterFilters=[{"Key": "Name", "Option": "Contains", "Values": ["ram"]}]557 )558 parameters = response["Parameters"]559 parameters.should.have.length_of(3)560 response.should_not.have.key("NextToken")561 response = client.describe_parameters(562 ParameterFilters=[{"Key": "Name", "Option": "Contains", "Values": ["/tan"]}]563 )564 parameters = response["Parameters"]565 parameters.should.have.length_of(2)566 response.should_not.have.key("NextToken")567@mock_ssm568def test_describe_parameters_with_parameter_filters_path():569 client = boto3.client("ssm", region_name="us-east-1")570 client.put_parameter(Name="/foo/name1", Value="value1", Type="String")571 client.put_parameter(Name="/foo/name2", Value="value2", Type="String")572 client.put_parameter(Name="/bar/name3", Value="value3", Type="String")573 client.put_parameter(Name="/bar/name3/name4", Value="value4", Type="String")574 client.put_parameter(Name="foo", Value="bar", Type="String")575 response = client.describe_parameters(576 ParameterFilters=[{"Key": "Path", "Values": ["/fo"]}]577 )578 parameters = response["Parameters"]579 parameters.should.have.length_of(0)580 response.should_not.have.key("NextToken")581 response = client.describe_parameters(582 ParameterFilters=[{"Key": "Path", "Values": ["/"]}]583 )584 parameters = response["Parameters"]585 parameters.should.have.length_of(1)586 parameters[0]["Name"].should.equal("foo")587 parameters[0]["Type"].should.equal("String")588 response.should_not.have.key("NextToken")589 response = client.describe_parameters(590 ParameterFilters=[{"Key": "Path", "Values": ["/", "/foo"]}]591 )592 parameters = response["Parameters"]593 parameters.should.have.length_of(3)594 {parameter["Name"] for parameter in response["Parameters"]}.should.equal(595 {"/foo/name1", "/foo/name2", "foo"}596 )597 response.should_not.have.key("NextToken")598 response = client.describe_parameters(599 ParameterFilters=[{"Key": "Path", "Values": ["/foo/"]}]600 )601 parameters = response["Parameters"]602 parameters.should.have.length_of(2)603 {parameter["Name"] for parameter in response["Parameters"]}.should.equal(604 {"/foo/name1", "/foo/name2"}605 )606 response.should_not.have.key("NextToken")607 response = client.describe_parameters(608 ParameterFilters=[609 {"Key": "Path", "Option": "OneLevel", "Values": ["/bar/name3"]}610 ]611 )612 parameters = response["Parameters"]613 parameters.should.have.length_of(1)614 parameters[0]["Name"].should.equal("/bar/name3/name4")615 parameters[0]["Type"].should.equal("String")616 response.should_not.have.key("NextToken")617 response = client.describe_parameters(618 ParameterFilters=[{"Key": "Path", "Option": "Recursive", "Values": ["/fo"]}]619 )620 parameters = response["Parameters"]621 parameters.should.have.length_of(0)622 response.should_not.have.key("NextToken")623 response = client.describe_parameters(624 ParameterFilters=[{"Key": "Path", "Option": "Recursive", "Values": ["/"]}]625 )626 parameters = response["Parameters"]627 parameters.should.have.length_of(5)628 response.should_not.have.key("NextToken")629 response = client.describe_parameters(630 ParameterFilters=[631 {"Key": "Path", "Option": "Recursive", "Values": ["/foo", "/bar"]}632 ]633 )634 parameters = response["Parameters"]635 parameters.should.have.length_of(4)636 {parameter["Name"] for parameter in response["Parameters"]}.should.equal(637 {"/foo/name1", "/foo/name2", "/bar/name3", "/bar/name3/name4"}638 )639 response.should_not.have.key("NextToken")640 response = client.describe_parameters(641 ParameterFilters=[{"Key": "Path", "Option": "Recursive", "Values": ["/foo/"]}]642 )643 parameters = response["Parameters"]644 parameters.should.have.length_of(2)645 {parameter["Name"] for parameter in response["Parameters"]}.should.equal(646 {"/foo/name1", "/foo/name2"}647 )648 response.should_not.have.key("NextToken")649 response = client.describe_parameters(650 ParameterFilters=[651 {"Key": "Path", "Option": "Recursive", "Values": ["/bar/name3"]}652 ]653 )654 parameters = response["Parameters"]655 parameters.should.have.length_of(1)656 parameters[0]["Name"].should.equal("/bar/name3/name4")657 parameters[0]["Type"].should.equal("String")658 response.should_not.have.key("NextToken")659@mock_ssm660def test_describe_parameters_invalid_parameter_filters():661 client = boto3.client("ssm", region_name="us-east-1")662 client.describe_parameters.when.called_with(663 Filters=[{"Key": "Name", "Values": ["test"]}],664 ParameterFilters=[{"Key": "Name", "Values": ["test"]}],665 ).should.throw(666 ClientError,667 "You can use either Filters or ParameterFilters in a single request.",668 )669 client.describe_parameters.when.called_with(ParameterFilters=[{}]).should.throw(670 ParamValidationError,671 'Parameter validation failed:\nMissing required parameter in ParameterFilters[0]: "Key"',672 )673 client.describe_parameters.when.called_with(674 ParameterFilters=[{"Key": "key"}]675 ).should.throw(676 ClientError,677 '1 validation error detected: Value "key" at "parameterFilters.1.member.key" failed to satisfy constraint: '678 "Member must satisfy regular expression pattern: tag:.+|Name|Type|KeyId|Path|Label|Tier",679 )680 long_key = "tag:" + "t" * 129681 client.describe_parameters.when.called_with(682 ParameterFilters=[{"Key": long_key}]683 ).should.throw(684 ClientError,685 '1 validation error detected: Value "{value}" at "parameterFilters.1.member.key" failed to satisfy constraint: '686 "Member must have length less than or equal to 132".format(value=long_key),687 )688 client.describe_parameters.when.called_with(689 ParameterFilters=[{"Key": "Name", "Option": "over 10 chars"}]690 ).should.throw(691 ClientError,692 '1 validation error detected: Value "over 10 chars" at "parameterFilters.1.member.option" failed to satisfy constraint: '693 "Member must have length less than or equal to 10",694 )695 many_values = ["test"] * 51696 client.describe_parameters.when.called_with(697 ParameterFilters=[{"Key": "Name", "Values": many_values}]698 ).should.throw(699 ClientError,700 '1 validation error detected: Value "{value}" at "parameterFilters.1.member.values" failed to satisfy constraint: '701 "Member must have length less than or equal to 50".format(value=many_values),702 )703 long_value = ["t" * 1025]704 client.describe_parameters.when.called_with(705 ParameterFilters=[{"Key": "Name", "Values": long_value}]706 ).should.throw(707 ClientError,708 '1 validation error detected: Value "{value}" at "parameterFilters.1.member.values" failed to satisfy constraint: '709 "[Member must have length less than or equal to 1024, Member must have length greater than or equal to 1]".format(710 value=long_value711 ),712 )713 client.describe_parameters.when.called_with(714 ParameterFilters=[{"Key": "Name", "Option": "over 10 chars"}, {"Key": "key"}]715 ).should.throw(716 ClientError,717 "2 validation errors detected: "718 'Value "over 10 chars" at "parameterFilters.1.member.option" failed to satisfy constraint: '719 "Member must have length less than or equal to 10; "720 'Value "key" at "parameterFilters.2.member.key" failed to satisfy constraint: '721 "Member must satisfy regular expression pattern: tag:.+|Name|Type|KeyId|Path|Label|Tier",722 )723 client.describe_parameters.when.called_with(724 ParameterFilters=[{"Key": "Label"}]725 ).should.throw(726 ClientError,727 "The following filter key is not valid: Label. Valid filter keys include: [Path, Name, Type, KeyId, Tier].",728 )729 client.describe_parameters.when.called_with(730 ParameterFilters=[{"Key": "Name"}]731 ).should.throw(732 ClientError,733 "The following filter values are missing : null for filter key Name.",734 )735 client.describe_parameters.when.called_with(736 ParameterFilters=[{"Key": "Name", "Values": []}]737 ).should.throw(738 ParamValidationError,739 "Invalid length for parameter ParameterFilters[0].Values, value: 0, valid range: 1-inf",740 )741 client.describe_parameters.when.called_with(742 ParameterFilters=[743 {"Key": "Name", "Values": ["test"]},744 {"Key": "Name", "Values": ["test test"]},745 ]746 ).should.throw(747 ClientError,748 "The following filter is duplicated in the request: Name. A request can contain only one occurrence of a specific filter.",749 )750 for value in ["/###", "//", "test"]:751 client.describe_parameters.when.called_with(752 ParameterFilters=[{"Key": "Path", "Values": [value]}]753 ).should.throw(754 ClientError,755 'The parameter doesn\'t meet the parameter name requirements. The parameter name must begin with a forward slash "/". '756 'It can\'t be prefixed with "aws" or "ssm" (case-insensitive). '757 "It must use only letters, numbers, or the following symbols: . (period), - (hyphen), _ (underscore). "758 'Special characters are not allowed. All sub-paths, if specified, must use the forward slash symbol "/". '759 "Valid example: /get/parameters2-/by1./path0_.",760 )761 client.describe_parameters.when.called_with(762 ParameterFilters=[{"Key": "Path", "Values": ["/aws", "/ssm"]}]763 ).should.throw(764 ClientError,765 'Filters for common parameters can\'t be prefixed with "aws" or "ssm" (case-insensitive). '766 "When using global parameters, please specify within a global namespace.",767 )768 client.describe_parameters.when.called_with(769 ParameterFilters=[{"Key": "Path", "Option": "Equals", "Values": ["test"]}]770 ).should.throw(771 ClientError,772 "The following filter option is not valid: Equals. Valid options include: [Recursive, OneLevel].",773 )774 client.describe_parameters.when.called_with(775 ParameterFilters=[{"Key": "Tier", "Values": ["test"]}]776 ).should.throw(777 ClientError,778 "The following filter value is not valid: test. Valid values include: [Standard, Advanced, Intelligent-Tiering]",779 )780 client.describe_parameters.when.called_with(781 ParameterFilters=[{"Key": "Type", "Values": ["test"]}]782 ).should.throw(783 ClientError,784 "The following filter value is not valid: test. Valid values include: [String, StringList, SecureString]",785 )786 client.describe_parameters.when.called_with(787 ParameterFilters=[{"Key": "Name", "Option": "option", "Values": ["test"]}]788 ).should.throw(789 ClientError,790 "The following filter option is not valid: option. Valid options include: [BeginsWith, Equals].",791 )792@mock_ssm793def test_describe_parameters_attributes():794 client = boto3.client("ssm", region_name="us-east-1")795 client.put_parameter(796 Name="aa", Value="11", Type="String", Description="my description"797 )798 client.put_parameter(Name="bb", Value="22", Type="String")799 response = client.describe_parameters()800 parameters = response["Parameters"]801 parameters.should.have.length_of(2)802 parameters[0]["Description"].should.equal("my description")803 parameters[0]["Version"].should.equal(1)804 parameters[0]["LastModifiedDate"].should.be.a(datetime.date)805 parameters[0]["LastModifiedUser"].should.equal("N/A")806 parameters[1].should_not.have.key("Description")807 parameters[1]["Version"].should.equal(1)808@mock_ssm809def test_get_parameter_invalid():810 client = client = boto3.client("ssm", region_name="us-east-1")811 response = client.get_parameters(Names=["invalid"], WithDecryption=False)812 len(response["Parameters"]).should.equal(0)813 len(response["InvalidParameters"]).should.equal(1)...

Full Screen

Full Screen

test_aws_ssm_client.py

Source:test_aws_ssm_client.py Github

copy

Full Screen

...9 def test_list_parameters(self) -> None:10 self.assertEqual(responses.EXPECTED_LIST_PARAMETERS, self.get_ssm_client().list_parameters())11 def get_ssm_client(self) -> AwsSSMClient:12 return AwsSSMClient(Mock(describe_parameters=Mock(side_effect=self.describe_parameters)))13 def describe_parameters(self, **kwargs: Dict[str, Any]) -> Dict[Any, Any]:14 self.assertEqual(50, kwargs["MaxResults"], f"expected MaxResults=50, got {kwargs['MaxResults']}")15 self.assertEqual([{"Key": "Path", "Option": "Recursive", "Values": ["/"]}], kwargs["ParameterFilters"])16 if "NextToken" in kwargs and str(kwargs["NextToken"]) == "token_for_params_page_2":17 return responses.DESCRIBE_PARAMETERS_PAGE_218 else:19 return responses.DESCRIBE_PARAMETERS_PAGE_120class TestAwsSSMClientFailure(TestCase):21 def test_list_parameters_failure(self) -> None:22 with self.assertRaisesRegex(ListSSMParametersException, "SomeErrorCode"):23 self.get_ssm_client().list_parameters()24 def get_ssm_client(self) -> AwsSSMClient:25 return AwsSSMClient(Mock(describe_parameters=Mock(side_effect=self.describe_parameters)))26 @staticmethod27 def describe_parameters(**kwargs: Dict[str, Any]) -> Dict[Any, Any]:...

Full Screen

Full Screen

uploads.py

Source:uploads.py Github

copy

Full Screen

1import boto32ssm_client = boto3.client('ssm')3def list_parameters():4 # creating paginator object for describe_parameters() method5 paginator = ssm_client.get_paginator('describe_parameters')6 # creating a PageIterator from the paginator7 page_iterator = paginator.paginate().build_full_result()8 # loop through each page from page_iterator9 for page in page_iterator['Parameters']:10 if str(page['Name']).startswith("/udacity"):11 response = ssm_client.get_parameter(12 Name=page['Name'],13 WithDecryption=True14 )15 value = response['Parameter']['Value']16 print(f"""'{page['Name']}': '{value}', """)17def get_parameter(name: str):18 response = ssm_client.get_parameter(...

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