-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConnection.cs
More file actions
160 lines (140 loc) · 5.51 KB
/
Connection.cs
File metadata and controls
160 lines (140 loc) · 5.51 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using System.Collections.Generic;
using Cognite.Extensions.Unstable;
using Cognite.Extractor.Common;
using Cognite.Extractor.Configuration;
using Microsoft.Extensions.Logging;
namespace Cognite.Extractor.Utils.Unstable.Configuration
{
/// <summary>
/// Configuration for connecting to CDF.
/// </summary>
public class ConnectionConfig : VersionedConfig
{
/// <summary>
/// The project name
/// </summary>
/// <value>project name</value>
public string? Project { get; set; }
/// <summary>
/// API base URL
/// </summary>
/// <value>Absolute Uri for the host. Default: https://api.cognitedata.com</value>
public string BaseUrl { get; set; } = "https://api.cognitedata.com";
/// <summary>
/// Authentication config.
/// </summary>
public BaseAuthenticationConfig? Authentication { get; set; }
/// <summary>
/// ID of integration in CDF, required.
/// </summary>
public IntegrationConfig? Integration { get; set; }
/// <summary>
/// Configuration for the connection to CDF.
/// </summary>
public CdfConnectionConfig Connection { get => _connection; set { _connection = value ?? _connection; } }
private CdfConnectionConfig _connection = new CdfConnectionConfig();
/// <summary>
/// Register any necessary yaml converters.
/// </summary>
public static void RegisterConverters(YamlConfigBuilder builder)
{
if (builder is null) throw new ArgumentNullException(nameof(builder));
builder.AddDiscriminatedType<BaseAuthenticationConfig>("type", BaseAuthenticationConfig.Variants());
}
/// <inheritdoc />
public override void GenerateDefaults()
{
}
}
/// <summary>
/// Configure automatic retries on requests to CDF.
/// </summary>
public class RetryConfig
{
/// <summary>
/// Timeout in milliseconds for each individual try. Less than or equal to zero for no timeout.
/// </summary>
public string Timeout { get => TimeoutValue.RawValue; set => TimeoutValue.RawValue = value; }
/// <summary>
/// Value of the timeout parameter.
/// </summary>
public TimeSpanWrapper TimeoutValue { get; } = new TimeSpanWrapper(false, "ms", "80s");
/// <summary>
/// Maximum number of retries. Less than 0 retries forever.
/// </summary>
public int MaxRetries { get; set; } = 5;
/// <summary>
/// Max backoff in ms between each retry. Base delay is calculated according to 125*2^retry ms.
/// If less than 0, there is no maximum.
/// </summary>
public string MaxBackoff { get => MaxBackoffValue.RawValue; set => MaxBackoffValue.RawValue = value; }
/// <summary>
/// Value of the max-backoff parameter.
/// </summary>
public TimeSpanWrapper MaxBackoffValue { get; } = new TimeSpanWrapper(true, "ms", "80s");
}
/// <summary>
/// Shared configuration for configuring the connection to CDF.
/// </summary>
public class CdfConnectionConfig
{
/// <summary>
/// Configuration for retries of failed requests to CDF.
/// </summary>
public RetryConfig Retries { get => _retries; set { _retries = value ?? _retries; } }
private RetryConfig _retries = new RetryConfig();
/// <summary>
/// Configuration for details around verification of SSL certificates.
/// </summary>
public CertificateConfig SslCertificates { get => _sslCertificates; set { _sslCertificates = value ?? _sslCertificates; } }
private CertificateConfig _sslCertificates = new CertificateConfig();
}
/// <summary>
/// Configure options relating to SSL certificates.
/// </summary>
public class CertificateConfig
{
/// <summary>
/// False to disable SSL verification. This must be considered a security risk in most circumstances.
/// The default value is true.
/// </summary>
public bool Verify { get; set; } = true;
/// <summary>
/// List of certificate thumbprints to manually allow. This is much safer.
/// </summary>
public IEnumerable<string>? AllowList { get; set; }
}
/// <summary>
/// Configuration for setting the integration in CDF.
/// </summary>
public class IntegrationConfig
{
/// <summary>
/// External ID of the integration.
/// </summary>
public string? ExternalId { get; set; }
}
/// <summary>
/// Configuration for logging information from the SDK.
/// </summary>
public class SdkLoggingConfig
{
/// <summary>
/// Disables Sdk logging
/// </summary>
/// <value></value>
public bool Enabled { get; set; } = true;
/// <summary>
/// Cognite Sdk logs are diplayed using this level.
/// </summary>
/// <value>One of the <see cref="LogLevel"/> levels, case insensitive</value>
public LogLevel Level { get; set; } = LogLevel.Debug;
/// <summary>
/// Format of the log message.
/// Default is <c>"CDF ({Message}): {HttpMethod} {Url} {ResponseHeader[X-Request-ID]} - {Elapsed} ms"</c>
/// </summary>
/// <returns>String format</returns>
public string Format { get; set; } = "CDF ({Message}): {HttpMethod} {Url} {ResponseHeader[X-Request-ID]} - {Elapsed} ms";
}
}