Class: Blacksmith::Forge

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(username = nil, password = nil, url = nil, forge_type = nil, token = nil, api_key = nil) ⇒ Forge

Returns a new instance of Forge.

Raises:



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_keyObject

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_typeObject

Returns the value of attribute forge_type.



17
18
19
# File 'lib/puppet_blacksmith/forge.rb', line 17

def forge_type
  @forge_type
end

#passwordObject

Returns the value of attribute password.



17
18
19
# File 'lib/puppet_blacksmith/forge.rb', line 17

def password
  @password
end

#tokenObject

Returns the value of attribute token.



17
18
19
# File 'lib/puppet_blacksmith/forge.rb', line 17

def token
  @token
end

#urlObject

Returns the value of attribute url.



17
18
19
# File 'lib/puppet_blacksmith/forge.rb', line 17

def url
  @url
end

#usernameObject

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

Raises:

  • (Errno::ENOENT)


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, author = nil, version = nil)
  user = author || username
  unless package
    v = version ? Regexp.escape(version) : '.*'
    regex = /^#{user}-#{name}-#{v}\.tar\.gz$/
    pkg = File.expand_path('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