in s3plugin/s3plugin.go [103:184]
func InitializeAndValidateConfig(config *PluginConfig) error {
var err error
var errTxt string
opt := &config.Options
// Initialize defaults
if opt.Region == "" {
opt.Region = "unused"
}
if opt.Encryption == "" {
opt.Encryption = "on"
}
if opt.RemoveDuplicateBucket == "" {
opt.RemoveDuplicateBucket = "false"
}
opt.UploadChunkSize = DefaultUploadChunkSize
opt.UploadConcurrency = DefaultConcurrency
opt.DownloadChunkSize = DefaultDownloadChunkSize
opt.DownloadConcurrency = DefaultConcurrency
// Validate configurations and overwrite defaults
if config.ExecutablePath == "" {
errTxt += fmt.Sprintf("executable_path must exist and cannot be empty in plugin configuration file\n")
}
if opt.Bucket == "" {
errTxt += fmt.Sprintf("bucket must exist and cannot be empty in plugin configuration file\n")
}
if opt.Folder == "" {
errTxt += fmt.Sprintf("folder must exist and cannot be empty in plugin configuration file\n")
}
if opt.AwsAccessKeyId == "" {
if opt.AwsSecretAccessKey != "" {
errTxt += fmt.Sprintf("aws_access_key_id must exist in plugin configuration file if aws_secret_access_key does\n")
}
} else if opt.AwsSecretAccessKey == "" {
errTxt += fmt.Sprintf("aws_secret_access_key must exist in plugin configuration file if aws_access_key_id does\n")
}
if opt.Region == "unused" && opt.Endpoint == "" {
errTxt += fmt.Sprintf("region or endpoint must exist in plugin configuration file\n")
}
if opt.Encryption != "on" && opt.Encryption != "off" {
errTxt += fmt.Sprintf("Invalid encryption configuration. Valid choices are on or off.\n")
}
if opt.RemoveDuplicateBucket != "true" && opt.RemoveDuplicateBucket != "false" {
errTxt += fmt.Sprintf("Invalid value for remove_duplicate_bucket. Valid choices are true or false.\n")
}
if opt.BackupMultipartChunksize != "" {
chunkSize, err := bytesize.Parse(opt.BackupMultipartChunksize)
if err != nil {
errTxt += fmt.Sprintf("Invalid backup_multipart_chunksize. Err: %s\n", err)
}
// Chunk size is being converted from uint64 to int64. This is safe as
// long as chunksize smaller than math.MaxInt64 bytes (~9223 Petabytes)
opt.UploadChunkSize = int64(chunkSize)
}
if opt.BackupMaxConcurrentRequests != "" {
opt.UploadConcurrency, err = strconv.Atoi(opt.BackupMaxConcurrentRequests)
if err != nil {
errTxt += fmt.Sprintf("Invalid backup_max_concurrent_requests. Err: %s\n", err)
}
}
if opt.RestoreMultipartChunksize != "" {
chunkSize, err := bytesize.Parse(opt.RestoreMultipartChunksize)
if err != nil {
errTxt += fmt.Sprintf("Invalid restore_multipart_chunksize. Err: %s\n", err)
}
// Chunk size is being converted from uint64 to int64. This is safe as
// long as chunksize smaller than math.MaxInt64 bytes (~9223 Petabytes)
opt.DownloadChunkSize = int64(chunkSize)
}
if opt.RestoreMaxConcurrentRequests != "" {
opt.DownloadConcurrency, err = strconv.Atoi(opt.RestoreMaxConcurrentRequests)
if err != nil {
errTxt += fmt.Sprintf("Invalid restore_max_concurrent_requests. Err: %s\n", err)
}
}
if errTxt != "" {
return errors.New(errTxt)
}
return nil
}