-
-
Notifications
You must be signed in to change notification settings - Fork 246
/
global_config_entry.pp
78 lines (71 loc) · 3.19 KB
/
global_config_entry.pp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# See README.md for usage information.
define nodejs::npm::global_config_entry (
Enum['present', 'absent'] $ensure = 'present',
$config_setting = $title,
$cmd_exe_path = $nodejs::cmd_exe_path,
$npm_path = $nodejs::npm_path,
$value = undef,
) {
include nodejs
case $ensure {
'absent': {
$command = "config delete ${config_setting} --global"
# If this is a secret key, determine if it is set properly outside of NPM
# https://github.com/voxpupuli/puppet-nodejs/issues/326
if $config_setting =~ /(_|:_)/ {
$onlyif_command = $facts['os']['family'] ? {
'Windows' => "${cmd_exe_path} /C FOR /F %G IN ('${npm_path} config get globalconfig') DO IF EXIST %G (FINDSTR /B /C:\"${$config_setting}\" %G) ELSE (EXIT 1)",
default => "test -f $(${npm_path} config get globalconfig) && grep -qe \"^${$config_setting}\" $(${npm_path} config get globalconfig)",
}
}
else {
$onlyif_command = $facts['os']['family'] ? {
'Windows' => "${cmd_exe_path} /C ${npm_path} get --global| FINDSTR /B \"${config_setting}\"",
default => "${npm_path} get --global | grep -e \"^${config_setting}\"",
}
}
}
default: {
$command = "config set ${config_setting} ${value} --global"
# If this is a secret key, determine if it is set properly outside of NPM
# https://github.com/voxpupuli/puppet-nodejs/issues/326
if $config_setting =~ /(_|:_)/ {
$onlyif_command = $facts['os']['family'] ? {
'Windows' => "${cmd_exe_path} /V /C FOR /F %G IN ('${npm_path} config get globalconfig') DO IF EXIST %G (FINDSTR /B /C:\"${$config_setting}=\\\"${$value}\\\"\" %G & IF !ERRORLEVEL! EQU 0 ( EXIT 1 ) ELSE ( EXIT 0 )) ELSE ( EXIT 0 )",
default => "! test -f $(${npm_path} config get globalconfig) || ! grep -qe '^${$config_setting}=\"\\?${$value}\"\\?$' $(${npm_path} config get globalconfig)",
}
}
else {
$onlyif_command = $facts['os']['family'] ? {
'Windows' => "${cmd_exe_path} /C FOR /F %i IN ('${npm_path} get ${config_setting} --global') DO IF \"%i\" NEQ \"${value}\" ( EXIT 0 ) ELSE ( EXIT 1 )",
default => "test \"$(${npm_path} get ${config_setting} --global | tr -d '\n')\" != \"${value}\"",
}
}
}
}
if $nodejs::npm_package_ensure != 'absent' {
$exec_require = "Package[${nodejs::npm_package_name}]"
} elsif $nodejs::repo_class == '::nodejs::repo::nodesource' {
$exec_require = "Package[${nodejs::nodejs_package_name}]"
} else {
$exec_require = undef
}
#Determine exec provider
$provider = $facts['os']['family'] ? {
'Windows' => 'windows',
default => 'shell',
}
# set a sensible path on Unix
$exec_path = $facts['os']['family'] ? {
'Windows' => undef,
'Darwin' => ['/bin', '/usr/bin', '/opt/local/bin', '/usr/local/bin'],
default => ['/bin', '/usr/bin', '/usr/local/bin'],
}
exec { "npm_config ${ensure} ${title}":
command => "${npm_path} ${command}",
path => $exec_path,
provider => $provider,
onlyif => $onlyif_command,
require => $exec_require,
}
}