-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathCosmosSettingsBase.cs
More file actions
44 lines (41 loc) · 1.97 KB
/
CosmosSettingsBase.cs
File metadata and controls
44 lines (41 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Microsoft.Azure.Cosmos;
using System.ComponentModel.DataAnnotations;
namespace Cosmos.DataTransfer.CosmosExtension
{
public abstract class CosmosSettingsBase : IValidatableObject
{
public string? ConnectionString { get; set; }
[Required]
public string? Database { get; set; }
[Required]
public string? Container { get; set; }
public ConnectionMode ConnectionMode { get; set; } = ConnectionMode.Gateway;
public string? WebProxy { get; set; }
public bool UseDefaultProxyCredentials { get; set; } = false;
public bool UseRbacAuth { get; set; }
public string? AccountEndpoint { get; set; }
public bool EnableInteractiveCredentials { get; set; }
public bool InitClientEncryption { get; set; } = false;
/// <summary>
/// <see cref="CosmosClientOptions.LimitToEndpoint"/>
/// When running the Azure Cosmos DB emulator in a Linux Container on Windows
/// a value of false results in failure to connect to Cosmos DB emulator.
/// </summary>
public bool LimitToEndpoint { get; set; } = false;
public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (!UseRbacAuth && string.IsNullOrEmpty(ConnectionString))
{
yield return new ValidationResult("ConnectionString must be specified unless UseRbacAuth is true", new[] { nameof(ConnectionString) });
}
if (UseRbacAuth && string.IsNullOrEmpty(AccountEndpoint))
{
yield return new ValidationResult("AccountEndpoint must be specified when UseRbacAuth is true", new[] { nameof(AccountEndpoint) });
}
if (!UseRbacAuth && InitClientEncryption)
{
yield return new ValidationResult("InitClientEncryption can only be used when UseRbacAuth is true", new[] { nameof(InitClientEncryption) });
}
}
}
}