Skip to content

Commit

Permalink
chore(API): Sync with the beta 16 swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
vlastahajek committed Aug 10, 2020
1 parent c62c843 commit 9fbbd78
Show file tree
Hide file tree
Showing 13 changed files with 5,686 additions and 7,058 deletions.
4 changes: 4 additions & 0 deletions 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 orgs labels API cause [it has been removed from the server API](https://github.com/influxdata/influxdb/pull/19104)

### 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]
Expand Down
4 changes: 2 additions & 2 deletions api/buckets.go
Expand Up @@ -152,15 +152,15 @@ func (b *bucketsAPI) CreateBucket(ctx context.Context, bucket *domain.Bucket) (*
bucketReq := &domain.PostBucketRequest{
Description: bucket.Description,
Name: bucket.Name,
OrgID: bucket.OrgID,
OrgID: *bucket.OrgID,
RetentionRules: bucket.RetentionRules,
Rp: bucket.Rp,
}
return b.createBucket(ctx, bucketReq)
}

func (b *bucketsAPI) CreateBucketWithNameWithID(ctx context.Context, orgID, bucketName string, rules ...domain.RetentionRule) (*domain.Bucket, error) {
bucket := &domain.PostBucketRequest{Name: bucketName, OrgID: &orgID, RetentionRules: rules}
bucket := &domain.PostBucketRequest{Name: bucketName, OrgID: orgID, RetentionRules: rules}
return b.createBucket(ctx, bucket)
}
func (b *bucketsAPI) CreateBucketWithName(ctx context.Context, org *domain.Organization, bucketName string, rules ...domain.RetentionRule) (*domain.Bucket, error) {
Expand Down
7 changes: 4 additions & 3 deletions api/buckets_e2e_test.go
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -290,7 +291,7 @@ func TestBucketsAPI_requestFailing(t *testing.T) {
bucketsAPI := client.BucketsAPI()

anID := "1000000000000000"
bucket := &domain.Bucket{Id: &anID}
bucket := &domain.Bucket{Id: &anID, OrgID: &anID}
user := &domain.User{Id: &anID}

_, err := bucketsAPI.GetBuckets(ctx)
Expand Down
12 changes: 0 additions & 12 deletions api/examples_test.go
Expand Up @@ -347,18 +347,6 @@ func ExampleLabelsAPI() {
panic(err)
}

// Get organization that will have the label
org, err := orgsAPI.FindOrganizationByName(ctx, "IT")
if err != nil {
panic(err)
}

// Add label to org
_, err = orgsAPI.AddLabel(ctx, org, label)
if err != nil {
panic(err)
}

// Change color property
label.Properties.AdditionalProperties = map[string]string{"color": "ff1122"}
label, err = labelsAPI.UpdateLabel(ctx, label)
Expand Down
54 changes: 0 additions & 54 deletions api/labels_e2e_test.go
Expand Up @@ -83,40 +83,6 @@ func TestLabelsAPI(t *testing.T) {
assert.NotNil(t, err)
assert.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)

err = orgAPI.DeleteOrganization(ctx, org)
assert.Nil(t, err, err)

err = labelsAPI.DeleteLabel(ctx, label)
require.Nil(t, err, err)
//
Expand Down Expand Up @@ -155,26 +121,6 @@ func TestLabelsAPI_failing(t *testing.T) {

err = labelsAPI.DeleteLabelWithID(ctx, invalidID)
assert.NotNil(t, err)

labels, err = orgAPI.GetLabelsWithID(ctx, wrongID)
assert.NotNil(t, err)
assert.Nil(t, labels)

label, err = orgAPI.AddLabelWithID(ctx, *org.Id, wrongID)
assert.NotNil(t, err)
assert.Nil(t, label)

label, err = orgAPI.AddLabelWithID(ctx, wrongID, wrongID)
assert.NotNil(t, err)
assert.Nil(t, label)

err = orgAPI.RemoveLabelWithID(ctx, *org.Id, invalidID)
assert.NotNil(t, err)
assert.Nil(t, label)

err = orgAPI.RemoveLabelWithID(ctx, invalidID, invalidID)
assert.NotNil(t, err, err)
assert.Nil(t, label)
}

func TestLabelsAPI_requestFailing(t *testing.T) {
Expand Down
61 changes: 0 additions & 61 deletions api/organizations.go
Expand Up @@ -54,18 +54,6 @@ type OrganizationsAPI interface {
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 organizationsAPI struct {
Expand Down Expand Up @@ -282,52 +270,3 @@ func (o *organizationsAPI) RemoveOwnerWithID(ctx context.Context, orgID, memberI
}
return nil
}

func (o *organizationsAPI) GetLabels(ctx context.Context, org *domain.Organization) (*[]domain.Label, error) {
return o.GetLabelsWithID(ctx, *org.Id)
}

func (o *organizationsAPI) GetLabelsWithID(ctx context.Context, orgID string) (*[]domain.Label, error) {
params := &domain.GetOrgsIDLabelsParams{}
response, err := o.apiClient.GetOrgsIDLabelsWithResponse(ctx, orgID, params)
if err != nil {
return nil, err
}
if response.JSONDefault != nil {
return nil, domain.DomainErrorToError(response.JSONDefault, response.StatusCode())
}
return (*[]domain.Label)(response.JSON200.Labels), nil
}

func (o *organizationsAPI) AddLabel(ctx context.Context, org *domain.Organization, label *domain.Label) (*domain.Label, error) {
return o.AddLabelWithID(ctx, *org.Id, *label.Id)
}

func (o *organizationsAPI) AddLabelWithID(ctx context.Context, orgID, labelID string) (*domain.Label, error) {
params := &domain.PostOrgsIDLabelsParams{}
body := &domain.PostOrgsIDLabelsJSONRequestBody{LabelID: &labelID}
response, err := o.apiClient.PostOrgsIDLabelsWithResponse(ctx, orgID, params, *body)
if err != nil {
return nil, err
}
if response.JSONDefault != nil {
return nil, domain.DomainErrorToError(response.JSONDefault, response.StatusCode())
}
return response.JSON201.Label, nil
}

func (o *organizationsAPI) RemoveLabel(ctx context.Context, org *domain.Organization, label *domain.Label) error {
return o.RemoveLabelWithID(ctx, *org.Id, *label.Id)
}

func (o *organizationsAPI) RemoveLabelWithID(ctx context.Context, orgID, memberID string) error {
params := &domain.DeleteOrgsIDLabelsIDParams{}
response, err := o.apiClient.DeleteOrgsIDLabelsIDWithResponse(ctx, orgID, memberID, params)
if err != nil {
return err
}
if response.JSONDefault != nil {
return domain.DomainErrorToError(response.JSONDefault, response.StatusCode())
}
return nil
}
36 changes: 0 additions & 36 deletions api/organizations_deprecated.go
Expand Up @@ -56,18 +56,6 @@ type OrganizationsApi interface {
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 {
Expand Down Expand Up @@ -165,27 +153,3 @@ func (o *organizationsApiImpl) RemoveOwner(ctx context.Context, org *domain.Orga
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)
}
7 changes: 0 additions & 7 deletions api/organizations_e2e_test.go
Expand Up @@ -325,11 +325,4 @@ func TestOrganizationAPI_requestFailing(t *testing.T) {

_, err = orgsAPI.GetOwnersWithID(ctx, invalidID)
assert.NotNil(t, err)

_, err = orgsAPI.AddLabelWithID(ctx, *org.Id, anID)
assert.NotNil(t, err)

// remove owner with invalid ID
err = orgsAPI.RemoveLabelWithID(ctx, anID, anID)
assert.NotNil(t, err)
}
2 changes: 1 addition & 1 deletion client.go
Expand Up @@ -180,7 +180,7 @@ func (c *clientImpl) Setup(ctx context.Context, username, password, org, bucket
body := &domain.PostSetupJSONRequestBody{
Bucket: bucket,
Org: org,
Password: password,
Password: &password,
RetentionPeriodHrs: &retentionPeriodHours,
Username: username,
}
Expand Down
57 changes: 1 addition & 56 deletions client_e2e_deprecated_test.go
Expand Up @@ -714,8 +714,7 @@ func TestBuckets(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)
Expand Down Expand Up @@ -827,60 +826,6 @@ func TestLabels(t *testing.T) {
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)

Expand Down

0 comments on commit 9fbbd78

Please sign in to comment.