简体   繁体   English

AWS PHP SDK过滤Aws \\ Result对象

[英]AWS PHP SDK Filter Aws\Result Object

I am using AWS SDK PHP V3. 我使用的是AWS SDK PHP V3。 If i run following code 如果我运行以下代码

$result = $client->getAccountPasswordPolicy([]);
$result = $result->toArray();

It returns result below 它返回下面的结果

Array
(
    [PasswordPolicy] => Array
        (
            [MinimumPasswordLength] => 6
            [RequireSymbols] => 
            [RequireNumbers] => 
            [RequireUppercaseCharacters] => 1
            [RequireLowercaseCharacters] => 
            [AllowUsersToChangePassword] => 
            [ExpirePasswords] => 
        )

    [@metadata] => Array
        (
            [statusCode] => 200
            [effectiveUri] => https://iam.amazonaws.com
            [headers] => Array
                (
                    [x-amzn-requestid] => 437f79e9-9ee0-11e7-8a82-47e702eaf8eb
                    [content-type] => text/xml
                    [content-length] => 740
                    [date] => Thu, 21 Sep 2017 15:19:29 GMT
                    [connection] => close
                )

            [transferStats] => Array
                (
                    [http] => Array
                        (
                            [0] => Array
                                (
                                )

                        )

                )

        )

)

How to get result of only RequireUppercaseCharacters or RequireLowercaseCharacters using AWS SDK or do i have to use array functions to filter data? 如何使用AWS SDK获取RequireUppercaseCharacters或RequireLowercaseCharacters的结果,还是必须使用数组函数来过滤数据?

Reference Link 参考链接

ah..you are asking about JMESPath. 啊..你在问JMESPath。 you can achieve what are you are trying to do by 你可以实现你想做的事情

$result = $client->getAccountPasswordPolicy([]);
$data = $result->search('PasswordPolicy.RequireUppercaseCharacters');

you can read more about JMESPath here 你可以在这里阅读更多关于JMESPath的内容

This seems like it's not possible with the current API. 对于当前的API来说,这似乎是不可能的。 Although it might seem like the method parameter is open to indicate which specific items you need (because it's an array), there is no signal whatsoever of this being the case anywhere in the documentation. 虽然看起来方法参数可能打开以指示您需要哪些特定项目(因为它是一个数组),但在文档中的任何地方都没有任何信号。

Compare the documentation for getAccountPasswordPolicy() with, for example, ListPolicies() . getAccountPasswordPolicy()文档ListPolicies() The latter explicitly says: 后者明确说:

You can filter the list of policies that is returned using the optional OnlyAttached, Scope, and PathPrefix parameters. 您可以使用可选的OnlyAttached,Scope和PathPrefix参数筛选返回的策略列表。

In contrast, the docs for getAccountPasswordPolicy() make no mention of this. 相比之下, getAccountPasswordPolicy()的文档没有提到这一点。 Not even a mention of the parameter. 甚至没有提到参数。 The parameter is mentioned however in the method signature, which makes me think this might come in a future version of the API. 参数在方法签名,这让我觉得这个可能出现的API的未来版本但是提及。

The CLI documentation doesn't have any parameters of the like either, so this definitely seems like something you can't do at the moment. CLI文档也没有任何类似的参数,所以这肯定是你目前无法做的事情。

I did some tests, just in case, with no success: 我做了一些测试,以防万一,没有成功:

$result = $client->getAccountPasswordPolicy(["RequireUppercaseCharacters"]);

returns 回报

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Found 1 error while validating the input provided for the GetAccountPasswordPolicy operation: must be an associative array. 致命错误:在验证为GetAccountPasswordPolicy操作提供的输入时,消息'发现1错误'的未捕获异常'InvalidArgumentException':必须是关联数组。 Found array(2)' in /Applications/MAMP/htdocs/awss3/vendor/aws/aws-sdk-php/src/Api/Validator.php:65 在/Applications/MAMP/htdocs/awss3/vendor/aws/aws-sdk-php/src/Api/Validator.php:65中找到数组(2)'

And specifying an associative array does not filter anything: 并且指定关联数组不会过滤任何内容:

$result = $client->getAccountPasswordPolicy(["PasswordPolicy" => ["RequireUppercaseCharacters"]]);

Aws\Result Object
(
    [data:Aws\Result:private] => Array
        (
            [PasswordPolicy] => Array
                (
                    [MinimumPasswordLength] => 6
                    [RequireSymbols] => 
                    [RequireNumbers] => 
                    [RequireUppercaseCharacters] => 1
                    [RequireLowercaseCharacters] => 
                    [AllowUsersToChangePassword] => 1
                    [ExpirePasswords] => 
                    [HardExpiry] => 
                )

            [@metadata] => Array
                (
                    [statusCode] => 200
                    [effectiveUri] => https://iam.amazonaws.com
                    [headers] => Array
                        (
                            // redacted
                        )

                    [transferStats] => Array
                        (
                            [http] => Array
                                (
                                    [0] => Array
                                        (
                                        )

                                )

                        )

                )

        )

)

So, you're only option for now is going through the array's keys, as always: 所以,你现在唯一的选择就是一如既往地通过数组的键:

$result["PasswordPolicy"]["RequireUppercaseCharacters"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM