puppet-blacksmith 4.1.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/puppet_blacksmith/forge.rb +68 -20
- data/lib/puppet_blacksmith/rake_tasks.rb +4 -4
- data/lib/puppet_blacksmith/version.rb +1 -1
- data/lib/puppet_blacksmith/version_helper.rb +4 -2
- data/spec/data/metadata.json +5 -5
- data/spec/puppet_blacksmith/forge_spec.rb +1 -1
- data/spec/puppet_blacksmith/modulefile_spec.rb +7 -4
- metadata +26 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a927a889bdf0cfbd7d704e233b43a6eab265a1388c7374c5d2190807cad807b8
|
4
|
+
data.tar.gz: 58c976364590d195ef251220e90801560b57433cbf7a65274ad2dbd8b4d30908
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0f90cd167ebd0d01d1f266795d8602548b0869654a48a98c58fc8c3652c125b9cde78e6041754fb4d3ab58ded58d277f059af8a7cb2f9955ccf2d14ffa2f2c7
|
7
|
+
data.tar.gz: 39df9eb53e3616be2f47ba972206c09d43928c7bbefb550b6cf167c2332c0a8764405f482bba59b99ee560a063b7ac3a8db295213460e4279d8363566e9541ad
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rest-client'
|
2
2
|
require 'json'
|
3
3
|
require 'yaml'
|
4
|
+
require 'base64'
|
4
5
|
|
5
6
|
module Blacksmith
|
6
7
|
class Forge
|
@@ -8,14 +9,18 @@ module Blacksmith
|
|
8
9
|
PUPPETLABS_FORGE = "https://forgeapi.puppetlabs.com"
|
9
10
|
CREDENTIALS_FILE_HOME = "~/.puppetforge.yml"
|
10
11
|
CREDENTIALS_FILE_PROJECT = '.puppetforge.yml'
|
11
|
-
|
12
|
+
FORGE_TYPE_PUPPET = 'puppet'
|
13
|
+
FORGE_TYPE_ARTIFACTORY = 'artifactory'
|
14
|
+
SUPPORTED_FORGE_TYPES = [FORGE_TYPE_PUPPET, FORGE_TYPE_ARTIFACTORY]
|
15
|
+
DEFAULT_CREDENTIALS = { 'url' => PUPPETLABS_FORGE, 'forge_type' => FORGE_TYPE_PUPPET }
|
12
16
|
HEADERS = { 'User-Agent' => "Blacksmith/#{Blacksmith::VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE}; #{RUBY_PLATFORM})" }
|
13
17
|
|
14
|
-
attr_accessor :username, :password, :url, :client_id, :client_secret
|
18
|
+
attr_accessor :username, :password, :url, :client_id, :client_secret, :forge_type, :token
|
15
19
|
|
16
|
-
def initialize(username = nil, password = nil, url = nil)
|
20
|
+
def initialize(username = nil, password = nil, url = nil, forge_type = nil, token = nil)
|
17
21
|
self.username = username
|
18
22
|
self.password = password
|
23
|
+
self.token = token
|
19
24
|
RestClient.proxy = ENV['http_proxy']
|
20
25
|
load_credentials
|
21
26
|
load_client_credentials_from_file
|
@@ -24,19 +29,61 @@ module Blacksmith
|
|
24
29
|
puts "Ignoring url entry in .puppetforge.yml: must point to the api server at #{PUPPETLABS_FORGE}, not the Forge webpage"
|
25
30
|
self.url = PUPPETLABS_FORGE
|
26
31
|
end
|
32
|
+
self.forge_type = forge_type unless forge_type.nil?
|
33
|
+
raise Blacksmith::Error, "Unsupported forge type: #{self.forge_type}" unless SUPPORTED_FORGE_TYPES.include?(self.forge_type)
|
27
34
|
end
|
28
35
|
|
29
|
-
def push!(name, package = nil)
|
36
|
+
def push!(name, package = nil, author = nil, version = nil)
|
37
|
+
user = author || username
|
30
38
|
unless package
|
31
|
-
|
39
|
+
v = version ? Regexp.escape(version) : '.*'
|
40
|
+
regex = /^#{user}-#{name}-#{v}\.tar\.gz$/
|
32
41
|
pkg = File.expand_path("pkg")
|
33
|
-
f = Dir.new(pkg).select{|
|
42
|
+
f = Dir.new(pkg).select{|fn| fn.match(regex)}.last
|
34
43
|
raise Errno::ENOENT, "File not found in #{pkg} with regex #{regex}" if f.nil?
|
35
44
|
package = File.join(pkg, f)
|
36
45
|
end
|
37
46
|
raise Errno::ENOENT, "File does not exist: #{package}" unless File.exists?(package)
|
38
47
|
|
39
|
-
|
48
|
+
upload(user, name, package)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def upload(author, name, file)
|
54
|
+
case forge_type
|
55
|
+
when FORGE_TYPE_ARTIFACTORY
|
56
|
+
RestClient::Request.execute(:method => :put, :url => http_url(author, name, file), :payload => File.new(file, 'rb'), :headers => http_headers)
|
57
|
+
else
|
58
|
+
RestClient::Request.execute(:method => :post, :url => http_url(author, name, file), :payload => {:file => File.new(file, 'rb')}, :headers => http_headers)
|
59
|
+
end
|
60
|
+
rescue RestClient::Exception => e
|
61
|
+
raise Blacksmith::Error, "Error uploading #{package} to the forge #{url} [#{e.message}]: #{e.response}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def http_url(author, name, file)
|
65
|
+
case forge_type
|
66
|
+
when FORGE_TYPE_ARTIFACTORY
|
67
|
+
"#{url}/#{author}/#{name}/#{File.basename(file)}"
|
68
|
+
else
|
69
|
+
"#{url}/v2/releases"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def http_headers
|
74
|
+
case forge_type
|
75
|
+
when FORGE_TYPE_ARTIFACTORY
|
76
|
+
if token
|
77
|
+
HEADERS.merge({'Authorization' => "Bearer #{token}"})
|
78
|
+
else
|
79
|
+
HEADERS.merge({'Authorization' => "Basic " + Base64.strict_encode64("#{username}:#{password}")})
|
80
|
+
end
|
81
|
+
else
|
82
|
+
HEADERS.merge({'Authorization' => "Bearer #{token || oauth_access_token}"})
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def oauth_access_token
|
40
87
|
begin
|
41
88
|
response = RestClient.post("#{url}/oauth/token", {
|
42
89
|
'client_id' => client_id,
|
@@ -49,20 +96,9 @@ module Blacksmith
|
|
49
96
|
raise Blacksmith::Error, "Error login to the forge #{url} as #{username} [#{e.message}]: #{e.response}"
|
50
97
|
end
|
51
98
|
login_data = JSON.parse(response)
|
52
|
-
|
53
|
-
|
54
|
-
# upload the file
|
55
|
-
begin
|
56
|
-
response = RestClient.post("#{url}/v2/releases",
|
57
|
-
{:file => File.new(package, 'rb')},
|
58
|
-
HEADERS.merge({'Authorization' => "Bearer #{access_token}"}))
|
59
|
-
rescue RestClient::Exception => e
|
60
|
-
raise Blacksmith::Error, "Error uploading #{package} to the forge #{url} [#{e.message}]: #{e.response}"
|
61
|
-
end
|
99
|
+
login_data['access_token']
|
62
100
|
end
|
63
101
|
|
64
|
-
private
|
65
|
-
|
66
102
|
def load_credentials
|
67
103
|
file_credentials = load_credentials_from_file
|
68
104
|
env_credentials = load_credentials_from_env
|
@@ -72,21 +108,25 @@ module Blacksmith
|
|
72
108
|
|
73
109
|
self.username = credentials['username'] if credentials['username']
|
74
110
|
self.password = credentials['password'] if credentials['password']
|
111
|
+
self.token = credentials['token'] if credentials['token']
|
75
112
|
if credentials['forge']
|
76
113
|
# deprecated
|
77
114
|
puts "'forge' entry is deprecated in .puppetforge.yml, use 'url'"
|
78
115
|
self.url = credentials['forge']
|
79
116
|
end
|
80
117
|
self.url = credentials['url'] if credentials['url']
|
118
|
+
self.forge_type = credentials['forge_type'] if credentials['forge_type']
|
81
119
|
|
82
|
-
unless self.username && self.password
|
120
|
+
unless (self.username && self.password) || self.token
|
83
121
|
raise Blacksmith::Error, <<-eos
|
84
122
|
Could not find Puppet Forge credentials!
|
85
123
|
|
86
124
|
Please set the environment variables
|
87
125
|
BLACKSMITH_FORGE_URL
|
126
|
+
BLACKSMITH_FORGE_TYPE
|
88
127
|
BLACKSMITH_FORGE_USERNAME
|
89
128
|
BLACKSMITH_FORGE_PASSWORD
|
129
|
+
BLACKSMITH_FORGE_TOKEN
|
90
130
|
|
91
131
|
or create the file '#{CREDENTIALS_FILE_PROJECT}' or '#{CREDENTIALS_FILE_HOME}'
|
92
132
|
with content similiar to:
|
@@ -132,6 +172,14 @@ password: mypassword
|
|
132
172
|
credentials['url'] = ENV['BLACKSMITH_FORGE_URL']
|
133
173
|
end
|
134
174
|
|
175
|
+
if ENV['BLACKSMITH_FORGE_TYPE']
|
176
|
+
credentials['forge_type'] = ENV['BLACKSMITH_FORGE_TYPE']
|
177
|
+
end
|
178
|
+
|
179
|
+
if ENV['BLACKSMITH_FORGE_TOKEN']
|
180
|
+
credentials['token'] = ENV['BLACKSMITH_FORGE_TOKEN']
|
181
|
+
end
|
182
|
+
|
135
183
|
return credentials
|
136
184
|
end
|
137
185
|
|
@@ -61,7 +61,7 @@ module Blacksmith
|
|
61
61
|
desc "Bump module version to the next #{level.upcase} version"
|
62
62
|
task level do
|
63
63
|
m = Blacksmith::Modulefile.new
|
64
|
-
v = m.
|
64
|
+
v = m.bump!(level)
|
65
65
|
puts "Bumping version from #{m.version} to #{v}"
|
66
66
|
end
|
67
67
|
end
|
@@ -129,8 +129,8 @@ module Blacksmith
|
|
129
129
|
task :push => :build do
|
130
130
|
m = Blacksmith::Modulefile.new
|
131
131
|
forge = Blacksmith::Forge.new
|
132
|
-
puts "Uploading to Puppet Forge #{
|
133
|
-
forge.push!(m.name)
|
132
|
+
puts "Uploading to Puppet Forge #{m.author}/#{m.name}"
|
133
|
+
forge.push!(m.name, nil, m.author, m.version)
|
134
134
|
end
|
135
135
|
|
136
136
|
desc "Runs clean again"
|
@@ -139,7 +139,7 @@ module Blacksmith
|
|
139
139
|
Rake::Task["clean"].execute
|
140
140
|
end
|
141
141
|
|
142
|
-
desc "Release the Puppet module, doing a clean, build, tag, push
|
142
|
+
desc "Release the Puppet module, doing a clean, build, bump_commit, tag, push and git push."
|
143
143
|
release_dependencies = @build ? [:clean, :build, :bump_commit, :tag, :push] : [:clean, :bump_commit, :tag]
|
144
144
|
task :release => release_dependencies do
|
145
145
|
puts "Pushing to remote git repo"
|
@@ -115,9 +115,11 @@ module Blacksmith
|
|
115
115
|
|
116
116
|
def increment!(term)
|
117
117
|
new_version = clone
|
118
|
-
new_value = send(term) + 1
|
119
118
|
|
120
|
-
|
119
|
+
if term != :patch || @pre.nil?
|
120
|
+
new_version.send("#{term}=", send(term) + 1)
|
121
|
+
end
|
122
|
+
|
121
123
|
new_version.minor = 0 if term == :major
|
122
124
|
new_version.patch = 0 if term == :major || term == :minor
|
123
125
|
new_version.build = new_version.pre = nil
|
data/spec/data/metadata.json
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
},
|
17
17
|
{
|
18
18
|
"name": "puppet",
|
19
|
-
"version_requirement": ">=2.7.20 <
|
19
|
+
"version_requirement": ">=2.7.20 <7.0.0"
|
20
20
|
}
|
21
21
|
],
|
22
22
|
"name": "maestrodev-test",
|
@@ -28,9 +28,9 @@
|
|
28
28
|
"description": "Standard Library for Puppet Modules",
|
29
29
|
"project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
|
30
30
|
"dependencies": [
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
{
|
32
|
+
"name": "puppetlabs-stdlib",
|
33
|
+
"version_requirement": ">= 3.0.0"
|
34
|
+
}
|
35
35
|
]
|
36
36
|
}
|
@@ -91,7 +91,7 @@ describe 'Blacksmith::Forge' do
|
|
91
91
|
:headers => {})
|
92
92
|
|
93
93
|
stub_request(:post, "#{forge}/v2/releases").with(
|
94
|
-
:headers => headers.merge({'Accept'=>'*/*', 'Accept-Encoding'=>'gzip,
|
94
|
+
:headers => headers.merge({'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer e52f78b62e97cb8d8db6659a73aa522cca0f5c74d4714e0ed0bdd10000000000', 'Content-Type'=>%r{\Amultipart/form-data;}})
|
95
95
|
) { |request |
|
96
96
|
request.body =~ %r{Content-Disposition: form-data; name=\"file\"; filename=\"maestrodev-test.tar.gz\"\r\nContent-Type: application/gzip}
|
97
97
|
}.to_return(:status => 200, :body => File.read(File.join(spec_data, "response.json")), :headers => {})
|
@@ -37,7 +37,7 @@ describe 'Blacksmith::Modulefile' do
|
|
37
37
|
},
|
38
38
|
{
|
39
39
|
"name": "puppet",
|
40
|
-
"version_requirement": ">=2.7.20 <
|
40
|
+
"version_requirement": ">=2.7.20 <7.0.0"
|
41
41
|
}
|
42
42
|
],
|
43
43
|
"name": "maestrodev-test",
|
@@ -83,7 +83,7 @@ describe 'Blacksmith::Modulefile' do
|
|
83
83
|
},
|
84
84
|
{
|
85
85
|
"name": "puppet",
|
86
|
-
"version_requirement": ">=2.7.20 <
|
86
|
+
"version_requirement": ">=2.7.20 <7.0.0"
|
87
87
|
}
|
88
88
|
],
|
89
89
|
"name": "maestrodev-test",
|
@@ -116,25 +116,28 @@ describe 'Blacksmith::Modulefile' do
|
|
116
116
|
describe 'increase_version' do
|
117
117
|
it { expect(subject.increase_version("1.0.0")).to eql("1.0.1") }
|
118
118
|
it { expect(subject.increase_version("1.0.1")).to eql("1.0.2") }
|
119
|
-
it { expect { subject.increase_version("1.0") }.to raise_error }
|
120
|
-
it { expect { subject.increase_version("1.0.12qwe") }.to raise_error }
|
119
|
+
it { expect { subject.increase_version("1.0") }.to raise_error(ArgumentError) }
|
120
|
+
it { expect { subject.increase_version("1.0.12qwe") }.to raise_error(ArgumentError) }
|
121
121
|
end
|
122
122
|
|
123
123
|
describe 'bump patch version' do
|
124
124
|
it { expect(subject.increase_version("1.0.0", :patch)).to eql("1.0.1") }
|
125
125
|
it { expect(subject.increase_version("1.1.0", :patch)).to eql("1.1.1") }
|
126
126
|
it { expect(subject.increase_version("1.1.1", :patch)).to eql("1.1.2") }
|
127
|
+
it { expect(subject.increase_version("1.1.2-rc0", :patch)).to eql("1.1.2") }
|
127
128
|
end
|
128
129
|
|
129
130
|
describe 'bump minor version' do
|
130
131
|
it { expect(subject.increase_version("1.0.0", :minor)).to eql("1.1.0") }
|
131
132
|
it { expect(subject.increase_version("1.1.0", :minor)).to eql("1.2.0") }
|
132
133
|
it { expect(subject.increase_version("1.1.1", :minor)).to eql("1.2.0") }
|
134
|
+
it { expect(subject.increase_version("1.1.1-rc0", :minor)).to eql("1.2.0") }
|
133
135
|
end
|
134
136
|
|
135
137
|
describe 'bump major version' do
|
136
138
|
it { expect(subject.increase_version("1.0.0", :major)).to eql("2.0.0") }
|
137
139
|
it { expect(subject.increase_version("1.1.0", :major)).to eql("2.0.0") }
|
138
140
|
it { expect(subject.increase_version("1.1.1", :major)).to eql("2.0.0") }
|
141
|
+
it { expect(subject.increase_version("1.1.1-rc0", :major)).to eql("2.0.0") }
|
139
142
|
end
|
140
143
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-blacksmith
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MaestroDev
|
8
|
+
- Vox Pupuli
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2019-09-13 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rest-client
|
@@ -38,6 +39,20 @@ dependencies:
|
|
38
39
|
- - ">="
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pdk
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
41
56
|
- !ruby/object:Gem::Dependency
|
42
57
|
name: puppet
|
43
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,7 +139,7 @@ dependencies:
|
|
124
139
|
version: '2.0'
|
125
140
|
description: Puppet module tools for development and Puppet Forge management
|
126
141
|
email:
|
127
|
-
-
|
142
|
+
- voxpupuli@groups.io
|
128
143
|
executables: []
|
129
144
|
extensions: []
|
130
145
|
extra_rdoc_files: []
|
@@ -160,7 +175,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
175
|
requirements:
|
161
176
|
- - ">="
|
162
177
|
- !ruby/object:Gem::Version
|
163
|
-
version: 2.
|
178
|
+
version: 2.4.0
|
164
179
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
180
|
requirements:
|
166
181
|
- - ">="
|
@@ -168,18 +183,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
183
|
version: '0'
|
169
184
|
requirements: []
|
170
185
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.7.
|
186
|
+
rubygems_version: 2.7.7
|
172
187
|
signing_key:
|
173
188
|
specification_version: 4
|
174
189
|
summary: Tasks to manage Puppet module builds
|
175
190
|
test_files:
|
176
|
-
- spec/data/Modulefile
|
177
|
-
- spec/data/maestrodev-test/metadata.json
|
178
|
-
- spec/data/response.json
|
179
|
-
- spec/data/metadata.json
|
180
|
-
- spec/puppet_blacksmith/forge_live_spec.rb
|
181
191
|
- spec/puppet_blacksmith/forge_shared.rb
|
182
|
-
- spec/puppet_blacksmith/
|
192
|
+
- spec/puppet_blacksmith/forge_live_spec.rb
|
183
193
|
- spec/puppet_blacksmith/git_spec.rb
|
184
194
|
- spec/puppet_blacksmith/modulefile_spec.rb
|
195
|
+
- spec/puppet_blacksmith/forge_spec.rb
|
185
196
|
- spec/spec_helper.rb
|
197
|
+
- spec/data/maestrodev-test/metadata.json
|
198
|
+
- spec/data/Modulefile
|
199
|
+
- spec/data/response.json
|
200
|
+
- spec/data/metadata.json
|