Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds UpdateRule method #176

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions redis_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,95 @@ func TestUpdateRedisRule(t *testing.T) {
require.NoError(t, err)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil_name_test.txt
Not sure a new model is needed, I got this test to pass (Name is nil, "name" is not present in output JSON)
Maybe I've completely missed the point though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redis_rules.UpdateRedisRuleRequest{
		RedisRule: redis.String("+@let-me-update-resources"),
}

This also works (same thing, bit neater than the explicit nil)

func TestUpdateRedisRuleOnly(t *testing.T) {
server := httptest.NewServer(
testServer(
"key",
"secret",
putRequest(
t,
"/acl/redisRules/20000",
`{"redisRule": "+@let-me-update-resources"}`,
`{
"taskId": "9a4178d9-0c84-4a7c-b02a-b0a559757df9",
"commandType": "aclRedisRuleUpdateRequest",
"status": "received",
"description": "Task request received and is being queued for processing.",
"timestamp": "2023-06-21T09:21:18.521282Z",
"links": [
{
"rel": "task",
"href": "https://api-cloudapi.qa.redislabs.com/v1/tasks/e3946019-994e-49f6-83bb-26694b3c241f",
"title": "getTaskStatusUpdates",
"type": "GET"
}
]
}`,
),
// Task doesn't exist just yet
getRequestWithStatus(t, "/tasks/9a4178d9-0c84-4a7c-b02a-b0a559757df9", 404, ""),
// Task exists, has just started
getRequest(t, "/tasks/9a4178d9-0c84-4a7c-b02a-b0a559757df9", `{
"taskId": "9a4178d9-0c84-4a7c-b02a-b0a559757df9",
"commandType": "aclRedisRuleUpdateRequest",
"status": "initialized",
"timestamp": "2023-06-21T09:22:18.521282Z",
"response": {},
"_links": {
"self": {
"rel": "task",
"href": "https://api-cloudapi.qa.redislabs.com/v1/tasks/9a4178d9-0c84-4a7c-b02a-b0a559757df9",
"title": "getTaskStatusUpdates",
"type": "GET"
}
}
}`),
// Task exists, is in progress
getRequest(t, "/tasks/9a4178d9-0c84-4a7c-b02a-b0a559757df9", `{
"taskId": "9a4178d9-0c84-4a7c-b02a-b0a559757df9",
"commandType": "aclRedisRuleUpdateRequest",
"status": "processing-in-progress",
"timestamp": "2023-06-21T09:23:18.521282Z",
"response": {},
"_links": {
"self": {
"rel": "task",
"href": "https://api-cloudapi.qa.redislabs.com/v1/tasks/9a4178d9-0c84-4a7c-b02a-b0a559757df9",
"title": "getTaskStatusUpdates",
"type": "GET"
}
}
}`),
// Task complete
getRequest(t, "/tasks/9a4178d9-0c84-4a7c-b02a-b0a559757df9", `{
"taskId": "9a4178d9-0c84-4a7c-b02a-b0a559757df9",
"commandType": "aclRedisRuleUpdateRequest",
"status": "processing-completed",
"timestamp": "2023-06-21T09:24:18.521282Z",
"response": {
"resourceId": 20000
},
"_links": {
"self": {
"rel": "task",
"href": "https://api-cloudapi.qa.redislabs.com/v1/tasks/9a4178d9-0c84-4a7c-b02a-b0a559757df9",
"title": "getTaskStatusUpdates",
"type": "GET"
}
}
}`),
),
)

subject, err := clientFromTestServer(server, "key", "secret")
require.NoError(t, err)

err = subject.RedisRules.UpdateRule(context.TODO(), 20000, redis_rules.UpdateRedisRuleRequest{
RedisRule: redis.String("+@let-me-update-resources"),
})
require.NoError(t, err)
}

func TestDeleteNonExistentRedisRule(t *testing.T) {
server := httptest.NewServer(
testServer(
Expand Down
8 changes: 8 additions & 0 deletions service/access_control_lists/redis_rules/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ func (o CreateRedisRuleRequest) String() string {
return internal.ToString(o)
}

type UpdateRedisRuleRequest struct {
RedisRule *string `json:"redisRule,omitempty"`
}

func (o UpdateRedisRuleRequest) String() string {
return internal.ToString(o)
}

const (
// StatusActive is the active value of the `Status` field in `RedisRule`
StatusActive = "active"
Expand Down
17 changes: 17 additions & 0 deletions service/access_control_lists/redis_rules/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ func (a *API) Update(ctx context.Context, id int, redisRule CreateRedisRuleReque
return nil
}

func (a *API) UpdateRule(ctx context.Context, id int, redisRule UpdateRedisRuleRequest) error {
var task internal.TaskResponse
err := a.client.Put(ctx, fmt.Sprintf("update redisRule %d", id), fmt.Sprintf("/acl/redisRules/%d", id), redisRule, &task)
if err != nil {
return wrap404Error(id, err)
}

a.logger.Printf("Waiting for task %s to finish updating the redisRule", task)

err = a.taskWaiter.Wait(ctx, *task.ID)
if err != nil {
return fmt.Errorf("failed when updating redisRule %d: %w", id, err)
}

return nil
}

// Delete will destroy an existing redisRule.
func (a *API) Delete(ctx context.Context, id int) error {
var task internal.TaskResponse
Expand Down