Move update versioning to query parameter, and fix up scope API tests (#244)
* Move update versioning to query parameter, and fix up scope API tests * Add version checks for update requests in other services
This commit is contained in:
1 parent
0d0660b061
commit
bbd200101f
16 files changed
+240
-102
No files matched your search
+19
-6
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/kr/pretty"
|
||||
@@ -41,7 +42,7 @@ func (c *groupsClient) Create(ctx context.Context, opt ...Option) (*Group, *api.
|
||||
|
||||
opts, apiOpts := getOpts(opt...)
|
||||
|
||||
req, err := c.client.NewRequest(ctx, "POST", fmt.Sprintf("groups"), opts.valueMap, apiOpts...)
|
||||
req, err := c.client.NewRequest(ctx, "POST", "groups", opts.valueMap, apiOpts...)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error creating Create request: %w", err)
|
||||
}
|
||||
@@ -116,13 +117,16 @@ func (c *groupsClient) Update(ctx context.Context, groupId string, version uint3
|
||||
}
|
||||
version = existingTarget.Version
|
||||
}
|
||||
opts.valueMap["version"] = version
|
||||
|
||||
req, err := c.client.NewRequest(ctx, "PATCH", fmt.Sprintf("groups/%s", groupId), opts.valueMap, apiOpts...)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error creating Update request: %w", err)
|
||||
}
|
||||
|
||||
q := url.Values{}
|
||||
q.Add("version", fmt.Sprintf("%d", version))
|
||||
req.URL.RawQuery = q.Encode()
|
||||
|
||||
resp, err := c.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error performing client request during Update call: %w", err)
|
||||
@@ -177,7 +181,7 @@ func (c *groupsClient) List(ctx context.Context, opt ...Option) ([]*Group, *api.
|
||||
|
||||
_, apiOpts := getOpts(opt...)
|
||||
|
||||
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("groups"), nil, apiOpts...)
|
||||
req, err := c.client.NewRequest(ctx, "GET", "groups", nil, apiOpts...)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error creating List request: %w", err)
|
||||
}
|
||||
@@ -225,7 +229,6 @@ func (c *groupsClient) AddMembers(ctx context.Context, groupId string, version u
|
||||
}
|
||||
version = existingTarget.Version
|
||||
}
|
||||
opts.valueMap["version"] = version
|
||||
|
||||
if len(memberIds) > 0 {
|
||||
opts.valueMap["member_ids"] = memberIds
|
||||
@@ -236,6 +239,10 @@ func (c *groupsClient) AddMembers(ctx context.Context, groupId string, version u
|
||||
return nil, nil, fmt.Errorf("error creating AddMembers request: %w", err)
|
||||
}
|
||||
|
||||
q := url.Values{}
|
||||
q.Add("version", fmt.Sprintf("%d", version))
|
||||
req.URL.RawQuery = q.Encode()
|
||||
|
||||
resp, err := c.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error performing client request during AddMembers call: %w", err)
|
||||
@@ -276,7 +283,6 @@ func (c *groupsClient) SetMembers(ctx context.Context, groupId string, version u
|
||||
}
|
||||
version = existingTarget.Version
|
||||
}
|
||||
opts.valueMap["version"] = version
|
||||
|
||||
if len(memberIds) > 0 {
|
||||
opts.valueMap["member_ids"] = memberIds
|
||||
@@ -290,6 +296,10 @@ func (c *groupsClient) SetMembers(ctx context.Context, groupId string, version u
|
||||
return nil, nil, fmt.Errorf("error creating SetMembers request: %w", err)
|
||||
}
|
||||
|
||||
q := url.Values{}
|
||||
q.Add("version", fmt.Sprintf("%d", version))
|
||||
req.URL.RawQuery = q.Encode()
|
||||
|
||||
resp, err := c.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error performing client request during SetMembers call: %w", err)
|
||||
@@ -330,7 +340,6 @@ func (c *groupsClient) RemoveMembers(ctx context.Context, groupId string, versio
|
||||
}
|
||||
version = existingTarget.Version
|
||||
}
|
||||
opts.valueMap["version"] = version
|
||||
|
||||
if len(memberIds) > 0 {
|
||||
opts.valueMap["member_ids"] = memberIds
|
||||
@@ -341,6 +350,10 @@ func (c *groupsClient) RemoveMembers(ctx context.Context, groupId string, versio
|
||||
return nil, nil, fmt.Errorf("error creating RemoveMembers request: %w", err)
|
||||
}
|
||||
|
||||
q := url.Values{}
|
||||
q.Add("version", fmt.Sprintf("%d", version))
|
||||
req.URL.RawQuery = q.Encode()
|
||||
|
||||
resp, err := c.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error performing client request during RemoveMembers call: %w", err)
|
||||
|
||||
Reference in new issue
Block a user