Je travaille sur un script python qui analyse tous les compartiments et fichiers S3. Je veux que le script enregistre tous les fichiers qui sont exposés au public dans le document de politique, je veux dire, il a: "Effect": "Allow"
et "Principal" : "*"
. J'ai donc cette ligne dans mon code:Comment analyser la réponse du document de politique par boto3
bucket_policy = storageClient.get_bucket_policy(Bucket='mybucket-documents-2017')
print(bucket_policy)
Il retourne une chaîne:
{
'Policy':
u'{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"",
"Effect":"Allow",
"Principal":
{"AWS":"arn:aws:iam::000000000000:user/myuser"},
"Action":"s3:GetObject",
"Resource":"arn:aws:s3:::mybucket-documents-2017/*"
},
{
"Sid":"",
"Effect":"Allow",
"Principal":{"AWS":"arn:aws:iam::0000000000000:user/myuser"},
"Action":"s3:PutObject",
"Resource":"arn:aws:s3:::mybucket-documents-2017/*"
}]
}',
'ResponseMetadata': {
'HTTPStatusCode': 200, 'RetryAttempts': 0, 'HostId': '0EkHM/G1rnRjZH3lhTim1uaDG+5dCJmbJAhSVTnniGsNZIAl6SOMlYgbJOR0XAJOtzmXuu/CSd0=', 'RequestId': '037CADEB6342E9C
2', 'HTTPHeaders': {'x-amz-id-2': '0EkHM/G1rnRjZH3lhTim1uaDG+5dCJmbJAhSVTnniGsNZIAl6SOMlYgbJOR0XAJOtzmXuu/CSd0=', 'server': 'AmazonS3', 'transfer-encoding': 'chunked', 'x-amz-request-id': '037CADEB634
2E9C2', 'date': 'Fri, 11 Aug 2017 10:03:21 GMT', 'content-type': 'application/json'}
}
}
Quand je fais quelque chose comme:
for policy in bucket_policy:
print(policy[0])
ou
for policy in bucket_policy['Policy']:
print(policy[0])
I n'obtiens rien. Comment faire pour obtenir la valeur Effect
et Principal
en analysant le document de politique?
Merci! cela a fonctionné pour moi – Somar
J'ai testé ceci et cela n'a pas fonctionné, j'obtiens une erreur de type sur l'importation de JSON. –
Postez votre erreur @AlexEshoo nous pouvons jeter un oeil. – MrName