-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy pathhelpers.rb
55 lines (45 loc) · 1.49 KB
/
helpers.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#
# Cookbook: consul
# License: Apache 2.0
#
# Copyright:: 2014-2016, Bloomberg Finance L.P.
#
module ConsulCookbook
module Helpers
include Chef::Mixin::ShellOut
extend self
def arch_64?
node['kernel']['machine'] =~ /x86_64/ ? true : false
end
def windows?
platform_family?('windows') ? true : false
end
# returns windows friendly version of the provided path,
# ensures backslashes are used everywhere
# Gently plucked from https://github.com/chef-cookbooks/windows
def win_friendly_path(path)
path.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR || '\\') if path
end
# Simply using ::File.join was causing several attributes
# to return strange values in the resources (e.g. "C:/Program Files/\\consul\\data")
def join_path(*path)
windows? ? win_friendly_path(::File.join(path)) : ::File.join(path)
end
def program_files
join_path('C:', 'Program Files') + (arch_64? ? '' : ' x(86)')
end
def config_prefix_path
windows? ? join_path(program_files, 'consul') : join_path('/etc', 'consul')
end
def data_path
windows? ? join_path(program_files, 'consul', 'data') : join_path('/var/lib', 'consul')
end
def command(config_file, config_dir, program = '/usr/local/bin/consul')
if windows?
%(agent -config-file="#{config_file}" -config-dir="#{config_dir}")
else
"#{program} agent -config-file=#{config_file} -config-dir=#{config_dir}"
end
end
end
end