retention.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. package s3
  2. import (
  3. "github.com/ks3sdklib/aws-sdk-go/aws"
  4. "time"
  5. )
  6. // PutBucketRetentionRequest generates a request for the PutBucketRetention operation.
  7. func (c *S3) PutBucketRetentionRequest(input *PutBucketRetentionInput) (req *aws.Request, output *PutBucketRetentionOutput) {
  8. op := &aws.Operation{
  9. Name: "PutBucketRetention",
  10. HTTPMethod: "PUT",
  11. HTTPPath: "/{Bucket}?retention",
  12. }
  13. if input == nil {
  14. input = &PutBucketRetentionInput{}
  15. }
  16. input.AutoFillMD5 = true
  17. req = c.newRequest(op, input, output)
  18. output = &PutBucketRetentionOutput{}
  19. req.Data = output
  20. return
  21. }
  22. // PutBucketRetention sets the retention configuration on a bucket.
  23. func (c *S3) PutBucketRetention(input *PutBucketRetentionInput) (*PutBucketRetentionOutput, error) {
  24. req, out := c.PutBucketRetentionRequest(input)
  25. err := req.Send()
  26. return out, err
  27. }
  28. func (c *S3) PutBucketRetentionWithContext(ctx aws.Context, input *PutBucketRetentionInput) (*PutBucketRetentionOutput, error) {
  29. req, out := c.PutBucketRetentionRequest(input)
  30. req.SetContext(ctx)
  31. err := req.Send()
  32. return out, err
  33. }
  34. type PutBucketRetentionInput struct {
  35. Bucket *string `location:"uri" locationName:"Bucket" type:"string" required:"true"`
  36. RetentionConfiguration *BucketRetentionConfiguration `locationName:"RetentionConfiguration" type:"structure"`
  37. ContentType *string `location:"header" locationName:"Content-Type" type:"string"`
  38. // Set extend request headers. If the existing fields do not support setting the request header you need, you can set it through this field.
  39. ExtendHeaders map[string]*string `location:"extendHeaders" type:"map"`
  40. // Set extend query params. If the existing fields do not support setting the query param you need, you can set it through this field.
  41. ExtendQueryParams map[string]*string `location:"extendQueryParams" type:"map"`
  42. metadataPutBucketRetentionInput `json:"-" xml:"-"`
  43. }
  44. type metadataPutBucketRetentionInput struct {
  45. SDKShapeTraits bool `type:"structure" payload:"RetentionConfiguration"`
  46. AutoFillMD5 bool
  47. }
  48. type BucketRetentionConfiguration struct {
  49. // Whether to enable multiple versions in the recycle bin. When the request does not carry this parameter,
  50. // multiple versions are enabled by default.
  51. EnableMultipleVersion *bool `locationName:"EnableMultipleVersion" type:"boolean"`
  52. // A container that contains a specific rule for the recycle bin.
  53. Rule *RetentionRule `locationName:"Rule" type:"structure" required:"true"`
  54. }
  55. type RetentionRule struct {
  56. // The open status of the recycle bin is not case-sensitive.
  57. // Valid values: Enabled, Disabled. Enabled indicates enabling the recycle bin, Disabled indicates disabling the recycle bin.
  58. Status *string `locationName:"Status" type:"string" required:"true"`
  59. // Specify how many days after the object enters the recycle bin to be completely deleted.
  60. // When Days is not set, the object will be permanently retained in the recycle bin after deletion.
  61. // Value range: 1-365
  62. Days *int64 `locationName:"Days" type:"integer"`
  63. }
  64. type PutBucketRetentionOutput struct {
  65. Metadata map[string]*string `location:"headers" type:"map"`
  66. StatusCode *int64 `location:"statusCode" type:"integer"`
  67. }
  68. // GetBucketRetentionRequest generates a request for the GetBucketRetention operation.
  69. func (c *S3) GetBucketRetentionRequest(input *GetBucketRetentionInput) (req *aws.Request, output *GetBucketRetentionOutput) {
  70. op := &aws.Operation{
  71. Name: "GetBucketRetention",
  72. HTTPMethod: "GET",
  73. HTTPPath: "/{Bucket}?retention",
  74. }
  75. if input == nil {
  76. input = &GetBucketRetentionInput{}
  77. }
  78. req = c.newRequest(op, input, output)
  79. output = &GetBucketRetentionOutput{
  80. RetentionConfiguration: &BucketRetentionConfiguration{},
  81. }
  82. req.Data = output
  83. return
  84. }
  85. // GetBucketRetention gets the retention configuration for the bucket.
  86. func (c *S3) GetBucketRetention(input *GetBucketRetentionInput) (*GetBucketRetentionOutput, error) {
  87. req, out := c.GetBucketRetentionRequest(input)
  88. err := req.Send()
  89. return out, err
  90. }
  91. func (c *S3) GetBucketRetentionWithContext(ctx aws.Context, input *GetBucketRetentionInput) (*GetBucketRetentionOutput, error) {
  92. req, out := c.GetBucketRetentionRequest(input)
  93. req.SetContext(ctx)
  94. err := req.Send()
  95. return out, err
  96. }
  97. type GetBucketRetentionInput struct {
  98. Bucket *string `location:"uri" locationName:"Bucket" type:"string" required:"true"`
  99. // Set extend request headers. If the existing fields do not support setting the request header you need, you can set it through this field.
  100. ExtendHeaders map[string]*string `location:"extendHeaders" type:"map"`
  101. // Set extend query params. If the existing fields do not support setting the query param you need, you can set it through this field.
  102. ExtendQueryParams map[string]*string `location:"extendQueryParams" type:"map"`
  103. }
  104. type GetBucketRetentionOutput struct {
  105. RetentionConfiguration *BucketRetentionConfiguration `locationName:"RetentionConfiguration" type:"structure"`
  106. Metadata map[string]*string `location:"headers" type:"map"`
  107. StatusCode *int64 `location:"statusCode" type:"integer"`
  108. metadataGetBucketRetentionInput `json:"-" xml:"-"`
  109. }
  110. type metadataGetBucketRetentionInput struct {
  111. SDKShapeTraits bool `type:"structure" payload:"RetentionConfiguration"`
  112. }
  113. // ListRetentionRequest generates a request for the ListRetention operation.
  114. func (c *S3) ListRetentionRequest(input *ListRetentionInput) (req *aws.Request, output *ListRetentionOutput) {
  115. op := &aws.Operation{
  116. Name: "ListRetention",
  117. HTTPMethod: "GET",
  118. HTTPPath: "/{Bucket}?recycle",
  119. }
  120. if input == nil {
  121. input = &ListRetentionInput{}
  122. }
  123. req = c.newRequest(op, input, output)
  124. output = &ListRetentionOutput{}
  125. req.Data = output
  126. return
  127. }
  128. // ListRetention lists the objects in the recycle bin.
  129. func (c *S3) ListRetention(input *ListRetentionInput) (*ListRetentionOutput, error) {
  130. req, out := c.ListRetentionRequest(input)
  131. err := req.Send()
  132. return out, err
  133. }
  134. func (c *S3) ListRetentionWithContext(ctx aws.Context, input *ListRetentionInput) (*ListRetentionOutput, error) {
  135. req, out := c.ListRetentionRequest(input)
  136. req.SetContext(ctx)
  137. err := req.Send()
  138. return out, err
  139. }
  140. type ListRetentionInput struct {
  141. // The name of the bucket.
  142. Bucket *string `location:"uri" locationName:"Bucket" type:"string" required:"true"`
  143. // Specifies the key to start with when listing objects in a bucket.
  144. Marker *string `location:"querystring" locationName:"marker" type:"string"`
  145. // Sets the maximum number of keys returned in the response. The response might
  146. // contain fewer keys but will never contain more.
  147. MaxKeys *int64 `location:"querystring" locationName:"max-keys" type:"integer"`
  148. // Limits the response to keys that begin with the specified prefix.
  149. Prefix *string `location:"querystring" locationName:"prefix" type:"string"`
  150. // Set extend request headers. If the existing fields do not support setting the request header you need, you can set it through this field.
  151. ExtendHeaders map[string]*string `location:"extendHeaders" type:"map"`
  152. // Set extend query params. If the existing fields do not support setting the query param you need, you can set it through this field.
  153. ExtendQueryParams map[string]*string `location:"extendQueryParams" type:"map"`
  154. }
  155. type ListRetentionOutput struct {
  156. // A container that lists information about the list of objects in the recycle bin.
  157. ListRetentionResult *ListRetentionResult `locationName:"ListRetentionResult" type:"structure"`
  158. Metadata map[string]*string `location:"headers" type:"map"`
  159. StatusCode *int64 `location:"statusCode" type:"integer"`
  160. metadataListRetentionOutput `json:"-" xml:"-"`
  161. }
  162. type metadataListRetentionOutput struct {
  163. SDKShapeTraits bool `type:"structure" payload:"ListRetentionResult"`
  164. }
  165. type ListRetentionResult struct {
  166. // The name of the bucket.
  167. Name *string `type:"string"`
  168. // Specify the prefix of the Key when requesting this List.
  169. Prefix *string `type:"string"`
  170. // The maximum number of objects returned is 1000 by default.
  171. MaxKeys *int64 `type:"integer"`
  172. // Specify the starting position of the object in the target bucket.
  173. Marker *string `type:"string"`
  174. // The starting point for the next listed file. Users can use this value as a marker parameter
  175. // for the next List Retention.
  176. NextMarker *string `type:"string"`
  177. // Whether it has been truncated. If the number of records in the Object list exceeds the set
  178. // maximum value, it will be truncated.
  179. IsTruncated *bool `type:"boolean"`
  180. // The encoding method for Object names.
  181. EncodingType *string `type:"string"`
  182. // List of Objects Listed.
  183. Contents []*RetentionObject `type:"list" flattened:"true"`
  184. }
  185. type RetentionObject struct {
  186. // The key of the object.
  187. Key *string `type:"string"`
  188. // The size of the object is measured in bytes.
  189. Size *int64 `type:"integer"`
  190. // The entity label of an object, ETag, is generated when uploading an object to identify its content.
  191. ETag *string `type:"string"`
  192. // The last time the object was modified.
  193. LastModified *time.Time `type:"timestamp" timestampFormat:"iso8601"`
  194. // The owner information of this bucket.
  195. Owner *Owner `type:"structure"`
  196. // The class of storage used to store the object.
  197. StorageClass *string `type:"string"`
  198. // The version ID of the object.
  199. RetentionId *string `type:"string"`
  200. // The time when the object was moved to the recycle bin.
  201. RecycleTime *time.Time `type:"timestamp" timestampFormat:"iso8601"`
  202. // The time when an object is completely deleted from the recycle bin.
  203. EstimatedClearTime *time.Time `type:"timestamp" timestampFormat:"iso8601"`
  204. }
  205. // RecoverObjectRequest generates a request for the RecoverObject operation.
  206. func (c *S3) RecoverObjectRequest(input *RecoverObjectInput) (req *aws.Request, output *RecoverObjectOutput) {
  207. op := &aws.Operation{
  208. Name: "RecoverObject",
  209. HTTPMethod: "POST",
  210. HTTPPath: "/{Bucket}/{Key+}?recover",
  211. }
  212. if input == nil {
  213. input = &RecoverObjectInput{}
  214. }
  215. req = c.newRequest(op, input, output)
  216. output = &RecoverObjectOutput{}
  217. req.Data = output
  218. return
  219. }
  220. // RecoverObject recovers the object from the recycle bin.
  221. func (c *S3) RecoverObject(input *RecoverObjectInput) (*RecoverObjectOutput, error) {
  222. req, out := c.RecoverObjectRequest(input)
  223. err := req.Send()
  224. return out, err
  225. }
  226. func (c *S3) RecoverObjectWithContext(ctx aws.Context, input *RecoverObjectInput) (*RecoverObjectOutput, error) {
  227. req, out := c.RecoverObjectRequest(input)
  228. req.SetContext(ctx)
  229. err := req.Send()
  230. return out, err
  231. }
  232. type RecoverObjectInput struct {
  233. // The name of the bucket.
  234. Bucket *string `location:"uri" locationName:"Bucket" type:"string" required:"true"`
  235. // The key of the object.
  236. Key *string `location:"uri" locationName:"Key" type:"string" required:"true"`
  237. // Does it support overwriting when an object with the same name exists in the bucket after being
  238. // recovered from the recycle bin. When the value is true, it indicates overwriting, and the overwritten
  239. // objects in the bucket will enter the recycle bin.
  240. RetentionOverwrite *bool `location:"header" locationName:"x-kss-retention-overwrite" type:"boolean"`
  241. // Specify the deletion ID of the recovered object. When the request header is not included,
  242. // only the latest version is restored by default.
  243. RetentionId *string `location:"header" locationName:"x-kss-retention-id" type:"string"`
  244. // Set extend request headers. If the existing fields do not support setting the request header you need, you can set it through this field.
  245. ExtendHeaders map[string]*string `location:"extendHeaders" type:"map"`
  246. // Set extend query params. If the existing fields do not support setting the query param you need, you can set it through this field.
  247. ExtendQueryParams map[string]*string `location:"extendQueryParams" type:"map"`
  248. }
  249. type RecoverObjectOutput struct {
  250. Metadata map[string]*string `location:"headers" type:"map"`
  251. StatusCode *int64 `location:"statusCode" type:"integer"`
  252. }
  253. // ClearObjectRequest generates a request for the ClearObject operation.
  254. func (c *S3) ClearObjectRequest(input *ClearObjectInput) (req *aws.Request, output *ClearObjectOutput) {
  255. op := &aws.Operation{
  256. Name: "ClearObject",
  257. HTTPMethod: "DELETE",
  258. HTTPPath: "/{Bucket}/{Key+}?clear",
  259. }
  260. if input == nil {
  261. input = &ClearObjectInput{}
  262. }
  263. req = c.newRequest(op, input, output)
  264. output = &ClearObjectOutput{}
  265. req.Data = output
  266. return
  267. }
  268. // ClearObject clears the object from the recycle bin.
  269. func (c *S3) ClearObject(input *ClearObjectInput) (*ClearObjectOutput, error) {
  270. req, out := c.ClearObjectRequest(input)
  271. err := req.Send()
  272. return out, err
  273. }
  274. func (c *S3) ClearObjectWithContext(ctx aws.Context, input *ClearObjectInput) (*ClearObjectOutput, error) {
  275. req, out := c.ClearObjectRequest(input)
  276. req.SetContext(ctx)
  277. err := req.Send()
  278. return out, err
  279. }
  280. type ClearObjectInput struct {
  281. // The name of the bucket.
  282. Bucket *string `location:"uri" locationName:"Bucket" type:"string" required:"true"`
  283. // The key of the object.
  284. Key *string `location:"uri" locationName:"Key" type:"string" required:"true"`
  285. // Specify the deletion ID of the deleted object.
  286. RetentionId *string `location:"header" locationName:"x-kss-retention-id" type:"string" required:"true"`
  287. // Set extend request headers. If the existing fields do not support setting the request header you need, you can set it through this field.
  288. ExtendHeaders map[string]*string `location:"extendHeaders" type:"map"`
  289. // Set extend query params. If the existing fields do not support setting the query param you need, you can set it through this field.
  290. ExtendQueryParams map[string]*string `location:"extendQueryParams" type:"map"`
  291. }
  292. type ClearObjectOutput struct {
  293. Metadata map[string]*string `location:"headers" type:"map"`
  294. StatusCode *int64 `location:"statusCode" type:"integer"`
  295. }