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.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#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.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/puppet_blacksmith/forge.rb', line 20 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['http_proxy'] load_credentials load_client_credentials_from_file self.url = url unless url.nil? if self.url =~ %r{http(s)?://forge.puppetlabs.com} 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.
18 19 20 |
# File 'lib/puppet_blacksmith/forge.rb', line 18 def api_key @api_key end |
#client_id ⇒ Object
Returns the value of attribute client_id.
18 19 20 |
# File 'lib/puppet_blacksmith/forge.rb', line 18 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
18 19 20 |
# File 'lib/puppet_blacksmith/forge.rb', line 18 def client_secret @client_secret end |
#forge_type ⇒ Object
Returns the value of attribute forge_type.
18 19 20 |
# File 'lib/puppet_blacksmith/forge.rb', line 18 def forge_type @forge_type end |
#password ⇒ Object
Returns the value of attribute password.
18 19 20 |
# File 'lib/puppet_blacksmith/forge.rb', line 18 def password @password end |
#token ⇒ Object
Returns the value of attribute token.
18 19 20 |
# File 'lib/puppet_blacksmith/forge.rb', line 18 def token @token end |
#url ⇒ Object
Returns the value of attribute url.
18 19 20 |
# File 'lib/puppet_blacksmith/forge.rb', line 18 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
18 19 20 |
# File 'lib/puppet_blacksmith/forge.rb', line 18 def username @username end |
Instance Method Details
#push!(name, package = nil, author = nil, version = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/puppet_blacksmith/forge.rb', line 37 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.exists?(package) upload(user, name, package) end |