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

Consolidate workspace actions #12457

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/msf/core/db_manager/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,16 @@ def update_workspace(opts)
Msf::Util::DBManager.delete_opts_workspace(opts)

::ActiveRecord::Base.connection_pool.with_connection {
ws_to_update = workspaces({ id: opts.delete(:id) }).first
ws_id = opts.delete(:id)
ws_to_update = workspaces({ id: ws_id }).first
default_renamed = true if ws_to_update.name == DEFAULT_WORKSPACE_NAME
updated_ws = ws_to_update.update!(opts)
Copy link
Contributor Author

@jmartin-tech jmartin-tech Oct 15, 2019

Choose a reason for hiding this comment

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

This line prompted this change as update!() actually returns a boolean not the workspace object.

begin
ws_to_update.update!(opts) # will raise exception if it fails
rescue ActiveRecord::RecordInvalid => e
raise ArgumentError.new(e.message)
end
add_workspace({ name: DEFAULT_WORKSPACE_NAME }) if default_renamed
updated_ws
workspaces({ id: ws_id }).first
}
end
end
5 changes: 0 additions & 5 deletions lib/msf/ui/console/command_dispatcher/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ def cmd_workspace(*args)
name: names.last
}
begin
if names.last == Msf::DBManager::Workspace::DEFAULT_WORKSPACE_NAME
print_error("Unable to rename a workspace to '#{Msf::DBManager::Workspace::DEFAULT_WORKSPACE_NAME}'")
return
end
updated_ws = framework.db.update_workspace(opts)
if updated_ws
framework.db.workspace = updated_ws if names.first == framework.db.workspace.name
Expand All @@ -197,7 +193,6 @@ def cmd_workspace(*args)
end
rescue => e
print_error "Failed to rename workspace: #{e.message}"
e.backtrace.each { |line| print_error "#{line}"}
end

elsif names
Expand Down