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

Bugfix: limit and offset params caused re-ordered resource list #2702

Merged
merged 1 commit into from
Jan 18, 2023

Conversation

john-odonnell
Copy link
Contributor

Desired Outcome

From ONYX-14314:

Running the offset option on the whole list doesn't work as defined, removes more item
When running the same command with filter, works correctly

Steps to reproduce:

  1. run conjur list
  2. run conjur list --offset 2

Current Results:
conjur list
[
"conjur:user:admin1",
"conjur:user:admin2",
"conjur:user:admin3",
"conjur:user:admin4",
"conjur:user:admin5",
"conjur:user:user1",
"conjur:user:user2",
"conjur:user:user3",
"conjur:user:user4",
"conjur:user:user5",
"conjur:policy:data",
"conjur:group:data/vault-admins",
"conjur:policy:data/vault",
"conjur:policy:conjur/authn-iam",
"conjur:policy:conjur/authn-gcp",
"conjur:policy:conjur/authn-azure"
]

conjur list --offset 2
[
"conjur:policy:conjur/authn-gcp",
"conjur:policy:conjur/authn-iam",
"conjur:policy:data",
"conjur:policy:data/vault",
"conjur:user:admin1",
"conjur:user:admin2",
"conjur:user:admin3",
"conjur:user:admin4",
"conjur:user:admin5",
"conjur:user:user1"
]

Expected Results:
conjur list
[
"conjur:user:admin1",
"conjur:user:admin2",
"conjur:user:admin3",
"conjur:user:admin4",
"conjur:user:admin5",
"conjur:user:user1",
"conjur:user:user2",
"conjur:user:user3",
"conjur:user:user4",
"conjur:user:user5",
"conjur:policy:data",
"conjur:group:data/vault-admins",
"conjur:policy:data/vault",
"conjur:policy:conjur/authn-iam",
"conjur:policy:conjur/authn-gcp",
"conjur:policy:conjur/authn-azure"
]

conjur list --offset 2
[
"conjur:user:admin3",
"conjur:user:admin4",
"conjur:user:admin5",
"conjur:user:user1",
"conjur:user:user2",
"conjur:user:user3",
"conjur:user:user4",
"conjur:user:user5",
"conjur:policy:data",
"conjur:group:data/vault-admins",
"conjur:policy:data/vault",
"conjur:policy:conjur/authn-iam",
"conjur:policy:conjur/authn-gcp",
"conjur:policy:conjur/authn-azure"
]

Implemented Changes

By default, listed resources are ordered by time-of-creation, which means related resources are typically grouped. When list or offset parameters are provided, the listed resources are ordered alphabetically by resource ID, which means resources are grouped by type.

I've removed the additional sorting when list or offset parameters are provided, so a limited or offset list will return resources in the expected order.

Connected Issue/Story

CyberArk internal issue ID: ONYX-14314

Definition of Done

At least 1 todo must be completed in the sections below for the PR to be
merged.

Changelog

  • The CHANGELOG has been updated, or
  • This PR does not include user-facing changes and doesn't require a
    CHANGELOG update

Test coverage

  • This PR includes new unit and integration tests to go with the code
    changes, or
  • The changes in this PR do not require tests

Documentation

  • Docs (e.g. READMEs) were updated in this PR
  • A follow-up issue to update official docs has been filed here: [insert issue ID]
  • This PR does not require updating any documentation

Behavior

  • This PR changes product behavior and has been reviewed by a PO, or
  • These changes are part of a larger initiative that will be reviewed later, or
  • No behavior was changed with this PR

Security

  • Security architect has reviewed the changes in this PR,
  • These changes are part of a larger initiative with a separate security review, or
  • There are no security aspects to these changes

@john-odonnell john-odonnell force-pushed the johnodon-resources-offset branch 3 times, most recently from e29864f to 35f7efa Compare January 13, 2023 20:03
## [1.19.2] - 2022-01-13

### Fixed
- Previously, including `limit` or `offset` parameters to a resource list request
Copy link

Choose a reason for hiding this comment

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

Lists should be surrounded by blank lines

@@ -114,7 +114,7 @@ def search account: nil, kind: nil, owner: nil, offset: nil, limit: nil, search:
raise ArgumentError, "'offset' contains an invalid value. 'offset' must be an integer greater than or equal to 0."
end

scope = scope.order(:resource_id).limit(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an excellent find, @john-odonnell!

However, I would suggest that the fix should be to make sure the order is applied to all queries, rather than remove it for all queries (I didn't see another order instance, but I also may have missed it).

It's important that the order be consistent, and if no order is given, postgresql documents that there is no order guarantee.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks. I updated the PR to order the resources before limiting based on limit & offset.

# Sort results alphabetically by resource ID
scope = scope.order(:resource_id)

if offset || limit
  ...

@john-odonnell john-odonnell force-pushed the johnodon-resources-offset branch from 35f7efa to 5226879 Compare January 17, 2023 19:49
@john-odonnell john-odonnell force-pushed the johnodon-resources-offset branch from 5226879 to 357af55 Compare January 17, 2023 19:52
@codeclimate
Copy link

codeclimate bot commented Jan 17, 2023

Code Climate has analyzed commit 357af55 and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Style 1

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 90.0% (-1.5% change).

View more on Code Climate.

@john-odonnell john-odonnell marked this pull request as ready for review January 18, 2023 14:55
@john-odonnell john-odonnell requested a review from a team as a code owner January 18, 2023 14:55
Copy link
Contributor

@micahlee micahlee left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @john-odonnell!

@john-odonnell john-odonnell merged commit 99e6170 into master Jan 18, 2023
@john-odonnell john-odonnell deleted the johnodon-resources-offset branch January 18, 2023 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants