1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include "rgw_rest_pubsub_common.h"
#include "common/dout.h"
#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_rgw
void RGWPSCreateTopicOp::execute() {
op_ret = get_params();
if (op_ret < 0) {
return;
}
ups.emplace(store, s->owner.get_id());
op_ret = ups->create_topic(topic_name, dest, topic_arn);
if (op_ret < 0) {
ldout(s->cct, 1) << "failed to create topic '" << topic_name << "', ret=" << op_ret << dendl;
return;
}
ldout(s->cct, 20) << "successfully created topic '" << topic_name << "'" << dendl;
}
void RGWPSListTopicsOp::execute() {
ups.emplace(store, s->owner.get_id());
op_ret = ups->get_user_topics(&result);
if (op_ret < 0) {
ldout(s->cct, 1) << "failed to get topics, ret=" << op_ret << dendl;
return;
}
ldout(s->cct, 20) << "successfully got topics" << dendl;
}
void RGWPSGetTopicOp::execute() {
op_ret = get_params();
if (op_ret < 0) {
return;
}
ups.emplace(store, s->owner.get_id());
op_ret = ups->get_topic(topic_name, &result);
if (op_ret < 0) {
ldout(s->cct, 1) << "failed to get topic '" << topic_name << "', ret=" << op_ret << dendl;
return;
}
ldout(s->cct, 1) << "successfully got topic '" << topic_name << "'" << dendl;
}
void RGWPSDeleteTopicOp::execute() {
op_ret = get_params();
if (op_ret < 0) {
return;
}
ups.emplace(store, s->owner.get_id());
op_ret = ups->remove_topic(topic_name);
if (op_ret < 0) {
ldout(s->cct, 1) << "failed to remove topic '" << topic_name << ", ret=" << op_ret << dendl;
return;
}
ldout(s->cct, 1) << "successfully removed topic '" << topic_name << "'" << dendl;
}
void RGWPSCreateSubOp::execute() {
op_ret = get_params();
if (op_ret < 0) {
return;
}
ups.emplace(store, s->owner.get_id());
auto sub = ups->get_sub(sub_name);
op_ret = sub->subscribe(topic_name, dest);
if (op_ret < 0) {
ldout(s->cct, 1) << "failed to create subscription '" << sub_name << "', ret=" << op_ret << dendl;
return;
}
ldout(s->cct, 20) << "successfully created subscription '" << sub_name << "'" << dendl;
}
void RGWPSGetSubOp::execute() {
op_ret = get_params();
if (op_ret < 0) {
return;
}
ups.emplace(store, s->owner.get_id());
auto sub = ups->get_sub(sub_name);
op_ret = sub->get_conf(&result);
if (op_ret < 0) {
ldout(s->cct, 1) << "failed to get subscription '" << sub_name << "', ret=" << op_ret << dendl;
return;
}
ldout(s->cct, 20) << "successfully got subscription '" << sub_name << "'" << dendl;
}
void RGWPSDeleteSubOp::execute() {
op_ret = get_params();
if (op_ret < 0) {
return;
}
ups.emplace(store, s->owner.get_id());
auto sub = ups->get_sub(sub_name);
op_ret = sub->unsubscribe(topic_name);
if (op_ret < 0) {
ldout(s->cct, 1) << "failed to remove subscription '" << sub_name << "', ret=" << op_ret << dendl;
return;
}
ldout(s->cct, 20) << "successfully removed subscription '" << sub_name << "'" << dendl;
}
void RGWPSAckSubEventOp::execute() {
op_ret = get_params();
if (op_ret < 0) {
return;
}
ups.emplace(store, s->owner.get_id());
auto sub = ups->get_sub_with_events(sub_name);
op_ret = sub->remove_event(event_id);
if (op_ret < 0) {
ldout(s->cct, 1) << "failed to ack event on subscription '" << sub_name << "', ret=" << op_ret << dendl;
return;
}
ldout(s->cct, 20) << "successfully acked event on subscription '" << sub_name << "'" << dendl;
}
void RGWPSPullSubEventsOp::execute() {
op_ret = get_params();
if (op_ret < 0) {
return;
}
ups.emplace(store, s->owner.get_id());
sub = ups->get_sub_with_events(sub_name);
if (!sub) {
op_ret = -ENOENT;
ldout(s->cct, 1) << "failed to get subscription '" << sub_name << "' for events, ret=" << op_ret << dendl;
return;
}
op_ret = sub->list_events(marker, max_entries);
if (op_ret < 0) {
ldout(s->cct, 1) << "failed to get events from subscription '" << sub_name << "', ret=" << op_ret << dendl;
return;
}
ldout(s->cct, 20) << "successfully got events from subscription '" << sub_name << "'" << dendl;
}
int RGWPSCreateNotifOp::verify_permission() {
int ret = get_params();
if (ret < 0) {
return ret;
}
const auto& id = s->owner.get_id();
ret = store->getRados()->get_bucket_info(store->svc(), id.tenant, bucket_name,
bucket_info, nullptr, null_yield, nullptr);
if (ret < 0) {
ldout(s->cct, 1) << "failed to get bucket info, cannot verify ownership" << dendl;
return ret;
}
if (bucket_info.owner != id) {
ldout(s->cct, 1) << "user doesn't own bucket, not allowed to create notification" << dendl;
return -EPERM;
}
return 0;
}
int RGWPSDeleteNotifOp::verify_permission() {
int ret = get_params();
if (ret < 0) {
return ret;
}
ret = store->getRados()->get_bucket_info(store->svc(), s->owner.get_id().tenant, bucket_name,
bucket_info, nullptr, null_yield, nullptr);
if (ret < 0) {
return ret;
}
if (bucket_info.owner != s->owner.get_id()) {
ldout(s->cct, 1) << "user doesn't own bucket, cannot remove notification" << dendl;
return -EPERM;
}
return 0;
}
int RGWPSListNotifsOp::verify_permission() {
int ret = get_params();
if (ret < 0) {
return ret;
}
ret = store->getRados()->get_bucket_info(store->svc(), s->owner.get_id().tenant, bucket_name,
bucket_info, nullptr, null_yield, nullptr);
if (ret < 0) {
return ret;
}
if (bucket_info.owner != s->owner.get_id()) {
ldout(s->cct, 1) << "user doesn't own bucket, cannot get topic list" << dendl;
return -EPERM;
}
return 0;
}
|