2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2020-02-05 04:42:34 -05:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
bucketsse "github.com/minio/minio/pkg/bucket/encryption"
|
|
|
|
)
|
|
|
|
|
|
|
|
// BucketSSEConfigSys - in-memory cache of bucket encryption config
|
2020-05-20 13:18:15 -04:00
|
|
|
type BucketSSEConfigSys struct{}
|
2020-02-05 04:42:34 -05:00
|
|
|
|
|
|
|
// NewBucketSSEConfigSys - Creates an empty in-memory bucket encryption configuration cache
|
|
|
|
func NewBucketSSEConfigSys() *BucketSSEConfigSys {
|
2020-05-20 13:18:15 -04:00
|
|
|
return &BucketSSEConfigSys{}
|
2020-02-05 04:42:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get - gets bucket encryption config for the given bucket.
|
2020-05-20 13:18:15 -04:00
|
|
|
func (sys *BucketSSEConfigSys) Get(bucket string) (*bucketsse.BucketSSEConfig, error) {
|
2020-02-05 04:42:34 -05:00
|
|
|
if globalIsGateway {
|
2020-10-09 12:59:52 -04:00
|
|
|
objAPI := newObjectLayerFn()
|
2020-02-05 04:42:34 -05:00
|
|
|
if objAPI == nil {
|
2020-05-19 16:53:54 -04:00
|
|
|
return nil, errServerNotInitialized
|
2020-02-05 04:42:34 -05:00
|
|
|
}
|
|
|
|
|
2020-05-19 16:53:54 -04:00
|
|
|
return nil, BucketSSEConfigNotFound{Bucket: bucket}
|
2020-02-05 04:42:34 -05:00
|
|
|
}
|
|
|
|
|
2020-05-20 13:18:15 -04:00
|
|
|
return globalBucketMetadataSys.GetSSEConfig(bucket)
|
2020-02-05 04:42:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// validateBucketSSEConfig parses bucket encryption configuration and validates if it is supported by MinIO.
|
|
|
|
func validateBucketSSEConfig(r io.Reader) (*bucketsse.BucketSSEConfig, error) {
|
|
|
|
encConfig, err := bucketsse.ParseBucketSSEConfig(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-14 03:59:05 -04:00
|
|
|
if len(encConfig.Rules) == 1 {
|
2020-02-05 04:42:34 -05:00
|
|
|
return encConfig, nil
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
|
2020-02-05 04:42:34 -05:00
|
|
|
return nil, errors.New("Unsupported bucket encryption configuration")
|
|
|
|
}
|