class Pkgman::Repositories::CloudSmith

Public Class Methods

new(target, repository, package) click to toggle source
# File lib/pkgman/repositories/cloud_smith.rb, line 8
def initialize(target, repository, package)
  @target = target
  @repository = repository
  @package = package
end

Public Instance Methods

execute() click to toggle source
# File lib/pkgman/repositories/cloud_smith.rb, line 14
def execute
  token = @repository['token']
  user = @repository['user']
  repo = @repository['repository']

  filename = File.basename(@package.path)

  hash, _, _ = @target.execute("md5sum #{@package.path} | cut -d ' ' -f 1")
  hash = hash.map { |it| it.to_s }.join("")

  cmd = "curl -q -X POST -H \"Authorization: token #{token}\" "
  cmd += "-d \"md5_checksum=#{hash}&filename=#{filename}\" "
  cmd +="https://api.cloudsmith.io/v1/files/#{user}/#{repo}/"

  file, _, _ = @target.execute(cmd)
  file = file.map { |it| it.to_s }.join("")

  file = JSON.load(file)

  cmd = "curl -vvv -X POST "
  file['upload_fields'].each_key do |key|
    cmd += "-F \"#{key}=#{file['upload_fields'][key]}\" "
  end
  cmd += "-F file=@#{@package.path} "
  cmd += file['upload_url']

  @target.execute(cmd)

  cmd = "curl -X POST -H \"Authorization: token #{token}\" "
  cmd += "-d \"distribution=el/7&package_file=#{file['identifier']}\" "
  cmd += "https://api.cloudsmith.io/v1/packages/#{user}/#{repo}/upload/rpm/"

  @target.execute(cmd)
end