-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from asgoodasnu/add-profiles
adds a define for adding awscli profiles
- Loading branch information
Showing
8 changed files
with
156 additions
and
1 deletion.
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
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,8 +1,13 @@ | ||
FORGE | ||
remote: https://forgeapi.puppetlabs.com | ||
specs: | ||
puppetlabs-concat (1.2.0) | ||
puppetlabs-stdlib (< 5.0.0, >= 3.2.0) | ||
puppetlabs-stdlib (4.5.1) | ||
stahnma-epel (1.0.2) | ||
|
||
DEPENDENCIES | ||
puppetlabs-concat (< 2.0.0, >= 1.0.0) | ||
puppetlabs-stdlib (< 5.0.0, >= 4.0.0) | ||
stahnma-epel (< 2.0.0, >= 1.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
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,55 @@ | ||
# == Define: awscli::profile | ||
# | ||
# Puts a profile into the awscred file | ||
# | ||
# === Options | ||
# | ||
# [*user*] | ||
# The user for whom the profile will be installed | ||
# [*aws_access_key_id*] | ||
# The aws_access_key_id for this profile | ||
# | ||
# [*aws_secret_access_key*] | ||
# The aws_secret_access_key for this profile | ||
# | ||
define awscli::profile( | ||
$user = 'root', | ||
$aws_access_key_id = undef, | ||
$aws_secret_access_key = undef, | ||
) { | ||
if $aws_access_key_id == undef { | ||
fail ('no aws_access_key_id provided') | ||
} | ||
|
||
if $aws_secret_access_key == undef { | ||
fail ('no aws_secret_access_key provided') | ||
} | ||
|
||
if $user != 'root' { | ||
$homedir = "/home/${user}" | ||
} else { | ||
$homedir = '/root' | ||
} | ||
|
||
if !defined(File["${homedir}/.aws"]) { | ||
file { "${homedir}/.aws": | ||
ensure => 'directory', | ||
owner => $user, | ||
group => $user | ||
} | ||
} | ||
|
||
if !defined(Concat["${homedir}/.aws/credentials"]) { | ||
concat { "${homedir}/.aws/credentials": | ||
ensure => 'present' | ||
} | ||
} | ||
|
||
|
||
concat::fragment{ $title: | ||
target => "${homedir}/.aws/credentials", | ||
content => template('awscli/credentials_concat.erb') | ||
} | ||
} | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'spec_helper' | ||
|
||
describe 'awscli::profile', :type => :define do | ||
context 'supported OS ' do | ||
['darwin', 'debian', 'redhat'].each do |osfamily| | ||
describe "#{osfamily} installation" do | ||
let(:facts) { { | ||
:osfamily => osfamily, | ||
:concat_basedir => '/var/lib/puppet/concat/' | ||
} } | ||
|
||
let(:title) { 'test_profile' } | ||
|
||
let(:params) { { } } | ||
|
||
it 'should report an error if no aws_access_key_id is given' do | ||
is_expected.to raise_error(Puppet::Error, /no aws_access_key_id provided/) | ||
end | ||
|
||
it 'should report an error if no aws_secret_access_key is given' do | ||
params.merge!({ 'aws_access_key_id' => 'TESTAWSACCESSKEYID' }) | ||
is_expected.to raise_error(Puppet::Error, /no aws_secret_access_key provided/) | ||
end | ||
|
||
it 'should create profile for root if no user is given' do | ||
params.merge!({ | ||
'aws_access_key_id' => 'TESTAWSACCESSKEYID', | ||
'aws_secret_access_key' => 'TESTSECRETACCESSKEY' | ||
}) | ||
is_expected.to contain_file('/root/.aws').with_ensure('directory') | ||
is_expected.to contain_concat('/root/.aws/credentials') | ||
is_expected.to contain_concat__fragment( 'test_profile' ).with | ||
({ | ||
:target => '/root/.aws/credentials' | ||
}) | ||
end | ||
|
||
it 'should create profile for user test' do | ||
params.merge!({ | ||
'user' => 'test', | ||
'aws_access_key_id' => 'TESTAWSACCESSKEYID', | ||
'aws_secret_access_key' => 'TESTSECRETACCESSKEY' | ||
}) | ||
is_expected.to contain_file('/home/test/.aws').with_ensure('directory') | ||
is_expected.to contain_concat('/home/test/.aws/credentials') | ||
is_expected.to contain_concat__fragment( 'test_profile' ).with | ||
({ | ||
:target => '/home/test/.aws/credentials' | ||
}) | ||
end | ||
|
||
|
||
end | ||
end | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[<%=@title%>] | ||
aws_access_key_id=<%=@aws_access_key_id%> | ||
aws_secret_access_key=<%=@aws_secret_access_key%> | ||
|
||
|
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 +1,6 @@ | ||
class { 'awscli': version => 'latest' } | ||
awscli::profile { 'default': | ||
user => 'vagrant', | ||
aws_access_key_id => 'MYTESTACCESSKEYID', | ||
aws_secret_access_key => 'MYTESTSECRETACCESSKEY' | ||
} |