api-get-info.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * MinIO Go Library for Amazon S3 Compatible Cloud Storage
  3. * Copyright 2015-2017 MinIO, Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package s3cli
  18. import (
  19. "context"
  20. "io/ioutil"
  21. "net/http"
  22. "net/url"
  23. "github.com/minio/minio-go/v6/pkg/s3utils"
  24. )
  25. // GetBucketInfo - get bucket info at a given path.
  26. func (c Client) GetBucketInfo(bucketName string) (string, error) {
  27. // Input validation.
  28. if err := s3utils.CheckValidBucketName(bucketName); err != nil {
  29. return "", err
  30. }
  31. bucketInfo, err := c.getBucketInfo(bucketName)
  32. if err != nil {
  33. errResponse := ToErrorResponse(err)
  34. if errResponse.Code == "NoSuchBucketPolicy" {
  35. return "", nil
  36. }
  37. return "", err
  38. }
  39. return bucketInfo, nil
  40. }
  41. // Request server for current bucket Info.
  42. func (c Client) getBucketInfo(bucketName string) (string, error) {
  43. // Get resources properly escaped and lined up before
  44. // using them in http request.
  45. urlValues := make(url.Values)
  46. urlValues.Set("bucketInfo", "")
  47. // Execute GET on bucket to list objects.
  48. resp, err := c.executeMethod(context.Background(), "GET", requestMetadata{
  49. bucketName: bucketName,
  50. queryValues: urlValues,
  51. contentSHA256Hex: emptySHA256Hex,
  52. })
  53. defer closeResponse(resp)
  54. if err != nil {
  55. return "", err
  56. }
  57. if resp != nil {
  58. if resp.StatusCode != http.StatusOK {
  59. return "", httpRespToErrorResponse(resp, bucketName, "")
  60. }
  61. }
  62. bucketInfoBuf, err := ioutil.ReadAll(resp.Body)
  63. if err != nil {
  64. return "", err
  65. }
  66. acl := string(bucketInfoBuf)
  67. return acl, err
  68. }