forked from voxpupuli/puppet-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nodejs::npm::global_config_entry: reimplement using ini_setting
Manage npm global config entries using the ini_setting resource instead of exec resources using `npm config` commands. Closes voxpupuli#439
- Loading branch information
Showing
6 changed files
with
64 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
fixtures: | ||
repositories: | ||
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git" | ||
"apt": "git://github.com/puppetlabs/puppetlabs-apt.git" | ||
"portage": "git://github.com/gentoo/puppet-portage.git" | ||
"chocolatey": "git://github.com/puppetlabs/puppetlabs-chocolatey.git" | ||
apt: git://github.com/puppetlabs/puppetlabs-apt.git | ||
chocolatey: git://github.com/puppetlabs/puppetlabs-chocolatey.git | ||
inifile: git://github.com/puppetlabs/puppetlabs-inifile.git | ||
portage: git://github.com/gentoo/puppet-portage.git | ||
stdlib: git://github.com/puppetlabs/puppetlabs-stdlib.git | ||
yumrepo_core: | ||
repo: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git | ||
puppet_version: ">= 6.0.0" | ||
repo: git://github.com/puppetlabs/puppetlabs-yumrepo_core.git | ||
puppet_version: '>= 6.0.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Facter.add('npm_globalconfig_path') do | ||
setcode 'npm config get globalconfig' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,13 @@ | ||
# 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, | ||
String[1] $config_setting = $title, | ||
Optional[String[1]] $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, | ||
ini_setting { $title: | ||
ensure => $ensure, | ||
path => $facts['npm_globalconfig_path'], | ||
setting => $config_setting, | ||
value => $value, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters