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

Manage /root/.npmrc #216

Merged
merged 1 commit into from
Apr 20, 2016
Merged
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
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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this instead of validate_string because I wanted to check for the Puppet::Error and a specific error string which can change quite a bit using validate_string() on different platforms.

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':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to manage the whole file? Can this be file_line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this because the docs read that this file is managed, even though it actually is not. So this is a step to get reality to match the docs.

I don't have any strong feelings between managing the contents of the file as it is now or using file_line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the docs read that the whole file is managed, how do you think we should do that? I'm thinking a concat resource.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should do what's in the PR :D

or file_line if you'd like.. whatever get's this merged.

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 -%>