| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- /*
- * MinIO Go Library for Amazon S3 Compatible Cloud Storage
- * Copyright 2015-2017 MinIO, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package s3cli
- import (
- "context"
- "fmt"
- "io/ioutil"
- "net/http"
- "net/url"
- "github.com/minio/minio-go/v6/pkg/s3utils"
- )
- // GetBucketWebsite - get bucket website at a given path.
- func (c Client) GetBucketWebsite(bucketName string) (string, error) {
- // Input validation.
- if err := s3utils.CheckValidBucketName(bucketName); err != nil {
- return "", err
- }
- bucketWebsite, err := c.getBucketWebsite(bucketName)
- if err != nil {
- errResponse := ToErrorResponse(err)
- if errResponse.Code == "NoSuchBucketPolicy" {
- return "", nil
- }
- return "", err
- }
- return bucketWebsite, nil
- }
- // Request server for current bucket Website.
- func (c Client) getBucketWebsite(bucketName string) (string, error) {
- // Get resources properly escaped and lined up before
- // using them in http request.
- urlValues := make(url.Values)
- urlValues.Set("website", "")
- // Execute GET on bucket to list objects.
- resp, err := c.executeMethod(context.Background(), "GET", requestMetadata{
- bucketName: bucketName,
- queryValues: urlValues,
- contentSHA256Hex: emptySHA256Hex,
- })
- defer closeResponse(resp)
- if err != nil {
- return "", err
- }
- fmt.Print(resp.Header, resp.StatusCode, resp.Status)
- if resp != nil {
- if resp.StatusCode != http.StatusOK {
- return "", httpRespToErrorResponse(resp, bucketName, "")
- }
- }
- bucketWebsiteBuf, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- return "", err
- }
- acl := string(bucketWebsiteBuf)
- return acl, err
- }
|