mirror of
https://github.com/ceph/ceph
synced 2026-08-02 07:03:18 +00:00
Merge pull request #37956 from dorindabassey/example-notific
examples/boto3/README: examples notification Reviewed-by: Yuval Lifshitz <ylifshit@redhat.com>
This commit is contained in:
commit
1e31479f64
@ -13,16 +13,86 @@ The standard [AWS CLI](https://docs.aws.amazon.com/cli/latest/) may also be used
|
||||
```
|
||||
aws --endpoint-url http://localhost:8000 s3api list-objects --bucket=mybucket --allow-unordered
|
||||
```
|
||||
- Bucket notifications with filtering extensions:
|
||||
|
||||
- Use the following command to set SNS signature to s3v2:
|
||||
```
|
||||
aws --region=default --endpoint-url http://localhost:8000 s3api put-bucket-notification-configuration --bucket mybucket --notification-configuration='{"TopicConfigurations": [{"Id": "notif1", "TopicArn": "arn:aws:sns:default::mytopic",
|
||||
"Events": ["s3:ObjectCreated:*", "s3:ObjectRemoved:*"],
|
||||
"Filter": {"Metadata": {"FilterRules": [{"Name": "x-amz-meta-foo", "Value": "bar"}, {"Name": "x-amz-meta-hello", "Value": "world"}]}, "Key": {"FilterRules": [{"Name": "regex", "Value": "([a-z]+)"}]}}}]}'
|
||||
```
|
||||
aws configure set default.sns.signature_version s3
|
||||
```
|
||||
|
||||
- Topic creation with endpoint:
|
||||
```
|
||||
aws --endpoint-url http://localhost:8000 sns create-topic --name=mytopic --attributes='{"push-endpoint": "amqp://localhost:5672", "amqp-exchange": "ex1", "amqp-ack-level": "broker"}'
|
||||
```
|
||||
Expected output:
|
||||
```
|
||||
{
|
||||
"TopicArn": "arn:aws:sns:default::mytopic"
|
||||
}
|
||||
```
|
||||
|
||||
- Get topic attributes:
|
||||
```
|
||||
aws --endpoint-url http://localhost:8000 sns get-topic-attributes --topic-arn="arn:aws:sns:default::mytopic"
|
||||
```
|
||||
Expected output:
|
||||
```
|
||||
{
|
||||
"Attributes": {
|
||||
"User": "",
|
||||
"Name": "mytopic",
|
||||
"EndPoint": "{\"EndpointAddress\":\"amqp://localhost:5672\",\"EndpointArgs\":\"Attributes.entry.1.key=push-endpoint&Attributes.entry.1.value=amqp://localhost:5672&Attributes.entry.2.key=amqp-exchange&Attributes.entry.2.value=ex1&Attributes.entry.3.key=amqp-ack-level&Attributes.entry.3.value=broker&Version=2010-03-31&amqp-ack-level=broker&amqp-exchange=ex1&push-endpoint=amqp://localhost:5672\",\"EndpointTopic\":\"mytopic\",\"HasStoredSecret\":\"false\",\"Persistent\":\"false\"}",
|
||||
"TopicArn": "arn:aws:sns:default::mytopic",
|
||||
"OpaqueData": ""
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- Bucket notifications with filtering extensions (bucket must exist before calling this command):
|
||||
```
|
||||
aws --region=default --endpoint-url http://localhost:8000 s3api put-bucket-notification-configuration --bucket=mybucket --notification-configuration='{"TopicConfigurations": [{"Id": "notif1", "TopicArn": "arn:aws:sns:default::mytopic", "Events": ["s3:ObjectCreated:*", "s3:ObjectRemoved:*"], "Filter": {"Metadata": {"FilterRules": [{"Name": "x-amz-meta-foo", "Value": "bar"}, {"Name": "x-amz-meta-hello", "Value": "world"}]}, "Key": {"FilterRules": [{"Name": "regex", "Value": "([a-z]+)"}]}}}]}'
|
||||
```
|
||||
|
||||
- Get configuration of a specific notification of a bucket:
|
||||
```
|
||||
aws --endpoint-url http://localhost:8000 s3api get-bucket-notification-configuration --bucket=mybucket --notification=notif1
|
||||
```
|
||||
Expected output:
|
||||
```
|
||||
{
|
||||
"TopicConfigurations": [
|
||||
{
|
||||
"Id": "notif1",
|
||||
"TopicArn": "arn:aws:sns:default::mytopic",
|
||||
"Events": [
|
||||
"s3:ObjectCreated:*",
|
||||
"s3:ObjectRemoved:*"
|
||||
],
|
||||
"Filter": {
|
||||
"Key": {
|
||||
"FilterRules": [
|
||||
{
|
||||
"Name": "regex",
|
||||
"Value": "([a-z]+)"
|
||||
}
|
||||
]
|
||||
},
|
||||
"Metadata": {
|
||||
"FilterRules": [
|
||||
{
|
||||
"Name": "x-amz-meta-foo",
|
||||
"Value": "bar"
|
||||
},
|
||||
{
|
||||
"Name": "x-amz-meta-hello",
|
||||
"Value": "world"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
# Developers
|
||||
Anyone developing an extension to the S3 API supported by AWS, please modify ``service-2.sdk-extras.json`` (all extensions should go into the same file), so that boto3 could be used to test the new API.
|
||||
|
||||
46
examples/boto3/topic_attributes.py
Normal file
46
examples/boto3/topic_attributes.py
Normal file
@ -0,0 +1,46 @@
|
||||
import sys
|
||||
import urllib
|
||||
import hmac
|
||||
import hashlib
|
||||
import base64
|
||||
import xmltodict
|
||||
import http.client
|
||||
from urllib import parse as urlparse
|
||||
from time import gmtime, strftime
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
# topic arn as first argument
|
||||
topic_arn = sys.argv[1]
|
||||
else:
|
||||
print ('Usage: ' + sys.argv[0] + ' <topic arn> [region name]')
|
||||
sys.exit(1)
|
||||
|
||||
# endpoint and keys from vstart
|
||||
endpoint = '127.0.0.1:8000'
|
||||
access_key='0555b35654ad1656d804'
|
||||
secret_key='h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q=='
|
||||
|
||||
|
||||
parameters = {'Action': 'GetTopic', 'TopicArn': topic_arn}
|
||||
body = urlparse.urlencode(parameters)
|
||||
string_date = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
|
||||
content_type = 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
resource = '/'
|
||||
method = 'POST'
|
||||
string_to_sign = method + '\n\n' + content_type + '\n' + string_date + '\n' + resource
|
||||
signature = base64.b64encode(hmac.new(secret_key.encode('utf-8'), string_to_sign.encode('utf-8'), hashlib.sha1).digest()).decode('ascii')
|
||||
headers = {'Authorization': 'AWS '+access_key+':'+signature,
|
||||
'Date': string_date,
|
||||
'Host': endpoint,
|
||||
'Content-Type': content_type}
|
||||
http_conn = http.client.HTTPConnection(endpoint)
|
||||
http_conn.request(method, resource, body, headers)
|
||||
response = http_conn.getresponse()
|
||||
data = response.read()
|
||||
status = response.status
|
||||
http_conn.close()
|
||||
dict_response = xmltodict.parse(data)
|
||||
|
||||
# getting attributes of a specific topic is an extension to AWS sns
|
||||
|
||||
print(dict_response, status)
|
||||
Loading…
Reference in New Issue
Block a user