Class: IKE::Artifactory::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ike_artifactory/client.rb

Constant Summary collapse

IMAGE_MANIFEST =
'manifest.json'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Client

Returns a new instance of Client.



19
20
21
22
23
24
25
26
# File 'lib/ike_artifactory/client.rb', line 19

def initialize(**args)
  @server = args[:server]
  @repo_key = args[:repo_key]
  @user = args[:user]
  @password = args[:password]

  raise IKEArtifactoryClientNotReady.new(msg = 'Required attributes are missing. IKEArtifactoryGem not ready.') unless self.ready?
end

Instance Attribute Details

#folder_pathObject

Returns the value of attribute folder_path.



15
16
17
# File 'lib/ike_artifactory/client.rb', line 15

def folder_path
  @folder_path
end

#passwordObject

Returns the value of attribute password.



17
18
19
# File 'lib/ike_artifactory/client.rb', line 17

def password
  @password
end

#repo_keyObject

Returns the value of attribute repo_key.



14
15
16
# File 'lib/ike_artifactory/client.rb', line 14

def repo_key
  @repo_key
end

#serverObject

Returns the value of attribute server.



13
14
15
# File 'lib/ike_artifactory/client.rb', line 13

def server
  @server
end

#userObject

Returns the value of attribute user.



16
17
18
# File 'lib/ike_artifactory/client.rb', line 16

def user
  @user
end

Instance Method Details

#delete_object(path) ⇒ Object



28
29
30
31
32
# File 'lib/ike_artifactory/client.rb', line 28

def delete_object(path)
  fetch(path, method: :delete) do |response, request, result|
    response.code == 204
  end
end

#get_images(path) ⇒ Object



64
65
66
67
68
# File 'lib/ike_artifactory/client.rb', line 64

def get_images(path)
  get_subdirectory_ages(path).select do |(folder, _age)|
    get_object_info([path, folder, IMAGE_MANIFEST].join('/'))
  end
end

#get_object_age(path) ⇒ Object



44
45
46
47
48
# File 'lib/ike_artifactory/client.rb', line 44

def get_object_age(path)
  get(path) do |response|
    ( ( Time.now - Time.iso8601(response['lastModified']) ) / (24*60*60) ).to_int
  end
end

#get_object_info(path) ⇒ Object



50
51
52
# File 'lib/ike_artifactory/client.rb', line 50

def get_object_info(path)
  get(path)
end

#get_subdirectories(path) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/ike_artifactory/client.rb', line 34

def get_subdirectories(path)
  get(path) do |response|
    (response['children'] || []).select do |c|
      c['folder']
    end.map do |f|
      f['uri'][1..]
    end
  end
end

#get_subdirectory_ages(path) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/ike_artifactory/client.rb', line 54

def get_subdirectory_ages(path)
  get(path, prefix: "#{server}:443/ui/api/v1/ui/nativeBrowser/#{repo_key}") do |response|
    (response['children'] || []).each_with_object({}) do |child, memo|
      days_old = ( ( Time.now.to_i - (child['lastModified']/1000) ) / (24*60*60) ).to_int
      memo[child['name']] = days_old
      memo
    end
  end
end