diff options
author | nimisha <nimisha.sharad@msystechnologies.com> | 2017-01-27 15:44:48 +0530 |
---|---|---|
committer | nimisha <nimisha.sharad@msystechnologies.com> | 2017-02-02 18:00:37 +0530 |
commit | c39006c5f757281525703d8506bfb6d4e9340082 (patch) | |
tree | 05477983a26f0d2db4bcabceaa9ac6c475c1301e /lib | |
parent | dd75bf444a73bc35c226aabaf4f5ea26b8528285 (diff) | |
download | chef-c39006c5f757281525703d8506bfb6d4e9340082.tar.gz |
Fixed bugs, review comments and specs
Signed-off-by: nimisha <nimisha.sharad@msystechnologies.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/mixin/user_identity.rb | 21 | ||||
-rw-r--r-- | lib/chef/provider/execute.rb | 10 |
2 files changed, 24 insertions, 7 deletions
diff --git a/lib/chef/mixin/user_identity.rb b/lib/chef/mixin/user_identity.rb index 8cb8f72ed6..bc8626ac65 100644 --- a/lib/chef/mixin/user_identity.rb +++ b/lib/chef/mixin/user_identity.rb @@ -53,18 +53,27 @@ class Chef raise ArgumentError, "The domain `#{specified_domain}` was specified, but no user name was given" end + # if domain is provided in both username and domain + if specified_user && ((specified_user.include? '\\') || (specified_user.include? "@")) && specified_domain + raise ArgumentError, "The domain is provided twice. Username: `#{specified_user}`, Domain: `#{specified_domain}`. Please specify domain only once." + end + if ! specified_user.nil? && specified_domain.nil? + # Splitting username of format: Domain\Username domain_and_user = user.split('\\') - if domain_and_user.length == 1 - domain_and_user = user.split("@") - end - if domain_and_user.length == 2 domain = domain_and_user[0] user = domain_and_user[1] - elsif domain_and_user.length != 1 - raise ArgumentError, "The specified user name `#{user}` is not a syntactically valid user name" + elsif domain_and_user.length == 1 + # Splitting username of format: Username@Domain + domain_and_user = user.split("@") + if domain_and_user.length == 2 + domain = domain_and_user[1] + user = domain_and_user[0] + elsif domain_and_user.length != 1 + raise ArgumentError, "The specified user name `#{user}` is not a syntactically valid user name" + end end end diff --git a/lib/chef/provider/execute.rb b/lib/chef/provider/execute.rb index c2498ab90b..5494405a02 100644 --- a/lib/chef/provider/execute.rb +++ b/lib/chef/provider/execute.rb @@ -43,6 +43,10 @@ class Chef def define_resource_requirements # @todo: this should change to raise in some appropriate major version bump. + requirements.assert(:all_actions) do |a| + a.assertion { validate_identity(new_resource.user, new_resource.password, new_resource.domain) } + end + if creates && creates_relative? && !cwd Chef::Log.warn "Providing a relative path for the creates attribute without the cwd is deprecated and will be changed to fail in the future (CHEF-3819)" end @@ -55,7 +59,11 @@ class Chef end def action_run - validate_identity(new_resource.user, new_resource.password, new_resource.domain) + # parse username if it's in the following format: domain/username or username@domain + identity = qualify_user(new_resource.user, new_resource.domain) + new_resource.user identity[:user] + new_resource.domain identity[:domain] + if creates && sentinel_file.exist? Chef::Log.debug("#{new_resource} sentinel file #{sentinel_file} exists - nothing to do") return false |