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

Cpe chrome fixes #258

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
61 changes: 35 additions & 26 deletions itchef/cookbooks/cpe_chrome/resources/cpe_chrome_posix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,14 @@ def manage_chrome
return if node['cpe_chrome']['validate_installed'] &&
!node.installed?('com.google.Chrome')
if node['cpe_chrome']['mp']['UseMasterPreferencesFile']
mprefs =
node['cpe_chrome']['mp']['FileContents'].reject { |_k, v| v.nil? }
mprefs = node['cpe_chrome']['mp']['FileContents'].compact
else
mprefs = {}
end
prefs = node['cpe_chrome']['profile'].reject do |_k, v|
v.nil? || (v.respond_to?(:empty?) && v.empty?)
end
return if prefs.empty? && mprefs.empty?

case node['os']
when 'darwin'
manage_chrome_macos(mprefs, prefs)
Expand All @@ -88,7 +87,10 @@ def manage_chrome
def manage_chrome_extensions
return if node['cpe_chrome']['validate_installed'] &&
!node.installed?('com.google.Chrome')
extprefs = node['cpe_chrome']['extension_profile'].reject do |_k, v|
extprefs = node['cpe_chrome']['extension_profile'].map do |k, v|
[k, v.compact]
end.to_h
extprefs = extprefs.reject do |_k, v|
v.nil? || (v.respond_to?(:empty?) && v.empty?)
end
case node['os']
Expand Down Expand Up @@ -140,7 +142,35 @@ def manage_chrome_linux(mprefs, prefs)
end
end

def manage_chrome_macos_master_prefs(mprefs)
# Apply the Master Preferences file
master_path = '/Library/Google/Google Chrome Master Preferences'
if mprefs.empty?
file master_path do
action :delete
end
else
directory '/Library/Google' do
mode '0755'
owner 'root'
group 'wheel'
action :create
end
# Create the Master Preferences file
file master_path do
mode '0644'
owner 'root'
group 'wheel'
action :create
content Chef::JSONCompat.to_json_pretty(mprefs)
end
end
end

def manage_chrome_macos(mprefs, prefs)
manage_chrome_macos_master_prefs(mprefs)
return if prefs.empty?

prefix = node['cpe_profiles']['prefix']
organization = node['organization'] ? node['organization'] : 'Facebook'
chrome_profile = {
Expand Down Expand Up @@ -197,32 +227,11 @@ def manage_chrome_macos(mprefs, prefs)
profile_domain = "#{node['cpe_profiles']['prefix']}.browsers.chromecanary"
node.default['cpe_profiles'][profile_domain] = canary_profile
end
# Apply the Master Preferences file
master_path = '/Library/Google/Google Chrome Master Preferences'
if mprefs.empty?
file master_path do
action :delete
end
else
directory '/Library/Google' do
mode '0755'
owner 'root'
group 'wheel'
action :create
end
# Create the Master Preferences file
file master_path do
mode '0644'
owner 'root'
group 'wheel'
action :create
content Chef::JSONCompat.to_json_pretty(mprefs)
end
end
end

def manage_chrome_extensions_macos(extprefs)
return if extprefs.empty?

prefix = node['cpe_profiles']['prefix']
organization = node['organization'] ? node['organization'] : 'Facebook'
extprefs.each do |k, v|
Expand Down
27 changes: 15 additions & 12 deletions itchef/cookbooks/cpe_chrome/resources/cpe_chrome_win.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
# chrome is installed on all machines
chrome_installed = ::File.file?(
"#{ENV['ProgramFiles(x86)']}\\Google\\Chrome\\Application\\chrome.exe",
)
) || ::File.file?(
"#{ENV['ProgramFiles']}\\Google\\Chrome\\Application\\chrome.exe",
) || !node['cpe_chrome']['validate_installed']

return unless chrome_installed || node.installed?('Google Chrome')
return unless node['cpe_chrome']['profile'].values.any?

Expand Down Expand Up @@ -255,10 +258,10 @@
'c:\\Program Files (x86)\\Google\\Chrome\\Application\\master_preferences'
file "delete-#{master_path}" do
only_if do
node['cpe_chrome']['mp']['FileContents'].
to_hash.
reject { |_k, v| v.nil? }.
empty?
node['cpe_chrome']['mp']['FileContents']
.to_hash
.compact
.empty?
end
path master_path
action :delete
Expand All @@ -281,16 +284,16 @@
# Create the Master Preferences file
file "create-#{master_path}" do # ~FB023
not_if do
node['cpe_chrome']['mp']['FileContents'].
to_hash.
reject { |_k, v| v.nil? }.
empty?
node['cpe_chrome']['mp']['FileContents']
.to_hash
.compact
.empty?
end
content lazy {
Chef::JSONCompat.to_json_pretty(
node['cpe_chrome']['mp']['FileContents'].
to_hash.
reject { |_k, v| v.nil? },
node['cpe_chrome']['mp']['FileContents']
.to_hash
.compact
)
}
path master_path
Expand Down