bucket_req.h 24 KB

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