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

Add cleanup for Windows env vars #694

Merged
merged 4 commits into from
Feb 27, 2020
Merged
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
25 changes: 25 additions & 0 deletions recipes/_install-windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@
# limitations under the License.
#

include_recipe 'chef_handler'

module Windows
class Helper
def do_cleanup(context)
Chef::Log.info 'Windows environment vars cleanup started.'
resource = context.resource_collection.lookup('windows_env[DDAGENTUSER_NAME]')
resource.run_action(:delete) if resource
resource = context.resource_collection.lookup('windows_env[DDAGENTUSER_PASSWORD]')
resource.run_action(:delete) if resource
Chef::Log.info 'Windows environment vars cleanup finished.'
end
end
end

Chef.event_handler do
on :run_failed do
Windows::Helper.new.do_cleanup(
Chef.run_context
)
end
end

dd_agent_version = Chef::Datadog.agent_version(node)

if dd_agent_version.nil?
Expand Down Expand Up @@ -144,8 +167,10 @@

windows_env 'DDAGENTUSER_NAME' do
action :delete
sensitive true
end

windows_env 'DDAGENTUSER_PASSWORD' do
action :delete
sensitive true
end