puppet-blacksmith 3.3.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 359eca2b13c47203990a6471f9186a503ad9760a
4
- data.tar.gz: ac8ca97a230403ef8977a91b5110449aae669a47
3
+ metadata.gz: 067263620b3ecaa64fcd67b770345766d46f2728
4
+ data.tar.gz: 87c4bc41babc57dd308dca7307af27ce25e994dd
5
5
  SHA512:
6
- metadata.gz: be24419c31bf14b66ad41808d0c4cc55fe00998f1ba469e19aa43ff337a99174e17bd7dc79af925cfa15de56291a3f0a490a13d313c65de71a6171f630c8d5aa
7
- data.tar.gz: b6ae24c1cc384e790040617d5c4a3e60f76a890fd654bf702da530f859601b17112a3df3d415ac42ba522b7211e470c40e7bdbe2fa2a063f0d78fd53a47f830d
6
+ metadata.gz: d7a3db4d6999ab0ea7ee416b9fbc8b6f93c40e95bb8bf904fa91766b7a45f8abf87a1a2f7aba226a5710705c50026ef8181330a31f6113e95ba440dcc352d137
7
+ data.tar.gz: f3514d2f03b03b182aaa6c826e5e01ab5b525456761d13d2fb08f97608bda1754b1f74af99917dc9a4b77615aaf18df88e6a0145342cd9400d9257257df1bfd1
@@ -6,16 +6,18 @@ module Blacksmith
6
6
  class Forge
7
7
 
8
8
  PUPPETLABS_FORGE = "https://forgeapi.puppetlabs.com"
9
+ CREDENTIALS_FILE_HOME = "~/.puppetforge.yml"
10
+ CREDENTIALS_FILE_PROJECT = '.puppetforge.yml'
11
+ DEFAULT_CREDENTIALS = { 'url' => PUPPETLABS_FORGE }
9
12
  HEADERS = { 'User-Agent' => "Blacksmith/#{Blacksmith::VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE}; #{RUBY_PLATFORM})" }
10
13
 
11
- attr_accessor :username, :password, :client_id, :client_secret
12
- attr_writer :url
14
+ attr_accessor :username, :password, :url, :client_id, :client_secret
13
15
 
14
16
  def initialize(username = nil, password = nil, url = nil)
15
17
  self.username = username
16
18
  self.password = password
17
19
  RestClient.proxy = ENV['http_proxy']
18
- load_credentials_from_file if username.nil?
20
+ load_credentials
19
21
  load_client_credentials_from_file
20
22
  self.url = url unless url.nil?
21
23
  if self.url =~ %r{http(s)?://forge.puppetlabs.com}
@@ -24,10 +26,6 @@ module Blacksmith
24
26
  end
25
27
  end
26
28
 
27
- def url
28
- @url || PUPPETLABS_FORGE
29
- end
30
-
31
29
  def push!(name, package = nil)
32
30
  unless package
33
31
  regex = /^#{username}-#{name}-.*\.tar\.gz$/
@@ -65,27 +63,76 @@ module Blacksmith
65
63
 
66
64
  private
67
65
 
68
- def load_credentials_from_file
69
- credentials_file = File.expand_path("~/.puppetforge.yml")
70
- unless File.exists?(credentials_file)
66
+ def load_credentials
67
+ file_credentials = load_credentials_from_file
68
+ env_credentials = load_credentials_from_env
69
+
70
+ credentials = DEFAULT_CREDENTIALS.merge file_credentials
71
+ credentials = credentials.merge env_credentials
72
+
73
+ self.username = credentials['username'] if credentials['username']
74
+ self.password = credentials['password'] if credentials['password']
75
+ if credentials['forge']
76
+ # deprecated
77
+ puts "'forge' entry is deprecated in .puppetforge.yml, use 'url'"
78
+ self.url = credentials['forge']
79
+ end
80
+ self.url = credentials['url'] if credentials['url']
81
+
82
+ unless self.username && self.password
71
83
  raise Blacksmith::Error, <<-eos
72
- Could not find Puppet Forge credentials file '#{credentials_file}'
73
- Please create it
84
+ Could not find Puppet Forge credentials!
85
+
86
+ Please set the environment variables
87
+ BLACKSMITH_FORGE_URL
88
+ BLACKSMITH_FORGE_USERNAME
89
+ BLACKSMITH_FORGE_PASSWORD
90
+
91
+ or create the file '#{CREDENTIALS_FILE_PROJECT}' or '#{CREDENTIALS_FILE_HOME}'
92
+ with content similiar to:
93
+
74
94
  ---
75
95
  url: https://forgeapi.puppetlabs.com
76
96
  username: myuser
77
97
  password: mypassword
98
+
78
99
  eos
79
100
  end
80
- credentials = YAML.load_file(credentials_file)
81
- self.username = credentials['username']
82
- self.password = credentials['password']
83
- if credentials['forge']
84
- # deprecated
85
- puts "'forge' entry is deprecated in .puppetforge.yml, use 'url'"
86
- self.url = credentials['forge']
101
+ end
102
+
103
+ def load_credentials_from_file
104
+ credentials_file = [
105
+ File.join(Dir.pwd, CREDENTIALS_FILE_PROJECT),
106
+ File.expand_path(CREDENTIALS_FILE_HOME)
107
+ ]
108
+ .select { |file| File.exists?(file) }
109
+ .first
110
+
111
+ if credentials_file
112
+ credentials = YAML.load_file(credentials_file)
113
+ else
114
+ credentials = Hash.new
87
115
  end
88
- self.url = credentials['url'] if credentials['url']
116
+
117
+ return credentials
118
+ end
119
+
120
+ def load_credentials_from_env
121
+ credentials = Hash.new
122
+
123
+ if ENV['BLACKSMITH_FORGE_USERNAME']
124
+ credentials['username'] = ENV['BLACKSMITH_FORGE_USERNAME']
125
+ end
126
+
127
+ if ENV['BLACKSMITH_FORGE_PASSWORD']
128
+ credentials['password'] = ENV['BLACKSMITH_FORGE_PASSWORD']
129
+ end
130
+
131
+ if ENV['BLACKSMITH_FORGE_URL']
132
+ credentials['url'] = ENV['BLACKSMITH_FORGE_URL']
133
+ end
134
+
135
+ return credentials
89
136
  end
90
137
 
91
138
  def load_client_credentials_from_file
@@ -60,7 +60,7 @@ module Blacksmith
60
60
  new_version
61
61
  end
62
62
 
63
- [:major, :minor, :patch].each do |level|
63
+ [:major, :minor, :patch, :full].each do |level|
64
64
  define_method("bump_#{level}!") { bump!(level) }
65
65
  end
66
66
 
@@ -24,8 +24,18 @@ module Blacksmith
24
24
  'bump:major',
25
25
  'bump:minor',
26
26
  'bump:patch',
27
+ 'bump:full',
27
28
  :tag,
29
+ :version,
30
+ 'version:next',
31
+ 'version:next:major',
32
+ 'version:next:minor',
33
+ 'version:next:patch',
28
34
  :bump_commit,
35
+ 'bump_commit:major',
36
+ 'bump_commit:minor',
37
+ 'bump_commit:patch',
38
+ 'bump_commit:full',
29
39
  :push,
30
40
  :clean,
31
41
  :release,
@@ -37,7 +47,7 @@ module Blacksmith
37
47
  namespace :module do
38
48
 
39
49
  namespace :bump do
40
- [:major, :minor, :patch].each do |level|
50
+ [:major, :minor, :patch, :full].each do |level|
41
51
  desc "Bump module version to the next #{level.upcase} version"
42
52
  task level do
43
53
  m = Blacksmith::Modulefile.new
@@ -62,6 +72,38 @@ module Blacksmith
62
72
  git.tag!(m.version)
63
73
  end
64
74
 
75
+ namespace :version do
76
+ desc "Get next module version"
77
+ task :next do
78
+ m = Blacksmith::Modulefile.new
79
+ puts m.increase_version(m.version, 'patch')
80
+ end
81
+
82
+ [:major, :minor, :patch].each do |level|
83
+ desc "Get the next #{level.upcase} version"
84
+ task "next:#{level}".to_sym do
85
+ m = Blacksmith::Modulefile.new
86
+ puts m.increase_version(m.version, level)
87
+ end
88
+ end
89
+ end
90
+
91
+ desc "Get current module version"
92
+ task :version do
93
+ m = Blacksmith::Modulefile.new
94
+ puts m.version
95
+ end
96
+
97
+ namespace :bump_commit do
98
+ [:major, :minor, :patch, :full].each do |level|
99
+ desc "Bump module version to the next #{level.upcase} version and git commit"
100
+ task level => "bump:#{level}".to_sym do
101
+ m = Blacksmith::Modulefile.new
102
+ Blacksmith::Git.new.commit_modulefile!(m.version)
103
+ end
104
+ end
105
+ end
106
+
65
107
  desc "Bump version and git commit"
66
108
  task :bump_commit => :bump do
67
109
  m = Blacksmith::Modulefile.new
@@ -1,3 +1,3 @@
1
1
  module Blacksmith
2
- VERSION = '3.3.1'
2
+ VERSION = '3.4.0'
3
3
  end
@@ -104,6 +104,15 @@ module Blacksmith
104
104
  define_method("#{term}!") { increment!(term) }
105
105
  end
106
106
 
107
+ def full!
108
+ env_var = "BLACKSMITH_FULL_VERSION"
109
+ begin
110
+ ENV.fetch env_var
111
+ rescue KeyError
112
+ raise Exception, "Setting the full version requires setting the #{env_var} environment variable to the new version"
113
+ end
114
+ end
115
+
107
116
  def increment!(term)
108
117
  new_version = clone
109
118
  new_value = send(term) + 1
@@ -6,21 +6,67 @@ require 'webmock/rspec'
6
6
  describe 'Blacksmith::Forge' do
7
7
  include_context 'forge'
8
8
 
9
- describe 'missing credentials file' do
9
+ describe 'resolving credentials' do
10
10
  before do
11
- allow(File).to receive(:expand_path) { '/home/mr_puppet/.puppetforge.yml' }
11
+ allow(Dir).to receive(:pwd) { '/home/mr_puppet/puppet-some-module' }
12
+ allow(File).to receive(:expand_path).with('~/.puppetforge.yml') { '/home/mr_puppet/.puppetforge.yml' }
13
+ allow(File).to receive(:expand_path).with(/credentials.yml/) { '/home/mr_puppet/puppet-blacksmith/credentials.yml' }
14
+ allow(YAML).to receive(:load_file).with('/home/mr_puppet/puppet-blacksmith/credentials.yml') { {
15
+ "client_id" => "b93eb708fd942cfc7b4ed71db6ce219b814954619dbe537ddfd208584e8cff8d",
16
+ "client_secret" => "216648059ad4afec3e4d77bd9e67817c095b2dcf94cdec18ac3d00584f863180",
17
+ } }
12
18
  end
13
19
 
14
- context "when the credentials file is missing" do
15
- before do
16
-
17
- end
20
+ it 'prefers env vars to file values' do
21
+ stubbed_forge_password = 'asdf1234'
22
+
23
+ allow(File).to receive(:exists?).
24
+ with('/home/mr_puppet/puppet-some-module/.puppetforge.yml').
25
+ and_return(false)
26
+ allow(File).to receive(:exists?).
27
+ with('/home/mr_puppet/.puppetforge.yml').
28
+ and_return(true)
29
+ allow(YAML).to receive(:load_file).
30
+ with('/home/mr_puppet/.puppetforge.yml').
31
+ and_return({'username' => username,
32
+ 'password' => password})
33
+ allow(ENV).to receive(:[]).
34
+ with(any_args)
35
+ allow(ENV).to receive(:[]).
36
+ with('BLACKSMITH_FORGE_PASSWORD').
37
+ and_return(stubbed_forge_password)
38
+
39
+ forge = Blacksmith::Forge.new()
40
+
41
+ expect(forge.url).to eq(Blacksmith::Forge::PUPPETLABS_FORGE)
42
+ expect(forge.password).to eq(stubbed_forge_password)
43
+ expect(forge.username).to eq(username)
44
+ end
18
45
 
46
+ context 'when the credentials values are unset' do
19
47
  it "should raise an error" do
20
- expect { foo = Blacksmith::Forge.new(nil, password, forge) }.to raise_error(/Could not find Puppet Forge credentials file '\/home\/mr\_puppet\/.puppetforge.yml'\s*Please create it\s*---\s*url: https:\/\/forgeapi.puppetlabs.com\s*username: myuser\s*password: mypassword/)
48
+ expect { foo = Blacksmith::Forge.new(nil, password, forge) }.to raise_error(/Could not find Puppet Forge credentials/)
21
49
  end
22
50
  end
23
51
 
52
+ it 'loads credentials from home dir' do
53
+ allow(File).to receive(:exists?).with('/home/mr_puppet/puppet-some-module/.puppetforge.yml') { false }
54
+ allow(File).to receive(:exists?).with('/home/mr_puppet/.puppetforge.yml') { true }
55
+ allow(YAML).to receive(:load_file).with('/home/mr_puppet/.puppetforge.yml') { {'username'=> 'puppet-user'} }
56
+
57
+ subject = Blacksmith::Forge.new(nil, password, forge)
58
+ expect(subject.username).to eq('puppet-user')
59
+ end
60
+
61
+ it 'loads credentials from project dir' do
62
+ allow(File).to receive(:exists?).with('/home/mr_puppet/puppet-some-module/.puppetforge.yml') { true }
63
+ allow(File).to receive(:exists?).with('/home/mr_puppet/.puppetforge.yml') { true }
64
+ allow(YAML).to receive(:load_file).with('/home/mr_puppet/puppet-some-module/.puppetforge.yml') { {'username'=> 'puppet-other-user'} }
65
+
66
+ subject = Blacksmith::Forge.new(nil, password, forge)
67
+ expect(subject.username).to eq('puppet-other-user')
68
+ end
69
+
24
70
  end
25
71
 
26
72
  describe 'push' do
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-blacksmith
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MaestroDev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-27 00:00:00.000000000 Z
11
+ date: 2016-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.8.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.8.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: puppet
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -112,16 +112,16 @@ dependencies:
112
112
  name: webmock
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: 1.23.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: 1.23.0
125
125
  description: Puppet module tools for development and Puppet Forge management
126
126
  email:
127
127
  - info@maestrodev.com
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  requirements: []
170
170
  rubyforge_project:
171
- rubygems_version: 2.4.3
171
+ rubygems_version: 2.4.6
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: Tasks to manage Puppet module builds