-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathInfluxDBClientFactory.cs
186 lines (166 loc) · 8.14 KB
/
InfluxDBClientFactory.cs
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
using System;
using System.Threading.Tasks;
using InfluxDB.Client.Api.Domain;
using InfluxDB.Client.Core;
namespace InfluxDB.Client
{
public static class InfluxDBClientFactory
{
/// <summary>
/// Create a instance of the InfluxDB 2.x client that is configured via <code>App.config</code>.
/// </summary>
/// <returns>client</returns>
/// <remarks>Deprecated - please use use object initializer <see cref="InfluxDBClient(InfluxDBClientOptions)"/>
/// together with <see cref="InfluxDBClientOptions.LoadConfig"/>
/// </remarks>
[Obsolete("This method is deprecated. Call 'InfluxDBClient' initializer instead.", false)]
public static InfluxDBClient Create()
{
var options = InfluxDBClientOptions.Builder
.CreateNew()
.LoadConfig()
.Build();
return Create(options);
}
/// <summary>
/// Create a instance of the InfluxDB 2.x client. The url could be a connection string with various configurations.
/// <para>
/// e.g.: "http://localhost:8086?timeout=5000&logLevel=BASIC
/// </para>
/// </summary>
/// <param name="connectionString">connection string with various configurations</param>
/// <returns>client</returns>
/// <remarks>Deprecated - please use use object initializer <see cref="InfluxDBClient(string)"/></remarks>
[Obsolete("This method is deprecated. Call 'InfluxDBClient' initializer instead.", false)]
public static InfluxDBClient Create(string connectionString)
{
var options = InfluxDBClientOptions.Builder
.CreateNew()
.ConnectionString(connectionString)
.Build();
return Create(options);
}
/// <summary>
/// Create a instance of the InfluxDB 2.x client.
/// </summary>
/// <param name="url">the url to connect to the InfluxDB 2.x</param>
/// <param name="username">the username to use in the basic auth</param>
/// <param name="password">the password to use in the basic auth</param>
/// <returns>client</returns>
/// <remarks>Deprecated - please use use object initializer <see cref="InfluxDBClient(string, string, string)"/></remarks>
[Obsolete("This method is deprecated. Call 'InfluxDBClient' initializer instead.", false)]
public static InfluxDBClient Create(string url, string username, char[] password)
{
var options = InfluxDBClientOptions.Builder
.CreateNew()
.Url(url)
.Authenticate(username, password)
.Build();
return Create(options);
}
/// <summary>
/// Create a instance of the InfluxDB 2.x client.
/// </summary>
/// <param name="url">the url to connect to the InfluxDB 2.x</param>
/// <param name="token">the token to use for the authorization</param>
/// <returns>client</returns>
/// <remarks>Deprecated - please use use object initializer <see cref="InfluxDBClient(string, string)"/></remarks>
[Obsolete("This method is deprecated. Call 'InfluxDBClient' initializer instead.", false)]
public static InfluxDBClient Create(string url, char[] token)
{
var options = InfluxDBClientOptions.Builder
.CreateNew()
.Url(url)
.AuthenticateToken(token)
.Build();
return Create(options);
}
/// <summary>
/// Create a instance of the InfluxDB 2.x client.
/// </summary>
/// <param name="url">the url to connect to the InfluxDB 2.x</param>
/// <param name="token">the token to use for the authorization</param>
/// <returns>client</returns>
/// <remarks>Deprecated - please use use object initializer <see cref="InfluxDBClient(string, string)"/></remarks>
[Obsolete("This method is deprecated. Call 'InfluxDBClient' initializer instead.", false)]
public static InfluxDBClient Create(string url, string token)
{
var options = InfluxDBClientOptions.Builder
.CreateNew()
.Url(url)
.AuthenticateToken(token)
.Build();
return Create(options);
}
/// <summary>
/// Create a instance of the InfluxDB 2.x client to connect into InfluxDB 1.8.
/// </summary>
/// <param name="url">the url to connect to the InfluxDB 1.8</param>
/// <param name="username">authorization username</param>
/// <param name="password">authorization password</param>
/// <param name="database">database name</param>
/// <param name="retentionPolicy">retention policy</param>
/// <returns>client</returns>
/// <remarks>Deprecated - please use use object initializer <see cref="InfluxDBClient(string, string, string, string, string)"/></remarks>
[Obsolete("This method is deprecated. Call 'InfluxDBClient' initializer instead.", false)]
public static InfluxDBClient CreateV1(string url, string username, char[] password, string database,
string retentionPolicy)
{
Arguments.CheckNonEmptyString(database, nameof(database));
var options = InfluxDBClientOptions.Builder
.CreateNew()
.Url(url)
.Org("-")
.AuthenticateToken($"{username}:{new string(password)}")
.Bucket($"{database}/{retentionPolicy}")
.Build();
return Create(options);
}
/// <summary>
/// Create a instance of the InfluxDB 2.x client.
/// </summary>
/// <param name="options">the connection configuration</param>
/// <returns>client</returns>
/// <remarks>Deprecated - please use use object initializer <see cref="InfluxDBClient(InfluxDBClientOptions)"/></remarks>
[Obsolete("This method is deprecated. Call 'InfluxDBClient' initializer instead.", false)]
public static InfluxDBClient Create(InfluxDBClientOptions options)
{
Arguments.CheckNotNull(options, nameof(options));
return new InfluxDBClient(options);
}
/// <summary>
/// Post onboarding request, to setup initial user, org and bucket.
/// </summary>
/// <param name="url">the url to connect to the InfluxDB</param>
/// <param name="username">the name of an user</param>
/// <param name="password">the password to connect as an user</param>
/// <param name="org">the name of an organization</param>
/// <param name="bucket">the name of a bucket</param>
/// <returns>Created default user, bucket, org.</returns>
public static Task<OnboardingResponse> Onboarding(string url, string username, string password,
string org,
string bucket)
{
Arguments.CheckNonEmptyString(url, nameof(url));
Arguments.CheckNonEmptyString(username, nameof(username));
Arguments.CheckNonEmptyString(password, nameof(password));
Arguments.CheckNonEmptyString(org, nameof(org));
Arguments.CheckNonEmptyString(bucket, nameof(bucket));
var onboarding = new OnboardingRequest(username, password, org, bucket);
return Onboarding(url, onboarding);
}
/// <summary>
/// Post onboarding request, to setup initial user, org and bucket.
/// </summary>
/// <param name="url">the url to connect to the InfluxDB</param>
/// <param name="onboarding">the defaults</param>
/// <returns>Created default user, bucket, org.</returns>
public static async Task<OnboardingResponse> Onboarding(string url, OnboardingRequest onboarding)
{
Arguments.CheckNonEmptyString(url, nameof(url));
Arguments.CheckNotNull(onboarding, nameof(onboarding));
using var client = new InfluxDBClient(new InfluxDBClientOptions(url));
return await client.OnboardingAsync(onboarding).ConfigureAwait(false);
}
}
}