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

Use jq instead of grep -P for finding users to delete during integrat… #2319

Merged
merged 3 commits into from
Sep 20, 2022

Conversation

moleske
Copy link
Member

@moleske moleske commented Sep 15, 2022

…ion cleanup

  • was annoying me cause mac grep doesn't have -P

Thank you for contributing to the CF CLI! Please read the following:

  • Please make sure you have implemented changes in line with the contributing guidelines
  • We're not allowed to accept any PRs without a signed CLA, no matter how small.
    If your contribution falls under a company CLA but your membership is not public, expect delays while we confirm.
  • All new code requires tests to protect against regressions.
  • Contributions must be made against the appropriate branch. See the contributing guidelines
  • Contributions must conform to our style guide. Please reach out to us if you have questions.

Does this PR modify CLI v6, CLI v7, or CLI v8?

none it is testing related

Please see the contribution doc above or review Architecture Guide.

Description of the Change

We must be able to understand the design of your change from this description.
Keep in mind that the maintainer reviewing this PR may not be familiar with or
have worked with the code here recently, so please walk us through the concepts.

Why Is This PR Valuable?

What benefits will be realized by the code change? What users would want this change? What user need is this change addressing?

easier to understand clean up code

Why Should This Be In Core?

Explain why this functionality should be in the cf CLI, as opposed to a plugin.

it's integration test cleanup related

Applicable Issues

List any applicable Github Issues here

How Urgent Is The Change?

Is the change urgent? If so, explain why it is time-sensitive.
🤷

Other Relevant Parties

Who else is affected by the change?

…ion cleanup

- was annoying me cause mac grep doesn't have -P
Copy link
Contributor

@jdgonzaleza jdgonzaleza left a comment

Choose a reason for hiding this comment

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

LGTM!!
Cleaner than the previous implementation.

@@ -62,8 +62,7 @@ for stack in $(cf stacks | awk '/INTEGRATION-STACK/ { print $1 }'); do
cf curl -X DELETE "/v3/stacks/$(cf stack --guid $stack)"
done

CF_USERS=$(cf curl /v3/users | grep -oP '(?<="total_results":)[^"]*' |grep -o '[0-9]\+')
USER_PAGES=$(( $CF_USERS / 50 + 1))
USER_PAGES=$(cf curl /v3/users | jq -r .pagination.total_pages)

for ((i=1; i<=${USER_PAGES}; i++)) ; do
cf curl "/v3/users?per_page=50&page=${i}" | \
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this line needs to remove the per_page=50 part because the change above I made is just getting the total number of paginated pages for whatever the default number of users of the page is

@moleske moleske merged commit c67c88e into master Sep 20, 2022
@moleske moleske deleted the use-jq-on-user-clean-integration branch September 20, 2022 21:13
moleske added a commit that referenced this pull request Sep 20, 2022
#2319)

* Use jq instead of grep -P for finding users to delete during integration cleanup
* remove per page cause we're already iterating over a known set of pages
moleske added a commit that referenced this pull request Sep 20, 2022
#2319)

* Use jq instead of grep -P for finding users to delete during integration cleanup
* remove per page cause we're already iterating over a known set of pages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants