Skip to content

Commit

Permalink
Merge pull request #16895 from douglasgabriel/chg_pass_impl
Browse files Browse the repository at this point in the history
Adding method to change password of a provider on its client
  • Loading branch information
agrare authored Apr 13, 2018
2 parents 05e85b1 + b8b0a73 commit 7558ac5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
45 changes: 45 additions & 0 deletions app/models/manageiq/providers/physical_infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,50 @@ def console_supported?
def console_url
raise MiqException::Error, _("Console not supported")
end

supports :change_password

# Changes the password of userId on provider client and database.
#
# @param [current_password] password currently used for connected userId in provider client
# @param [new_password] password that will replace the current one
#
# @return [Boolean] true if the password was changed successfully
def change_password(current_password, new_password, auth_type = :default)
raw_change_password(current_password, new_password)
update_authentication(auth_type => {:userid => authentication_userid, :password => new_password})

true
end

def change_password_queue(userid, current_password, new_password, auth_type = :default)
task_opts = {
:action => "Changing the password for Physical Provider named '#{name}'",
:userid => userid
}

queue_opts = {
:class_name => self.class.name,
:instance_id => id,
:method_name => 'change_password',
:role => 'ems_operations',
:zone => my_zone,
:args => [current_password, new_password, auth_type]
}

MiqTask.generic_action_with_callback(task_opts, queue_opts)
end

# This method must provide a way to change password on provider client.
#
# @param [_current_password] password currently used for connected userId in provider client
# @param [_new_password] password that will replace the current one
#
# @return [Boolean] true if the password was changed successfully
#
# @raise [MiqException::Error] containing the error message if was not changed successfully
def raw_change_password(_current_password, _new_password)
raise NotImplementedError, _("must be implemented in subclass")
end
end
end
1 change: 1 addition & 0 deletions app/models/mixins/supports_feature_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ module SupportsFeatureMixin
:block_storage => 'Block Storage',
:object_storage => 'Object Storage',
:vm_import => 'VM Import',
:change_password => 'Change Password'
}.freeze

# Whenever this mixin is included we define all features as unsupported by default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,17 @@
:hostname => "0.0.0.0")
expect { ps.console_url }.to raise_error(MiqException::Error)
end

context "#change_password" do
it "should update the provider password" do
pim = FactoryGirl.create(:generic_physical_infra,
:name => "LXCA",
:hostname => "0.0.0.0")
allow(pim).to receive(:raw_change_password) { true }

current_password = "current_pass"
new_password = "new_pass"
expect(pim.change_password(current_password, new_password)).to be_truthy
end
end
end

0 comments on commit 7558ac5

Please sign in to comment.