Class: Blacksmith::Forge
- Inherits:
-
Object
- Object
- Blacksmith::Forge
- Defined in:
- lib/puppet_blacksmith/forge.rb
Constant Summary collapse
- PUPPETLABS_FORGE =
'https://forgeapi.puppetlabs.com'
- CREDENTIALS_FILE_HOME =
'~/.puppetforge.yml'
- CREDENTIALS_FILE_PROJECT =
'.puppetforge.yml'
- FORGE_TYPE_PUPPET =
'puppet'
- FORGE_TYPE_ARTIFACTORY =
'artifactory'
- SUPPORTED_FORGE_TYPES =
[FORGE_TYPE_PUPPET, FORGE_TYPE_ARTIFACTORY]
- DEFAULT_CREDENTIALS =
{ 'url' => PUPPETLABS_FORGE, 'forge_type' => FORGE_TYPE_PUPPET }
- HEADERS =
{ 'User-Agent' => "Blacksmith/#{Blacksmith::VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE}; #{RUBY_PLATFORM})" }
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#forge_type ⇒ Object
Returns the value of attribute forge_type.
-
#password ⇒ Object
Returns the value of attribute password.
-
#token ⇒ Object
Returns the value of attribute token.
-
#url ⇒ Object
Returns the value of attribute url.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(username = nil, password = nil, url = nil, forge_type = nil, token = nil, api_key = nil) ⇒ Forge
constructor
A new instance of Forge.
- #push!(name, package = nil, author = nil, version = nil) ⇒ Object
Constructor Details
#initialize(username = nil, password = nil, url = nil, forge_type = nil, token = nil, api_key = nil) ⇒ Forge
Returns a new instance of Forge.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/puppet_blacksmith/forge.rb', line 19 def initialize(username = nil, password = nil, url = nil, forge_type = nil, token = nil, api_key = nil) self.username = username self.password = password self.token = token self.api_key = api_key RestClient.proxy = ENV.fetch('http_proxy', nil) load_credentials self.url = url unless url.nil? if %r{http(s)?://forge.puppetlabs.com}.match?(self.url) puts "Ignoring url entry in .puppetforge.yml: must point to the api server at #{PUPPETLABS_FORGE}, not the Forge webpage" self.url = PUPPETLABS_FORGE end self.forge_type = forge_type unless forge_type.nil? raise Blacksmith::Error, "Unsupported forge type: #{self.forge_type}" unless SUPPORTED_FORGE_TYPES.include?(self.forge_type) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
17 18 19 |
# File 'lib/puppet_blacksmith/forge.rb', line 17 def api_key @api_key end |
#forge_type ⇒ Object
Returns the value of attribute forge_type.
17 18 19 |
# File 'lib/puppet_blacksmith/forge.rb', line 17 def forge_type @forge_type end |
#password ⇒ Object
Returns the value of attribute password.
17 18 19 |
# File 'lib/puppet_blacksmith/forge.rb', line 17 def password @password end |
#token ⇒ Object
Returns the value of attribute token.
17 18 19 |
# File 'lib/puppet_blacksmith/forge.rb', line 17 def token @token end |
#url ⇒ Object
Returns the value of attribute url.
17 18 19 |
# File 'lib/puppet_blacksmith/forge.rb', line 17 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
17 18 19 |
# File 'lib/puppet_blacksmith/forge.rb', line 17 def username @username end |
Instance Method Details
#push!(name, package = nil, author = nil, version = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/puppet_blacksmith/forge.rb', line 35 def push!(name, package = nil, = nil, version = nil) user = || username unless package v = version ? Regexp.escape(version) : '.*' regex = /^#{user}-#{name}-#{v}\.tar\.gz$/ pkg = File.('pkg') f = Dir.new(pkg).select { |fn| fn.match(regex) }.last raise Errno::ENOENT, "File not found in #{pkg} with regex #{regex}" if f.nil? package = File.join(pkg, f) end raise Errno::ENOENT, "File does not exist: #{package}" unless File.exist?(package) upload(user, name, package) end |