Class: Pkgman::Repositories::CloudSmith

Inherits:
Object
  • Object
show all
Defined in:
lib/pkgman/repositories/cloud_smith.rb

Instance Method Summary collapse

Constructor Details

#initialize(target, repository, package) ⇒ CloudSmith

Returns a new instance of CloudSmith.



8
9
10
11
12
# File 'lib/pkgman/repositories/cloud_smith.rb', line 8

def initialize(target, repository, package)
  @target = target
  @repository = repository
  @package = package
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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