apache_felix_webconsole_client 0.0.1

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.
data/git_push.sh ADDED
@@ -0,0 +1,53 @@
1
+ #!/bin/sh
2
+ # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3
+ #
4
+ # Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
5
+
6
+ cd "$(dirname "$0")"
7
+
8
+ git_user_id=$1
9
+ git_repo_id=$2
10
+ release_note=$3
11
+
12
+ if [ "$git_user_id" = "" ]; then
13
+ git_user_id="bstopp"
14
+ echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
15
+ fi
16
+
17
+ if [ "$git_repo_id" = "" ]; then
18
+ git_repo_id="apache-felix-webconsole-client-gem"
19
+ echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
20
+ fi
21
+
22
+ if [ "$release_note" = "" ]; then
23
+ echo "[ERROR] No release note provided. Exiting."
24
+ exit
25
+ fi
26
+
27
+ # Initialize the local directory as a Git repository
28
+ git init
29
+
30
+ # Sets the new remote
31
+ git_remote=`git remote`
32
+ if [ "$git_remote" = "" ]; then # git remote not defined
33
+
34
+ if [ "$GIT_TOKEN" = "" ]; then
35
+ echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
36
+ git remote add origin git@github.com:${git_user_id}/${git_repo_id}.git
37
+ else
38
+ git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
39
+ fi
40
+
41
+ fi
42
+
43
+ git pull origin master
44
+
45
+ # Adds the files in the local repository and stages them for commit.
46
+ git add .
47
+
48
+ # Commits the tracked changes and prepares them to be pushed to a remote repository.
49
+ git commit -m "$release_note"
50
+
51
+ # Pushes (Forces) the changes in the local repository up to the remote repository
52
+ echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
53
+ git push origin master 2>&1 | grep -v 'To git:'
@@ -0,0 +1,54 @@
1
+ =begin
2
+ Apache Felix WebConsole
3
+
4
+ Client for Apache Felix Web Console API. List bundles, configure services, etc.
5
+
6
+ OpenAPI spec version: 4.3.0
7
+ Contact: bryan.stopp@gmail.com
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+ Licensed under the Apache License, Version 2.0 (the "License");
11
+ you may not use this file except in compliance with the License.
12
+ You may obtain a copy of the License at
13
+
14
+ http://www.apache.org/licenses/LICENSE-2.0
15
+
16
+ Unless required by applicable law or agreed to in writing, software
17
+ distributed under the License is distributed on an "AS IS" BASIS,
18
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ See the License for the specific language governing permissions and
20
+ limitations under the License.
21
+
22
+ =end
23
+
24
+ # Common files
25
+ require 'apache_felix_webconsole_client/api_client'
26
+ require 'apache_felix_webconsole_client/api_error'
27
+ require 'apache_felix_webconsole_client/version'
28
+ require 'apache_felix_webconsole_client/configuration'
29
+
30
+ # Models
31
+ require 'apache_felix_webconsole_client/models/bundle'
32
+ require 'apache_felix_webconsole_client/models/bundle_list'
33
+ require 'apache_felix_webconsole_client/models/bundle_props'
34
+
35
+ # APIs
36
+ require 'apache_felix_webconsole_client/api/default_api'
37
+
38
+ module ApacheFelix
39
+ class << self
40
+ # Customize default settings for the SDK using block.
41
+ # ApacheFelix.configure do |config|
42
+ # config.username = "xxx"
43
+ # config.password = "xxx"
44
+ # end
45
+ # If no block given, return the default Configuration object.
46
+ def configure
47
+ if block_given?
48
+ yield(Configuration.default)
49
+ else
50
+ Configuration.default
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,132 @@
1
+ =begin
2
+ Apache Felix WebConsole
3
+
4
+ Client for Apache Felix Web Console API. List bundles, configure services, etc.
5
+
6
+ OpenAPI spec version: 4.3.0
7
+ Contact: bryan.stopp@gmail.com
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+ Licensed under the Apache License, Version 2.0 (the "License");
11
+ you may not use this file except in compliance with the License.
12
+ You may obtain a copy of the License at
13
+
14
+ http://www.apache.org/licenses/LICENSE-2.0
15
+
16
+ Unless required by applicable law or agreed to in writing, software
17
+ distributed under the License is distributed on an "AS IS" BASIS,
18
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ See the License for the specific language governing permissions and
20
+ limitations under the License.
21
+
22
+ =end
23
+
24
+ require "uri"
25
+
26
+ module ApacheFelix
27
+ class DefaultApi
28
+ attr_accessor :api_client
29
+
30
+ def initialize(api_client = ApiClient.default)
31
+ @api_client = api_client
32
+ end
33
+
34
+ # Bundle Info
35
+ # Display all information about a bundle. Same response structure as bundle listing; only one entry exists in the list.
36
+ # @param bundle_id The symbolic name or id of the bundle.
37
+ # @param [Hash] opts the optional parameters
38
+ # @return [BundleList]
39
+ def bundle_info(bundle_id, opts = {})
40
+ data, _status_code, _headers = bundle_info_with_http_info(bundle_id, opts)
41
+ return data
42
+ end
43
+
44
+ # Bundle Info
45
+ # Display all information about a bundle. Same response structure as bundle listing; only one entry exists in the list.
46
+ # @param bundle_id The symbolic name or id of the bundle.
47
+ # @param [Hash] opts the optional parameters
48
+ # @return [Array<(BundleList, Fixnum, Hash)>] BundleList data, response status code and response headers
49
+ def bundle_info_with_http_info(bundle_id, opts = {})
50
+ if @api_client.config.debugging
51
+ @api_client.config.logger.debug "Calling API: DefaultApi.bundle_info ..."
52
+ end
53
+ # verify the required parameter 'bundle_id' is set
54
+ fail ArgumentError, "Missing the required parameter 'bundle_id' when calling DefaultApi.bundle_info" if bundle_id.nil?
55
+ # resource path
56
+ local_var_path = "/bundles/{bundleId}.json".sub('{format}','json').sub('{' + 'bundleId' + '}', bundle_id.to_s)
57
+
58
+ # query parameters
59
+ query_params = {}
60
+
61
+ # header parameters
62
+ header_params = {}
63
+ # HTTP header 'Accept' (if needed)
64
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
65
+
66
+ # form parameters
67
+ form_params = {}
68
+
69
+ # http body (model)
70
+ post_body = nil
71
+ auth_names = ['basic']
72
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
73
+ :header_params => header_params,
74
+ :query_params => query_params,
75
+ :form_params => form_params,
76
+ :body => post_body,
77
+ :auth_names => auth_names,
78
+ :return_type => 'BundleList')
79
+ if @api_client.config.debugging
80
+ @api_client.config.logger.debug "API called: DefaultApi#bundle_info\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
81
+ end
82
+ return data, status_code, headers
83
+ end
84
+
85
+ # List bundles
86
+ # List all the bundles in the Felix system. Properties for a bundle will not be populated.
87
+ # @param [Hash] opts the optional parameters
88
+ # @return [BundleList]
89
+ def bundles(opts = {})
90
+ data, _status_code, _headers = bundles_with_http_info(opts)
91
+ return data
92
+ end
93
+
94
+ # List bundles
95
+ # List all the bundles in the Felix system. Properties for a bundle will not be populated.
96
+ # @param [Hash] opts the optional parameters
97
+ # @return [Array<(BundleList, Fixnum, Hash)>] BundleList data, response status code and response headers
98
+ def bundles_with_http_info(opts = {})
99
+ if @api_client.config.debugging
100
+ @api_client.config.logger.debug "Calling API: DefaultApi.bundles ..."
101
+ end
102
+ # resource path
103
+ local_var_path = "/bundles.json".sub('{format}','json')
104
+
105
+ # query parameters
106
+ query_params = {}
107
+
108
+ # header parameters
109
+ header_params = {}
110
+ # HTTP header 'Accept' (if needed)
111
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
112
+
113
+ # form parameters
114
+ form_params = {}
115
+
116
+ # http body (model)
117
+ post_body = nil
118
+ auth_names = ['basic']
119
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
120
+ :header_params => header_params,
121
+ :query_params => query_params,
122
+ :form_params => form_params,
123
+ :body => post_body,
124
+ :auth_names => auth_names,
125
+ :return_type => 'BundleList')
126
+ if @api_client.config.debugging
127
+ @api_client.config.logger.debug "API called: DefaultApi#bundles\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
128
+ end
129
+ return data, status_code, headers
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,388 @@
1
+ =begin
2
+ Apache Felix WebConsole
3
+
4
+ Client for Apache Felix Web Console API. List bundles, configure services, etc.
5
+
6
+ OpenAPI spec version: 4.3.0
7
+ Contact: bryan.stopp@gmail.com
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+ Licensed under the Apache License, Version 2.0 (the "License");
11
+ you may not use this file except in compliance with the License.
12
+ You may obtain a copy of the License at
13
+
14
+ http://www.apache.org/licenses/LICENSE-2.0
15
+
16
+ Unless required by applicable law or agreed to in writing, software
17
+ distributed under the License is distributed on an "AS IS" BASIS,
18
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ See the License for the specific language governing permissions and
20
+ limitations under the License.
21
+
22
+ =end
23
+
24
+ require 'date'
25
+ require 'json'
26
+ require 'logger'
27
+ require 'tempfile'
28
+ require 'typhoeus'
29
+ require 'uri'
30
+
31
+ module ApacheFelix
32
+ class ApiClient
33
+ # The Configuration object holding settings to be used in the API client.
34
+ attr_accessor :config
35
+
36
+ # Defines the headers to be used in HTTP requests of all API calls by default.
37
+ #
38
+ # @return [Hash]
39
+ attr_accessor :default_headers
40
+
41
+ # Initializes the ApiClient
42
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
43
+ def initialize(config = Configuration.default)
44
+ @config = config
45
+ @user_agent = "Swagger-Codegen/#{VERSION}/ruby"
46
+ @default_headers = {
47
+ 'Content-Type' => "application/json",
48
+ 'User-Agent' => @user_agent
49
+ }
50
+ end
51
+
52
+ def self.default
53
+ @@default ||= ApiClient.new
54
+ end
55
+
56
+ # Call an API with given options.
57
+ #
58
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
59
+ # the data deserialized from response body (could be nil), response status code and response headers.
60
+ def call_api(http_method, path, opts = {})
61
+ request = build_request(http_method, path, opts)
62
+ response = request.run
63
+
64
+ if @config.debugging
65
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
66
+ end
67
+
68
+ unless response.success?
69
+ if response.timed_out?
70
+ fail ApiError.new('Connection timed out')
71
+ elsif response.code == 0
72
+ # Errors from libcurl will be made visible here
73
+ fail ApiError.new(:code => 0,
74
+ :message => response.return_message)
75
+ else
76
+ fail ApiError.new(:code => response.code,
77
+ :response_headers => response.headers,
78
+ :response_body => response.body),
79
+ response.status_message
80
+ end
81
+ end
82
+
83
+ if opts[:return_type]
84
+ data = deserialize(response, opts[:return_type])
85
+ else
86
+ data = nil
87
+ end
88
+ return data, response.code, response.headers
89
+ end
90
+
91
+ # Builds the HTTP request
92
+ #
93
+ # @param [String] http_method HTTP method/verb (e.g. POST)
94
+ # @param [String] path URL path (e.g. /account/new)
95
+ # @option opts [Hash] :header_params Header parameters
96
+ # @option opts [Hash] :query_params Query parameters
97
+ # @option opts [Hash] :form_params Query parameters
98
+ # @option opts [Object] :body HTTP body (JSON/XML)
99
+ # @return [Typhoeus::Request] A Typhoeus Request
100
+ def build_request(http_method, path, opts = {})
101
+ url = build_request_url(path)
102
+ http_method = http_method.to_sym.downcase
103
+
104
+ header_params = @default_headers.merge(opts[:header_params] || {})
105
+ query_params = opts[:query_params] || {}
106
+ form_params = opts[:form_params] || {}
107
+
108
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
109
+
110
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
111
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
112
+
113
+ req_opts = {
114
+ :method => http_method,
115
+ :headers => header_params,
116
+ :params => query_params,
117
+ :params_encoding => @config.params_encoding,
118
+ :timeout => @config.timeout,
119
+ :ssl_verifypeer => @config.verify_ssl,
120
+ :ssl_verifyhost => _verify_ssl_host,
121
+ :sslcert => @config.cert_file,
122
+ :sslkey => @config.key_file,
123
+ :verbose => @config.debugging
124
+ }
125
+
126
+ # set custom cert, if provided
127
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
128
+
129
+ if [:post, :patch, :put, :delete].include?(http_method)
130
+ req_body = build_request_body(header_params, form_params, opts[:body])
131
+ req_opts.update :body => req_body
132
+ if @config.debugging
133
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
134
+ end
135
+ end
136
+
137
+ Typhoeus::Request.new(url, req_opts)
138
+ end
139
+
140
+ # Check if the given MIME is a JSON MIME.
141
+ # JSON MIME examples:
142
+ # application/json
143
+ # application/json; charset=UTF8
144
+ # APPLICATION/JSON
145
+ # */*
146
+ # @param [String] mime MIME
147
+ # @return [Boolean] True if the MIME is application/json
148
+ def json_mime?(mime)
149
+ (mime == "*/*") || !(mime =~ /\Aapplication\/json(;.*)?\z/i).nil?
150
+ end
151
+
152
+ # Deserialize the response to the given return type.
153
+ #
154
+ # @param [Response] response HTTP response
155
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
156
+ def deserialize(response, return_type)
157
+ body = response.body
158
+ return nil if body.nil? || body.empty?
159
+
160
+ # return response body directly for String return type
161
+ return body if return_type == 'String'
162
+
163
+ # handle file downloading - save response body into a tmp file and return the File instance
164
+ return download_file(response) if return_type == 'File'
165
+
166
+ # ensuring a default content type
167
+ content_type = response.headers['Content-Type'] || 'application/json'
168
+
169
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
170
+
171
+ begin
172
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
173
+ rescue JSON::ParserError => e
174
+ if %w(String Date DateTime).include?(return_type)
175
+ data = body
176
+ else
177
+ raise e
178
+ end
179
+ end
180
+
181
+ convert_to_type data, return_type
182
+ end
183
+
184
+ # Convert data to the given return type.
185
+ # @param [Object] data Data to be converted
186
+ # @param [String] return_type Return type
187
+ # @return [Mixed] Data in a particular type
188
+ def convert_to_type(data, return_type)
189
+ return nil if data.nil?
190
+ case return_type
191
+ when 'String'
192
+ data.to_s
193
+ when 'Integer'
194
+ data.to_i
195
+ when 'Float'
196
+ data.to_f
197
+ when 'BOOLEAN'
198
+ data == true
199
+ when 'DateTime'
200
+ # parse date time (expecting ISO 8601 format)
201
+ DateTime.parse data
202
+ when 'Date'
203
+ # parse date time (expecting ISO 8601 format)
204
+ Date.parse data
205
+ when 'Object'
206
+ # generic object (usually a Hash), return directly
207
+ data
208
+ when /\AArray<(.+)>\z/
209
+ # e.g. Array<Pet>
210
+ sub_type = $1
211
+ data.map {|item| convert_to_type(item, sub_type) }
212
+ when /\AHash\<String, (.+)\>\z/
213
+ # e.g. Hash<String, Integer>
214
+ sub_type = $1
215
+ {}.tap do |hash|
216
+ data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
217
+ end
218
+ else
219
+ # models, e.g. Pet
220
+ ApacheFelix.const_get(return_type).new.tap do |model|
221
+ model.build_from_hash data
222
+ end
223
+ end
224
+ end
225
+
226
+ # Save response body into a file in (the defined) temporary folder, using the filename
227
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
228
+ #
229
+ # @see Configuration#temp_folder_path
230
+ # @return [Tempfile] the file downloaded
231
+ def download_file(response)
232
+ content_disposition = response.headers['Content-Disposition']
233
+ if content_disposition and content_disposition =~ /filename=/i
234
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
235
+ prefix = sanitize_filename(filename)
236
+ else
237
+ prefix = 'download-'
238
+ end
239
+ prefix = prefix + '-' unless prefix.end_with?('-')
240
+
241
+ tempfile = nil
242
+ encoding = response.body.encoding
243
+ Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
244
+ file.write(response.body)
245
+ tempfile = file
246
+ end
247
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
248
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
249
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
250
+ "explicitly with `tempfile.delete`"
251
+ tempfile
252
+ end
253
+
254
+ # Sanitize filename by removing path.
255
+ # e.g. ../../sun.gif becomes sun.gif
256
+ #
257
+ # @param [String] filename the filename to be sanitized
258
+ # @return [String] the sanitized filename
259
+ def sanitize_filename(filename)
260
+ filename.gsub(/.*[\/\\]/, '')
261
+ end
262
+
263
+ def build_request_url(path)
264
+ # Add leading and trailing slashes to path
265
+ path = "/#{path}".gsub(/\/+/, '/')
266
+ URI.encode(@config.base_url + path)
267
+ end
268
+
269
+ # Builds the HTTP request body
270
+ #
271
+ # @param [Hash] header_params Header parameters
272
+ # @param [Hash] form_params Query parameters
273
+ # @param [Object] body HTTP body (JSON/XML)
274
+ # @return [String] HTTP body data in the form of string
275
+ def build_request_body(header_params, form_params, body)
276
+ # http form
277
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
278
+ header_params['Content-Type'] == 'multipart/form-data'
279
+ data = {}
280
+ form_params.each do |key, value|
281
+ case value
282
+ when File, Array, nil
283
+ # let typhoeus handle File, Array and nil parameters
284
+ data[key] = value
285
+ else
286
+ data[key] = value.to_s
287
+ end
288
+ end
289
+ elsif body
290
+ data = body.is_a?(String) ? body : body.to_json
291
+ else
292
+ data = nil
293
+ end
294
+ data
295
+ end
296
+
297
+ # Update hearder and query params based on authentication settings.
298
+ #
299
+ # @param [Hash] header_params Header parameters
300
+ # @param [Hash] query_params Query parameters
301
+ # @param [String] auth_names Authentication scheme name
302
+ def update_params_for_auth!(header_params, query_params, auth_names)
303
+ Array(auth_names).each do |auth_name|
304
+ auth_setting = @config.auth_settings[auth_name]
305
+ next unless auth_setting
306
+ case auth_setting[:in]
307
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
308
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
309
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
310
+ end
311
+ end
312
+ end
313
+
314
+ # Sets user agent in HTTP header
315
+ #
316
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
317
+ def user_agent=(user_agent)
318
+ @user_agent = user_agent
319
+ @default_headers['User-Agent'] = @user_agent
320
+ end
321
+
322
+ # Return Accept header based on an array of accepts provided.
323
+ # @param [Array] accepts array for Accept
324
+ # @return [String] the Accept header (e.g. application/json)
325
+ def select_header_accept(accepts)
326
+ return nil if accepts.nil? || accepts.empty?
327
+ # use JSON when present, otherwise use all of the provided
328
+ json_accept = accepts.find { |s| json_mime?(s) }
329
+ return json_accept || accepts.join(',')
330
+ end
331
+
332
+ # Return Content-Type header based on an array of content types provided.
333
+ # @param [Array] content_types array for Content-Type
334
+ # @return [String] the Content-Type header (e.g. application/json)
335
+ def select_header_content_type(content_types)
336
+ # use application/json by default
337
+ return 'application/json' if content_types.nil? || content_types.empty?
338
+ # use JSON when present, otherwise use the first one
339
+ json_content_type = content_types.find { |s| json_mime?(s) }
340
+ return json_content_type || content_types.first
341
+ end
342
+
343
+ # Convert object (array, hash, object, etc) to JSON string.
344
+ # @param [Object] model object to be converted into JSON string
345
+ # @return [String] JSON string representation of the object
346
+ def object_to_http_body(model)
347
+ return model if model.nil? || model.is_a?(String)
348
+ local_body = nil
349
+ if model.is_a?(Array)
350
+ local_body = model.map{|m| object_to_hash(m) }
351
+ else
352
+ local_body = object_to_hash(model)
353
+ end
354
+ local_body.to_json
355
+ end
356
+
357
+ # Convert object(non-array) to hash.
358
+ # @param [Object] obj object to be converted into JSON string
359
+ # @return [String] JSON string representation of the object
360
+ def object_to_hash(obj)
361
+ if obj.respond_to?(:to_hash)
362
+ obj.to_hash
363
+ else
364
+ obj
365
+ end
366
+ end
367
+
368
+ # Build parameter value according to the given collection format.
369
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
370
+ def build_collection_param(param, collection_format)
371
+ case collection_format
372
+ when :csv
373
+ param.join(',')
374
+ when :ssv
375
+ param.join(' ')
376
+ when :tsv
377
+ param.join("\t")
378
+ when :pipes
379
+ param.join('|')
380
+ when :multi
381
+ # return the array directly as typhoeus will handle it as expected
382
+ param
383
+ else
384
+ fail "unknown collection format: #{collection_format.inspect}"
385
+ end
386
+ end
387
+ end
388
+ end