using System; using System.Threading.Tasks; using InfluxDB.Client.Api.Domain; using InfluxDB.Client.Core; namespace InfluxDB.Client { public static class InfluxDBClientFactory { /// /// Create a instance of the InfluxDB 2.x client that is configured via App.config. /// /// client /// Deprecated - please use use object initializer /// together with /// [Obsolete("This method is deprecated. Call 'InfluxDBClient' initializer instead.", false)] public static InfluxDBClient Create() { var options = InfluxDBClientOptions.Builder .CreateNew() .LoadConfig() .Build(); return Create(options); } /// /// Create a instance of the InfluxDB 2.x client. The url could be a connection string with various configurations. /// /// e.g.: "http://localhost:8086?timeout=5000&logLevel=BASIC /// /// /// connection string with various configurations /// client /// Deprecated - please use use object initializer [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); } /// /// Create a instance of the InfluxDB 2.x client. /// /// the url to connect to the InfluxDB 2.x /// the username to use in the basic auth /// the password to use in the basic auth /// client /// Deprecated - please use use object initializer [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); } /// /// Create a instance of the InfluxDB 2.x client. /// /// the url to connect to the InfluxDB 2.x /// the token to use for the authorization /// client /// Deprecated - please use use object initializer [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); } /// /// Create a instance of the InfluxDB 2.x client. /// /// the url to connect to the InfluxDB 2.x /// the token to use for the authorization /// client /// Deprecated - please use use object initializer [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); } /// /// Create a instance of the InfluxDB 2.x client to connect into InfluxDB 1.8. /// /// the url to connect to the InfluxDB 1.8 /// authorization username /// authorization password /// database name /// retention policy /// client /// Deprecated - please use use object initializer [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); } /// /// Create a instance of the InfluxDB 2.x client. /// /// the connection configuration /// client /// Deprecated - please use use object initializer [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); } /// /// Post onboarding request, to setup initial user, org and bucket. /// /// the url to connect to the InfluxDB /// the name of an user /// the password to connect as an user /// the name of an organization /// the name of a bucket /// Created default user, bucket, org. public static Task 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); } /// /// Post onboarding request, to setup initial user, org and bucket. /// /// the url to connect to the InfluxDB /// the defaults /// Created default user, bucket, org. public static async Task 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); } } }