From 13f7b52ac87708b2532c5f95f842d2751f6c7b56 Mon Sep 17 00:00:00 2001 From: vlastahajek Date: Mon, 10 Aug 2020 13:37:56 +0200 Subject: [PATCH 1/3] chore(APIs): removed deprecated interfaces and methods --- CHANGELOG.md | 4 + api/authorizations_deprecated.go | 83 --- api/buckets_deprecated.go | 166 ------ api/delete_deprecated.go | 51 -- api/http/options_deprecated_test.go | 29 - api/labels_deprecated.go | 98 --- api/organizations_deprecated.go | 191 ------ api/query_deprecated.go | 17 - api/users_deprecated.go | 101 ---- api/write_deprecated.go | 43 -- client.go | 124 +--- client_e2e_deprecated_test.go | 889 ---------------------------- client_test.go | 12 +- options_deprecated_test.go | 93 --- 14 files changed, 15 insertions(+), 1886 deletions(-) delete mode 100644 api/authorizations_deprecated.go delete mode 100644 api/buckets_deprecated.go delete mode 100644 api/delete_deprecated.go delete mode 100644 api/http/options_deprecated_test.go delete mode 100644 api/labels_deprecated.go delete mode 100644 api/organizations_deprecated.go delete mode 100644 api/query_deprecated.go delete mode 100644 api/users_deprecated.go delete mode 100644 api/write_deprecated.go delete mode 100644 client_e2e_deprecated_test.go delete mode 100644 options_deprecated_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index cf0b111f..750239b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ ## 1.5.0 [In progress] +### Breaking changes +1. [#173](https://github.com/influxdata/influxdb-client-go/pull/173) Removed deprecated API. + +### Features 1. [#165](https://github.com/influxdata/influxdb-client-go/pull/165) Allow overriding the http.Client for the http service. ## 1.4.0 [2020-07-17] diff --git a/api/authorizations_deprecated.go b/api/authorizations_deprecated.go deleted file mode 100644 index f979c7d5..00000000 --- a/api/authorizations_deprecated.go +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2020 InfluxData, Inc. All rights reserved. -// Use of this source code is governed by MIT -// license that can be found in the LICENSE file. - -package api - -import ( - "context" - "github.com/influxdata/influxdb-client-go/domain" -) - -//lint:file-ignore ST1003 This is deprecated API to be removed in next release - -// AuthorizationsApi provides methods for organizing Authorization in a InfluxDB server -// Deprecated: Use AuthorizationsAPI instead -type AuthorizationsApi interface { - // GetAuthorizations returns all authorizations - GetAuthorizations(ctx context.Context) (*[]domain.Authorization, error) - // FindAuthorizationsByUserName returns all authorizations for given userName - FindAuthorizationsByUserName(ctx context.Context, userName string) (*[]domain.Authorization, error) - // FindAuthorizationsByUserId returns all authorizations for given userID - FindAuthorizationsByUserId(ctx context.Context, userId string) (*[]domain.Authorization, error) - // FindAuthorizationsByOrgName returns all authorizations for given organization name - FindAuthorizationsByOrgName(ctx context.Context, orgName string) (*[]domain.Authorization, error) - // FindAuthorizationsByUserId returns all authorizations for given organization id - FindAuthorizationsByOrgId(ctx context.Context, orgId string) (*[]domain.Authorization, error) - // CreateAuthorization creates new authorization - CreateAuthorization(ctx context.Context, authorization *domain.Authorization) (*domain.Authorization, error) - // CreateAuthorizationWithOrgId creates new authorization with given permissions scoped to given orgId - CreateAuthorizationWithOrgId(ctx context.Context, orgId string, permissions []domain.Permission) (*domain.Authorization, error) - // UpdateAuthorizationStatus updates status of authorization with authId - UpdateAuthorizationStatus(ctx context.Context, authId string, status domain.AuthorizationUpdateRequestStatus) (*domain.Authorization, error) - // DeleteAuthorization deletes authorization with authId - DeleteAuthorization(ctx context.Context, authId string) error -} - -type authorizationsApiImpl struct { - authorizationsAPI AuthorizationsAPI -} - -// NewAuthorizationsApi creates instance of AuthorizationsApi -// Deprecated: Use NewAuthorizationsAPI instead. -func NewAuthorizationsApi(apiClient *domain.ClientWithResponses) AuthorizationsApi { - return &authorizationsApiImpl{ - authorizationsAPI: NewAuthorizationsAPI(apiClient), - } -} - -func (a *authorizationsApiImpl) GetAuthorizations(ctx context.Context) (*[]domain.Authorization, error) { - return a.authorizationsAPI.GetAuthorizations(ctx) -} - -func (a *authorizationsApiImpl) FindAuthorizationsByUserName(ctx context.Context, userName string) (*[]domain.Authorization, error) { - return a.authorizationsAPI.FindAuthorizationsByUserName(ctx, userName) -} - -func (a *authorizationsApiImpl) FindAuthorizationsByUserId(ctx context.Context, userId string) (*[]domain.Authorization, error) { - return a.authorizationsAPI.FindAuthorizationsByUserID(ctx, userId) -} - -func (a *authorizationsApiImpl) FindAuthorizationsByOrgName(ctx context.Context, orgName string) (*[]domain.Authorization, error) { - return a.authorizationsAPI.FindAuthorizationsByOrgName(ctx, orgName) -} - -func (a *authorizationsApiImpl) FindAuthorizationsByOrgId(ctx context.Context, orgId string) (*[]domain.Authorization, error) { - return a.authorizationsAPI.FindAuthorizationsByOrgID(ctx, orgId) -} - -func (a *authorizationsApiImpl) CreateAuthorization(ctx context.Context, authorization *domain.Authorization) (*domain.Authorization, error) { - return a.authorizationsAPI.CreateAuthorization(ctx, authorization) -} - -func (a *authorizationsApiImpl) CreateAuthorizationWithOrgId(ctx context.Context, orgId string, permissions []domain.Permission) (*domain.Authorization, error) { - return a.authorizationsAPI.CreateAuthorizationWithOrgID(ctx, orgId, permissions) -} - -func (a *authorizationsApiImpl) UpdateAuthorizationStatus(ctx context.Context, authId string, status domain.AuthorizationUpdateRequestStatus) (*domain.Authorization, error) { - return a.authorizationsAPI.UpdateAuthorizationStatusWithID(ctx, authId, status) -} - -func (a *authorizationsApiImpl) DeleteAuthorization(ctx context.Context, authId string) error { - return a.authorizationsAPI.DeleteAuthorizationWithID(ctx, authId) -} diff --git a/api/buckets_deprecated.go b/api/buckets_deprecated.go deleted file mode 100644 index a0545d5e..00000000 --- a/api/buckets_deprecated.go +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2020 InfluxData, Inc. All rights reserved. -// Use of this source code is governed by MIT -// license that can be found in the LICENSE file. - -package api - -import ( - "context" - "github.com/influxdata/influxdb-client-go/domain" -) - -//lint:file-ignore ST1003 This is deprecated API to be removed in next release. - -// BucketsApi provides methods for managing Buckets in a InfluxDB server. -// Deprecated: Use BucketsAPI instead. -type BucketsApi interface { - // GetBuckets returns all buckets, with the specified paging. Empty pagingOptions means the default paging (first 20 results). - GetBuckets(ctx context.Context, pagingOptions ...PagingOption) (*[]domain.Bucket, error) - // FindBucketByName returns a bucket found using bucketName. - FindBucketByName(ctx context.Context, bucketName string) (*domain.Bucket, error) - // FindBucketById returns a bucket found using bucketId. - FindBucketById(ctx context.Context, bucketId string) (*domain.Bucket, error) - // FindBucketsByOrgId returns buckets belonging to the organization with Id orgId, with the specified paging. Empty pagingOptions means the default paging (first 20 results). - FindBucketsByOrgId(ctx context.Context, orgId string, pagingOptions ...PagingOption) (*[]domain.Bucket, error) - // FindBucketsByOrgName returns buckets belonging to the organization with name orgName, with the specified paging. Empty pagingOptions means the default paging (first 20 results). - FindBucketsByOrgName(ctx context.Context, orgName string, pagingOptions ...PagingOption) (*[]domain.Bucket, error) - // CreateBucket creates a new bucket. - CreateBucket(ctx context.Context, bucket *domain.Bucket) (*domain.Bucket, error) - // CreateBucketWithName creates a new bucket with bucketName in organization org, with retention specified in rules. Empty rules means infinite retention. - CreateBucketWithName(ctx context.Context, org *domain.Organization, bucketName string, rules ...domain.RetentionRule) (*domain.Bucket, error) - // CreateBucketWithNameWithId creates a new bucket with bucketName in organization with orgId, with retention specified in rules. Empty rules means infinite retention. - CreateBucketWithNameWithId(ctx context.Context, orgId, bucketName string, rules ...domain.RetentionRule) (*domain.Bucket, error) - // UpdateBucket updates a bucket. - UpdateBucket(ctx context.Context, bucket *domain.Bucket) (*domain.Bucket, error) - // DeleteBucket deletes a bucket. - DeleteBucket(ctx context.Context, bucket *domain.Bucket) error - // DeleteBucketWithId deletes a bucket with bucketId. - DeleteBucketWithId(ctx context.Context, bucketId string) error - // GetMembers returns members of a bucket. - GetMembers(ctx context.Context, bucket *domain.Bucket) (*[]domain.ResourceMember, error) - // GetMembersWithId returns members of a bucket with bucketId. - GetMembersWithId(ctx context.Context, bucketId string) (*[]domain.ResourceMember, error) - // AddMember adds a member to a bucket. - AddMember(ctx context.Context, bucket *domain.Bucket, user *domain.User) (*domain.ResourceMember, error) - // AddMember adds a member with id memberId to a bucket with bucketId. - AddMemberWithId(ctx context.Context, bucketId, memberId string) (*domain.ResourceMember, error) - // RemoveMember removes a member from a bucket. - RemoveMember(ctx context.Context, bucket *domain.Bucket, user *domain.User) error - // RemoveMember removes a member with id memberId from a bucket with bucketId. - RemoveMemberWithId(ctx context.Context, bucketId, memberId string) error - // GetOwners returns owners of a bucket. - GetOwners(ctx context.Context, bucket *domain.Bucket) (*[]domain.ResourceOwner, error) - // GetOwnersWithId returns owners of a bucket with bucketId. - GetOwnersWithId(ctx context.Context, bucketId string) (*[]domain.ResourceOwner, error) - // AddOwner adds an owner to a bucket. - AddOwner(ctx context.Context, bucket *domain.Bucket, user *domain.User) (*domain.ResourceOwner, error) - // AddOwner adds an owner with id memberId to a bucket with bucketId. - AddOwnerWithId(ctx context.Context, bucketId, memberId string) (*domain.ResourceOwner, error) - // RemoveOwner removes an owner from a bucket. - RemoveOwner(ctx context.Context, bucket *domain.Bucket, user *domain.User) error - // RemoveOwner removes a member with id memberId from a bucket with bucketId. - RemoveOwnerWithId(ctx context.Context, bucketId, memberId string) error -} - -type bucketsApiImpl struct { - bucketsAPI BucketsAPI -} - -// NewBucketsApi creates instance of BucketsApi -// Deprecated: Use NewBucketsAPI instead -func NewBucketsApi(apiClient *domain.ClientWithResponses) BucketsApi { - return &bucketsApiImpl{ - bucketsAPI: NewBucketsAPI(apiClient), - } -} - -func (b *bucketsApiImpl) GetBuckets(ctx context.Context, pagingOptions ...PagingOption) (*[]domain.Bucket, error) { - return b.bucketsAPI.GetBuckets(ctx, pagingOptions...) -} - -func (b *bucketsApiImpl) FindBucketByName(ctx context.Context, bucketName string) (*domain.Bucket, error) { - return b.bucketsAPI.FindBucketByName(ctx, bucketName) -} - -func (b *bucketsApiImpl) FindBucketById(ctx context.Context, bucketId string) (*domain.Bucket, error) { - return b.bucketsAPI.FindBucketByID(ctx, bucketId) -} - -func (b *bucketsApiImpl) FindBucketsByOrgId(ctx context.Context, orgId string, pagingOptions ...PagingOption) (*[]domain.Bucket, error) { - return b.bucketsAPI.FindBucketsByOrgID(ctx, orgId, pagingOptions...) -} - -func (b *bucketsApiImpl) FindBucketsByOrgName(ctx context.Context, orgName string, pagingOptions ...PagingOption) (*[]domain.Bucket, error) { - return b.bucketsAPI.FindBucketsByOrgName(ctx, orgName, pagingOptions...) -} - -func (b *bucketsApiImpl) CreateBucket(ctx context.Context, bucket *domain.Bucket) (*domain.Bucket, error) { - return b.bucketsAPI.CreateBucket(ctx, bucket) -} - -func (b *bucketsApiImpl) CreateBucketWithNameWithId(ctx context.Context, orgId, bucketName string, rules ...domain.RetentionRule) (*domain.Bucket, error) { - return b.bucketsAPI.CreateBucketWithNameWithID(ctx, orgId, bucketName, rules...) -} -func (b *bucketsApiImpl) CreateBucketWithName(ctx context.Context, org *domain.Organization, bucketName string, rules ...domain.RetentionRule) (*domain.Bucket, error) { - return b.bucketsAPI.CreateBucketWithName(ctx, org, bucketName, rules...) -} - -func (b *bucketsApiImpl) DeleteBucket(ctx context.Context, bucket *domain.Bucket) error { - return b.bucketsAPI.DeleteBucket(ctx, bucket) -} - -func (b *bucketsApiImpl) DeleteBucketWithId(ctx context.Context, bucketId string) error { - return b.bucketsAPI.DeleteBucketWithID(ctx, bucketId) -} - -func (b *bucketsApiImpl) UpdateBucket(ctx context.Context, bucket *domain.Bucket) (*domain.Bucket, error) { - return b.bucketsAPI.UpdateBucket(ctx, bucket) -} - -func (b *bucketsApiImpl) GetMembers(ctx context.Context, bucket *domain.Bucket) (*[]domain.ResourceMember, error) { - return b.bucketsAPI.GetMembers(ctx, bucket) -} - -func (b *bucketsApiImpl) GetMembersWithId(ctx context.Context, bucketId string) (*[]domain.ResourceMember, error) { - return b.bucketsAPI.GetMembersWithID(ctx, bucketId) -} - -func (b *bucketsApiImpl) AddMember(ctx context.Context, bucket *domain.Bucket, user *domain.User) (*domain.ResourceMember, error) { - return b.bucketsAPI.AddMember(ctx, bucket, user) -} - -func (b *bucketsApiImpl) AddMemberWithId(ctx context.Context, bucketId, memberId string) (*domain.ResourceMember, error) { - return b.bucketsAPI.AddMemberWithID(ctx, bucketId, memberId) -} - -func (b *bucketsApiImpl) RemoveMember(ctx context.Context, bucket *domain.Bucket, user *domain.User) error { - return b.bucketsAPI.RemoveMember(ctx, bucket, user) -} - -func (b *bucketsApiImpl) RemoveMemberWithId(ctx context.Context, bucketId, memberId string) error { - return b.bucketsAPI.RemoveMemberWithID(ctx, bucketId, memberId) -} - -func (b *bucketsApiImpl) GetOwners(ctx context.Context, bucket *domain.Bucket) (*[]domain.ResourceOwner, error) { - return b.bucketsAPI.GetOwners(ctx, bucket) -} - -func (b *bucketsApiImpl) GetOwnersWithId(ctx context.Context, bucketId string) (*[]domain.ResourceOwner, error) { - return b.bucketsAPI.GetOwnersWithID(ctx, bucketId) -} - -func (b *bucketsApiImpl) AddOwner(ctx context.Context, bucket *domain.Bucket, user *domain.User) (*domain.ResourceOwner, error) { - return b.bucketsAPI.AddOwner(ctx, bucket, user) -} - -func (b *bucketsApiImpl) AddOwnerWithId(ctx context.Context, bucketId, ownerId string) (*domain.ResourceOwner, error) { - return b.bucketsAPI.AddOwnerWithID(ctx, bucketId, ownerId) -} - -func (b *bucketsApiImpl) RemoveOwner(ctx context.Context, bucket *domain.Bucket, user *domain.User) error { - return b.bucketsAPI.RemoveOwner(ctx, bucket, user) -} - -func (b *bucketsApiImpl) RemoveOwnerWithId(ctx context.Context, bucketId, memberId string) error { - return b.bucketsAPI.RemoveMemberWithID(ctx, bucketId, memberId) -} diff --git a/api/delete_deprecated.go b/api/delete_deprecated.go deleted file mode 100644 index 8cc4a19b..00000000 --- a/api/delete_deprecated.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2020 InfluxData, Inc. All rights reserved. -// Use of this source code is governed by MIT -// license that can be found in the LICENSE file. - -package api - -import ( - "context" - "github.com/influxdata/influxdb-client-go/domain" - "time" -) - -//lint:file-ignore ST1003 This is deprecated API to be removed in next release. - -// DeleteApi provides methods for deleting time series data from buckets. -// Deleted series are selected by the time range specified by start and stop arguments and optional predicate string which contains condition for selecting data for deletion, such as: -// tag1="value1" and (tag2="value2" and tag3!="value3"). Empty predicate string means all data from the given time range will be deleted. See https://v2.docs.influxdata.com/v2.0/reference/syntax/delete-predicate/ -// for more info about predicate syntax. -// Deprecated: Use DeleteAPI instead. -type DeleteApi interface { - // Delete deletes series selected by by the time range specified by start and stop arguments and optional predicate string from the bucket bucket belonging to the organization org. - Delete(ctx context.Context, org *domain.Organization, bucket *domain.Bucket, start, stop time.Time, predicate string) error - // Delete deletes series selected by by the time range specified by start and stop arguments and optional predicate string from the bucket with Id bucketId belonging to the organization with Id orgId. - DeleteWithId(ctx context.Context, orgId, bucketId string, start, stop time.Time, predicate string) error - // Delete deletes series selected by by the time range specified by start and stop arguments and optional predicate string from the bucket with name bucketName belonging to the organization with name orgName. - DeleteWithName(ctx context.Context, orgName, bucketName string, start, stop time.Time, predicate string) error -} - -type deleteApiImpl struct { - deleteAPI DeleteAPI -} - -// NewDeleteApi creates instance of DeleteApi -// Deprecated: Use NewDeleteAPI instead -func NewDeleteApi(apiClient *domain.ClientWithResponses) DeleteApi { - return &deleteApiImpl{ - deleteAPI: NewDeleteAPI(apiClient), - } -} - -func (d *deleteApiImpl) Delete(ctx context.Context, org *domain.Organization, bucket *domain.Bucket, start, stop time.Time, predicate string) error { - return d.deleteAPI.Delete(ctx, org, bucket, start, stop, predicate) -} - -func (d *deleteApiImpl) DeleteWithId(ctx context.Context, orgId, bucketId string, start, stop time.Time, predicate string) error { - return d.deleteAPI.DeleteWithID(ctx, orgId, bucketId, start, stop, predicate) -} - -func (d *deleteApiImpl) DeleteWithName(ctx context.Context, orgName, bucketName string, start, stop time.Time, predicate string) error { - return d.deleteAPI.DeleteWithName(ctx, orgName, bucketName, start, stop, predicate) -} diff --git a/api/http/options_deprecated_test.go b/api/http/options_deprecated_test.go deleted file mode 100644 index a0e2afb2..00000000 --- a/api/http/options_deprecated_test.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020 InfluxData, Inc. All rights reserved. -// Use of this source code is governed by MIT -// license that can be found in the LICENSE file. - -package http_test - -import ( - "crypto/tls" - "github.com/influxdata/influxdb-client-go/api/http" - "github.com/stretchr/testify/assert" - "testing" -) - -func TestDefaultOptionsDeprecated(t *testing.T) { - opts := http.DefaultOptions() - assert.Equal(t, (*tls.Config)(nil), opts.TlsConfig()) - assert.Equal(t, uint(20), opts.HttpRequestTimeout()) -} - -func TestOptionsSettingDeprecated(t *testing.T) { - tlsConfig := &tls.Config{ - InsecureSkipVerify: true, - } - opts := http.DefaultOptions(). - SetTlsConfig(tlsConfig). - SetHttpRequestTimeout(50) - assert.Equal(t, tlsConfig, opts.TlsConfig()) - assert.Equal(t, uint(50), opts.HttpRequestTimeout()) -} diff --git a/api/labels_deprecated.go b/api/labels_deprecated.go deleted file mode 100644 index 4ccfc13e..00000000 --- a/api/labels_deprecated.go +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2020 InfluxData, Inc. All rights reserved. -// Use of this source code is governed by MIT -// license that can be found in the LICENSE file. - -package api - -import ( - "context" - "github.com/influxdata/influxdb-client-go/domain" -) - -//lint:file-ignore ST1003 This is deprecated API to be removed in next release. - -// LabelsApi provides methods for managing labels in a InfluxDB server. -// Deprecated: Use LabelsAPI instead. -type LabelsApi interface { - // GetLabels returns all labels. - GetLabels(ctx context.Context) (*[]domain.Label, error) - // FindLabelsByOrg returns labels belonging to organization org. - FindLabelsByOrg(ctx context.Context, org *domain.Organization) (*[]domain.Label, error) - // FindLabelsByOrgId returns labels belonging to organization with id orgId. - FindLabelsByOrgId(ctx context.Context, orgID string) (*[]domain.Label, error) - // FindLabelById returns a label with labelID. - FindLabelById(ctx context.Context, labelID string) (*domain.Label, error) - // FindLabelByName returns a label with name labelName under an organization orgId. - FindLabelByName(ctx context.Context, orgId, labelName string) (*domain.Label, error) - // CreateLabel creates a new label. - CreateLabel(ctx context.Context, label *domain.LabelCreateRequest) (*domain.Label, error) - // CreateLabelWithName creates a new label with label labelName and properties, under the organization org. - // Properties example: {"color": "ffb3b3", "description": "this is a description"}. - CreateLabelWithName(ctx context.Context, org *domain.Organization, labelName string, properties map[string]string) (*domain.Label, error) - // CreateLabelWithName creates a new label with label labelName and properties, under the organization with id orgId. - // Properties example: {"color": "ffb3b3", "description": "this is a description"}. - CreateLabelWithNameWithId(ctx context.Context, orgId, labelName string, properties map[string]string) (*domain.Label, error) - // UpdateLabel updates the label. - // Properties can be removed by sending an update with an empty value. - UpdateLabel(ctx context.Context, label *domain.Label) (*domain.Label, error) - // DeleteLabelWithId deletes a label with labelId. - DeleteLabelWithId(ctx context.Context, labelID string) error - // DeleteLabel deletes a label. - DeleteLabel(ctx context.Context, label *domain.Label) error -} - -type labelsApiImpl struct { - labelsAPI LabelsAPI -} - -// NewLabelsApi creates instance of LabelsApi -// Deprecated: use NewLabelsAPI instead. -func NewLabelsApi(apiClient *domain.ClientWithResponses) LabelsApi { - return &labelsApiImpl{ - labelsAPI: NewLabelsAPI(apiClient), - } -} - -func (l *labelsApiImpl) GetLabels(ctx context.Context) (*[]domain.Label, error) { - return l.labelsAPI.GetLabels(ctx) -} - -func (l *labelsApiImpl) FindLabelsByOrg(ctx context.Context, org *domain.Organization) (*[]domain.Label, error) { - return l.labelsAPI.FindLabelsByOrg(ctx, org) -} - -func (l *labelsApiImpl) FindLabelsByOrgId(ctx context.Context, orgID string) (*[]domain.Label, error) { - return l.labelsAPI.FindLabelsByOrgID(ctx, orgID) -} - -func (l *labelsApiImpl) FindLabelById(ctx context.Context, labelID string) (*domain.Label, error) { - return l.labelsAPI.FindLabelByID(ctx, labelID) -} - -func (l *labelsApiImpl) FindLabelByName(ctx context.Context, orgId, labelName string) (*domain.Label, error) { - return l.labelsAPI.FindLabelByName(ctx, orgId, labelName) -} - -func (l *labelsApiImpl) CreateLabelWithName(ctx context.Context, org *domain.Organization, labelName string, properties map[string]string) (*domain.Label, error) { - return l.labelsAPI.CreateLabelWithName(ctx, org, labelName, properties) -} - -func (l *labelsApiImpl) CreateLabelWithNameWithId(ctx context.Context, orgId, labelName string, properties map[string]string) (*domain.Label, error) { - return l.labelsAPI.CreateLabelWithNameWithID(ctx, orgId, labelName, properties) -} - -func (l *labelsApiImpl) CreateLabel(ctx context.Context, label *domain.LabelCreateRequest) (*domain.Label, error) { - return l.labelsAPI.CreateLabel(ctx, label) -} - -func (l *labelsApiImpl) UpdateLabel(ctx context.Context, label *domain.Label) (*domain.Label, error) { - return l.labelsAPI.UpdateLabel(ctx, label) -} - -func (l *labelsApiImpl) DeleteLabel(ctx context.Context, label *domain.Label) error { - return l.labelsAPI.DeleteLabel(ctx, label) -} - -func (l *labelsApiImpl) DeleteLabelWithId(ctx context.Context, labelID string) error { - return l.labelsAPI.DeleteLabelWithID(ctx, labelID) -} diff --git a/api/organizations_deprecated.go b/api/organizations_deprecated.go deleted file mode 100644 index 22dcef0d..00000000 --- a/api/organizations_deprecated.go +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright 2020 InfluxData, Inc. All rights reserved. -// Use of this source code is governed by MIT -// license that can be found in the LICENSE file. - -package api - -import ( - "context" - "github.com/influxdata/influxdb-client-go/domain" -) - -//lint:file-ignore ST1003 This is deprecated API to be removed in next release. - -// OrganizationsApi provides methods for managing Organizations in a InfluxDB server. -// Deprecated: Use OrganizationsAPI instead. -type OrganizationsApi interface { - // GetOrganizations returns all organizations. - GetOrganizations(ctx context.Context) (*[]domain.Organization, error) - // FindOrganizationByName returns an organization found using orgName. - FindOrganizationByName(ctx context.Context, orgName string) (*domain.Organization, error) - // FindOrganizationById returns an organization found using orgId. - FindOrganizationById(ctx context.Context, orgId string) (*domain.Organization, error) - // FindOrganizationsByUserId returns organizations an user with userID belongs to. - FindOrganizationsByUserId(ctx context.Context, userID string) (*[]domain.Organization, error) - // CreateOrganization creates new organization. - CreateOrganization(ctx context.Context, org *domain.Organization) (*domain.Organization, error) - // CreateOrganizationWithName creates new organization with orgName and with status active. - CreateOrganizationWithName(ctx context.Context, orgName string) (*domain.Organization, error) - // UpdateOrganization updates organization. - UpdateOrganization(ctx context.Context, org *domain.Organization) (*domain.Organization, error) - // DeleteOrganization deletes an organization. - DeleteOrganization(ctx context.Context, org *domain.Organization) error - // DeleteOrganizationWithId deletes an organization with orgId. - DeleteOrganizationWithId(ctx context.Context, orgId string) error - // GetMembers returns members of an organization. - GetMembers(ctx context.Context, org *domain.Organization) (*[]domain.ResourceMember, error) - // GetMembersWithId returns members of an organization with orgId. - GetMembersWithId(ctx context.Context, orgId string) (*[]domain.ResourceMember, error) - // AddMember adds a member to an organization. - AddMember(ctx context.Context, org *domain.Organization, user *domain.User) (*domain.ResourceMember, error) - // AddMemberWithId adds a member with id memberId to an organization with orgId. - AddMemberWithId(ctx context.Context, orgId, memberId string) (*domain.ResourceMember, error) - // RemoveMember removes a member from an organization. - RemoveMember(ctx context.Context, org *domain.Organization, user *domain.User) error - // RemoveMemberWithId removes a member with id memberId from an organization with orgId. - RemoveMemberWithId(ctx context.Context, orgId, memberId string) error - // GetOwners returns owners of an organization. - GetOwners(ctx context.Context, org *domain.Organization) (*[]domain.ResourceOwner, error) - // GetOwnersWithId returns owners of an organization with orgId. - GetOwnersWithId(ctx context.Context, orgId string) (*[]domain.ResourceOwner, error) - // AddOwner adds an owner to an organization. - AddOwner(ctx context.Context, org *domain.Organization, user *domain.User) (*domain.ResourceOwner, error) - // AddOwnerWithId adds an owner with id memberId to an organization with orgId. - AddOwnerWithId(ctx context.Context, orgId, memberId string) (*domain.ResourceOwner, error) - // RemoveOwner removes an owner from an organization. - RemoveOwner(ctx context.Context, org *domain.Organization, user *domain.User) error - // RemoveOwnerWithId removes an owner with id memberId from an organization with orgId. - RemoveOwnerWithId(ctx context.Context, orgId, memberId string) error - // GetLabels returns labels of an organization. - GetLabels(ctx context.Context, org *domain.Organization) (*[]domain.Label, error) - // GetLabelsWithId returns labels of an organization with orgId. - GetLabelsWithId(ctx context.Context, orgId string) (*[]domain.Label, error) - // AddLabel adds a label to an organization. - AddLabel(ctx context.Context, org *domain.Organization, label *domain.Label) (*domain.Label, error) - // AddLabelWithId adds a label with id labelId to an organization with orgId. - AddLabelWithId(ctx context.Context, orgId, labelId string) (*domain.Label, error) - // RemoveLabel removes an label from an organization. - RemoveLabel(ctx context.Context, org *domain.Organization, label *domain.Label) error - // RemoveLabelWithId removes an label with id labelId from an organization with orgId. - RemoveLabelWithId(ctx context.Context, orgId, labelId string) error -} - -type organizationsApiImpl struct { - organizationsAPI OrganizationsAPI -} - -// NewOrganizationsApi creates instance of OrganizationsApi -// Deprecated: use NewOrganizationsAPI instead. -func NewOrganizationsApi(apiClient *domain.ClientWithResponses) OrganizationsApi { - return &organizationsApiImpl{ - organizationsAPI: NewOrganizationsAPI(apiClient), - } -} - -func (o *organizationsApiImpl) GetOrganizations(ctx context.Context) (*[]domain.Organization, error) { - return o.organizationsAPI.GetOrganizations(ctx) -} - -func (o *organizationsApiImpl) FindOrganizationByName(ctx context.Context, orgName string) (*domain.Organization, error) { - return o.organizationsAPI.FindOrganizationByName(ctx, orgName) -} - -func (o *organizationsApiImpl) FindOrganizationById(ctx context.Context, orgId string) (*domain.Organization, error) { - return o.organizationsAPI.FindOrganizationByID(ctx, orgId) -} - -func (o *organizationsApiImpl) FindOrganizationsByUserId(ctx context.Context, userID string) (*[]domain.Organization, error) { - return o.organizationsAPI.FindOrganizationsByUserID(ctx, userID) -} - -func (o *organizationsApiImpl) CreateOrganization(ctx context.Context, org *domain.Organization) (*domain.Organization, error) { - return o.organizationsAPI.CreateOrganization(ctx, org) -} - -func (o *organizationsApiImpl) CreateOrganizationWithName(ctx context.Context, orgName string) (*domain.Organization, error) { - return o.organizationsAPI.CreateOrganizationWithName(ctx, orgName) -} - -func (o *organizationsApiImpl) DeleteOrganization(ctx context.Context, org *domain.Organization) error { - return o.organizationsAPI.DeleteOrganization(ctx, org) -} - -func (o *organizationsApiImpl) DeleteOrganizationWithId(ctx context.Context, orgId string) error { - return o.organizationsAPI.DeleteOrganizationWithID(ctx, orgId) -} - -func (o *organizationsApiImpl) UpdateOrganization(ctx context.Context, org *domain.Organization) (*domain.Organization, error) { - return o.organizationsAPI.UpdateOrganization(ctx, org) -} - -func (o *organizationsApiImpl) GetMembers(ctx context.Context, org *domain.Organization) (*[]domain.ResourceMember, error) { - return o.organizationsAPI.GetMembers(ctx, org) -} - -func (o *organizationsApiImpl) GetMembersWithId(ctx context.Context, orgId string) (*[]domain.ResourceMember, error) { - return o.organizationsAPI.GetMembersWithID(ctx, orgId) -} - -func (o *organizationsApiImpl) AddMember(ctx context.Context, org *domain.Organization, user *domain.User) (*domain.ResourceMember, error) { - return o.organizationsAPI.AddMember(ctx, org, user) -} - -func (o *organizationsApiImpl) AddMemberWithId(ctx context.Context, orgId, memberId string) (*domain.ResourceMember, error) { - return o.organizationsAPI.AddMemberWithID(ctx, orgId, memberId) -} - -func (o *organizationsApiImpl) RemoveMember(ctx context.Context, org *domain.Organization, user *domain.User) error { - return o.organizationsAPI.RemoveMember(ctx, org, user) -} - -func (o *organizationsApiImpl) RemoveMemberWithId(ctx context.Context, orgId, memberId string) error { - return o.organizationsAPI.RemoveMemberWithID(ctx, orgId, memberId) -} - -func (o *organizationsApiImpl) GetOwners(ctx context.Context, org *domain.Organization) (*[]domain.ResourceOwner, error) { - return o.organizationsAPI.GetOwners(ctx, org) -} - -func (o *organizationsApiImpl) GetOwnersWithId(ctx context.Context, orgId string) (*[]domain.ResourceOwner, error) { - return o.organizationsAPI.GetOwnersWithID(ctx, orgId) -} - -func (o *organizationsApiImpl) AddOwner(ctx context.Context, org *domain.Organization, user *domain.User) (*domain.ResourceOwner, error) { - return o.organizationsAPI.AddOwner(ctx, org, user) -} - -func (o *organizationsApiImpl) AddOwnerWithId(ctx context.Context, orgId, ownerId string) (*domain.ResourceOwner, error) { - return o.organizationsAPI.AddOwnerWithID(ctx, orgId, ownerId) -} - -func (o *organizationsApiImpl) RemoveOwner(ctx context.Context, org *domain.Organization, user *domain.User) error { - return o.organizationsAPI.RemoveOwner(ctx, org, user) -} - -func (o *organizationsApiImpl) RemoveOwnerWithId(ctx context.Context, orgId, memberId string) error { - return o.organizationsAPI.RemoveMemberWithID(ctx, orgId, memberId) -} - -func (o *organizationsApiImpl) GetLabels(ctx context.Context, org *domain.Organization) (*[]domain.Label, error) { - return o.organizationsAPI.GetLabels(ctx, org) -} - -func (o *organizationsApiImpl) GetLabelsWithId(ctx context.Context, orgId string) (*[]domain.Label, error) { - return o.organizationsAPI.GetLabelsWithID(ctx, orgId) -} - -func (o *organizationsApiImpl) AddLabel(ctx context.Context, org *domain.Organization, label *domain.Label) (*domain.Label, error) { - return o.organizationsAPI.AddLabel(ctx, org, label) -} - -func (o *organizationsApiImpl) AddLabelWithId(ctx context.Context, orgId, labelId string) (*domain.Label, error) { - return o.organizationsAPI.AddLabelWithID(ctx, orgId, labelId) -} - -func (o *organizationsApiImpl) RemoveLabel(ctx context.Context, org *domain.Organization, label *domain.Label) error { - return o.organizationsAPI.RemoveLabel(ctx, org, label) -} - -func (o *organizationsApiImpl) RemoveLabelWithId(ctx context.Context, orgId, memberId string) error { - return o.organizationsAPI.RemoveLabelWithID(ctx, orgId, memberId) -} diff --git a/api/query_deprecated.go b/api/query_deprecated.go deleted file mode 100644 index f28fc23e..00000000 --- a/api/query_deprecated.go +++ /dev/null @@ -1,17 +0,0 @@ -package api - -import ( - "context" - "github.com/influxdata/influxdb-client-go/domain" -) - -//lint:file-ignore ST1003 This is deprecated API to be removed in next release. - -// QueryApi provides methods for performing synchronously flux query against InfluxDB server. -// Deprecated: Use QueryAPI instead. -type QueryApi interface { - // QueryRaw executes flux query on the InfluxDB server and returns complete query result as a string with table annotations according to dialect - QueryRaw(ctx context.Context, query string, dialect *domain.Dialect) (string, error) - // Query executes flux query on the InfluxDB server and returns QueryTableResult which parses streamed response into structures representing flux table parts - Query(ctx context.Context, query string) (*QueryTableResult, error) -} diff --git a/api/users_deprecated.go b/api/users_deprecated.go deleted file mode 100644 index 5698be90..00000000 --- a/api/users_deprecated.go +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2020 InfluxData, Inc. All rights reserved. -// Use of this source code is governed by MIT -// license that can be found in the LICENSE file. - -package api - -import ( - "context" - "github.com/influxdata/influxdb-client-go/domain" -) - -//lint:file-ignore ST1003 This is deprecated API to be removed in next release. - -// UsersApi provides methods for managing users in a InfluxDB server. -// Deprecated: use UsersAPI instead. -type UsersApi interface { - // GetUsers returns all users - GetUsers(ctx context.Context) (*[]domain.User, error) - // FindUserById returns user with userID - FindUserById(ctx context.Context, userID string) (*domain.User, error) - // FindUserByName returns user with name userName - FindUserByName(ctx context.Context, userName string) (*domain.User, error) - // CreateUser creates new user - CreateUser(ctx context.Context, user *domain.User) (*domain.User, error) - // CreateUserWithName creates new user with userName - CreateUserWithName(ctx context.Context, userName string) (*domain.User, error) - // UpdateUser updates user - UpdateUser(ctx context.Context, user *domain.User) (*domain.User, error) - // UpdateUserPassword sets password for an user - UpdateUserPassword(ctx context.Context, user *domain.User, password string) error - // UpdateUserPasswordWithId sets password for an user with userId - UpdateUserPasswordWithId(ctx context.Context, userID string, password string) error - // DeleteUserWithId deletes an user with userId - DeleteUserWithId(ctx context.Context, userID string) error - // DeleteUser deletes an user - DeleteUser(ctx context.Context, user *domain.User) error - // Me returns actual user - Me(ctx context.Context) (*domain.User, error) - // MeUpdatePassword set password of actual user - MeUpdatePassword(ctx context.Context, password string) error -} - -type usersApiImpl struct { - usersAPI UsersAPI -} - -// NewUsersApi creates instance of UsersApi -// Deprecated: use NewUsersAPI instead. -func NewUsersApi(apiClient *domain.ClientWithResponses) UsersApi { - return &usersApiImpl{ - usersAPI: NewUsersAPI(apiClient), - } -} - -func (u *usersApiImpl) GetUsers(ctx context.Context) (*[]domain.User, error) { - return u.usersAPI.GetUsers(ctx) -} - -func (u *usersApiImpl) FindUserById(ctx context.Context, userID string) (*domain.User, error) { - return u.usersAPI.FindUserByID(ctx, userID) -} - -func (u *usersApiImpl) FindUserByName(ctx context.Context, userName string) (*domain.User, error) { - return u.usersAPI.FindUserByName(ctx, userName) -} - -func (u *usersApiImpl) CreateUserWithName(ctx context.Context, userName string) (*domain.User, error) { - return u.usersAPI.CreateUserWithName(ctx, userName) -} - -func (u *usersApiImpl) CreateUser(ctx context.Context, user *domain.User) (*domain.User, error) { - return u.usersAPI.CreateUser(ctx, user) -} - -func (u *usersApiImpl) UpdateUser(ctx context.Context, user *domain.User) (*domain.User, error) { - return u.usersAPI.UpdateUser(ctx, user) -} - -func (u *usersApiImpl) UpdateUserPassword(ctx context.Context, user *domain.User, password string) error { - return u.usersAPI.UpdateUserPassword(ctx, user, password) -} - -func (u *usersApiImpl) UpdateUserPasswordWithId(ctx context.Context, userID string, password string) error { - return u.usersAPI.UpdateUserPasswordWithID(ctx, userID, password) -} - -func (u *usersApiImpl) DeleteUser(ctx context.Context, user *domain.User) error { - return u.usersAPI.DeleteUser(ctx, user) -} - -func (u *usersApiImpl) DeleteUserWithId(ctx context.Context, userID string) error { - return u.usersAPI.DeleteUserWithID(ctx, userID) -} - -func (u *usersApiImpl) Me(ctx context.Context) (*domain.User, error) { - return u.usersAPI.Me(ctx) -} - -func (u *usersApiImpl) MeUpdatePassword(ctx context.Context, password string) error { - return u.usersAPI.MeUpdatePassword(ctx, password) -} diff --git a/api/write_deprecated.go b/api/write_deprecated.go deleted file mode 100644 index 99bcd80e..00000000 --- a/api/write_deprecated.go +++ /dev/null @@ -1,43 +0,0 @@ -package api - -import ( - "context" - - "github.com/influxdata/influxdb-client-go/api/write" -) - -//lint:file-ignore ST1003 This is deprecated API to be removed in next release. - -// WriteApi is Write client interface with non-blocking methods for writing time series data asynchronously in batches into an InfluxDB server. -// Deprecated: Use WriteAPI instead. -type WriteApi interface { - // WriteRecord writes asynchronously line protocol record into bucket. - // WriteRecord adds record into the buffer which is sent on the background when it reaches the batch size. - // Blocking alternative is available in the WriteApiBlocking interface - WriteRecord(line string) - // WritePoint writes asynchronously Point into bucket. - // WritePoint adds Point into the buffer which is sent on the background when it reaches the batch size. - // Blocking alternative is available in the WriteApiBlocking interface - WritePoint(point *write.Point) - // Flush forces all pending writes from the buffer to be sent - Flush() - // Flushes all pending writes and stop async processes. After this the Write client cannot be used - Close() - // Errors returns a channel for reading errors which occurs during async writes. - // Must be called before performing any writes for errors to be collected. - // The chan is unbuffered and must be drained or the writer will block. - Errors() <-chan error -} - -// WriteApiBlocking offers blocking methods for writing time series data synchronously into an InfluxDB server. -// Deprecated: use WriteAPIBlocking instead. -type WriteApiBlocking interface { - // WriteRecord writes line protocol record(s) into bucket. - // WriteRecord writes without implicit batching. Batch is created from given number of records - // Non-blocking alternative is available in the WriteApi interface - WriteRecord(ctx context.Context, line ...string) error - // WritePoint data point into bucket. - // WritePoint writes without implicit batching. Batch is created from given number of points - // Non-blocking alternative is available in the WriteApi interface - WritePoint(ctx context.Context, point ...*write.Point) error -} diff --git a/client.go b/client.go index 8853d432..6a3ce32c 100644 --- a/client.go +++ b/client.go @@ -43,49 +43,22 @@ type Client interface { ServerUrl() string // WriteAPI returns the asynchronous, non-blocking, Write client WriteAPI(org, bucket string) api.WriteAPI - // WriteApi returns the asynchronous, non-blocking, Write client - // Deprecated: Use WriteAPI instead - WriteApi(org, bucket string) api.WriteApi // WriteAPIBlocking returns the synchronous, blocking, Write client WriteAPIBlocking(org, bucket string) api.WriteAPIBlocking - // WriteApi returns the synchronous, blocking, Write client. - // Deprecated: Use WriteAPIBlocking instead. - WriteApiBlocking(org, bucket string) api.WriteApiBlocking // QueryAPI returns Query client QueryAPI(org string) api.QueryAPI - // QueryApi returns Query client - // Deprecated: Use QueryAPI instead. - QueryApi(org string) api.QueryApi // AuthorizationsAPI returns Authorizations API client. AuthorizationsAPI() api.AuthorizationsAPI - // AuthorizationsApi returns Authorizations API client. - // Deprecated: Use AuthorizationsAPI instead. - AuthorizationsApi() api.AuthorizationsApi // OrganizationsAPI returns Organizations API client OrganizationsAPI() api.OrganizationsAPI - // OrganizationsApi returns Organizations API client. - // Deprecated: Use OrganizationsAPI instead. - OrganizationsApi() api.OrganizationsApi // UsersAPI returns Users API client. UsersAPI() api.UsersAPI - // UsersApi returns Users API client. - // Deprecated: Use UsersAPI instead. - UsersApi() api.UsersApi // DeleteAPI returns Delete API client DeleteAPI() api.DeleteAPI - // DeleteApi returns Delete API client. - // Deprecated: Use DeleteAPI instead. - DeleteApi() api.DeleteApi // BucketsAPI returns Buckets API client BucketsAPI() api.BucketsAPI - // BucketsApi returns Buckets API client. - // Deprecated: Use BucketsAPI instead. - BucketsApi() api.BucketsApi // LabelsAPI returns Labels API client LabelsAPI() api.LabelsAPI - // LabelsApi returns Labels API client; - // Deprecated: Use LabelsAPI instead. - LabelsApi() api.LabelsApi } // clientImpl implements Client interface @@ -97,23 +70,11 @@ type clientImpl struct { httpService ihttp.Service apiClient *domain.ClientWithResponses authAPI api.AuthorizationsAPI - //lint:ignore ST1003 Field for deprecated API to be removed in the next release - authApi api.AuthorizationsApi - orgAPI api.OrganizationsAPI - //lint:ignore ST1003 Field for deprecated API to be removed in the next release - orgApi api.OrganizationsApi - //lint:ignore ST1003 Field for deprecated API to be removed in the next release - usersApi api.UsersApi - usersAPI api.UsersAPI - deleteAPI api.DeleteAPI - //lint:ignore ST1003 Field for deprecated API to be removed in the next release - deleteApi api.DeleteApi - bucketsAPI api.BucketsAPI - //lint:ignore ST1003 Field for deprecated API to be removed in the next release - bucketsApi api.BucketsApi - //lint:ignore ST1003 Field for deprecated API to be removed in the next release - labelsApi api.LabelsApi - labelsAPI api.LabelsAPI + orgAPI api.OrganizationsAPI + usersAPI api.UsersAPI + deleteAPI api.DeleteAPI + bucketsAPI api.BucketsAPI + labelsAPI api.LabelsAPI } // NewClient creates Client for connecting to given serverURL with provided authentication token, with the default options. @@ -212,22 +173,12 @@ func (c *clientImpl) Health(ctx context.Context) (*domain.HealthCheck, error) { return response.JSON200, nil } -//lint:ignore ST1003 Deprecated method to be removed in the next release -func (c *clientImpl) WriteApi(org, bucket string) api.WriteApi { - return c.WriteAPI(org, bucket) -} - func (c *clientImpl) WriteAPI(org, bucket string) api.WriteAPI { w := api.NewWriteAPI(org, bucket, c.httpService, c.options.writeOptions) c.writeAPIs = append(c.writeAPIs, w) return w } -//lint:ignore ST1003 Deprecated method to be removed in the next release -func (c *clientImpl) WriteApiBlocking(org, bucket string) api.WriteApiBlocking { - return c.WriteAPIBlocking(org, bucket) -} - func (c *clientImpl) WriteAPIBlocking(org, bucket string) api.WriteAPIBlocking { w := api.NewWriteAPIBlocking(org, bucket, c.httpService, c.options.writeOptions) return w @@ -243,11 +194,6 @@ func (c *clientImpl) QueryAPI(org string) api.QueryAPI { return api.NewQueryAPI(org, c.httpService) } -//lint:ignore ST1003 Deprecated method to be removed in the next release -func (c *clientImpl) QueryApi(org string) api.QueryApi { - return c.QueryAPI(org) -} - func (c *clientImpl) AuthorizationsAPI() api.AuthorizationsAPI { c.lock.Lock() defer c.lock.Unlock() @@ -257,16 +203,6 @@ func (c *clientImpl) AuthorizationsAPI() api.AuthorizationsAPI { return c.authAPI } -//lint:ignore ST1003 Deprecated method to be removed in the next release -func (c *clientImpl) AuthorizationsApi() api.AuthorizationsApi { - c.lock.Lock() - defer c.lock.Unlock() - if c.authApi == nil { - c.authApi = api.NewAuthorizationsApi(c.apiClient) - } - return c.authApi -} - func (c *clientImpl) OrganizationsAPI() api.OrganizationsAPI { c.lock.Lock() defer c.lock.Unlock() @@ -276,16 +212,6 @@ func (c *clientImpl) OrganizationsAPI() api.OrganizationsAPI { return c.orgAPI } -//lint:ignore ST1003 Deprecated method to be removed in the next release -func (c *clientImpl) OrganizationsApi() api.OrganizationsApi { - c.lock.Lock() - defer c.lock.Unlock() - if c.orgApi == nil { - c.orgApi = api.NewOrganizationsApi(c.apiClient) - } - return c.orgApi -} - func (c *clientImpl) UsersAPI() api.UsersAPI { c.lock.Lock() defer c.lock.Unlock() @@ -295,16 +221,6 @@ func (c *clientImpl) UsersAPI() api.UsersAPI { return c.usersAPI } -//lint:ignore ST1003 Deprecated method to be removed in the next release -func (c *clientImpl) UsersApi() api.UsersApi { - c.lock.Lock() - defer c.lock.Unlock() - if c.usersApi == nil { - c.usersApi = api.NewUsersApi(c.apiClient) - } - return c.usersApi -} - func (c *clientImpl) DeleteAPI() api.DeleteAPI { c.lock.Lock() defer c.lock.Unlock() @@ -314,16 +230,6 @@ func (c *clientImpl) DeleteAPI() api.DeleteAPI { return c.deleteAPI } -//lint:ignore ST1003 Deprecated method to be removed in the next release -func (c *clientImpl) DeleteApi() api.DeleteApi { - c.lock.Lock() - defer c.lock.Unlock() - if c.deleteApi == nil { - c.deleteApi = api.NewDeleteApi(c.apiClient) - } - return c.deleteApi -} - func (c *clientImpl) BucketsAPI() api.BucketsAPI { c.lock.Lock() defer c.lock.Unlock() @@ -333,16 +239,6 @@ func (c *clientImpl) BucketsAPI() api.BucketsAPI { return c.bucketsAPI } -//lint:ignore ST1003 Deprecated method to be removed in the next release -func (c *clientImpl) BucketsApi() api.BucketsApi { - c.lock.Lock() - defer c.lock.Unlock() - if c.bucketsApi == nil { - c.bucketsApi = api.NewBucketsApi(c.apiClient) - } - return c.bucketsApi -} - func (c *clientImpl) LabelsAPI() api.LabelsAPI { c.lock.Lock() defer c.lock.Unlock() @@ -351,13 +247,3 @@ func (c *clientImpl) LabelsAPI() api.LabelsAPI { } return c.labelsAPI } - -//lint:ignore ST1003 Deprecated method to be removed in the next release -func (c *clientImpl) LabelsApi() api.LabelsApi { - c.lock.Lock() - defer c.lock.Unlock() - if c.labelsApi == nil { - c.labelsApi = api.NewLabelsApi(c.apiClient) - } - return c.labelsApi -} diff --git a/client_e2e_deprecated_test.go b/client_e2e_deprecated_test.go deleted file mode 100644 index 25863d6e..00000000 --- a/client_e2e_deprecated_test.go +++ /dev/null @@ -1,889 +0,0 @@ -// +build e2e - -// Copyright 2020 InfluxData, Inc. All rights reserved. -// Use of this source code is governed by MIT -// license that can be found in the LICENSE file. - -package influxdb2_test - -import ( - "context" - "fmt" - "github.com/influxdata/influxdb-client-go/api/write" - "strconv" - "strings" - "testing" - "time" - - influxdb2 "github.com/influxdata/influxdb-client-go" - "github.com/influxdata/influxdb-client-go/api" - "github.com/influxdata/influxdb-client-go/domain" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestWriteDeprecated(t *testing.T) { - client := influxdb2.NewClientWithOptions(serverURL, authToken, influxdb2.DefaultOptions().SetLogLevel(3)) - writeAPI := client.WriteApi("my-org", "my-bucket") - errCh := writeAPI.Errors() - errorsCount := 0 - go func() { - for err := range errCh { - errorsCount++ - fmt.Println("Write error: ", err.Error()) - } - }() - timestamp := time.Now() - for i, f := 0, 3.3; i < 10; i++ { - writeAPI.WriteRecord(fmt.Sprintf("test,a=%d,b=local f=%.2f,i=%di %d", i%2, f, i, timestamp.UnixNano())) - //writeAPI.Flush() - f += 3.3 - timestamp = timestamp.Add(time.Nanosecond) - } - - for i, f := int64(10), 33.0; i < 20; i++ { - p := influxdb2.NewPoint("test", - map[string]string{"a": strconv.FormatInt(i%2, 10), "b": "static"}, - map[string]interface{}{"f": f, "i": i}, - timestamp) - writeAPI.WritePoint(p) - f += 3.3 - timestamp = timestamp.Add(time.Nanosecond) - } - - err := client.WriteApiBlocking("my-org", "my-bucket").WritePoint(context.Background(), influxdb2.NewPointWithMeasurement("test"). - AddTag("a", "3").AddField("i", 20).AddField("f", 4.4)) - assert.Nil(t, err) - - client.Close() - assert.Equal(t, 0, errorsCount) - -} - -func TestQueryRawDeprecated(t *testing.T) { - client := influxdb2.NewClient(serverURL, authToken) - - queryAPI := client.QueryApi("my-org") - res, err := queryAPI.QueryRaw(context.Background(), `from(bucket:"my-bucket")|> range(start: -24h) |> filter(fn: (r) => r._measurement == "test")`, influxdb2.DefaultDialect()) - if err != nil { - t.Error(err) - } else { - fmt.Println("QueryResult:") - fmt.Println(res) - } -} - -func TestQueryDeprecated(t *testing.T) { - client := influxdb2.NewClient(serverURL, authToken) - - queryAPI := client.QueryApi("my-org") - fmt.Println("QueryResult") - result, err := queryAPI.Query(context.Background(), `from(bucket:"my-bucket")|> range(start: -24h) |> filter(fn: (r) => r._measurement == "test")`) - if err != nil { - t.Error(err) - } else { - rows := 0 - for result.Next() { - rows++ - if result.TableChanged() { - fmt.Printf("table: %s\n", result.TableMetadata().String()) - } - fmt.Printf("row: %sv\n", result.Record().String()) - } - if result.Err() != nil { - t.Error(result.Err()) - } - assert.Equal(t, 42, rows) - } - -} - -func TestAuthorizationsApi(t *testing.T) { - client := influxdb2.NewClient(serverURL, authToken) - authAPI := client.AuthorizationsApi() - listRes, err := authAPI.GetAuthorizations(context.Background()) - require.Nil(t, err) - require.NotNil(t, listRes) - assert.Len(t, *listRes, 1) - - orgName := "my-org" - org, err := client.OrganizationsApi().FindOrganizationByName(context.Background(), orgName) - require.Nil(t, err) - require.NotNil(t, org) - assert.Equal(t, orgName, org.Name) - - permission := &domain.Permission{ - Action: domain.PermissionActionWrite, - Resource: domain.Resource{ - Type: domain.ResourceTypeBuckets, - }, - } - permissions := []domain.Permission{*permission} - - auth, err := authAPI.CreateAuthorizationWithOrgId(context.Background(), *org.Id, permissions) - require.Nil(t, err) - require.NotNil(t, auth) - assert.Equal(t, domain.AuthorizationUpdateRequestStatusActive, *auth.Status, *auth.Status) - - listRes, err = authAPI.GetAuthorizations(context.Background()) - require.Nil(t, err) - require.NotNil(t, listRes) - assert.Len(t, *listRes, 2) - - listRes, err = authAPI.FindAuthorizationsByUserName(context.Background(), "my-user") - require.Nil(t, err) - require.NotNil(t, listRes) - assert.Len(t, *listRes, 2) - - listRes, err = authAPI.FindAuthorizationsByOrgId(context.Background(), *org.Id) - require.Nil(t, err) - require.NotNil(t, listRes) - assert.Len(t, *listRes, 2) - - listRes, err = authAPI.FindAuthorizationsByOrgName(context.Background(), "my-org") - require.Nil(t, err) - require.NotNil(t, listRes) - assert.Len(t, *listRes, 2) - - listRes, err = authAPI.FindAuthorizationsByOrgName(context.Background(), "not-existent-org") - require.Nil(t, listRes) - require.NotNil(t, err) - //assert.Len(t, *listRes, 0) - - auth, err = authAPI.UpdateAuthorizationStatus(context.Background(), *auth.Id, domain.AuthorizationUpdateRequestStatusInactive) - require.Nil(t, err) - require.NotNil(t, auth) - assert.Equal(t, domain.AuthorizationUpdateRequestStatusInactive, *auth.Status, *auth.Status) - - listRes, err = authAPI.GetAuthorizations(context.Background()) - require.Nil(t, err) - require.NotNil(t, listRes) - assert.Len(t, *listRes, 2) - - err = authAPI.DeleteAuthorization(context.Background(), *auth.Id) - require.Nil(t, err) - - listRes, err = authAPI.GetAuthorizations(context.Background()) - require.Nil(t, err) - require.NotNil(t, listRes) - assert.Len(t, *listRes, 1) - -} - -func TestOrganizations(t *testing.T) { - client := influxdb2.NewClient(serverURL, authToken) - orgsAPI := client.OrganizationsApi() - usersAPI := client.UsersApi() - orgName := "my-org-2" - orgDescription := "my-org 2 description" - ctx := context.Background() - invalidID := "aaaaaaaaaaaaaaaa" - - orgList, err := orgsAPI.GetOrganizations(ctx) - require.Nil(t, err) - require.NotNil(t, orgList) - assert.Len(t, *orgList, 1) - - //test error - org, err := orgsAPI.CreateOrganizationWithName(ctx, "") - assert.NotNil(t, err) - require.Nil(t, org) - - org, err = orgsAPI.CreateOrganizationWithName(ctx, orgName) - require.Nil(t, err) - require.NotNil(t, org) - assert.Equal(t, orgName, org.Name) - - //test duplicit org - _, err = orgsAPI.CreateOrganizationWithName(ctx, orgName) - require.NotNil(t, err) - - org.Description = &orgDescription - - org, err = orgsAPI.UpdateOrganization(ctx, org) - require.Nil(t, err) - require.NotNil(t, org) - assert.Equal(t, orgDescription, *org.Description) - - orgList, err = orgsAPI.GetOrganizations(ctx) - - require.Nil(t, err) - require.NotNil(t, orgList) - assert.Len(t, *orgList, 2) - - permission := &domain.Permission{ - Action: domain.PermissionActionWrite, - Resource: domain.Resource{ - Type: domain.ResourceTypeBuckets, - }, - } - permissions := []domain.Permission{*permission} - - //create authorization for new org - auth, err := client.AuthorizationsApi().CreateAuthorizationWithOrgId(context.Background(), *org.Id, permissions) - require.Nil(t, err) - require.NotNil(t, auth) - - // create client with new auth token without permission - clientOrg2 := influxdb2.NewClient(serverURL, *auth.Token) - - orgList, err = clientOrg2.OrganizationsApi().GetOrganizations(ctx) - require.Nil(t, err) - require.NotNil(t, orgList) - assert.Len(t, *orgList, 0) - - org2, err := orgsAPI.FindOrganizationByName(ctx, orgName) - require.Nil(t, err) - require.NotNil(t, org2) - - //find unknown org - org2, err = orgsAPI.FindOrganizationByName(ctx, "not-existetn-org") - assert.NotNil(t, err) - assert.Nil(t, org2) - - //find org using token without org permission - org2, err = clientOrg2.OrganizationsApi().FindOrganizationByName(ctx, org.Name) - assert.NotNil(t, err) - assert.Nil(t, org2) - - client.AuthorizationsApi().DeleteAuthorization(ctx, *auth.Id) - - members, err := orgsAPI.GetMembers(ctx, org) - require.Nil(t, err) - require.NotNil(t, members) - require.Len(t, *members, 0) - - user, err := usersAPI.CreateUserWithName(ctx, "user-01") - require.Nil(t, err) - require.NotNil(t, user) - - member, err := orgsAPI.AddMember(ctx, org, user) - require.Nil(t, err) - require.NotNil(t, member) - assert.Equal(t, *user.Id, *member.Id) - assert.Equal(t, user.Name, member.Name) - - // Add member with invalid id - member, err = orgsAPI.AddMemberWithId(ctx, *org.Id, invalidID) - assert.NotNil(t, err) - assert.Nil(t, member) - - members, err = orgsAPI.GetMembers(ctx, org) - require.Nil(t, err) - require.NotNil(t, members) - require.Len(t, *members, 1) - - // get member with invalid id - members, err = orgsAPI.GetMembersWithId(ctx, invalidID) - assert.NotNil(t, err) - assert.Nil(t, members) - - org2, err = orgsAPI.FindOrganizationById(ctx, *org.Id) - require.Nil(t, err) - require.NotNil(t, org2) - assert.Equal(t, org.Name, org2.Name) - - // find invalid id - org2, err = orgsAPI.FindOrganizationById(ctx, invalidID) - assert.NotNil(t, err) - assert.Nil(t, org2) - - orgs, err := orgsAPI.FindOrganizationsByUserId(ctx, *user.Id) - require.Nil(t, err) - require.NotNil(t, orgs) - require.Len(t, *orgs, 1) - assert.Equal(t, org.Name, (*orgs)[0].Name) - - // look for not existent - orgs, err = orgsAPI.FindOrganizationsByUserId(ctx, invalidID) - assert.Nil(t, err) - assert.NotNil(t, orgs) - assert.Len(t, *orgs, 0) - - orgName2 := "my-org-3" - - org2, err = orgsAPI.CreateOrganizationWithName(ctx, orgName2) - require.Nil(t, err) - require.NotNil(t, org2) - assert.Equal(t, orgName2, org2.Name) - - orgList, err = orgsAPI.GetOrganizations(ctx) - require.Nil(t, err) - require.NotNil(t, orgList) - assert.Len(t, *orgList, 3) - - owners, err := orgsAPI.GetOwners(ctx, org2) - assert.Nil(t, err) - assert.NotNil(t, owners) - assert.Len(t, *owners, 1) - - //get owners with invalid id - owners, err = orgsAPI.GetOwnersWithId(ctx, invalidID) - assert.NotNil(t, err) - assert.Nil(t, owners) - - owner, err := orgsAPI.AddOwner(ctx, org2, user) - require.Nil(t, err) - require.NotNil(t, owner) - - // add owner with invalid ID - owner, err = orgsAPI.AddOwnerWithId(ctx, *org2.Id, invalidID) - assert.NotNil(t, err) - assert.Nil(t, owner) - - owners, err = orgsAPI.GetOwners(ctx, org2) - require.Nil(t, err) - require.NotNil(t, owners) - assert.Len(t, *owners, 2) - - u, err := usersAPI.FindUserByName(ctx, "my-user") - require.Nil(t, err) - require.NotNil(t, u) - - err = orgsAPI.RemoveOwner(ctx, org2, u) - require.Nil(t, err) - - // remove owner with invalid ID - err = orgsAPI.RemoveOwnerWithId(ctx, invalidID, invalidID) - assert.NotNil(t, err) - - owners, err = orgsAPI.GetOwners(ctx, org2) - require.Nil(t, err) - require.NotNil(t, owners) - assert.Len(t, *owners, 1) - - orgs, err = orgsAPI.FindOrganizationsByUserId(ctx, *user.Id) - require.Nil(t, err) - require.NotNil(t, orgs) - require.Len(t, *orgs, 2) - - err = orgsAPI.RemoveMember(ctx, org, user) - require.Nil(t, err) - - // remove invalid memberID - err = orgsAPI.RemoveMemberWithId(ctx, invalidID, invalidID) - assert.NotNil(t, err) - - members, err = orgsAPI.GetMembers(ctx, org) - require.Nil(t, err) - require.NotNil(t, members) - require.Len(t, *members, 0) - - err = orgsAPI.DeleteOrganization(ctx, org) - require.Nil(t, err) - - err = orgsAPI.DeleteOrganization(ctx, org2) - assert.Nil(t, err) - - // delete invalid org - err = orgsAPI.DeleteOrganizationWithId(ctx, invalidID) - assert.NotNil(t, err) - - orgList, err = orgsAPI.GetOrganizations(ctx) - require.Nil(t, err) - require.NotNil(t, orgList) - assert.Len(t, *orgList, 1) - - err = usersAPI.DeleteUser(ctx, user) - require.Nil(t, err) - -} - -func TestUsers(t *testing.T) { - client := influxdb2.NewClient(serverURL, authToken) - - usersAPI := client.UsersApi() - - me, err := usersAPI.Me(context.Background()) - assert.Nil(t, err) - assert.NotNil(t, me) - - users, err := usersAPI.GetUsers(context.Background()) - require.Nil(t, err) - require.NotNil(t, users) - assert.Len(t, *users, 1) - - user, err := usersAPI.CreateUserWithName(context.Background(), "user-01") - require.Nil(t, err) - require.NotNil(t, user) - - users, err = usersAPI.GetUsers(context.Background()) - require.Nil(t, err) - require.NotNil(t, users) - assert.Len(t, *users, 2) - - status := domain.UserStatusInactive - user.Status = &status - user, err = usersAPI.UpdateUser(context.Background(), user) - require.Nil(t, err) - require.NotNil(t, user) - assert.Equal(t, status, *user.Status) - - user, err = usersAPI.FindUserById(context.Background(), *user.Id) - require.Nil(t, err) - require.NotNil(t, user) - - err = usersAPI.UpdateUserPassword(context.Background(), user, "my-password") - require.Nil(t, err) - - err = usersAPI.DeleteUser(context.Background(), user) - require.Nil(t, err) - - users, err = usersAPI.GetUsers(context.Background()) - require.Nil(t, err) - require.NotNil(t, users) - assert.Len(t, *users, 1) -} - -func TestDelete(t *testing.T) { - ctx := context.Background() - client := influxdb2.NewClient(serverURL, authToken) - writeAPI := client.WriteApiBlocking("my-org", "my-bucket") - queryAPI := client.QueryApi("my-org") - tmStart := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC) - writeF := func(start time.Time, count int64) time.Time { - tm := start - for i, f := int64(0), 0.0; i < count; i++ { - p := write.NewPoint("test", - map[string]string{"a": strconv.FormatInt(i%2, 10), "b": "static"}, - map[string]interface{}{"f": f, "i": i}, - tm) - err := writeAPI.WritePoint(ctx, p) - require.Nil(t, err, err) - f += 1.2 - tm = tm.Add(time.Minute) - } - return tm - } - countF := func(start, stop time.Time) int64 { - result, err := queryAPI.Query(ctx, `from(bucket:"my-bucket")|> range(start: `+start.Format(time.RFC3339)+`, stop:`+stop.Format(time.RFC3339)+`) - |> filter(fn: (r) => r._measurement == "test" and r._field == "f") - |> drop(columns: ["a", "b"]) - |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value") - |> count(column: "f")`) - - require.Nil(t, err, err) - count := int64(0) - if result.Next() { - require.NotNil(t, result.Record().ValueByKey("f")) - count = result.Record().ValueByKey("f").(int64) - } - return count - } - tmEnd := writeF(tmStart, 100) - assert.Equal(t, int64(100), countF(tmStart, tmEnd)) - deleteAPI := client.DeleteApi() - - org, err := client.OrganizationsApi().FindOrganizationByName(ctx, "my-org") - require.Nil(t, err, err) - require.NotNil(t, org) - - bucket, err := client.BucketsApi().FindBucketByName(ctx, "my-bucket") - require.Nil(t, err, err) - require.NotNil(t, bucket) - - err = deleteAPI.DeleteWithName(ctx, "my-org", "my-bucket", tmStart, tmEnd, "") - require.Nil(t, err, err) - assert.Equal(t, int64(0), countF(tmStart, tmEnd)) - - tmEnd = writeF(tmStart, 100) - assert.Equal(t, int64(100), countF(tmStart, tmEnd)) - - err = deleteAPI.DeleteWithId(ctx, *org.Id, *bucket.Id, tmStart, tmEnd, "a=1") - require.Nil(t, err, err) - assert.Equal(t, int64(50), countF(tmStart, tmEnd)) - - err = deleteAPI.Delete(ctx, org, bucket, tmStart.Add(50*time.Minute), tmEnd, "b=static") - require.Nil(t, err, err) - assert.Equal(t, int64(25), countF(tmStart, tmEnd)) - - err = deleteAPI.DeleteWithName(ctx, "org", "my-bucket", tmStart.Add(50*time.Minute), tmEnd, "b=static") - require.NotNil(t, err, err) - assert.True(t, strings.Contains(err.Error(), "not found")) - - err = deleteAPI.DeleteWithName(ctx, "my-org", "bucket", tmStart.Add(50*time.Minute), tmEnd, "b=static") - require.NotNil(t, err, err) - assert.True(t, strings.Contains(err.Error(), "not found")) -} - -func TestBuckets(t *testing.T) { - ctx := context.Background() - client := influxdb2.NewClient(serverURL, authToken) - - bucketsAPI := client.BucketsApi() - - buckets, err := bucketsAPI.GetBuckets(ctx) - require.Nil(t, err, err) - require.NotNil(t, buckets) - //at least three buckets, my-bucket and two system buckets. - assert.True(t, len(*buckets) > 2) - - // test find existing bucket - bucket, err := bucketsAPI.FindBucketByName(ctx, "my-bucket") - require.Nil(t, err, err) - require.NotNil(t, bucket) - assert.Equal(t, "my-bucket", bucket.Name) - - //test find non-existing bucket - bucket, err = bucketsAPI.FindBucketByName(ctx, "not existing bucket") - assert.NotNil(t, err) - assert.Nil(t, bucket) - - // create organizatiton for bucket - org, err := client.OrganizationsApi().CreateOrganizationWithName(ctx, "bucket-org") - require.Nil(t, err) - require.NotNil(t, org) - - // collect all buckets including system ones created for new organization - buckets, err = bucketsAPI.GetBuckets(ctx) - require.Nil(t, err, err) - //store #all buckets before creating new ones - bucketsNum := len(*buckets) - - name := "bucket-x" - b, err := bucketsAPI.CreateBucketWithName(ctx, org, name, domain.RetentionRule{EverySeconds: 3600 * 1}, domain.RetentionRule{EverySeconds: 3600 * 24}) - require.Nil(t, err, err) - require.NotNil(t, b) - assert.Equal(t, name, b.Name) - assert.Len(t, b.RetentionRules, 1) - - // Test update - desc := "bucket description" - b.Description = &desc - b.RetentionRules = []domain.RetentionRule{{EverySeconds: 60}} - b, err = bucketsAPI.UpdateBucket(ctx, b) - require.Nil(t, err, err) - require.NotNil(t, b) - assert.Equal(t, name, b.Name) - assert.Equal(t, desc, *b.Description) - assert.Len(t, b.RetentionRules, 1) - - // Test owners - userOwner, err := client.UsersApi().CreateUserWithName(ctx, "bucket-owner") - require.Nil(t, err, err) - require.NotNil(t, userOwner) - - owners, err := bucketsAPI.GetOwners(ctx, b) - require.Nil(t, err, err) - require.NotNil(t, owners) - assert.Len(t, *owners, 0) - - owner, err := bucketsAPI.AddOwner(ctx, b, userOwner) - require.Nil(t, err, err) - require.NotNil(t, owner) - assert.Equal(t, *userOwner.Id, *owner.Id) - - owners, err = bucketsAPI.GetOwners(ctx, b) - require.Nil(t, err, err) - require.NotNil(t, owners) - assert.Len(t, *owners, 1) - - err = bucketsAPI.RemoveOwnerWithId(ctx, *b.Id, *(&(*owners)[0]).Id) - require.Nil(t, err, err) - - owners, err = bucketsAPI.GetOwners(ctx, b) - require.Nil(t, err, err) - require.NotNil(t, owners) - assert.Len(t, *owners, 0) - - //test failures - _, err = bucketsAPI.AddOwnerWithId(ctx, "000000000000000", *userOwner.Id) - assert.NotNil(t, err) - - _, err = bucketsAPI.AddOwnerWithId(ctx, *b.Id, "000000000000000") - assert.NotNil(t, err) - - _, err = bucketsAPI.GetOwnersWithId(ctx, "000000000000000") - assert.NotNil(t, err) - - err = bucketsAPI.RemoveOwnerWithId(ctx, *b.Id, "000000000000000") - assert.NotNil(t, err) - - err = bucketsAPI.RemoveOwnerWithId(ctx, "000000000000000", *userOwner.Id) - assert.NotNil(t, err) - - // Test members - userMember, err := client.UsersApi().CreateUserWithName(ctx, "bucket-member") - require.Nil(t, err, err) - require.NotNil(t, userMember) - - members, err := bucketsAPI.GetMembers(ctx, b) - require.Nil(t, err, err) - require.NotNil(t, members) - assert.Len(t, *members, 0) - - member, err := bucketsAPI.AddMember(ctx, b, userMember) - require.Nil(t, err, err) - require.NotNil(t, member) - assert.Equal(t, *userMember.Id, *member.Id) - - members, err = bucketsAPI.GetMembers(ctx, b) - require.Nil(t, err, err) - require.NotNil(t, members) - assert.Len(t, *members, 1) - - err = bucketsAPI.RemoveMemberWithId(ctx, *b.Id, *(&(*members)[0]).Id) - require.Nil(t, err, err) - - members, err = bucketsAPI.GetMembers(ctx, b) - require.Nil(t, err, err) - require.NotNil(t, members) - assert.Len(t, *members, 0) - - //test failures - _, err = bucketsAPI.AddMemberWithId(ctx, "000000000000000", *userMember.Id) - assert.NotNil(t, err) - - _, err = bucketsAPI.AddMemberWithId(ctx, *b.Id, "000000000000000") - assert.NotNil(t, err) - - _, err = bucketsAPI.GetMembersWithId(ctx, "000000000000000") - assert.NotNil(t, err) - - err = bucketsAPI.RemoveMemberWithId(ctx, *b.Id, "000000000000000") - assert.NotNil(t, err) - - err = bucketsAPI.RemoveMemberWithId(ctx, "000000000000000", *userMember.Id) - assert.NotNil(t, err) - - err = bucketsAPI.DeleteBucketWithId(ctx, *b.Id) - assert.Nil(t, err, err) - - err = client.UsersApi().DeleteUser(ctx, userOwner) - assert.Nil(t, err, err) - - err = client.UsersApi().DeleteUser(ctx, userMember) - assert.Nil(t, err, err) - - //test failures - _, err = bucketsAPI.FindBucketById(ctx, *b.Id) - assert.NotNil(t, err) - - _, err = bucketsAPI.UpdateBucket(ctx, b) - assert.NotNil(t, err) - - b.OrgID = b.Id - _, err = bucketsAPI.CreateBucket(ctx, b) - assert.NotNil(t, err) - - // create bucket by object - b = &domain.Bucket{ - Description: &desc, - Name: name, - OrgID: org.Id, - RetentionRules: []domain.RetentionRule{{EverySeconds: 3600}}, - } - - b, err = bucketsAPI.CreateBucket(ctx, b) - require.Nil(t, err, err) - require.NotNil(t, b) - assert.Equal(t, name, b.Name) - assert.Equal(t, *org.Id, *b.OrgID) - assert.Equal(t, desc, *b.Description) - assert.Len(t, b.RetentionRules, 1) - - // fail duplicit name - _, err = bucketsAPI.CreateBucketWithName(ctx, org, b.Name) - assert.NotNil(t, err) - - // fail org not found - _, err = bucketsAPI.CreateBucketWithNameWithId(ctx, *b.Id, b.Name) - assert.NotNil(t, err) - - err = bucketsAPI.DeleteBucketWithId(ctx, *b.Id) - assert.Nil(t, err, err) - - err = bucketsAPI.DeleteBucketWithId(ctx, *b.Id) - assert.NotNil(t, err) - - // create new buckets inside org - for i := 0; i < 30; i++ { - name := fmt.Sprintf("bucket-%03d", i) - b, err := bucketsAPI.CreateBucketWithName(ctx, org, name) - require.Nil(t, err, err) - require.NotNil(t, b) - assert.Equal(t, name, b.Name) - } - - // test paging, 1st page - buckets, err = bucketsAPI.GetBuckets(ctx) - require.Nil(t, err, err) - require.NotNil(t, buckets) - assert.Len(t, *buckets, 20) - // test paging, 2nd, last page - buckets, err = bucketsAPI.GetBuckets(ctx, api.PagingWithOffset(20)) - require.Nil(t, err, err) - require.NotNil(t, buckets) - //+2 is a bug, when using offset>4 there are returned also system buckets - assert.Len(t, *buckets, 10+2+bucketsNum) - // test paging with increase limit to cover all buckets - buckets, err = bucketsAPI.GetBuckets(ctx, api.PagingWithLimit(100)) - require.Nil(t, err, err) - require.NotNil(t, buckets) - assert.Len(t, *buckets, 30+bucketsNum) - // test filtering buckets by org id - buckets, err = bucketsAPI.FindBucketsByOrgId(ctx, *org.Id, api.PagingWithLimit(100)) - require.Nil(t, err, err) - require.NotNil(t, buckets) - assert.Len(t, *buckets, 30+2) - // test filtering buckets by org name - buckets, err = bucketsAPI.FindBucketsByOrgName(ctx, org.Name, api.PagingWithLimit(100)) - require.Nil(t, err, err) - require.NotNil(t, buckets) - assert.Len(t, *buckets, 30+2) - // delete buckete - for _, b := range *buckets { - if strings.HasPrefix(b.Name, "bucket-") { - err = bucketsAPI.DeleteBucket(ctx, &b) - assert.Nil(t, err, err) - } - } - // check all created buckets deleted - buckets, err = bucketsAPI.FindBucketsByOrgName(ctx, org.Name, api.PagingWithLimit(100)) - require.Nil(t, err, err) - require.NotNil(t, buckets) - assert.Len(t, *buckets, 2) - - err = client.OrganizationsApi().DeleteOrganization(ctx, org) - assert.Nil(t, err, err) - - // should fail with org not found - _, err = bucketsAPI.FindBucketsByOrgName(ctx, org.Name, api.PagingWithLimit(100)) - assert.NotNil(t, err) -} - -func TestLabels(t *testing.T) { - client := influxdb2.NewClientWithOptions(serverURL, authToken, influxdb2.DefaultOptions().SetLogLevel(3)) - labelsAPI := client.LabelsApi() - orgAPI := client.OrganizationsApi() - - ctx := context.Background() - - myorg, err := orgAPI.FindOrganizationByName(ctx, "my-org") - require.Nil(t, err, err) - require.NotNil(t, myorg) - - labels, err := labelsAPI.GetLabels(ctx) - require.Nil(t, err, err) - require.NotNil(t, labels) - assert.Len(t, *labels, 0) - - labelName := "Active State" - props := map[string]string{"color": "#33ffddd", "description": "Marks org active"} - label, err := labelsAPI.CreateLabelWithName(ctx, myorg, labelName, props) - require.Nil(t, err, err) - require.NotNil(t, label) - assert.Equal(t, labelName, *label.Name) - require.NotNil(t, label.Properties) - assert.Equal(t, props, label.Properties.AdditionalProperties) - - //remove properties - label.Properties.AdditionalProperties = map[string]string{"color": "", "description": ""} - label2, err := labelsAPI.UpdateLabel(ctx, label) - require.Nil(t, err, err) - require.NotNil(t, label2) - assert.Equal(t, labelName, *label2.Name) - assert.Nil(t, label2.Properties) - - label2, err = labelsAPI.FindLabelById(ctx, *label.Id) - require.Nil(t, err, err) - require.NotNil(t, label2) - assert.Equal(t, labelName, *label2.Name) - - label2, err = labelsAPI.FindLabelById(ctx, "000000000000000") - require.NotNil(t, err, err) - require.Nil(t, label2) - - label2, err = labelsAPI.FindLabelByName(ctx, *myorg.Id, labelName) - require.Nil(t, err, err) - require.NotNil(t, label2) - assert.Equal(t, labelName, *label2.Name) - - label2, err = labelsAPI.FindLabelByName(ctx, *myorg.Id, "wrong label") - require.NotNil(t, err, err) - require.Nil(t, label2) - - labels, err = labelsAPI.GetLabels(ctx) - require.Nil(t, err, err) - require.NotNil(t, labels) - assert.Len(t, *labels, 1) - - labels, err = labelsAPI.FindLabelsByOrg(ctx, myorg) - require.Nil(t, err, err) - require.NotNil(t, labels) - assert.Len(t, *labels, 1) - - labels, err = labelsAPI.FindLabelsByOrgId(ctx, *myorg.Id) - require.Nil(t, err, err) - require.NotNil(t, labels) - assert.Len(t, *labels, 1) - - labels, err = labelsAPI.FindLabelsByOrgId(ctx, "000000000000000") - require.NotNil(t, err, err) - require.Nil(t, labels) - - // duplicate label - label2, err = labelsAPI.CreateLabelWithName(ctx, myorg, labelName, nil) - require.NotNil(t, err, err) - require.Nil(t, label2) - - labels, err = orgAPI.GetLabels(ctx, myorg) - require.Nil(t, err, err) - require.NotNil(t, labels) - assert.Len(t, *labels, 0) - - org, err := orgAPI.CreateOrganizationWithName(ctx, "org1") - require.Nil(t, err, err) - require.NotNil(t, org) - - labels, err = orgAPI.GetLabels(ctx, org) - require.Nil(t, err, err) - require.NotNil(t, labels) - assert.Len(t, *labels, 0) - - labelx, err := orgAPI.AddLabel(ctx, org, label) - require.Nil(t, err, err) - require.NotNil(t, labelx) - - labels, err = orgAPI.GetLabels(ctx, org) - require.Nil(t, err, err) - require.NotNil(t, labels) - assert.Len(t, *labels, 1) - - err = orgAPI.RemoveLabel(ctx, org, label) - require.Nil(t, err, err) - - labels, err = orgAPI.GetLabels(ctx, org) - require.Nil(t, err, err) - require.NotNil(t, labels) - assert.Len(t, *labels, 0) - - labels, err = orgAPI.GetLabelsWithId(ctx, "000000000000000") - require.NotNil(t, err, err) - require.Nil(t, labels) - - label2, err = orgAPI.AddLabelWithId(ctx, *org.Id, "000000000000000") - require.NotNil(t, err, err) - require.Nil(t, label2) - - label2, err = orgAPI.AddLabelWithId(ctx, "000000000000000", "000000000000000") - require.NotNil(t, err, err) - require.Nil(t, label2) - - err = orgAPI.RemoveLabelWithId(ctx, *org.Id, "000000000000000") - require.NotNil(t, err, err) - require.Nil(t, label2) - - err = orgAPI.RemoveLabelWithId(ctx, "000000000000000", "000000000000000") - require.NotNil(t, err, err) - require.Nil(t, label2) - - err = orgAPI.DeleteOrganization(ctx, org) - assert.Nil(t, err, err) - - err = labelsAPI.DeleteLabel(ctx, label) - require.Nil(t, err, err) - - err = labelsAPI.DeleteLabel(ctx, label) - require.NotNil(t, err, err) -} diff --git a/client_test.go b/client_test.go index bef817e1..1b638149 100644 --- a/client_test.go +++ b/client_test.go @@ -61,7 +61,7 @@ func TestUserAgent(t *testing.T) { assert.True(t, ready) assert.Nil(t, err) - err = c.WriteApiBlocking("o", "b").WriteRecord(context.Background(), "a,a=a a=1i") + err = c.WriteAPIBlocking("o", "b").WriteRecord(context.Background(), "a,a=a a=1i") assert.Nil(t, err) } @@ -76,7 +76,7 @@ func TestServerError429(t *testing.T) { defer server.Close() c := NewClient(server.URL, "x") - err := c.WriteApiBlocking("o", "b").WriteRecord(context.Background(), "a,a=a a=1i") + err := c.WriteAPIBlocking("o", "b").WriteRecord(context.Background(), "a,a=a a=1i") require.NotNil(t, err) perror, ok := err.(*http2.Error) require.True(t, ok) @@ -97,7 +97,7 @@ func TestServerOnPath(t *testing.T) { defer server.Close() c := NewClient(server.URL+"/proxy/0:0/influx/", "x") - err := c.WriteApiBlocking("o", "b").WriteRecord(context.Background(), "a,a=a a=1i") + err := c.WriteAPIBlocking("o", "b").WriteRecord(context.Background(), "a,a=a a=1i") require.Nil(t, err) } @@ -110,7 +110,7 @@ func TestServerErrorNonJSON(t *testing.T) { defer server.Close() c := NewClient(server.URL, "x") - err := c.WriteApiBlocking("o", "b").WriteRecord(context.Background(), "a,a=a a=1i") + err := c.WriteAPIBlocking("o", "b").WriteRecord(context.Background(), "a,a=a a=1i") require.NotNil(t, err) perror, ok := err.(*http2.Error) require.True(t, ok) @@ -129,7 +129,7 @@ func TestServerErrorInflux1_8(t *testing.T) { defer server.Close() c := NewClient(server.URL, "x") - err := c.WriteApiBlocking("o", "b").WriteRecord(context.Background(), "a,a=a a=1i") + err := c.WriteAPIBlocking("o", "b").WriteRecord(context.Background(), "a,a=a a=1i") require.NotNil(t, err) perror, ok := err.(*http2.Error) require.True(t, ok) @@ -145,7 +145,7 @@ func TestServerErrorEmptyBody(t *testing.T) { defer server.Close() c := NewClient(server.URL, "x") - err := c.WriteApiBlocking("o", "b").WriteRecord(context.Background(), "a,a=a a=1i") + err := c.WriteAPIBlocking("o", "b").WriteRecord(context.Background(), "a,a=a a=1i") require.NotNil(t, err) assert.Equal(t, "Unexpected status code 404", err.Error()) } diff --git a/options_deprecated_test.go b/options_deprecated_test.go deleted file mode 100644 index 5dcbabba..00000000 --- a/options_deprecated_test.go +++ /dev/null @@ -1,93 +0,0 @@ -package influxdb2_test - -import ( - "context" - "crypto/tls" - influxdb2 "github.com/influxdata/influxdb-client-go" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "net/http" - "net/http/httptest" - "strings" - "testing" - "time" -) - -func TestDefaultOptionsDeprecated(t *testing.T) { - opts := influxdb2.DefaultOptions() - assert.Equal(t, uint(5000), opts.BatchSize()) - assert.Equal(t, false, opts.UseGZip()) - assert.Equal(t, uint(1000), opts.FlushInterval()) - assert.Equal(t, time.Nanosecond, opts.Precision()) - assert.Equal(t, uint(10000), opts.RetryBufferLimit()) - assert.Equal(t, uint(1000), opts.RetryInterval()) - assert.Equal(t, uint(3), opts.MaxRetries()) - assert.Equal(t, (*tls.Config)(nil), opts.TlsConfig()) - assert.Equal(t, uint(20), opts.HttpRequestTimeout()) - assert.Equal(t, uint(0), opts.LogLevel()) -} - -func TestSettingsOptionsDeprecated(t *testing.T) { - tlsConfig := &tls.Config{ - InsecureSkipVerify: true, - } - opts := influxdb2.DefaultOptions(). - SetBatchSize(5). - SetUseGZip(true). - SetFlushInterval(5000). - SetPrecision(time.Millisecond). - SetRetryBufferLimit(5). - SetRetryInterval(5000). - SetMaxRetries(7). - SetTlsConfig(tlsConfig). - SetHttpRequestTimeout(50). - SetLogLevel(3). - AddDefaultTag("t", "a") - assert.Equal(t, uint(5), opts.BatchSize()) - assert.Equal(t, true, opts.UseGZip()) - assert.Equal(t, uint(5000), opts.FlushInterval()) - assert.Equal(t, time.Millisecond, opts.Precision()) - assert.Equal(t, uint(5), opts.RetryBufferLimit()) - assert.Equal(t, uint(5000), opts.RetryInterval()) - assert.Equal(t, uint(7), opts.MaxRetries()) - assert.Equal(t, tlsConfig, opts.TlsConfig()) - assert.Equal(t, uint(50), opts.HttpRequestTimeout()) - assert.Equal(t, uint(3), opts.LogLevel()) - assert.Len(t, opts.WriteOptions().DefaultTags(), 1) -} - -func TestTimeoutDeprecated(t *testing.T) { - response := `,result,table,_start,_stop,_time,_value,_field,_measurement,a,b, - ,,0,2020-02-17T22:19:49.747562847Z,2020-02-18T22:19:49.747562847Z,2020-02-18T10:34:08.135814545Z,1.4,f,test,1,adsfasdf - ,,0,2020-02-17T22:19:49.747562847Z,2020-02-18T22:19:49.747562847Z,2020-02-18T22:08:44.850214724Z,6.6,f,test,1,adsfasdf - ` - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - time.Sleep(100 * time.Millisecond) - if r.Method == http.MethodPost { - w.Header().Set("Content-Type", "text/csv") - w.WriteHeader(http.StatusOK) - time.Sleep(2 * time.Second) - _, err := w.Write([]byte(response)) - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - _, _ = w.Write([]byte(err.Error())) - } - } else { - w.WriteHeader(http.StatusNotFound) - } - })) - defer server.Close() - client := influxdb2.NewClientWithOptions(server.URL, "a", influxdb2.DefaultOptions().SetHttpRequestTimeout(1)) - queryAPI := client.QueryApi("org") - - _, err := queryAPI.QueryRaw(context.Background(), "flux", nil) - require.NotNil(t, err) - assert.True(t, strings.Contains(err.Error(), "Client.Timeout exceeded")) - - client = influxdb2.NewClientWithOptions(server.URL, "a", influxdb2.DefaultOptions().SetHttpRequestTimeout(5)) - queryAPI = client.QueryApi("org") - - result, err := queryAPI.QueryRaw(context.Background(), "flux", nil) - require.Nil(t, err) - assert.Equal(t, response, result) -} From 1bfed0eee1c8ef35e2205df9c6c24c6050976f72 Mon Sep 17 00:00:00 2001 From: vlastahajek Date: Mon, 10 Aug 2020 13:38:56 +0200 Subject: [PATCH 2/3] test: Removed workaround for system buckets --- api/buckets_e2e_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/buckets_e2e_test.go b/api/buckets_e2e_test.go index 03608472..f10a6fd2 100644 --- a/api/buckets_e2e_test.go +++ b/api/buckets_e2e_test.go @@ -199,8 +199,7 @@ func TestBucketsAPI(t *testing.T) { buckets, err = bucketsAPI.GetBuckets(ctx, api.PagingWithOffset(20)) require.Nil(t, err, err) require.NotNil(t, buckets) - //+2 is a bug, when using offset>4 there are returned also system buckets - assert.Len(t, *buckets, 10+2+bucketsNum) + assert.Len(t, *buckets, 10+bucketsNum) // test paging with increase limit to cover all buckets buckets, err = bucketsAPI.GetBuckets(ctx, api.PagingWithLimit(100)) require.Nil(t, err, err) @@ -210,11 +209,13 @@ func TestBucketsAPI(t *testing.T) { buckets, err = bucketsAPI.FindBucketsByOrgID(ctx, *org.Id, api.PagingWithLimit(100)) require.Nil(t, err, err) require.NotNil(t, buckets) + //+2 for system buckets assert.Len(t, *buckets, 30+2) // test filtering buckets by org name buckets, err = bucketsAPI.FindBucketsByOrgName(ctx, org.Name, api.PagingWithLimit(100)) require.Nil(t, err, err) require.NotNil(t, buckets) + //+2 for system buckets assert.Len(t, *buckets, 30+2) // delete buckete for _, b := range *buckets { From 77466ed7968ebb9578b8486b53d21f72299edaab Mon Sep 17 00:00:00 2001 From: vlastahajek Date: Tue, 11 Aug 2020 11:04:34 +0200 Subject: [PATCH 3/3] chore: Api -> API leftovers --- CHANGELOG.md | 2 +- api/query.go | 2 +- api/write.go | 4 ++-- api/writeAPIBlocking.go | 6 +++--- api/write_test.go | 4 ++-- client.go | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e952742..65873c4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,6 @@ - initial release of new client version -### Apis +### APIs - initial release of new client version diff --git a/api/query.go b/api/query.go index ef0230c8..cdceae68 100644 --- a/api/query.go +++ b/api/query.go @@ -55,7 +55,7 @@ func NewQueryAPI(org string, service ihttp.Service) QueryAPI { } } -// queryAPI implements QueryApi interface +// queryAPI implements QueryAPI interface type queryAPI struct { org string httpService ihttp.Service diff --git a/api/write.go b/api/write.go index cacf2f21..da2f7473 100644 --- a/api/write.go +++ b/api/write.go @@ -19,11 +19,11 @@ import ( type WriteAPI interface { // WriteRecord writes asynchronously line protocol record into bucket. // WriteRecord adds record into the buffer which is sent on the background when it reaches the batch size. - // Blocking alternative is available in the WriteApiBlocking interface + // Blocking alternative is available in the WriteAPIBlocking interface WriteRecord(line string) // WritePoint writes asynchronously Point into bucket. // WritePoint adds Point into the buffer which is sent on the background when it reaches the batch size. - // Blocking alternative is available in the WriteApiBlocking interface + // Blocking alternative is available in the WriteAPIBlocking interface WritePoint(point *write.Point) // Flush forces all pending writes from the buffer to be sent Flush() diff --git a/api/writeAPIBlocking.go b/api/writeAPIBlocking.go index 7cf5c5bd..e269a569 100644 --- a/api/writeAPIBlocking.go +++ b/api/writeAPIBlocking.go @@ -17,15 +17,15 @@ import ( type WriteAPIBlocking interface { // WriteRecord writes line protocol record(s) into bucket. // WriteRecord writes without implicit batching. Batch is created from given number of records - // Non-blocking alternative is available in the WriteApi interface + // Non-blocking alternative is available in the WriteAPI interface WriteRecord(ctx context.Context, line ...string) error // WritePoint data point into bucket. // WritePoint writes without implicit batching. Batch is created from given number of points - // Non-blocking alternative is available in the WriteApi interface + // Non-blocking alternative is available in the WriteAPI interface WritePoint(ctx context.Context, point ...*write.Point) error } -// writeAPIBlocking implements WriteApiBlocking interface +// writeAPIBlocking implements WriteAPIBlocking interface type writeAPIBlocking struct { service *iwrite.Service writeOptions *write.Options diff --git a/api/write_test.go b/api/write_test.go index 7fc4c99b..ac72521e 100644 --- a/api/write_test.go +++ b/api/write_test.go @@ -181,7 +181,7 @@ func genRecords(num int) []string { return lines } -func TestWriteApiWriteDefaultTag(t *testing.T) { +func TestWriteAPIWriteDefaultTag(t *testing.T) { service := newTestService(t, "http://localhost:8888") opts := write.DefaultOptions(). SetBatchSize(1) @@ -200,7 +200,7 @@ func TestWriteApiWriteDefaultTag(t *testing.T) { assert.Equal(t, "test,dft=a,vendor=AWS mem_free=1234567i 60000000060", service.Lines()[0]) } -func TestWriteApiImpl_Write(t *testing.T) { +func TestWriteAPIImpl_Write(t *testing.T) { service := newTestService(t, "http://localhost:8888") writeAPI := NewWriteAPI("my-org", "my-bucket", service, write.DefaultOptions().SetBatchSize(5)) points := genPoints(10) diff --git a/client.go b/client.go index e01dcd8e..69026ffc 100644 --- a/client.go +++ b/client.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Package influxdb2 provides API for using InfluxDB client in Go. -// It's intended to use with InfluxDB 2 server. WriteApi, QueryApi and Health work also with InfluxDB 1.8 +// It's intended to use with InfluxDB 2 server. WriteAPI, QueryAPI and Health work also with InfluxDB 1.8 package influxdb2 import ( @@ -19,9 +19,9 @@ import ( ) // Client provides API to communicate with InfluxDBServer. -// There two APIs for writing, WriteApi and WriteApiBlocking. -// WriteApi provides asynchronous, non-blocking, methods for writing time series data. -// WriteApiBlocking provides blocking methods for writing time series data. +// There two APIs for writing, WriteAPI and WriteAPIBlocking. +// WriteAPI provides asynchronous, non-blocking, methods for writing time series data. +// WriteAPIBlocking provides blocking methods for writing time series data. type Client interface { // Setup sends request to initialise new InfluxDB server with user, org and bucket, and data retention period // and returns details about newly created entities along with the authorization object.