artifactory 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile +1 -1
- data/lib/artifactory.rb +13 -9
- data/lib/artifactory/client.rb +16 -3
- data/lib/artifactory/errors.rb +1 -2
- data/lib/artifactory/resources/artifact.rb +56 -27
- data/lib/artifactory/resources/backup.rb +104 -0
- data/lib/artifactory/resources/base.rb +47 -0
- data/lib/artifactory/resources/layout.rb +1 -50
- data/lib/artifactory/resources/ldap_setting.rb +105 -0
- data/lib/artifactory/resources/mail_server.rb +61 -0
- data/lib/artifactory/resources/repository.rb +11 -14
- data/lib/artifactory/resources/url_base.rb +74 -0
- data/lib/artifactory/util.rb +41 -0
- data/lib/artifactory/version.rb +1 -1
- data/spec/integration/resources/backup.rb +22 -0
- data/spec/integration/resources/build_spec.rb +1 -3
- data/spec/integration/resources/group_spec.rb +2 -2
- data/spec/integration/resources/ldap_setting_spec.rb +22 -0
- data/spec/integration/resources/mail_server_spec.rb +22 -0
- data/spec/integration/resources/repository_spec.rb +1 -1
- data/spec/integration/resources/system_spec.rb +1 -1
- data/spec/integration/resources/url_base_spec.rb +22 -0
- data/spec/integration/resources/user_spec.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/support/api_server/system_endpoints.rb +44 -1
- data/spec/unit/artifactory_spec.rb +3 -3
- data/spec/unit/client_spec.rb +1 -1
- data/spec/unit/resources/artifact_spec.rb +18 -36
- data/spec/unit/resources/backup_spec.rb +61 -0
- data/spec/unit/resources/base_spec.rb +3 -3
- data/spec/unit/resources/build_spec.rb +3 -3
- data/spec/unit/resources/group_spec.rb +6 -6
- data/spec/unit/resources/layout_spec.rb +4 -4
- data/spec/unit/resources/ldap_setting_spec.rb +65 -0
- data/spec/unit/resources/mail_server_spec.rb +57 -0
- data/spec/unit/resources/plugin_spec.rb +2 -2
- data/spec/unit/resources/repository_spec.rb +19 -27
- data/spec/unit/resources/system_spec.rb +6 -6
- data/spec/unit/resources/url_base_spec.rb +53 -0
- data/spec/unit/resources/user_spec.rb +8 -8
- metadata +23 -3
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
require 'rexml/document'
|
|
2
|
+
|
|
3
|
+
module Artifactory
|
|
4
|
+
class Resource::LDAPSetting < Resource::Base
|
|
5
|
+
class << self
|
|
6
|
+
#
|
|
7
|
+
# Get a list of all ldap settings in the system.
|
|
8
|
+
#
|
|
9
|
+
# @param [Hash] options
|
|
10
|
+
# the list of options
|
|
11
|
+
#
|
|
12
|
+
# @option options [Artifactory::Client] :client
|
|
13
|
+
# the client object to make the request with
|
|
14
|
+
#
|
|
15
|
+
# @return [Array<Resource::LDAPSetting>]
|
|
16
|
+
# the list of layouts
|
|
17
|
+
#
|
|
18
|
+
def all(options = {})
|
|
19
|
+
config = Resource::System.configuration(options)
|
|
20
|
+
list_from_config('config/security/ldapSettings/ldapSetting', config, options)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
# Find (fetch) an ldap setting by its name.
|
|
25
|
+
#
|
|
26
|
+
# @example Find an LDAPSetting by its name.
|
|
27
|
+
# ldap_config.find('ldap.example.com') #=> #<MailServer host: 'ldap.example.com' ...>
|
|
28
|
+
#
|
|
29
|
+
# @param [String] name
|
|
30
|
+
# the name of the ldap config setting to find
|
|
31
|
+
# @param [Hash] options
|
|
32
|
+
# the list of options
|
|
33
|
+
#
|
|
34
|
+
# @option options [Artifactory::Client] :client
|
|
35
|
+
# the client object to make the request with
|
|
36
|
+
#
|
|
37
|
+
# @return [Resource::LDAPSetting, nil]
|
|
38
|
+
# an instance of the ldap setting that matches the given name, or +nil+
|
|
39
|
+
# if one does not exist
|
|
40
|
+
#
|
|
41
|
+
def find(name, options = {})
|
|
42
|
+
config = Resource::System.configuration(options)
|
|
43
|
+
find_from_config("config/security/ldapSettings/ldapSetting/key[text()='#{name}']", config, options)
|
|
44
|
+
rescue Error::HTTPError => e
|
|
45
|
+
raise unless e.code == 404
|
|
46
|
+
nil
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
#
|
|
51
|
+
# List all the child text elements in the Artifactory configuration file
|
|
52
|
+
# of a node matching the specified xpath
|
|
53
|
+
#
|
|
54
|
+
# @param [String] xpath
|
|
55
|
+
# xpath expression for the parent element whose children are to be listed
|
|
56
|
+
#
|
|
57
|
+
# @param [REXML] config
|
|
58
|
+
# Artifactory config as an REXML file
|
|
59
|
+
#
|
|
60
|
+
# @param [Hash] options
|
|
61
|
+
# the list of options
|
|
62
|
+
#
|
|
63
|
+
def list_from_config(xpath, config, options = {})
|
|
64
|
+
REXML::XPath.match(config, xpath).map do |r|
|
|
65
|
+
hash = Util.xml_to_hash(r, 'search')
|
|
66
|
+
from_hash(hash, options)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
#
|
|
71
|
+
# Find all the sibling text elements in the Artifactory configuration file
|
|
72
|
+
# of a node matching the specified xpath
|
|
73
|
+
#
|
|
74
|
+
# @param [String] xpath
|
|
75
|
+
# xpath expression for the element whose siblings are to be found
|
|
76
|
+
#
|
|
77
|
+
# @param [REXML] config
|
|
78
|
+
# Artifactory configuration file as an REXML doc
|
|
79
|
+
#
|
|
80
|
+
# @param [Hash] options
|
|
81
|
+
# the list of options
|
|
82
|
+
#
|
|
83
|
+
def find_from_config(xpath, config, options = {})
|
|
84
|
+
name_node = REXML::XPath.match(config, xpath)
|
|
85
|
+
return nil if name_node.empty?
|
|
86
|
+
properties = Util.xml_to_hash(name_node[0].parent, 'search')
|
|
87
|
+
from_hash(properties, options)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Ordered to match the artifactory xsd to make consuming the attributes
|
|
92
|
+
# hash when writing artifactory xml more convenient.
|
|
93
|
+
# http://bit.ly/UHMrHc
|
|
94
|
+
attribute :key, ->{ raise 'name missing!' }
|
|
95
|
+
attribute :enabled, true
|
|
96
|
+
attribute :ldap_url
|
|
97
|
+
attribute :search_filter
|
|
98
|
+
attribute :search_base
|
|
99
|
+
attribute :search_sub_tree
|
|
100
|
+
attribute :manager_dn
|
|
101
|
+
attribute :manager_password
|
|
102
|
+
attribute :auto_create_user
|
|
103
|
+
attribute :email_attribute, 'mail'
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'rexml/document'
|
|
2
|
+
|
|
3
|
+
module Artifactory
|
|
4
|
+
class Resource::MailServer < Resource::Base
|
|
5
|
+
class << self
|
|
6
|
+
#
|
|
7
|
+
# Get a list of all mail servers in the system.
|
|
8
|
+
#
|
|
9
|
+
# @param [Hash] options
|
|
10
|
+
# the list of options
|
|
11
|
+
#
|
|
12
|
+
# @option options [Artifactory::Client] :client
|
|
13
|
+
# the client object to make the request with
|
|
14
|
+
#
|
|
15
|
+
# @return [Array<Resource::MailServer>]
|
|
16
|
+
# the list of layouts
|
|
17
|
+
#
|
|
18
|
+
def all(options = {})
|
|
19
|
+
config = Resource::System.configuration(options)
|
|
20
|
+
list_from_config('config/mailServer', config, options)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
# Find (fetch) a mail server by its host.
|
|
25
|
+
#
|
|
26
|
+
# @example Find a MailServer by its host.
|
|
27
|
+
# mail_server.find('smtp.gmail.com') #=> #<MailServer host: 'smtp.gmail.com' ...>
|
|
28
|
+
#
|
|
29
|
+
# @param [String] host
|
|
30
|
+
# the host of the mail server to find
|
|
31
|
+
# @param [Hash] options
|
|
32
|
+
# the list of options
|
|
33
|
+
#
|
|
34
|
+
# @option options [Artifactory::Client] :client
|
|
35
|
+
# the client object to make the request with
|
|
36
|
+
#
|
|
37
|
+
# @return [Resource::MailServer, nil]
|
|
38
|
+
# an instance of the mail server that matches the given host, or +nil+
|
|
39
|
+
# if one does not exist
|
|
40
|
+
#
|
|
41
|
+
def find(host, options = {})
|
|
42
|
+
config = Resource::System.configuration(options)
|
|
43
|
+
find_from_config("config/mailServer/host[text()='#{host}']", config, options)
|
|
44
|
+
rescue Error::HTTPError => e
|
|
45
|
+
raise unless e.code == 404
|
|
46
|
+
nil
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
attribute :enabled
|
|
51
|
+
attribute :host, ->{ raise 'host missing!' }
|
|
52
|
+
attribute :port
|
|
53
|
+
attribute :username
|
|
54
|
+
attribute :password
|
|
55
|
+
attribute :from
|
|
56
|
+
attribute :subject_prefix
|
|
57
|
+
attribute :tls
|
|
58
|
+
attribute :ssl
|
|
59
|
+
attribute :artifactory_url
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -77,9 +77,9 @@ module Artifactory
|
|
|
77
77
|
#
|
|
78
78
|
# @return [Resource::Artifact]
|
|
79
79
|
#
|
|
80
|
-
def upload(
|
|
81
|
-
artifact = Resource::Artifact.new
|
|
82
|
-
artifact.upload(key,
|
|
80
|
+
def upload(local_path, remote_path, properties = {}, headers = {})
|
|
81
|
+
artifact = Resource::Artifact.new(local_path: local_path)
|
|
82
|
+
artifact.upload(key, remote_path, properties, headers)
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
#
|
|
@@ -87,25 +87,22 @@ module Artifactory
|
|
|
87
87
|
# documentation for the possible responses when the checksums fail to
|
|
88
88
|
# match.
|
|
89
89
|
#
|
|
90
|
-
# @see Artifact#
|
|
90
|
+
# @see Artifact#upload_with_checksum More syntax examples
|
|
91
91
|
#
|
|
92
|
-
def upload_with_checksum(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
'X-Checksum-Sha1' => checksum,
|
|
96
|
-
)
|
|
92
|
+
def upload_with_checksum(local_path, remote_path, checksum, properties = {})
|
|
93
|
+
artifact = Resource::Artifact.new(local_path: local_path)
|
|
94
|
+
artifact.upload_with_checksum(key, remote_path, checksum, properties)
|
|
97
95
|
end
|
|
98
96
|
|
|
99
97
|
#
|
|
100
98
|
# Upload an artifact with the given archive. Consult the artifactory
|
|
101
99
|
# documentation for the format of the archive to upload.
|
|
102
100
|
#
|
|
103
|
-
# @see Artifact#
|
|
101
|
+
# @see Artifact#upload_from_archive More syntax examples
|
|
104
102
|
#
|
|
105
|
-
def upload_from_archive(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
)
|
|
103
|
+
def upload_from_archive(local_path, remote_path, properties = {})
|
|
104
|
+
artifact = Resource::Artifact.new(local_path: local_path)
|
|
105
|
+
artifact.upload_from_archive(key, remote_path, properties)
|
|
109
106
|
end
|
|
110
107
|
|
|
111
108
|
#
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require 'rexml/document'
|
|
2
|
+
|
|
3
|
+
module Artifactory
|
|
4
|
+
class Resource::URLBase < Resource::Base
|
|
5
|
+
class << self
|
|
6
|
+
#
|
|
7
|
+
# List UrlBase in the system configuration.
|
|
8
|
+
#
|
|
9
|
+
# @param [Hash] options
|
|
10
|
+
# the list of options
|
|
11
|
+
#
|
|
12
|
+
# @option options [Artifactory::Client] :client
|
|
13
|
+
# the client object to make the request with
|
|
14
|
+
#
|
|
15
|
+
# @return [Array<Resource::URLBase>]
|
|
16
|
+
# the list of UrlBases
|
|
17
|
+
#
|
|
18
|
+
def all(options = {})
|
|
19
|
+
config = Resource::System.configuration(options)
|
|
20
|
+
simple_text_from_config('config/urlBase', config, options)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
# Find (fetch) the url base.
|
|
25
|
+
#
|
|
26
|
+
# @example Find a URLBase by its url_base.
|
|
27
|
+
# url_base.find('http://33.33.33.20/artifactory') #=> #<URLBase url_base: 'http://33.33.33.20/artifactory' ...>
|
|
28
|
+
#
|
|
29
|
+
# @param [String] url
|
|
30
|
+
# the base url to find
|
|
31
|
+
# @param [Hash] options
|
|
32
|
+
# the list of options
|
|
33
|
+
#
|
|
34
|
+
# @option options [Artifactory::Client] :client
|
|
35
|
+
# the client object to make the request with
|
|
36
|
+
#
|
|
37
|
+
# @return [Resource::MailServer, nil]
|
|
38
|
+
# an instance of the mail server that matches the given host, or +nil+
|
|
39
|
+
# if one does not exist
|
|
40
|
+
#
|
|
41
|
+
def find(url, options = {})
|
|
42
|
+
config = Resource::System.configuration(options)
|
|
43
|
+
find_from_config("config/urlBase[text()='#{url}']", config, options)
|
|
44
|
+
rescue Error::HTTPError => e
|
|
45
|
+
raise unless e.code == 404
|
|
46
|
+
nil
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
#
|
|
51
|
+
# List all the text elements in the Artifactory configuration file
|
|
52
|
+
# matching the given xpath. Ignore any children of elements that match the xpath.
|
|
53
|
+
#
|
|
54
|
+
# @param [String] xpath
|
|
55
|
+
# xpath expression for which matches are to be listed
|
|
56
|
+
#
|
|
57
|
+
# @param [REXML] config
|
|
58
|
+
# Artifactory config as an REXML file
|
|
59
|
+
#
|
|
60
|
+
# @param [Hash] options
|
|
61
|
+
# the list of options
|
|
62
|
+
#
|
|
63
|
+
def simple_text_from_config(xpath, config, options = {})
|
|
64
|
+
REXML::XPath.match(config, xpath).map do |r|
|
|
65
|
+
hash = {}
|
|
66
|
+
hash[r.name] = r.text
|
|
67
|
+
from_hash(hash, options)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
attribute :url_base, ->{ raise 'URL base missing!' }
|
|
73
|
+
end
|
|
74
|
+
end
|
data/lib/artifactory/util.rb
CHANGED
|
@@ -95,5 +95,46 @@ module Artifactory
|
|
|
95
95
|
hash
|
|
96
96
|
end
|
|
97
97
|
end
|
|
98
|
+
|
|
99
|
+
#
|
|
100
|
+
# Flatten an xml element with at most one child node with children
|
|
101
|
+
# into a hash.
|
|
102
|
+
#
|
|
103
|
+
# @param [REXML] element
|
|
104
|
+
# xml element
|
|
105
|
+
#
|
|
106
|
+
def xml_to_hash(element, child_with_children = '', unique_children = true)
|
|
107
|
+
properties = {}
|
|
108
|
+
element.each_element_with_text do |e|
|
|
109
|
+
if e.name.eql?(child_with_children)
|
|
110
|
+
if unique_children
|
|
111
|
+
e.each_element_with_text do |t|
|
|
112
|
+
properties[t.name] = to_type(t.text)
|
|
113
|
+
end
|
|
114
|
+
else
|
|
115
|
+
children = []
|
|
116
|
+
e.each_element_with_text do |t|
|
|
117
|
+
properties[t.name] = children.push(to_type(t.text))
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
else
|
|
121
|
+
properties[e.name] = to_type(e.text)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
properties
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def to_type(string)
|
|
128
|
+
return true if string.eql?('true')
|
|
129
|
+
return false if string.eql?('false')
|
|
130
|
+
return string.to_i if numeric?(string)
|
|
131
|
+
return string
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
private
|
|
135
|
+
|
|
136
|
+
def numeric?(string)
|
|
137
|
+
string.to_i.to_s == string || string.to_f.to_s == string
|
|
138
|
+
end
|
|
98
139
|
end
|
|
99
140
|
end
|
data/lib/artifactory/version.rb
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Artifactory
|
|
4
|
+
describe Resource::Backup, :integration do
|
|
5
|
+
describe '.all' do
|
|
6
|
+
it 'returns an array of Backups' do
|
|
7
|
+
results = described_class.all
|
|
8
|
+
expect(results).to be_a(Array)
|
|
9
|
+
expect(results.first).to be_a(described_class)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '.find' do
|
|
14
|
+
it 'finds a Backup by key' do
|
|
15
|
+
backup = described_class.find('backup-daily')
|
|
16
|
+
|
|
17
|
+
expect(backup).to be_a(described_class)
|
|
18
|
+
expect(backup.key).to eq('backup-daily')
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -3,9 +3,7 @@ require 'spec_helper'
|
|
|
3
3
|
module Artifactory
|
|
4
4
|
describe Resource::Build, :integration do
|
|
5
5
|
describe '.all' do
|
|
6
|
-
it 'returns an array of build objects'
|
|
7
|
-
pending 'Need more information about what the Build API returns'
|
|
8
|
-
end
|
|
6
|
+
it 'returns an array of build objects'
|
|
9
7
|
end
|
|
10
8
|
end
|
|
11
9
|
end
|
|
@@ -31,14 +31,14 @@ module Artifactory
|
|
|
31
31
|
describe '#delete' do
|
|
32
32
|
it 'deletes the group from the server' do
|
|
33
33
|
readers = described_class.find('readers')
|
|
34
|
-
expect(readers.delete).to
|
|
34
|
+
expect(readers.delete).to be_truthy
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
describe '#save' do
|
|
39
39
|
it 'saves the group to the server' do
|
|
40
40
|
group = described_class.new(name: 'testing')
|
|
41
|
-
expect(group.save).to
|
|
41
|
+
expect(group.save).to be_truthy
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Artifactory
|
|
4
|
+
describe Resource::LDAPSetting, :integration do
|
|
5
|
+
describe '.all' do
|
|
6
|
+
it 'returns an array of LdapSetting' do
|
|
7
|
+
results = described_class.all
|
|
8
|
+
expect(results).to be_a(Array)
|
|
9
|
+
expect(results.first).to be_a(described_class)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '.find' do
|
|
14
|
+
it 'finds an LdapSetting by key' do
|
|
15
|
+
ldap = described_class.find('example-ldap')
|
|
16
|
+
|
|
17
|
+
expect(ldap).to be_a(described_class)
|
|
18
|
+
expect(ldap.key).to eq('example-ldap')
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Artifactory
|
|
4
|
+
describe Resource::MailServer, :integration do
|
|
5
|
+
describe '.all' do
|
|
6
|
+
it 'returns an array of MailServer' do
|
|
7
|
+
results = described_class.all
|
|
8
|
+
expect(results).to be_a(Array)
|
|
9
|
+
expect(results.first).to be_a(described_class)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '.find' do
|
|
14
|
+
it 'finds a MailServer by host' do
|
|
15
|
+
smtp = described_class.find('smtp.gmail.com')
|
|
16
|
+
|
|
17
|
+
expect(smtp).to be_a(described_class)
|
|
18
|
+
expect(smtp.host).to eq('smtp.gmail.com')
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|