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

Modify public REST API to get profiles for a host #79

Closed
wants to merge 1 commit into from
Closed

Modify public REST API to get profiles for a host #79

wants to merge 1 commit into from

Conversation

akofink
Copy link
Contributor

@akofink akofink commented Mar 6, 2019

@dLobatog WIP for feedback: This endpoint is required for the client. Should we be using subscription-manager ID or host fqdn (or allow either)? There's also an insights_id supplied by the canonical facts, but I'm not sure if we're storing that anywhere? it seems we don't store sub-man ID or insights_id anywhere, so hostname is the only identifier for hosts. Please correct me if that's not the case.

(Also WIP for tests)

@akofink
Copy link
Contributor Author

akofink commented Mar 6, 2019

Another thing that seems obvious but may be incorrect: we don't need to make a request to the systems API to see if the system exists if we just request this profiles API. Systems registered with old insights would not be in our compliance systems response anyway.

@quarckster quarckster force-pushed the master branch 5 times, most recently from ded0853 to 25f9004 Compare March 7, 2019 09:45
Copy link
Contributor

@dLobatog dLobatog left a comment

Choose a reason for hiding this comment

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

@akofink I agree with the direction of the PR, can you include some tests so we don't go down on code coverage? It's true we don't have any subman-id, however, the ID of the host is === to the ID of the host in the inventory.

https://github.com/RedHatInsights/compliance-backend/blob/master/app/services/host_inventory_api.rb makes sure that when a report is uploaded, we make sure to get the ID from the inventory if the host is not there, or create it there with an ID of our choosing.

.paginate(page: params[:page], per_page: params[:per_page])
.sort_by(&:score)
)
end

def index_relation
relation = Profile.includes(:rules, :hosts)
unless profile_index_params[:hostname].nil?
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick

return (relation = Profile.includes(:rules, :hosts) if profile_index_params[:hostname].blank?
relation.where(hosts: {name: profile_index_params[:hostname]})

Copy link
Contributor Author

@akofink akofink Mar 7, 2019

Choose a reason for hiding this comment

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

I have two issues with this:

  1. It's not extensible. In the future if we decide we want the ability to filter on other columns, we'd have to modify this code rather than adding code. I certainly wanted to write it like this, but see the next point about line length:
relation.where(hosts: {name: profile_index_params[:hostname]}) unless profile_index_params[:hostname].nil?
  1. It's not as readable (and it goes over the 80 character line limit - I think rubocop is enforcing that default)

@codecov-io
Copy link

codecov-io commented Mar 7, 2019

Codecov Report

Merging #79 into master will decrease coverage by 0.44%.
The diff coverage is 87.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #79      +/-   ##
==========================================
- Coverage   69.72%   69.28%   -0.45%     
==========================================
  Files          40       39       -1     
  Lines         555      547       -8     
==========================================
- Hits          387      379       -8     
  Misses        168      168
Impacted Files Coverage Δ
app/controllers/profiles_controller.rb 73.33% <87.5%> (+16.19%) ⬆️
app/models/profile.rb 91.3% <0%> (-1.01%) ⬇️
app/services/concerns/xccdf_report/profiles.rb 100% <0%> (ø) ⬆️
app/services/concerns/xccdf_report/rules.rb
app/services/xccdf_report_parser.rb 97.18% <0%> (+0.88%) ⬆️
app/policies/profile_policy.rb 75% <0%> (+5%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 444a9cc...8762d6b. Read the comment docs.

def index_relation
relation = Profile.includes(:rules, :hosts)
relation.where(hosts: { name: profile_index_params[:hostname] }) \
unless profile_index_params[:hostname].nil?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dLobatog how about this? It's kind of a compromise. 🤷‍♂️

@akofink akofink changed the title [WIP] Modify public REST API to get profiles for a host Modify public REST API to get profiles for a host Mar 25, 2019
@akofink
Copy link
Contributor Author

akofink commented Mar 25, 2019

Updated with tests. Rubocop doesn't like multiline trailing conditionals, so I had to use the traditional if. My previous points about extensibility and readability still hold.

@akofink
Copy link
Contributor Author

akofink commented Jun 14, 2019

This PR is out of date. We should use scoped search for this.

@akofink akofink closed this Jun 14, 2019
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.

3 participants