AccessControlPolicy.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Xml.Serialization;
  4. using System.Text;
  5. namespace COSXML.Model.Tag
  6. {
  7. /// <summary>
  8. /// ACL权限
  9. /// <see href="https://cloud.tencent.com/document/product/436/7733"/>
  10. /// </summary>
  11. [XmlRoot]
  12. public sealed class AccessControlPolicy
  13. {
  14. /// <summary>
  15. /// Bucket 持有者信息
  16. /// <see href="Owner"/>
  17. /// </summary>
  18. [XmlElement("Owner")]
  19. public Owner owner;
  20. /// <summary>
  21. /// 被授权者信息与权限信息
  22. /// <see href="AccessControlList"/>
  23. /// </summary>
  24. [XmlElement("AccessControlList")]
  25. public AccessControlList accessControlList;
  26. public string GetInfo()
  27. {
  28. StringBuilder stringBuilder = new StringBuilder("{AccessControlPolicy:\n");
  29. if (owner != null)
  30. {
  31. stringBuilder.Append(owner.GetInfo()).Append("\n");
  32. }
  33. if (accessControlList != null)
  34. {
  35. stringBuilder.Append(accessControlList.GetInfo()).Append("\n");
  36. }
  37. stringBuilder.Append("}");
  38. return stringBuilder.ToString();
  39. }
  40. public sealed class Owner
  41. {
  42. /// <summary>
  43. /// Bucket 持有者 ID
  44. /// 格式:qcs::cam::uin/&lt;OwnerUin&gt;:uin/&lt;SubUin&gt; 如果是根帐号,&lt;OwnerUin&gt; 和 &lt;SubUin&gt; 是同一个值
  45. /// </summary>
  46. [XmlElement("ID")]
  47. public string id;
  48. /// <summary>
  49. /// Bucket 持有者
  50. /// </summary>
  51. [XmlElement("DisplayName")]
  52. public string displayName;
  53. public string GetInfo()
  54. {
  55. StringBuilder stringBuilder = new StringBuilder("{Owner:\n");
  56. stringBuilder.Append("Id:").Append(id).Append("\n");
  57. stringBuilder.Append("}");
  58. return stringBuilder.ToString();
  59. }
  60. }
  61. public sealed class AccessControlList
  62. {
  63. /// <summary>
  64. /// 单个 Bucket 的授权信息。一个 AccessControlList 可以拥有 100 条 Grant
  65. /// <see href="Grant"/>
  66. /// </summary>
  67. [XmlElement("Grant")]
  68. public List<Grant> grants;
  69. public string GetInfo()
  70. {
  71. StringBuilder stringBuilder = new StringBuilder("{AccessControlList:\n");
  72. if (grants != null)
  73. {
  74. foreach (Grant grant in grants)
  75. {
  76. if (grant != null)
  77. {
  78. stringBuilder.Append(grant.GetInfo()).Append("\n");
  79. }
  80. }
  81. }
  82. stringBuilder.Append("}");
  83. return stringBuilder.ToString();
  84. }
  85. }
  86. public sealed class Grant
  87. {
  88. /// <summary>
  89. /// 说明被授权者的信息,
  90. /// <see href="Grantee"/>
  91. /// </summary>
  92. [XmlElement("Grantee")]
  93. public Grantee grantee;
  94. /// <summary>
  95. /// 指明授予被授权者的权限信息
  96. /// <see href="COSXML.Common.CosGrantPermission"/>
  97. /// </summary>
  98. [XmlElement("Permission")]
  99. public string permission;
  100. public string GetInfo()
  101. {
  102. StringBuilder stringBuilder = new StringBuilder("{Grant:\n");
  103. if (grantee != null)
  104. {
  105. stringBuilder.Append(grantee.GetInfo()).Append("\n");
  106. }
  107. stringBuilder.Append("Permission:").Append(permission).Append("\n");
  108. stringBuilder.Append("}");
  109. return stringBuilder.ToString();
  110. }
  111. }
  112. public sealed class Grantee
  113. {
  114. /// <summary>
  115. /// 用户的 ID,如果是根帐号,格式为:qcs::cam::uin/&lt;OwnerUin&gt;:uin/&lt;OwnerUin&gt;
  116. /// 如果是子帐号,格式为: qcs::cam::uin/&lt;OwnerUin&gt;:uin/&lt;SubUin&gt;
  117. /// </summary>
  118. [XmlElement("ID")]
  119. public string id;
  120. /// <summary>
  121. /// 或 http://cam.qcloud.com/groups/global/AllUsers (指代所有用户).
  122. /// </summary>
  123. [XmlElement("URI")]
  124. public string uri;
  125. /// <summary>
  126. /// 或 qcs::cam::anyone:anyone (指代所有用户).
  127. /// </summary>
  128. [XmlElement("DisplayName")]
  129. public string displayName;
  130. public string GetInfo()
  131. {
  132. StringBuilder stringBuilder = new StringBuilder("{Grantee:\n");
  133. if (uri != null)
  134. {
  135. stringBuilder.Append("URI:").Append(uri).Append("\n");
  136. }
  137. if (id != null)
  138. {
  139. stringBuilder.Append("Id:").Append(id).Append("\n");
  140. }
  141. stringBuilder.Append("}");
  142. return stringBuilder.ToString();
  143. }
  144. }
  145. }
  146. }