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

Fixes #14158 - Add support for tailoring files #225

Merged
merged 1 commit into from Jan 6, 2017

Conversation

xprazak2
Copy link
Contributor

@xprazak2 xprazak2 commented Nov 21, 2016

TODO:

  • tests

FactoryGirl.create(:openscap_proxy)
ForemanOpenscap::TailoringFile.any_instance.stubs(:fetch_profiles).returns({ 'test_profile_key' => 'test_profile_title' })
end
end

Choose a reason for hiding this comment

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

Final newline missing.


test 'index' do
get :index, set_session_user
binding.pry

Choose a reason for hiding this comment

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

Remove debugger entry point binding.pry.

private

def redigest
self[:digest] = Digest::SHA256.hexdigest "#{scap_file}"

Choose a reason for hiding this comment

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

Prefer to_s over string interpolation.

end

def digest
self[:digest] ||= Digest::SHA256.hexdigest "#{scap_file}"

Choose a reason for hiding this comment

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

Prefer to_s over string interpolation.


def index
@tailoring_files = resource_base.search_for(params[:search], :order => params[:order])
.paginate(:page => params[:page], :per_page => params[:per_page])

Choose a reason for hiding this comment

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

Place the . on the previous line, together with the method call receiver.
Align .paginate with .search_for on line 13.

end

def index
@tailoring_files = resource_base.search_for(params[:search], :order => params[:order])

Choose a reason for hiding this comment

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

Use 2 (not 0) spaces for indentation.

@@ -13,7 +14,7 @@ def index
@policies = resource_base
.search_for(params[:search], :order => params[:order])
.paginate(:page => params[:page], :per_page => params[:per_page])
.includes(:scap_content, :scap_content_profile)
.includes(:scap_content, :scap_content_profile, :tailoring_file)

Choose a reason for hiding this comment

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

Place the . on the previous line, together with the method call receiver.
Align .includes with resource_base on line 14.

@ares
Copy link
Member

ares commented Nov 22, 2016

trying to update name of tailoring file results in 500

2016-11-22T14:37:56 26c05376 [app] [I] Started PATCH "/compliance/tailoring_files/1" for ::1 at 2016-11-22 14:37:56 +0100
2016-11-22T14:37:56 26c05376 [app] [I] Processing by TailoringFilesController#update as HTML
2016-11-22T14:37:56 26c05376 [app] [I]   Parameters: {"utf8"=>"✓", "authenticity_token"=>"D1uNodKYx/YcaE5LYINGIvMwNFi2TigegZ+iW4UOzM1+9PToKnvAgtTCGQjpte6Cnli56y/0NVcw907tdoazgg==", "tailoring_file"=>{"name"=>"my_tailor2", "location_ids"=>["", "2"], "organization_ids"=>["", "1"]}, "commit"=>"Submit", "id"=>"1"}
2016-11-22T14:37:56 26c05376 [sql] [D]   ActiveRecord::SessionStore::Session Load (0.3ms)  SELECT  "sessions".* FROM "sessions" WHERE "sessions"."session_id" = $1  ORDER BY "sessions"."id" ASC LIMIT 1  [["session_id", "26c05376c1e8353aad4a78ba13461875"]]
2016-11-22T14:37:56 26c05376 [sql] [D]   User Load (0.2ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 3]]
2016-11-22T14:37:56 26c05376 [app] [D] Setting current user thread-local variable to admin
2016-11-22T14:37:56 26c05376 [sql] [D]    (0.3ms)  SELECT COUNT(*) FROM "taxonomies" WHERE "taxonomies"."type" IN ('Organization')
2016-11-22T14:37:56 26c05376 [app] [D] Setting current organization thread-local variable to none
2016-11-22T14:37:56 26c05376 [sql] [D]    (0.2ms)  SELECT COUNT(*) FROM "taxonomies" WHERE "taxonomies"."type" IN ('Location')
2016-11-22T14:37:56 26c05376 [app] [D] Setting current location thread-local variable to none
2016-11-22T14:37:56 26c05376 [sql] [D]   AuthSource Load (0.1ms)  SELECT  "auth_sources".* FROM "auth_sources" WHERE "auth_sources"."id" = $1 LIMIT 1  [["id", 1]]
2016-11-22T14:37:56 26c05376 [sql] [D]    (0.2ms)  SELECT  "taxonomies"."id" FROM "taxonomies" WHERE "taxonomies"."type" IN ('Location') LIMIT 1
2016-11-22T14:37:56 26c05376 [sql] [D]    (0.1ms)  SELECT  "taxonomies"."id" FROM "taxonomies" WHERE "taxonomies"."type" IN ('Organization') LIMIT 1
2016-11-22T14:37:56 26c05376 [sql] [D]   ForemanOpenscap::TailoringFile Load (0.2ms)  SELECT  "foreman_openscap_tailoring_files".* FROM "foreman_openscap_tailoring_files" WHERE "foreman_openscap_tailoring_files"."id" = $1 LIMIT 1  [["id", 1]]
2016-11-22T14:37:56 26c05376 [sql] [D]   ForemanOpenscap::TailoringFile Load (0.3ms)  SELECT "foreman_openscap_tailoring_files".* FROM "foreman_openscap_tailoring_files"
2016-11-22T14:37:56 26c05376 [app] [I] Completed 500 Internal Server Error in 19ms (ActiveRecord: 1.5ms)
2016-11-22T14:37:56 26c05376 [app] [F] 
 | NameError (undefined local variable or method `scap_content_params' for #<TailoringFilesController:0x0055e42e8f7a10>):
 |   /home/ares/Projekty/Zdrojaky/foreman_openscap/app/controllers/tailoring_files_controller.rb:34:in `update'
 |   app/controllers/concerns/application_shared.rb:14:in `set_timezone'
 |   app/models/concerns/foreman/thread_session.rb:32:in `clear_thread'
 |   lib/middleware/catch_json_parse_errors.rb:8:in `call'
 |   lib/middleware/tagged_logging.rb:18:in `call'
 | 
 | 
2016-11-22T14:37:57 26c05376 [app] [I]   Rendered /home/ares/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (4.7ms)
2016-11-22T14:37:57 26c05376 [app] [I]   Rendered /home/ares/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.9ms)
2016-11-22T14:37:57 26c05376 [app] [I]   Rendered /home/ares/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.7ms)
2016-11-22T14:37:57 26c05376 [app] [I]   Rendered /home/ares/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (20.0ms

@ares
Copy link
Member

ares commented Nov 22, 2016

One more issue found during testing, when I change tailoring file for a policy, the tailoring file is already cached on smart proxy at tailoring/5/5_tailoring_file.xml. Even if foreman_scap_client gets new hash, it downloads old tailoring file. We either need to change the way we store files on proxy and start using hashes there too or proxy needs invalidating the files which should be triggered from Foreman whenever tailoring file was changed for policy or the content of the file changed itself. Do we have the same issue for regular scap content file?

Except for this issue it works pretty well 👍

@theforeman-bot
Copy link
Member

@xprazak2, this pull request is currently not mergeable. Please rebase against the master branch and push again.

If you have a remote called 'upstream' that points to this repository, you can do this by running:

    $ git pull --rebase upstream master

This message was auto-generated by Foreman's prprocessor

.includes(:scap_content, :scap_content_profile)
@policies = resource_base.search_for(params[:search], :order => params[:order])
.paginate(:page => params[:page], :per_page => params[:per_page])
.includes(:scap_content, :scap_content_profile, :tailoring_file)

Choose a reason for hiding this comment

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

Place the . on the previous line, together with the method call receiver.

.paginate(:page => params[:page], :per_page => params[:per_page])
.includes(:scap_content, :scap_content_profile)
@policies = resource_base.search_for(params[:search], :order => params[:order])
.paginate(:page => params[:page], :per_page => params[:per_page])

Choose a reason for hiding this comment

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

Place the . on the previous line, together with the method call receiver.

Copy link
Member

Choose a reason for hiding this comment

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

+1

@xprazak2
Copy link
Contributor Author

I added more tests, fixed style most of style issues, disabled a couple of obnoxious cops, fixed the 500. Not sure if we have the problems when changing scap contents for policy, I will have to verify.

ProxyAPI::Openscap.any_instance.stubs(:fetch_policies_for_scap_content).
returns({'xccdf_org.ssgproject.content_profile_common' => 'Common Profile for General-Purpose Fedora Systems'})
ProxyAPI::Openscap.any_instance.stubs(:fetch_profiles_for_tailoring_file).
returns({'xccdf_org.ssgproject.test_profile_common' => 'Stubbed test profile'})

Choose a reason for hiding this comment

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

Use 2 (not 19) spaces for indenting an expression spanning multiple lines.

ProxyAPI::Version.any_instance.stubs(:proxy_versions).returns(versions)
ProxyAPI::Openscap.any_instance.stubs(:validate_scap_file).returns({'errors' => []})
ProxyAPI::Openscap.any_instance.stubs(:fetch_policies_for_scap_content).
returns({'xccdf_org.ssgproject.content_profile_common' => 'Common Profile for General-Purpose Fedora Systems'})

Choose a reason for hiding this comment

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

Use 2 (not 19) spaces for indenting an expression spanning multiple lines.

@xprazak2
Copy link
Contributor Author

xprazak2 commented Jan 2, 2017

Changes:

  • I moved the dots to end of lines and enabled the corresponding cop
  • Tailoring file XML can be downloaded from UI through action menu
  • When uploading a tailoring file with old proxy version, notification is shown
  • grouping dropdowns for tailoring file and its profiles in policy wizard, tailoring profiles dropdown is not shown when tailoring file is not selected

@xprazak2 xprazak2 force-pushed the tailoring branch 3 times, most recently from 7284d2d to 5099c84 Compare January 2, 2017 13:16
end
end

def edit; end

Choose a reason for hiding this comment

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

Put the end of empty method definitions on the next line.


api :GET, '/compliance/tailoring_files/:id', N_('Show a Tailoring file')
param :id, :identifier, :required => true
def show; end

Choose a reason for hiding this comment

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

Put the end of empty method definitions on the next line.

@xprazak2 xprazak2 force-pushed the tailoring branch 4 times, most recently from a8a8b15 to 1651821 Compare January 3, 2017 12:38

def index
@tailoring_files = resource_base.search_for(params[:search], :order => params[:order]).
paginate(:page => params[:page], :per_page => params[:per_page])

Choose a reason for hiding this comment

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

Align paginate with resource_base.search_for(params[:search], :order => params[:order]). on line 13.

@xprazak2
Copy link
Contributor Author

xprazak2 commented Jan 5, 2017

Adjusted column width on tailoring_files/index page.

@ares
Copy link
Member

ares commented Jan 5, 2017

Cool, you even added Created column 👍 I think it's ready for merge now pending jenkins. Once we get smart proxy PR also confirmed by Jenkins I'll merge the whole train of PRs

@shlomizadok
Copy link
Member

Thanks @xprazak2, @ares 🎉

@shlomizadok shlomizadok merged commit 4a75cb4 into theforeman:master Jan 6, 2017
@ares
Copy link
Member

ares commented Jan 6, 2017

👍 @xprazak2 I think you have a good material for next community demo :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants