bucket_req.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  1. // Copyright (c) 2017, Tencent Inc.
  2. // All rights reserved.
  3. //
  4. // Author: sevenyou <sevenyou@tencent.com>
  5. // Created: 07/21/17
  6. // Description:
  7. #ifndef BUCKET_REQ_H
  8. #define BUCKET_REQ_H
  9. #pragma once
  10. #include "cos_defines.h"
  11. #include "request/base_req.h"
  12. #include "util/string_util.h"
  13. #include "util/illegal_intercept.h"
  14. namespace qcloud_cos {
  15. class BucketReq : public BaseReq {
  16. public:
  17. BucketReq() : m_bucket_name("") {}
  18. explicit BucketReq(const std::string& bucket_name) : m_bucket_name(bucket_name) {
  19. if (!IllegalIntercept::CheckBucket(bucket_name)) {
  20. throw std::invalid_argument("Invalid bucket_name argument :" + bucket_name);
  21. }
  22. }
  23. virtual ~BucketReq() {}
  24. // getter and setter
  25. std::string GetBucketName() const { return m_bucket_name; }
  26. void SetBucketName(const std::string& bucket_name) {
  27. if (!IllegalIntercept::CheckBucket(bucket_name)) {
  28. throw std::invalid_argument("Invalid bucket_name argument :" + bucket_name);
  29. }
  30. m_bucket_name = bucket_name;
  31. }
  32. virtual bool GenerateRequestBody(std::string* body) const { UNUSED_PARAM(body); return true; }
  33. private:
  34. std::string m_bucket_name;
  35. };
  36. class HeadBucketReq : public BucketReq {
  37. public:
  38. explicit HeadBucketReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  39. m_method = "HEAD";
  40. }
  41. virtual ~HeadBucketReq() {}
  42. };
  43. class PutBucketReq : public BucketReq {
  44. public:
  45. explicit PutBucketReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  46. SetMethod("PUT");
  47. SetPath("/");
  48. }
  49. virtual ~PutBucketReq() {}
  50. /// 定义Bucket的ACL属性,有效值:private,public-read-write,public-read
  51. /// 默认值:private
  52. void SetXCosAcl(const std::string& str) { AddHeader("x-cos-acl", str); }
  53. /// 赋予被授权者读的权限.格式:x-cos-grant-read: id=" ",id=" ".
  54. /// 当需要给子账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>"
  55. /// 当需要给根账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>"
  56. void SetXCosGrantRead(const std::string& str) {
  57. AddHeader("x-cos-grant-read", str);
  58. }
  59. /// 赋予被授权者写的权限,格式:x-cos-grant-write: id=" ",id=" "./
  60. /// 当需要给子账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>",
  61. /// 当需要给根账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>"
  62. void SetXCosGrantWrite(const std::string& str) {
  63. AddHeader("x-cos-grant-write", str);
  64. }
  65. /// 赋予被授权者读写权限.格式:x-cos-grant-full-control: id=" ",id=" ".
  66. /// 当需要给子账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>",
  67. /// 当需要给根账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>"
  68. void SetXCosGrantFullControl(const std::string& str) {
  69. AddHeader("x-cos-grant-full-control", str);
  70. }
  71. //设置桶为多az存储桶
  72. void SetMAZBucket() {
  73. std::string maz = "<CreateBucketConfiguration>";
  74. maz += " <BucketAZConfig>MAZ</BucketAZConfig>";
  75. maz += "</CreateBucketConfiguration>";
  76. SetBody(maz);
  77. }
  78. };
  79. class GetBucketReq : public BucketReq {
  80. public:
  81. explicit GetBucketReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  82. SetMethod("GET");
  83. SetPath("/");
  84. }
  85. virtual ~GetBucketReq() {}
  86. /// \@brief 设置前缀,用来规定返回的文件前缀地址
  87. void SetPrefix(const std::string& prefix) { AddParam("prefix", prefix); }
  88. /// \brief 设置定界符,如果有 Prefix,则将 Prefix 到 delimiter
  89. /// 之间的相同路径归为一类,
  90. /// 定义为 Common Prefix,然后列出所有 Common Prefix。如果没有
  91. /// Prefix,则从路径起点开始
  92. void SetDelimiter(const std::string& delimiter) {
  93. AddParam("delimiter", delimiter);
  94. }
  95. /// \brief 规定返回值的编码方式,可选值:url
  96. void SetEncodingType(const std::string& encoding_type) {
  97. AddParam("encoding-type", encoding_type);
  98. }
  99. /// \brief 默认以 UTF-8 二进制顺序列出条目,所有列出条目从marker开始
  100. void SetMarker(const std::string& marker) { AddParam("marker", marker); }
  101. /// \brief 单次返回最大的条目数量,默认1000
  102. void SetMaxKeys(uint64_t max_keys) {
  103. AddParam("max-keys", StringUtil::Uint64ToString(max_keys));
  104. }
  105. };
  106. class ListMultipartUploadReq : public BucketReq {
  107. public:
  108. explicit ListMultipartUploadReq(const std::string& bucket_name)
  109. : BucketReq(bucket_name) {
  110. SetMethod("GET");
  111. SetPath("/");
  112. AddParam("uploads", "");
  113. }
  114. virtual ~ListMultipartUploadReq() {}
  115. void SetPrefix(const std::string& prefix) { AddParam("prefix", prefix); }
  116. void SetDelimiter(const std::string& delimiter) {
  117. AddParam("delimiter", delimiter);
  118. }
  119. void SetEncodingType(const std::string& encoding_type) {
  120. AddParam("encoding-type", encoding_type);
  121. }
  122. void SetKeyMarker(const std::string& marker) {
  123. AddParam("key-marker", marker);
  124. }
  125. void SetMaxUploads(const std::string& max_uploads) {
  126. AddParam("max-uploads", max_uploads);
  127. }
  128. void SetUploadIdMarker(const std::string& upload_id_marker) {
  129. AddParam("upload-id-marker", upload_id_marker);
  130. }
  131. };
  132. class DeleteBucketReq : public BucketReq {
  133. public:
  134. explicit DeleteBucketReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  135. SetMethod("DELETE");
  136. }
  137. ~DeleteBucketReq() {}
  138. };
  139. class GetBucketVersioningReq : public BucketReq {
  140. public:
  141. explicit GetBucketVersioningReq(const std::string& bucket_name)
  142. : BucketReq(bucket_name) {
  143. SetMethod("GET");
  144. SetPath("/");
  145. AddParam("versioning", "");
  146. }
  147. virtual ~GetBucketVersioningReq() {}
  148. };
  149. class PutBucketVersioningReq : public BucketReq {
  150. public:
  151. explicit PutBucketVersioningReq(const std::string& bucket_name)
  152. : BucketReq(bucket_name), m_status(true) {
  153. SetMethod("PUT");
  154. SetPath("/");
  155. AddParam("versioning", "");
  156. }
  157. virtual ~PutBucketVersioningReq() {}
  158. /// \brief 版本是否开启
  159. void SetStatus(bool is_enable) { m_status = is_enable; }
  160. bool GetStatus() const { return m_status; }
  161. bool GenerateRequestBody(std::string* body) const;
  162. private:
  163. bool m_status;
  164. };
  165. class GetBucketReplicationReq : public BucketReq {
  166. public:
  167. explicit GetBucketReplicationReq(const std::string& bucket_name)
  168. : BucketReq(bucket_name) {
  169. SetMethod("GET");
  170. SetPath("/");
  171. AddParam("replication", "");
  172. }
  173. virtual ~GetBucketReplicationReq() {}
  174. };
  175. class PutBucketReplicationReq : public BucketReq {
  176. public:
  177. explicit PutBucketReplicationReq(const std::string& bucket_name)
  178. : BucketReq(bucket_name) {
  179. SetMethod("PUT");
  180. SetPath("/");
  181. AddParam("replication", "");
  182. }
  183. virtual ~PutBucketReplicationReq() {}
  184. void SetRole(const std::string& role) { m_role = role; }
  185. void AddReplicationRule(const ReplicationRule& rule) {
  186. m_rules.push_back(rule);
  187. }
  188. void SetReplicationRule(const std::vector<ReplicationRule>& rules) {
  189. m_rules = rules;
  190. }
  191. bool GenerateRequestBody(std::string* body) const;
  192. private:
  193. std::string m_role;
  194. std::vector<ReplicationRule> m_rules;
  195. };
  196. class DeleteBucketReplicationReq : public BucketReq {
  197. public:
  198. explicit DeleteBucketReplicationReq(const std::string& bucket_name)
  199. : BucketReq(bucket_name) {
  200. SetMethod("Delete");
  201. SetPath("/");
  202. AddParam("replication", "");
  203. }
  204. virtual ~DeleteBucketReplicationReq() {}
  205. };
  206. class GetBucketLifecycleReq : public BucketReq {
  207. public:
  208. explicit GetBucketLifecycleReq(const std::string& bucket_name)
  209. : BucketReq(bucket_name) {
  210. SetMethod("GET");
  211. SetPath("/");
  212. AddParam("lifecycle", "");
  213. }
  214. virtual ~GetBucketLifecycleReq() {}
  215. };
  216. class PutBucketLifecycleReq : public BucketReq {
  217. public:
  218. explicit PutBucketLifecycleReq(const std::string& bucket_name)
  219. : BucketReq(bucket_name) {
  220. SetMethod("PUT");
  221. SetPath("/");
  222. AddParam("lifecycle", "");
  223. }
  224. virtual ~PutBucketLifecycleReq() {}
  225. void AddRule(const LifecycleRule& rule) { m_rules.push_back(rule); }
  226. void SetRule(const std::vector<LifecycleRule>& rules) { m_rules = rules; }
  227. bool GenerateRequestBody(std::string* body) const;
  228. private:
  229. std::vector<LifecycleRule> m_rules;
  230. };
  231. class DeleteBucketLifecycleReq : public BucketReq {
  232. public:
  233. explicit DeleteBucketLifecycleReq(const std::string& bucket_name)
  234. : BucketReq(bucket_name) {
  235. SetMethod("DELETE");
  236. SetPath("/");
  237. AddParam("lifecycle", "");
  238. }
  239. virtual ~DeleteBucketLifecycleReq() {}
  240. };
  241. class GetBucketACLReq : public BucketReq {
  242. public:
  243. explicit GetBucketACLReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  244. SetMethod("GET");
  245. SetPath("/");
  246. AddParam("acl", "");
  247. }
  248. virtual ~GetBucketACLReq() {}
  249. };
  250. class PutBucketACLReq : public BucketReq {
  251. public:
  252. explicit PutBucketACLReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  253. SetMethod("PUT");
  254. SetPath("/");
  255. AddParam("acl", "");
  256. }
  257. virtual ~PutBucketACLReq() {}
  258. /// 定义Bucket的ACL属性,有效值:private,public-read-write,public-read
  259. /// 默认值:private
  260. void SetXCosAcl(const std::string& str) { AddHeader("x-cos-acl", str); }
  261. /// 赋予被授权者读的权限.格式:x-cos-grant-read: id=" ",id=" ".
  262. /// 当需要给子账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>"
  263. /// 当需要给根账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>"
  264. void SetXCosGrantRead(const std::string& str) {
  265. AddHeader("x-cos-grant-read", str);
  266. }
  267. /// 赋予被授权者写的权限,格式:x-cos-grant-write: id=" ",id=" "./
  268. /// 当需要给子账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>",
  269. /// 当需要给根账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>"
  270. void SetXCosGrantWrite(const std::string& str) {
  271. AddHeader("x-cos-grant-write", str);
  272. }
  273. /// 赋予被授权者读写权限.格式:x-cos-grant-full-control: id=" ",id=" ".
  274. /// 当需要给子账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>",
  275. /// 当需要给根账户授权时,id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>"
  276. void SetXCosGrantFullControl(const std::string& str) {
  277. AddHeader("x-cos-grant-full-control", str);
  278. }
  279. /// Bucket 持有者 ID
  280. void SetOwner(const Owner& owner) { m_owner = owner; }
  281. /// 设置被授权者信息与权限信息
  282. void SetAccessControlList(const std::vector<Grant>& grants) {
  283. m_acl = grants;
  284. }
  285. /// 添加单个 Bucket 的授权信息
  286. void AddAccessControlList(const Grant& grant) { m_acl.push_back(grant); }
  287. /// 清空权限信息
  288. void ClearAccessControlList() {
  289. std::vector<Grant> tmp;
  290. m_acl.swap(tmp);
  291. }
  292. bool GenerateRequestBody(std::string* body) const;
  293. private:
  294. Owner m_owner;
  295. std::vector<Grant> m_acl;
  296. };
  297. class GetBucketPolicyReq : public BucketReq {
  298. public:
  299. explicit GetBucketPolicyReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  300. SetMethod("GET");
  301. SetPath("/");
  302. AddParam("policy", "");
  303. }
  304. virtual ~GetBucketPolicyReq() {}
  305. };
  306. class PutBucketPolicyReq : public BucketReq {
  307. public:
  308. explicit PutBucketPolicyReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  309. SetMethod("PUT");
  310. SetPath("/");
  311. AddParam("policy", "");
  312. }
  313. virtual ~PutBucketPolicyReq() {}
  314. };
  315. class DeleteBucketPolicyReq : public BucketReq {
  316. public:
  317. explicit DeleteBucketPolicyReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  318. SetMethod("DELETE");
  319. SetPath("/");
  320. AddParam("policy", "");
  321. }
  322. virtual ~DeleteBucketPolicyReq() {}
  323. };
  324. class DeleteBucketACLReq : public BucketReq {
  325. public:
  326. explicit DeleteBucketACLReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  327. SetMethod("DELETE");
  328. }
  329. virtual ~DeleteBucketACLReq() {}
  330. };
  331. class GetBucketCORSReq : public BucketReq {
  332. public:
  333. explicit GetBucketCORSReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  334. SetMethod("GET");
  335. SetPath("/");
  336. AddParam("cors", "");
  337. }
  338. virtual ~GetBucketCORSReq() {}
  339. };
  340. class PutBucketCORSReq : public BucketReq {
  341. public:
  342. explicit PutBucketCORSReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  343. SetMethod("PUT");
  344. SetPath("/");
  345. AddParam("cors", "");
  346. AddHeader("Content-Type", "application/xml");
  347. }
  348. virtual ~PutBucketCORSReq() {}
  349. bool GenerateRequestBody(std::string* body) const;
  350. void AddRule(const CORSRule& rule) { m_rules.push_back(rule); }
  351. void SetRules(const std::vector<CORSRule>& rules) { m_rules = rules; }
  352. private:
  353. std::vector<CORSRule> m_rules;
  354. };
  355. class DeleteBucketCORSReq : public BucketReq {
  356. public:
  357. explicit DeleteBucketCORSReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  358. SetMethod("DELETE");
  359. SetPath("/");
  360. AddParam("cors", "");
  361. }
  362. virtual ~DeleteBucketCORSReq() {}
  363. };
  364. class GetBucketLocationReq : public BucketReq {
  365. public:
  366. explicit GetBucketLocationReq(const std::string& bucket_name)
  367. : BucketReq(bucket_name) {
  368. SetMethod("GET");
  369. SetPath("/");
  370. AddParam("location", "");
  371. }
  372. virtual ~GetBucketLocationReq() {}
  373. };
  374. class GetBucketObjectVersionsReq : public BucketReq {
  375. public:
  376. explicit GetBucketObjectVersionsReq(const std::string& bucket_name)
  377. : BucketReq(bucket_name) {
  378. SetMethod("GET");
  379. SetPath("/");
  380. AddParam("versions", "");
  381. }
  382. virtual ~GetBucketObjectVersionsReq() {}
  383. /// \@brief 设置前缀,用来规定返回的文件前缀地址
  384. void SetPrefix(const std::string& prefix) { AddParam("prefix", prefix); }
  385. /// \brief 设置定界符,如果有 Prefix,则将 Prefix 到 delimiter
  386. /// 之间的相同路径归为一类,
  387. /// 定义为 Common Prefix,然后列出所有 Common Prefix。如果没有
  388. /// Prefix,则从路径起点开始
  389. void SetDelimiter(const std::string& delimiter) {
  390. AddParam("delimiter", delimiter);
  391. }
  392. /// \brief 规定返回值的编码方式,可选值:url
  393. void SetEncodingType(const std::string& encoding_type) {
  394. AddParam("encoding-type", encoding_type);
  395. }
  396. /// \brief 默认以 UTF-8 二进制顺序列出条目,所有列出条目从marker开始
  397. void SetKeyMarker(const std::string& marker) {
  398. AddParam("key-marker", marker);
  399. }
  400. /// \brief 单次返回最大的条目数量,默认1000
  401. void SetMaxKeys(uint64_t max_keys) {
  402. AddParam("max-keys", StringUtil::Uint64ToString(max_keys));
  403. }
  404. void SetVersionIdMarker(const std::string& version_id_marker) {
  405. AddParam("version-id-marker", version_id_marker);
  406. }
  407. };
  408. class PutBucketLoggingReq : public BucketReq {
  409. public:
  410. explicit PutBucketLoggingReq(const std::string& bucket_name)
  411. : BucketReq(bucket_name), m_mask(0x00000000u) {
  412. SetMethod("PUT");
  413. SetPath("/");
  414. AddParam("logging", "");
  415. }
  416. virtual ~PutBucketLoggingReq() {}
  417. void SetLoggingEnabled(const LoggingEnabled& rules) {
  418. m_mask = m_mask | 0x00000001u;
  419. m_rules = rules;
  420. }
  421. bool HasLoggingEnabled() const { return (m_mask & 0x00000001u) != 0; }
  422. bool GenerateRequestBody(std::string* body) const;
  423. private:
  424. uint64_t m_mask;
  425. LoggingEnabled m_rules;
  426. };
  427. class GetBucketLoggingReq : public BucketReq {
  428. public:
  429. explicit GetBucketLoggingReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  430. SetMethod("GET");
  431. SetPath("/");
  432. AddParam("logging", "");
  433. }
  434. virtual ~GetBucketLoggingReq() {}
  435. };
  436. class PutBucketDomainReq : public BucketReq {
  437. public:
  438. explicit PutBucketDomainReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  439. SetMethod("PUT");
  440. SetPath("/");
  441. AddParam("domain", "");
  442. }
  443. virtual ~PutBucketDomainReq() {}
  444. void SetDomainRule(const DomainRule& rules) { m_rules = rules; }
  445. bool GenerateRequestBody(std::string* body) const;
  446. private:
  447. DomainRule m_rules;
  448. };
  449. class GetBucketDomainReq : public BucketReq {
  450. public:
  451. explicit GetBucketDomainReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  452. SetMethod("GET");
  453. SetPath("/");
  454. AddParam("domain", "");
  455. }
  456. virtual ~GetBucketDomainReq() {}
  457. };
  458. class PutBucketWebsiteReq : public BucketReq {
  459. public:
  460. explicit PutBucketWebsiteReq(const std::string& bucket_name)
  461. : BucketReq(bucket_name),
  462. m_mask(0x00000000u),
  463. m_suffix(""),
  464. m_protocol(""),
  465. m_key("") {
  466. SetMethod("PUT");
  467. SetPath("/");
  468. AddParam("website", "");
  469. }
  470. virtual ~PutBucketWebsiteReq() {}
  471. void SetSuffix(const std::string& suffix) {
  472. m_mask = m_mask | 0x00000001u;
  473. m_suffix = suffix;
  474. }
  475. void SetProtocol(const std::string& protocol) {
  476. m_mask = m_mask | 0x00000002u;
  477. m_protocol = protocol;
  478. }
  479. void SetKey(const std::string& key) {
  480. m_mask = m_mask | 0x00000004u;
  481. m_key = key;
  482. }
  483. std::string GetSuffix() const { return m_suffix; }
  484. std::string GetProtocol() const { return m_protocol; }
  485. std::string GetKey() const { return m_key; }
  486. bool HasSuffix() const { return (m_mask & 0x00000001u) != 0; }
  487. bool HasProtocol() const { return (m_mask & 0x00000002u) != 0; }
  488. bool HasKey() const { return (m_mask & 0x00000004u) != 0; }
  489. bool HasRoutingRules() const { return !m_routingrules.empty(); }
  490. /// 设置重定向规则
  491. void SetRoutingRules(const std::vector<RoutingRule>& routingrules) {
  492. m_routingrules = routingrules;
  493. }
  494. /// 添加单个rule
  495. void AddRoutingRule(const RoutingRule& routingrule) {
  496. m_routingrules.push_back(routingrule);
  497. }
  498. /// 清空重定向规则
  499. void ClearRoutingRules() {
  500. std::vector<RoutingRule> tmp;
  501. m_routingrules.swap(tmp);
  502. }
  503. bool GenerateRequestBody(std::string* body) const;
  504. private:
  505. uint64_t m_mask;
  506. std::string m_suffix;
  507. std::string m_protocol;
  508. std::string m_key;
  509. std::vector<RoutingRule> m_routingrules;
  510. };
  511. class GetBucketWebsiteReq : public BucketReq {
  512. public:
  513. explicit GetBucketWebsiteReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  514. SetMethod("Get");
  515. SetPath("/");
  516. AddParam("website", "");
  517. }
  518. virtual ~GetBucketWebsiteReq() {}
  519. };
  520. class DeleteBucketWebsiteReq : public BucketReq {
  521. public:
  522. explicit DeleteBucketWebsiteReq(const std::string& bucket_name)
  523. : BucketReq(bucket_name) {
  524. SetMethod("DELETE");
  525. SetPath("/");
  526. AddParam("website", "");
  527. }
  528. virtual ~DeleteBucketWebsiteReq() {}
  529. };
  530. class PutBucketTaggingReq : public BucketReq {
  531. public:
  532. explicit PutBucketTaggingReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  533. SetMethod("PUT");
  534. SetPath("/");
  535. AddParam("tagging", "");
  536. }
  537. void SetTagSet(std::vector<Tag>& tagset) { m_tagset = tagset; }
  538. std::vector<Tag> GetTagSet() { return m_tagset; }
  539. //清除tag规则.
  540. void ClearTagSet() {
  541. std::vector<Tag> temp;
  542. m_tagset.swap(temp);
  543. }
  544. /// 添加单个tag.
  545. void AddTag(const Tag& tag) { m_tagset.push_back(tag); }
  546. bool GenerateRequestBody(std::string* body) const;
  547. virtual ~PutBucketTaggingReq() {}
  548. private:
  549. std::vector<Tag> m_tagset;
  550. };
  551. class GetBucketTaggingReq : public BucketReq {
  552. public:
  553. explicit GetBucketTaggingReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  554. SetMethod("GET");
  555. SetPath("/");
  556. AddParam("tagging", "");
  557. }
  558. virtual ~GetBucketTaggingReq() {}
  559. };
  560. class DeleteBucketTaggingReq : public BucketReq {
  561. public:
  562. explicit DeleteBucketTaggingReq(const std::string& bucket_name)
  563. : BucketReq(bucket_name) {
  564. SetMethod("DELETE");
  565. SetPath("/");
  566. AddParam("tagging", "");
  567. }
  568. virtual ~DeleteBucketTaggingReq() {}
  569. };
  570. class PutBucketInventoryReq : public BucketReq {
  571. public:
  572. explicit PutBucketInventoryReq(const std::string& bucket_name)
  573. : BucketReq(bucket_name), m_mask(0x00000000u) {
  574. SetMethod("PUT");
  575. SetPath("/");
  576. AddParam("inventory", "");
  577. }
  578. void SetInventory(Inventory& inventory) {
  579. m_mask = m_mask | 0x00000001u;
  580. m_inventory = inventory;
  581. }
  582. bool HasInventory() const { return (m_mask & 0x00000001u) != 0; }
  583. const Inventory& GetInventory() const { return m_inventory; }
  584. void SetId(const std::string id) {
  585. m_mask = m_mask | 0x00000001u;
  586. m_id = id;
  587. AddParam("id", m_id);
  588. }
  589. std::string GetId() const { return m_id; }
  590. bool HasId() const { return (m_mask & 0x00000001u) != 0; }
  591. bool GenerateRequestBody(std::string* body) const;
  592. virtual ~PutBucketInventoryReq() {}
  593. private:
  594. uint64_t m_mask;
  595. std::string m_id;
  596. Inventory m_inventory;
  597. };
  598. class GetBucketInventoryReq : public BucketReq {
  599. public:
  600. explicit GetBucketInventoryReq(const std::string& bucket_name)
  601. : BucketReq(bucket_name), m_mask(0x00000000u) {
  602. SetMethod("GET");
  603. SetPath("/");
  604. AddParam("inventory", "");
  605. }
  606. void SetId(const std::string id) {
  607. m_mask = m_mask | 0x00000001u;
  608. m_id = id;
  609. AddParam("id", m_id);
  610. }
  611. std::string GetId() const { return m_id; }
  612. bool HasId() const { return (m_mask & 0x00000001u) != 0; }
  613. virtual ~GetBucketInventoryReq() {}
  614. private:
  615. uint64_t m_mask;
  616. std::string m_id;
  617. };
  618. class ListBucketInventoryConfigurationsReq : public BucketReq {
  619. public:
  620. explicit ListBucketInventoryConfigurationsReq(const std::string& bucket_name)
  621. : BucketReq(bucket_name), m_mask(0x00000000u) {
  622. SetMethod("GET");
  623. SetPath("/");
  624. AddParam("inventory", "");
  625. }
  626. void SetContinuationToken(const std::string continuation_token) {
  627. m_mask = m_mask | 0x00000001u;
  628. m_continuation_token = continuation_token;
  629. AddParam("continuation-token", m_continuation_token);
  630. }
  631. std::string GetContinuationToken() const { return m_continuation_token; }
  632. bool HasContinuationToken() const { return (m_mask & 0x00000001u) != 0; }
  633. virtual ~ListBucketInventoryConfigurationsReq() {}
  634. private:
  635. uint64_t m_mask;
  636. std::string m_continuation_token;
  637. };
  638. class DeleteBucketInventoryReq : public BucketReq {
  639. public:
  640. explicit DeleteBucketInventoryReq(const std::string& bucket_name)
  641. : BucketReq(bucket_name), m_mask(0x00000000u), m_id("") {
  642. SetMethod("DELETE");
  643. SetPath("/");
  644. AddParam("inventory", "");
  645. }
  646. void SetId(const std::string id) {
  647. m_mask = m_mask | 0x00000001u;
  648. m_id = id;
  649. AddParam("id", m_id);
  650. }
  651. std::string GetId() const { return m_id; }
  652. bool HasId() const { return (m_mask & 0x00000001u) != 0; }
  653. virtual ~DeleteBucketInventoryReq() {}
  654. private:
  655. uint64_t m_mask;
  656. std::string m_id;
  657. };
  658. /// \brief: 列举直播通道请求
  659. class ListLiveChannelReq : public BucketReq {
  660. public:
  661. explicit ListLiveChannelReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  662. SetMethod("GET");
  663. SetPath("/");
  664. AddParam("live", "");
  665. }
  666. void SetMaxKeys(uint32_t max_keys) {
  667. AddParam("max-keys", StringUtil::IntToString(max_keys));
  668. }
  669. void SetMarker(const std::string& marker) { AddParam("marker", marker); }
  670. void SetPrefix(const std::string& prefix) { AddParam("prefix", prefix); }
  671. virtual ~ListLiveChannelReq() {}
  672. };
  673. /// \brief: 配置存储桶智能分层特性
  674. class PutBucketIntelligentTieringReq : public BucketReq {
  675. public:
  676. explicit PutBucketIntelligentTieringReq(const std::string& bucket_name)
  677. : BucketReq(bucket_name), m_status(false), m_days(30) {
  678. SetMethod("PUT");
  679. SetPath("/");
  680. AddParam("intelligenttiering", "");
  681. }
  682. virtual ~PutBucketIntelligentTieringReq() {}
  683. /// \brief 设置智能分层的状态,true表示Enabled,false表示Suspended
  684. void SetStatus(bool is_enable) { m_status = is_enable; }
  685. /// \brief
  686. /// 指定智能分层存储配置中标准层数据转换为低频层数据的天数限制,默认值为30天
  687. void SetDays(uint32_t days) { m_days = days; }
  688. bool GenerateRequestBody(std::string* body) const;
  689. private:
  690. bool m_status;
  691. uint32_t m_days;
  692. };
  693. /// \brief: 获取存储桶智能分层配置
  694. class GetBucketIntelligentTieringReq : public BucketReq {
  695. public:
  696. explicit GetBucketIntelligentTieringReq(const std::string& bucket_name)
  697. : BucketReq(bucket_name) {
  698. SetMethod("GET");
  699. SetPath("/");
  700. AddParam("intelligenttiering", "");
  701. }
  702. virtual ~GetBucketIntelligentTieringReq() {}
  703. };
  704. class PutBucketRefererReq : public BucketReq {
  705. public:
  706. explicit PutBucketRefererReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  707. SetMethod("PUT");
  708. SetPath("/");
  709. AddParam("referer", "");
  710. }
  711. /// \brief 是否开启防盗链,枚举值:Enabled、Disabled
  712. void SetStatus(const std::string& status) { m_status = status; }
  713. /// \brief 防盗链类型,枚举值:Black-List、White-List
  714. void SetRefererType(const std::string& referer_type) {
  715. m_referer_type = referer_type;
  716. }
  717. /// \brief 生效域名列表, 支持多个域名且为前缀匹配, 支持带端口的域名和 IP,
  718. /// 支持通配符*,做二级域名或多级域名的通配
  719. void AddDomain(const std::string& domain) { m_domain_list.push_back(domain); }
  720. /// \brief 是否允许空 Referer 访问,枚举值:Allow、Deny,默认值为 Deny
  721. void SetEmptyReferConfig(const std::string& empty_refer_conf) {
  722. m_empty_refer_conf = empty_refer_conf;
  723. }
  724. bool GenerateRequestBody(std::string* body) const;
  725. virtual ~PutBucketRefererReq() {}
  726. private:
  727. std::string m_status;
  728. std::string m_referer_type;
  729. std::vector<std::string> m_domain_list;
  730. std::string m_empty_refer_conf;
  731. };
  732. class GetBucketRefererReq : public BucketReq {
  733. public:
  734. explicit GetBucketRefererReq(const std::string& bucket_name) : BucketReq(bucket_name) {
  735. SetMethod("GET");
  736. SetPath("/");
  737. AddParam("referer", "");
  738. }
  739. virtual ~GetBucketRefererReq() {}
  740. };
  741. } // namespace qcloud_cos
  742. #endif // BUCKET_REQ_H