runcible / lib / runcible / resources / repository.rb @ 27b106f4
1 |
require 'active_support/core_ext/hash'
|
---|---|
2 |
|
3 |
module Runcible |
4 |
module Resources |
5 |
# @see https://docs.pulpproject.org/dev-guide/integration/rest-api/repo/index.html
|
6 |
class Repository < Runcible::Base |
7 |
# Generates the API path for Repositories
|
8 |
#
|
9 |
# @param [String] id the id of the repository
|
10 |
# @return [String] the repository path, may contain the id if passed
|
11 |
def self.path(id = nil) |
12 |
id.nil? ? 'repositories/' : "repositories/#{id}/" |
13 |
end
|
14 |
|
15 |
# Creates a repository
|
16 |
#
|
17 |
# @param [String] id the id of the repository
|
18 |
# @param [Hash] optional container for all optional parameters
|
19 |
# @return [RestClient::Response]
|
20 |
def create(id, optional = {}) |
21 |
required = required_params(binding.send(:local_variables), binding)
|
22 |
call(:post, path, :payload => { :required => required, :optional => optional }) |
23 |
end
|
24 |
|
25 |
# Retrieves a repository
|
26 |
#
|
27 |
# @param [String] id the id of the repository
|
28 |
# @param [Hash] params container for optional query parameters
|
29 |
# @return [RestClient::Response]
|
30 |
def retrieve(id, params = {}) |
31 |
call(:get, path(id), :params => params) |
32 |
end
|
33 |
|
34 |
# Updates a repository
|
35 |
#
|
36 |
# @param [String] id the id of the repository
|
37 |
# @param [Hash] optional container for all optional parameters
|
38 |
# @return [RestClient::Response]
|
39 |
def update(id, optional = {}) |
40 |
call(:put, path(id), :payload => { :delta => optional }) |
41 |
end
|
42 |
|
43 |
# Deletes a repository
|
44 |
#
|
45 |
# @param [String] id the id of the repository
|
46 |
# @return [RestClient::Response]
|
47 |
def delete(id) |
48 |
call(:delete, path(id))
|
49 |
end
|
50 |
|
51 |
# Retrieve all repositories
|
52 |
#
|
53 |
# @param [Hash] optional container for all optional parameters
|
54 |
# @return [RestClient::Response]
|
55 |
def retrieve_all(optional = {}) |
56 |
call(:get, path, :payload => { :optional => optional }) |
57 |
end
|
58 |
|
59 |
# Searches for repositories based on criteria
|
60 |
#
|
61 |
# @param [Hash] criteria criteria object containing Mongo syntax
|
62 |
# @param [Hash] optional container for all optional parameters
|
63 |
# @return [RestClient::Response]
|
64 |
def search(criteria, optional = {}) |
65 |
required = required_params(binding.send(:local_variables), binding)
|
66 |
call(:post, path('search'), :payload => { :required => required, :optional => optional }) |
67 |
end
|
68 |
|
69 |
# Associates an importer to a repository
|
70 |
#
|
71 |
# @param [String] id the ID of the repository
|
72 |
# @param [String] importer_type_id the type ID of the importer being associated
|
73 |
# @param [Hash] importer_config configuration options for the importer
|
74 |
# @return [RestClient::Response]
|
75 |
def associate_importer(id, importer_type_id, importer_config) |
76 |
required = required_params(binding.send(:local_variables), binding)
|
77 |
call(:post, path("#{id}/importers"), :payload => { :required => required }) |
78 |
end
|
79 |
|
80 |
# Associates a distributor to a repository
|
81 |
#
|
82 |
# @param [String] id the ID of the repository
|
83 |
# @param [String] distributor_type_id the type ID of the distributor being associated
|
84 |
# @param [Hash] distributor_config configuration options for the distributor
|
85 |
# @param [Hash] optional container for all optional parameters
|
86 |
# @return [RestClient::Response]
|
87 |
def associate_distributor(id, distributor_type_id, distributor_config, optional = {}) |
88 |
required = required_params(binding.send(:local_variables), binding, ['id']) |
89 |
call(:post, path("#{id}/distributors"), :payload => { :required => required, :optional => optional }) |
90 |
end
|
91 |
|
92 |
# Syncs a repository
|
93 |
#
|
94 |
# @param [String] id the id of the repository
|
95 |
# @param [Hash] optional container for all optional parameters
|
96 |
# @return [RestClient::Response]
|
97 |
def sync(id, optional = {}) |
98 |
call(:post, "#{path(id)}actions/sync/", :payload => { :optional => optional }) |
99 |
end
|
100 |
|
101 |
# Downloads all units in a repository (useful in the case of on_demand repositories)
|
102 |
#
|
103 |
# @param [String] id the id of the repository
|
104 |
# @param [Hash] optional container for all optional parameters
|
105 |
# @return [RestClient::Response]
|
106 |
def download(id, optional = {}) |
107 |
call(:post, "#{path(id)}actions/download/", :payload => { :optional => optional }) |
108 |
end
|
109 |
|
110 |
# History of all sync actions on a repository
|
111 |
#
|
112 |
# @param [String] id the id of the repository
|
113 |
# @return [RestClient::Response]
|
114 |
def sync_history(id) |
115 |
call(:get, "#{path(id)}/history/sync/") |
116 |
end
|
117 |
|
118 |
# Copies units from one repository to another
|
119 |
#
|
120 |
# @param [String] destination_repo_id the id of the destination repository
|
121 |
# @param [String] source_repo_id the id of the source repository
|
122 |
# @param [Hash] optional container for all optional parameters
|
123 |
# @return [RestClient::Response]
|
124 |
def unit_copy(destination_repo_id, source_repo_id, optional = {}) |
125 |
required = required_params(binding.send(:local_variables), binding, ['destination_repo_id']) |
126 |
call(:post, "#{path(destination_repo_id)}actions/associate/", |
127 |
:payload => { :required => required, :optional => optional }) |
128 |
end
|
129 |
|
130 |
# Unassociates units from the repository
|
131 |
#
|
132 |
# @param [String] source_repo_id the id of the source repository
|
133 |
# @param [Hash] criteria criteria object containing Mongo syntax
|
134 |
# @return [RestClient::Response]
|
135 |
def unassociate_units(source_repo_id, criteria = {}) |
136 |
required = required_params(binding.send(:local_variables), binding, ['source_repo_id']) |
137 |
call(:post, "#{path(source_repo_id)}actions/unassociate/", |
138 |
:payload => { :required => required }) |
139 |
end
|
140 |
|
141 |
# Searches the repository for units based on criteria
|
142 |
#
|
143 |
# @param [String] id the id of the repository
|
144 |
# @param [Hash] criteria criteria object containing Mongo syntax
|
145 |
# @return [RestClient::Response]
|
146 |
def unit_search(id, criteria = {}) |
147 |
call(:post, "#{path(id)}search/units/", :payload => {:required => {:criteria => criteria}}) |
148 |
end
|
149 |
|
150 |
# Publishes a repository using the specified distributor
|
151 |
#
|
152 |
# @param [String] id the id of the repository
|
153 |
# @param [String] distributor_id the id of the distributor
|
154 |
# @param [Hash] optional optional params
|
155 |
# @return [RestClient::Response]
|
156 |
def publish(id, distributor_id, optional = {}) |
157 |
call(:post, "#{path(id)}actions/publish/", |
158 |
:payload => {:required => {:id => distributor_id}, :optional => optional}) |
159 |
end
|
160 |
|
161 |
# Deletes the specified distributor from the repository
|
162 |
#
|
163 |
# @param [String] id the id of the repository
|
164 |
# @param [String] distributor_id the id of the distributor
|
165 |
# @return [RestClient::Response]
|
166 |
def delete_distributor(id, distributor_id) |
167 |
call(:delete, "#{path(id)}/distributors/#{distributor_id}/") |
168 |
end
|
169 |
|
170 |
# Updates the specified distributor from the repository
|
171 |
#
|
172 |
# @param [String] id the id of the repository
|
173 |
# @param [String] distributor_id the id of the distributor
|
174 |
# @param [Hash] distributor_config attributes to change
|
175 |
# @return [RestClient::Response]
|
176 |
def update_distributor(id, distributor_id, distributor_config) |
177 |
required = required_params(binding.send(:local_variables), binding, ['id', 'distributor_id']) |
178 |
call(:put, path("#{id}/distributors/#{distributor_id}/"), :payload => { :required => required}) |
179 |
end
|
180 |
|
181 |
# Deletes the specified importer from the repository
|
182 |
#
|
183 |
# @param [String] id the id of the repository
|
184 |
# @param [String] importer_id the id of the importer
|
185 |
# @return [RestClient::Response]
|
186 |
def delete_importer(id, importer_id) |
187 |
call(:delete, "#{path(id)}/importers/#{importer_id}/") |
188 |
end
|
189 |
|
190 |
# Updates the specified distributor from the repository
|
191 |
#
|
192 |
# @param [String] id the id of the repository
|
193 |
# @param [String] importer_id the id of the importer
|
194 |
# @param [Hash] importer_config attributes to change
|
195 |
# @return [RestClient::Response]
|
196 |
def update_importer(id, importer_id, importer_config) |
197 |
required = required_params(binding.send(:local_variables), binding, ['id', 'importer_id']) |
198 |
call(:put, path("#{id}/importers/#{importer_id}/"), :payload => { :required => required}) |
199 |
end
|
200 |
|
201 |
# Regenerate the applicability for consumers bound to a given set of repositories
|
202 |
#
|
203 |
# @param [Hash] options payload representing criteria
|
204 |
# @return [RestClient::Response]
|
205 |
def regenerate_applicability(options = {}) |
206 |
call(:post, path('actions/content/regenerate_applicability/'), :payload => { :required => options}) |
207 |
end
|
208 |
end
|
209 |
end
|
210 |
end
|