/* SPDX-License-Identifier: Apache-2.0 * * The OpenSearch Contributors require contributions made to * this file be licensed under the Apache-2.0 license or a * compatible open source license. */ /* * Modifications Copyright OpenSearch Contributors. See * GitHub history for details. * * Licensed to Elasticsearch B.V. under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Elasticsearch B.V. licenses this file to you 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. */ using System; using System.Runtime.Serialization; using OpenSearch.Net.Utf8Json; namespace OpenSearch.Client.Specification.SnapshotApi { /// /// A snapshot repository that stores snapshots in an Amazon S3 bucket /// /// Requires the repository-s3 plugin to be installed on the cluster /// public interface IS3Repository : IRepository { } /// public class S3Repository : IS3Repository { public S3Repository(IS3RepositorySettings settings) => Settings = settings; public IS3RepositorySettings Settings { get; set; } object IRepositoryWithSettings.DelegateSettings => Settings; public string Type { get; } = "s3"; } /// /// Snapshot repository settings for /// public interface IS3RepositorySettings : IRepositorySettings { /// /// Specifies the path within bucket to repository data. /// Defaults to value of repositories.s3.base_path or to root directory if not set. /// [DataMember(Name ="base_path")] string BasePath { get; set; } /// /// The name of the bucket to be used for snapshots. This field is required /// [DataMember(Name ="bucket")] string Bucket { get; set; } /// /// Minimum threshold below which the chunk is uploaded using a single request. /// Beyond this threshold, the S3 repository will use the AWS Multipart Upload API to split the chunk into /// several parts, each of buffer_size length, and to upload each part in its own request. Note that setting a /// buffer size lower than 5mb is not allowed since it will prevent the use of the Multipart API and may result /// in upload errors. It is also not possible to set a buffer size greater than 5gb as it is the maximum upload /// size allowed by S3. Defaults to the minimum between 100mb and 5% of the heap size. /// [DataMember(Name ="buffer_size")] string BufferSize { get; set; } /// /// Specify a canned ACL for the S3 bucket. /// The S3 repository supports all S3 canned ACLs : private, public-read, public-read-write, authenticated-read, /// log-delivery-write, bucket-owner-read, bucket-owner-full-control. Defaults to private. /// [DataMember(Name ="canned_acl")] string CannedAcl { get; set; } /// /// Big files can be broken down into chunks during snapshotting if needed. /// The chunk size can be specified in bytes or by using size value notation, /// i.e. 1gb, 10mb, 5kb. Defaults to 1gb. /// [DataMember(Name ="chunk_size")] string ChunkSize { get; set; } /// /// The name of the s3 client to use to connect to S3. Defaults to default. /// [DataMember(Name ="client")] string Client { get; set; } /// /// When set to true metadata files are stored in compressed format. /// This setting doesn't affect index files that are already compressed by default. /// Defaults to false. /// [DataMember(Name ="compress")] [JsonFormatter(typeof(NullableStringBooleanFormatter))] bool? Compress { get; set; } /// /// When set to true files are encrypted on server side using AES256 algorithm. /// Defaults to false. /// [DataMember(Name ="server_side_encryption")] [JsonFormatter(typeof(NullableStringBooleanFormatter))] bool? ServerSideEncryption { get; set; } /// /// Sets the S3 storage class type for the backup files. Values may be standard, reduced_redundancy, standard_ia. /// Defaults to standard. /// [DataMember(Name ="storage_class")] string StorageClass { get; set; } /// /// Whether to force the use of the path style access pattern. If `true`, the /// path style access pattern will be used. If `false`, the access pattern will /// be automatically determined by the AWS Java SDK used internally by OpenSearch /// [DataMember(Name = "path_style_access")] [JsonFormatter(typeof(NullableStringBooleanFormatter))] bool? PathStyleAccess { get; set; } /// /// Whether chunked encoding should be disabled or not. If false, chunked encoding is enabled and will be used where appropriate. /// If true, chunked encoding is disabled and will not be used, which may mean that snapshot operations consume more resources /// and take longer to complete. It should only be set to true if you are using a storage service that does not support chunked /// encoding. Defaults to false. /// [DataMember(Name = "disable_chunked_encoding")] [JsonFormatter(typeof(NullableStringBooleanFormatter))] bool? DisableChunkedEncoding { get; set; } /// /// Make the repository readonly. Defaults to false. /// [DataMember(Name = "readonly")] [JsonFormatter(typeof(NullableStringBooleanFormatter))] bool? ReadOnly { get; set; } /// /// Throttles per node restore rate. Defaults to 40mb per second. /// [DataMember(Name = "max_restore_bytes_per_sec")] string MaxRestoreBytesPerSecond { get; set; } /// /// Throttles per node snapshot rate. Defaults to 40mb per second. /// [DataMember(Name = "max_snapshot_bytes_per_sec")] string MaxSnapshotBytesPerSecond { get; set; } } /// public class S3RepositorySettings : IS3RepositorySettings { internal S3RepositorySettings() { } public S3RepositorySettings(string bucket) => Bucket = bucket; /// public string BasePath { get; set; } /// public string Bucket { get; set; } /// public string BufferSize { get; set; } /// public string CannedAcl { get; set; } /// public string ChunkSize { get; set; } /// public string Client { get; set; } /// public bool? Compress { get; set; } /// public bool? ServerSideEncryption { get; set; } /// public string StorageClass { get; set; } /// public bool? PathStyleAccess { get; set; } /// public bool? DisableChunkedEncoding { get; set; } /// public bool? ReadOnly { get; set; } /// public string MaxRestoreBytesPerSecond { get; set; } /// public string MaxSnapshotBytesPerSecond { get; set; } } /// public class S3RepositorySettingsDescriptor : DescriptorBase, IS3RepositorySettings { public S3RepositorySettingsDescriptor(string bucket) => Self.Bucket = bucket; string IS3RepositorySettings.BasePath { get; set; } string IS3RepositorySettings.Bucket { get; set; } string IS3RepositorySettings.BufferSize { get; set; } string IS3RepositorySettings.CannedAcl { get; set; } string IS3RepositorySettings.ChunkSize { get; set; } string IS3RepositorySettings.Client { get; set; } bool? IS3RepositorySettings.Compress { get; set; } bool? IS3RepositorySettings.ServerSideEncryption { get; set; } string IS3RepositorySettings.StorageClass { get; set; } bool? IS3RepositorySettings.PathStyleAccess { get; set; } bool? IS3RepositorySettings.DisableChunkedEncoding { get; set; } bool? IS3RepositorySettings.ReadOnly { get; set; } string IS3RepositorySettings.MaxRestoreBytesPerSecond { get; set; } string IS3RepositorySettings.MaxSnapshotBytesPerSecond { get; set; } /// public S3RepositorySettingsDescriptor Bucket(string bucket) => Assign(bucket, (a, v) => a.Bucket = v); /// public S3RepositorySettingsDescriptor Client(string client) => Assign(client, (a, v) => a.Client = v); /// public S3RepositorySettingsDescriptor BasePath(string basePath) => Assign(basePath, (a, v) => a.BasePath = v); /// public S3RepositorySettingsDescriptor Compress(bool? compress = true) => Assign(compress, (a, v) => a.Compress = v); /// public S3RepositorySettingsDescriptor ChunkSize(string chunkSize) => Assign(chunkSize, (a, v) => a.ChunkSize = v); /// public S3RepositorySettingsDescriptor ServerSideEncryption(bool? serverSideEncryption = true) => Assign(serverSideEncryption, (a, v) => a.ServerSideEncryption = v); /// public S3RepositorySettingsDescriptor BufferSize(string bufferSize) => Assign(bufferSize, (a, v) => a.BufferSize = v); /// public S3RepositorySettingsDescriptor CannedAcl(string cannedAcl) => Assign(cannedAcl, (a, v) => a.CannedAcl = v); /// public S3RepositorySettingsDescriptor StorageClass(string storageClass) => Assign(storageClass, (a, v) => a.StorageClass = v); /// public S3RepositorySettingsDescriptor PathStyleAccess(bool? pathStyleAccess = true) => Assign(pathStyleAccess, (a, v) => a.PathStyleAccess = v); /// public S3RepositorySettingsDescriptor DisableChunkedEncoding(bool? disableChunkedEncoding = true) => Assign(disableChunkedEncoding, (a, v) => a.DisableChunkedEncoding = v); /// public S3RepositorySettingsDescriptor ReadOnly(bool? readOnly = true) => Assign(readOnly, (a, v) => a.ReadOnly = v); /// public S3RepositorySettingsDescriptor MaxRestoreBytesPerSecond(string maxRestoreBytesPerSecond) => Assign(maxRestoreBytesPerSecond, (a, v) => a.MaxRestoreBytesPerSecond = v); /// public S3RepositorySettingsDescriptor MaxSnapshotBytesPerSecond(string maxSnapshotBytesPerSecond) => Assign(maxSnapshotBytesPerSecond, (a, v) => a.MaxSnapshotBytesPerSecond = v); } /// public class S3RepositoryDescriptor : DescriptorBase, IS3Repository { IS3RepositorySettings IRepository.Settings { get; set; } object IRepositoryWithSettings.DelegateSettings => Self.Settings; string ISnapshotRepository.Type { get; } = "s3"; /// public S3RepositoryDescriptor Settings(string bucket, Func settingsSelector = null) => Assign(settingsSelector.InvokeOrDefault(new S3RepositorySettingsDescriptor(bucket)), (a, v) => a.Settings = v); } }