public new async Task SetUp() { _organization = await FindMyOrg(); var retention = new BucketRetentionRules(BucketRetentionRules.TypeEnum.Expire, 3600); _bucket = await Client.GetBucketsApi() .CreateBucketAsync(GenerateName("h2o"), retention, _organization); // // Add Permissions to read and write to the Bucket // var resource = new PermissionResource(PermissionResource.TypeEnum.Buckets, _bucket.Id, null, _organization.Id); var readBucket = new Permission(Permission.ActionEnum.Read, resource); var writeBucket = new Permission(Permission.ActionEnum.Write, resource); var loggedUser = await Client.GetUsersApi().MeAsync(); Assert.IsNotNull(loggedUser); var authorization = await Client.GetAuthorizationsApi() .CreateAuthorizationAsync(await FindMyOrg(), new List <Permission> { readBucket, writeBucket }); _token = authorization.Token; Client.Dispose(); var options = new InfluxDBClientOptions.Builder().Url(InfluxDbUrl).AuthenticateToken(_token.ToCharArray()) .Org(_organization.Id).Bucket(_bucket.Id).Build(); Client = InfluxDBClientFactory.Create(options); }
/// <summary> /// Creates a new bucket and sets <see cref="Bucket.Id" /> with the new identifier. /// </summary> /// <param name="name">name of the bucket</param> /// <param name="bucketRetentionRules">retention rule of the bucket</param> /// <param name="organization">owner of the bucket</param> /// <returns>created Bucket</returns> public async Task <Bucket> CreateBucket(string name, BucketRetentionRules bucketRetentionRules, Organization organization) { Arguments.CheckNonEmptyString(name, nameof(name)); Arguments.CheckNotNull(organization, nameof(organization)); return(await CreateBucket(name, bucketRetentionRules, organization.Id)); }
private async Task <Bucket> EnsureBucketCreated(InfluxDBClient influxDBClient, Organization organization) { var bucket = await influxDBClient.GetBucketsApi().FindBucketByNameAsync(_options.Bucket); if (bucket == null) { var retention = new BucketRetentionRules(BucketRetentionRules.TypeEnum.Expire, (int)TimeSpan.Parse(_options.RetentionPolicy).TotalSeconds); bucket = await influxDBClient.GetBucketsApi().CreateBucketAsync(_options.Bucket, retention, organization.Id); } return(bucket); }
/// <summary> /// Creates a new bucket and sets <see cref="Bucket.Id" /> with the new identifier. /// </summary> /// <param name="name">name of the bucket</param> /// <param name="bucketRetentionRules">retention rule of the bucket</param> /// <param name="orgId">owner of the bucket</param> /// <returns>created Bucket</returns> public async Task <Bucket> CreateBucket(string name, BucketRetentionRules bucketRetentionRules, string orgId) { Arguments.CheckNonEmptyString(name, nameof(name)); Arguments.CheckNonEmptyString(orgId, nameof(orgId)); var bucket = new Bucket(null, name, null, orgId, null, new List <BucketRetentionRules>()); if (bucketRetentionRules != null) { bucket.RetentionRules.Add(bucketRetentionRules); } return(await CreateBucket(bucket)); }
private Bucket CreateBucket(InfluxDBClient createBucketClient) { var retention = new BucketRetentionRules(BucketRetentionRules.TypeEnum.Expire, (int)_connectionInfo.BucketRetentionPeriod.TotalSeconds); Bucket bucket; try { bucket = createBucketClient .GetBucketsApi() .CreateBucketAsync(_connectionInfo.BucketName, retention, _connectionInfo.OrganizationId) .GetAwaiter().GetResult(); } catch (HttpException ex) { SelfLog.WriteLine($"Error while creating {_connectionInfo.BucketName} (Org: {_connectionInfo.OrganizationId}), Message : {ex.Message}. Check if Token has enough access or set AllAccessToken or is active"); throw new InfluxDbClientCreateBucketException($"Cannot create bucket {_connectionInfo.BucketName}. Check if Token has enough access or set AllAccessToken or is active", ex); } SelfLog.WriteLine($"Bucket {bucket.Name} ({bucket.Id} / Org: {bucket.OrgID}) created at {bucket.CreatedAt}"); return(bucket); }