diff options
author | harikesh-kolekar <harikesh.kolekar@msystechnologies.com> | 2017-12-01 15:02:51 +0530 |
---|---|---|
committer | harikesh-kolekar <harikesh.kolekar@msystechnologies.com> | 2018-01-30 07:31:47 +0000 |
commit | c75f6632d55b93e6e3313ac7f8f01ae910daabd5 (patch) | |
tree | 464293c835904b7dcd3ecf8a454341a79ece1b7a | |
parent | 6ff560e7a36e92c24bbe2437face183263778f87 (diff) | |
download | chef-c75f6632d55b93e6e3313ac7f8f01ae910daabd5.tar.gz |
Add user attribute to create env variable
Signed-off-by: harikesh-kolekar <harikesh.kolekar@msystechnologies.com>
-rw-r--r-- | lib/chef/provider/env/windows.rb | 12 | ||||
-rw-r--r-- | lib/chef/resource/env.rb | 1 |
2 files changed, 9 insertions, 4 deletions
diff --git a/lib/chef/provider/env/windows.rb b/lib/chef/provider/env/windows.rb index e813025c81..c74911e40f 100644 --- a/lib/chef/provider/env/windows.rb +++ b/lib/chef/provider/env/windows.rb @@ -35,7 +35,7 @@ class Chef unless obj obj = WIN32OLE.connect("winmgmts://").get("Win32_Environment").spawninstance_ obj.name = @new_resource.key_name - obj.username = "<System>" + obj.username = new_resource.user end obj.variablevalue = @new_resource.value obj.put_ @@ -58,18 +58,22 @@ class Chef def env_value(key_name) obj = env_obj(key_name) - obj ? obj.variablevalue : ENV[key_name] + obj.variablevalue if obj end def env_obj(key_name) + return @env_obj if @env_obj wmi = WmiLite::Wmi.new # Note that by design this query is case insensitive with regard to key_name environment_variables = wmi.query("select * from Win32_Environment where name = '#{key_name}'") if environment_variables && environment_variables.length > 0 - environment_variables[0].wmi_ole_object + environment_variables.each do |env| + @env_obj = env.wmi_ole_object + return @env_obj if @env_obj.username.split('\\').last.casecmp(new_resource.user) == 0 + end end + @env_obj = nil end - end end end diff --git a/lib/chef/resource/env.rb b/lib/chef/resource/env.rb index 12133f4368..4f2919c3b2 100644 --- a/lib/chef/resource/env.rb +++ b/lib/chef/resource/env.rb @@ -31,6 +31,7 @@ class Chef property :key_name, String, identity: true, name_property: true property :value, String, required: true property :delim, [ String, nil, false ], desired_state: false + property :user, String, default: "<System>" end end end |