Skip to content

Commit

Permalink
Merge pull request #216 from ghoneycutt/root_npmrc
Browse files Browse the repository at this point in the history
Manage /root/.npmrc
  • Loading branch information
jyaworski committed Apr 20, 2016
2 parents 50f03a8 + a0ee47d commit dc08606
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ using the EPEL repository.

Path to the npm binary.

#### `npmrc_auth`

A string that contains the value for the key `_auth` that will be set in
`/root/.npmrc`, as this value is not allowed to be set by
nodejs::npm::global_config_entry. The default value is `undef`.

#### `repo_class`

Name of the Puppet class used for the setup and management of the Node.js
Expand Down
7 changes: 7 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$npm_package_ensure = $nodejs::params::npm_package_ensure,
$npm_package_name = $nodejs::params::npm_package_name,
$npm_path = $nodejs::params::npm_path,
$npmrc_auth = $nodejs::params::npmrc_auth,
$repo_class = $nodejs::params::repo_class,
$repo_enable_src = $nodejs::params::repo_enable_src,
$repo_ensure = $nodejs::params::repo_ensure,
Expand Down Expand Up @@ -107,6 +108,12 @@
validate_string($npm_package_name)
}

if $npmrc_auth {
if is_string($npmrc_auth) == false {
fail('npmrc_auth must be a string')
}
}

validate_array($use_flags)

include '::nodejs::install'
Expand Down
13 changes: 12 additions & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# PRIVATE CLASS: do not call directly
class nodejs::install {

$npmrc_auth = $::nodejs::npmrc_auth

if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
}
Expand Down Expand Up @@ -55,5 +58,13 @@
tag => 'nodesource_repo',
}
}
}

file { 'root_npmrc':
ensure => 'file',
path => '/root/.npmrc',
content => template('nodejs/npmrc.erb'),
owner => 'root',
group => 'root',
mode => '0600',
}
}
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class nodejs::params {
$legacy_debian_symlinks = false
$npmrc_auth = undef
$nodejs_debug_package_ensure = 'absent'
$nodejs_dev_package_ensure = 'absent'
$nodejs_package_ensure = 'present'
Expand Down
32 changes: 32 additions & 0 deletions spec/classes/nodejs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,38 @@
}
end

it 'the file resource root_npmrc should be in the catalog' do
is_expected.to contain_file('root_npmrc').with(
'ensure' => 'file',
'path' => '/root/.npmrc',
'owner' => 'root',
'group' => 'root',
'mode' => '0600',
)
end

context 'with npmrc_auth set to a string' do
let :params do
{
npmrc_auth: 'dXNlcjpwYXNzd29yZA==',
}
end

it { should contain_file('root_npmrc').with_content(/^_auth="dXNlcjpwYXNzd29yZA=="$/) }
end

context 'with npmrc_auth set to an invalid type (non-string)' do
let :params do
{
npmrc_auth: %w(invalid type),
}
end

it 'should fail' do
expect { catalogue }.to raise_error(Puppet::Error, /npmrc_auth must be a string/)
end
end

# legacy_debian_symlinks
context 'with legacy_debian_symlinks set to true' do
let :params do
Expand Down
6 changes: 6 additions & 0 deletions templates/npmrc.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file is being maintained by Puppet.
# DO NOT EDIT

<% if @npmrc_auth -%>
_auth="<%= @npmrc_auth %>"
<% end -%>

0 comments on commit dc08606

Please sign in to comment.