Skip to content

Commit

Permalink
pass userid before going to automation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooli Tayer committed Jul 4, 2017
1 parent 3318c67 commit 221fa7a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ def scan_job_create(entity)
check_policy_prevent(:request_containerimage_scan, entity, :raw_scan_job_create)
end

def raw_scan_job_create(target_class, target_id = nil)
def raw_scan_job_create(target_class, target_id = nil, userid = nil)
target_class, target_id = target_class.class.name, target_class.id if target_class.kind_of?(ContainerImage)
userid ||= User.current_user.userid

Job.create_job(
"ManageIQ::Providers::Kubernetes::ContainerManager::Scanning::Job",
:userid => User.current_user.userid,
:userid => userid,
:name => "Container image analysis",
:target_class => target_class,
:target_id => target_id,
Expand All @@ -184,7 +186,7 @@ def check_policy_prevent(policy_event, event_target, cb_method)
:class_name => self.class.to_s,
:instance_id => id,
:method_name => :check_policy_prevent_callback,
:args => [cb_method, event_target.class.name, event_target.id],
:args => [cb_method, event_target.class.name, event_target.id, User.current_user.userid],
:server_guid => MiqServer.my_guid
}
enforce_policy(event_target, policy_event, {}, { :miq_callback => cb }) unless policy_event.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def fetch_oscap_arf
context "#initialize" do
it "Creates a new scan job" do
image = FactoryGirl.create(:container_image, :ext_management_system => @ems)
User.current_user = FactoryGirl.create(:user, :userid => "bob")
job = @ems.raw_scan_job_create(image.class, image.id)
job = @ems.raw_scan_job_create(image.class, image.id, "bob")
expect(job).to have_attributes(
:dispatch_status => "pending",
:state => "waiting_to_start",
Expand All @@ -105,6 +104,21 @@ def fetch_oscap_arf
:userid => "bob"
)
end

it "Is backward compatible with #54" do
# https://github.com/ManageIQ/manageiq-providers-kubernetes/pull/54/files
image = FactoryGirl.create(:container_image, :ext_management_system => @ems)
User.current_user = FactoryGirl.create(:user, :userid => "bob")
job = @ems.raw_scan_job_create(image.class, image.id)
expect(job).to have_attributes(
:dispatch_status => "pending",
:state => "waiting_to_start",
:status => "ok",
:message => "process initiated",
:target_class => "ContainerImage",
:userid => "bob"
)
end
end
end

Expand Down

0 comments on commit 221fa7a

Please sign in to comment.