foreman_api_client 1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e47793146ddac89979aaccea887f49004a0a0c1b8e3a0c8cc2fd8328c1fcc73e
4
+ data.tar.gz: 0e9504dcfce39a52c1211de9915de4975479e521700e69ea6682103fd7aab143
5
+ SHA512:
6
+ metadata.gz: 3e7eb06be332bffa93d9c36f72c46012deb9e8e48a5d78af5d891d7f6e6a8df47e5869934605366936e9bafc38bfb689cf94c64a5fd677c63ef845fee44192bc
7
+ data.tar.gz: dedc137e2d6708707c69c977306cd86cb0a1667d294ea57177208b8b74d70bff6ffe68a72b548cb2c1a316285b14a5f77ee15d49255ce85c0287062ce303b6fd
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0"
4
+ - "2.1"
5
+ - "2.2.5"
6
+ - "2.3.4"
7
+ - "2.4.1"
8
+ - ruby-head
9
+ - jruby-head
10
+ sudo: false
11
+ cache: bundler
12
+ before_install: gem install bundler -v ">=1.12"
13
+ after_script: bundle exec codeclimate-test-reporter
14
+ matrix:
15
+ allow_failures:
16
+ - rvm: ruby-head
17
+ - rvm: jruby-head
18
+ fast_finish: true
data/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [1.0.0] - 2020-02-18
10
+ ### Changed
11
+ - Initial release to rubygems.org
12
+ - Miscellaneous cleanup and dependency updates
13
+
14
+ ## [0.1.0] - 2016-07-08
15
+ ### Breaking changes
16
+ - Mass rename from ManageiqForeman to ForemanApiClient
17
+
18
+ ### Other changes
19
+ - Extracted from https://github.com/ManageIQ/manageiq/tree/master/gems/manageiq_foreman
20
+ - Move inventory logic to Foreman provider refresher in ManageIQ/manageiq
21
+
22
+ [Unreleased]: https://github.com/ManageIQ/foreman_api_client/compare/v1.0.0...HEAD
23
+ [1.0.0]: https://github.com/ManageIQ/foreman_api_client/compare/v0.1.0...v1.0.0
24
+ [0.1.0]: https://github.com/ManageIQ/foreman_api_client/releases/tag/v0.1.0
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in foreman_api_client.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "codeclimate-test-reporter", :require => false
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Foreman API Client
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/foreman_api_client.svg)](http://badge.fury.io/rb/foreman_api_client)
4
+ [![Build Status](https://travis-ci.org/ManageIQ/foreman_api_client.svg)](https://travis-ci.org/ManageIQ/foreman_api_client)
5
+ [![Code Climate](https://codeclimate.com/github/ManageIQ/foreman_api_client/badges/gpa.svg)](https://codeclimate.com/github/ManageIQ/foreman_api_client)
6
+ [![Test Coverage](https://codeclimate.com/github/ManageIQ/foreman_api_client/badges/coverage.svg)](https://codeclimate.com/github/ManageIQ/foreman_api_client/coverage)
7
+ [![Dependency Status](https://gemnasium.com/ManageIQ/foreman_api_client.svg)](https://gemnasium.com/ManageIQ/foreman_api_client)
8
+ [![Security](https://hakiri.io/github/ManageIQ/foreman_api_client/master.svg)](https://hakiri.io/github/ManageIQ/foreman_api_client/master)
9
+
10
+ A simple wrapper around Apipie-bindings to provide Ruby classes for [Foreman](https://theforeman.org/).
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'foreman_api_client', :git => "git://github.com/ManageIQ/foreman_api_client.git", :branch => "master"
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ require 'foreman_api_client'
26
+ ForemanApiClient.logger = Logger.new(STDOUT)
27
+ connection = ForemanApiClient::Connection.new(
28
+ :base_url => base_url,
29
+ :username => username,
30
+ :password => password,
31
+ :verify_ssl => verify_ssl
32
+ )
33
+ c.host(1)
34
+ => #<ForemanApiClient::Host:0x0055b8a05daa58 ...>
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [Apache License 2.0](https://opensource.org/licenses/Apache-2.0).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :test => :spec
7
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "foreman_api_client"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'foreman_api_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "foreman_api_client"
8
+ spec.version = ForemanApiClient::VERSION
9
+ spec.authors = ["Keenan Brock", "Brandon Dunne"]
10
+ spec.email = ["keenan@thebrocks.net", "bdunne@redhat.com"]
11
+
12
+ spec.description = %q{Foreman apipie-bindings wrapper}
13
+ spec.summary = %q{Foreman apipie-bindings wrapper}
14
+ spec.homepage = "https://github.com/ManageIQ/foreman_api_client"
15
+ spec.license = "Apache-2.0"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "apipie-bindings", "= 0.0.15"
23
+ spec.add_runtime_dependency "rest-client", ">= 2.0.0.rc1"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "vcr", "~> 3.0.2"
30
+ spec.add_development_dependency "webmock", "~> 2.3.1"
31
+ end
@@ -0,0 +1,11 @@
1
+ require "foreman_api_client/logging"
2
+ require "foreman_api_client/version"
3
+
4
+ require 'apipie-bindings'
5
+
6
+ require "foreman_api_client/connection"
7
+ require "foreman_api_client/host"
8
+ require "foreman_api_client/paged_response"
9
+
10
+ module ForemanApiClient
11
+ end
@@ -0,0 +1,81 @@
1
+ module ForemanApiClient
2
+ class Connection
3
+ include ForemanApiClient::Logging
4
+ # some foreman servers don't have locations or organizations, just return nil
5
+ ALLOW_404 = [:locations, :organizations]
6
+ attr_accessor :connection_attrs
7
+
8
+ def initialize(attrs)
9
+ self.connection_attrs = attrs.dup
10
+ connection_attrs[:uri] = connection_attrs.delete(:base_url)
11
+ connection_attrs[:api_version] ||= 2
12
+ connection_attrs[:apidoc_cache_dir] ||= tmpdir
13
+ options = {:verify_ssl => connection_attrs.delete(:verify_ssl)}
14
+ @api = ApipieBindings::API.new(connection_attrs, options)
15
+ end
16
+
17
+ def verify?
18
+ results = Array(fetch(:home).try(:results)).first
19
+ results.respond_to?(:key?) && results.key?("links")
20
+ end
21
+
22
+ def all(resource, filter = {})
23
+ page = 0
24
+ all = []
25
+
26
+ loop do
27
+ page_params = {:page => (page += 1), :per_page => 50}.merge(filter)
28
+ small = fetch(resource, :index, page_params)
29
+ return if small.nil? # 404
30
+ all += small.to_a
31
+ break if small.empty? || all.size >= small.total
32
+ end
33
+ PagedResponse.new(all)
34
+ end
35
+
36
+ # ala n+1
37
+ def all_with_details(resource, filter = {})
38
+ load_details(all(resource, filter), resource)
39
+ end
40
+
41
+ def load_details(resources, resource)
42
+ resources.map! { |os| fetch(resource, :show, "id" => os["id"]).first } if resources
43
+ end
44
+
45
+ # filter: "page" => 2, "per_page" => 50, "search" => "field=value", "value"
46
+ def fetch(resource, action = :index, filter = {})
47
+ action, filter = :index, action if action.kind_of?(Hash)
48
+ logger.info("#{self.class.name}##{__method__} Calling Apipie Resource: #{resource.inspect} Action: #{action.inspect} Params: #{dump_hash(filter)}")
49
+ PagedResponse.new(@api.resource(resource).action(action).call(filter))
50
+ rescue RestClient::ResourceNotFound
51
+ raise unless ALLOW_404.include?(resource)
52
+ nil
53
+ end
54
+
55
+ def host(manager_ref)
56
+ ::ForemanApiClient::Host.new(self, manager_ref)
57
+ end
58
+
59
+ # used for tests to manually invoke loading api from server
60
+ # this keeps http calls consistent
61
+
62
+ def api_cached?
63
+ File.exist?(@api.apidoc_cache_file)
64
+ end
65
+
66
+ def ensure_api_cached
67
+ @api.apidoc
68
+ end
69
+
70
+ private
71
+
72
+ def tmpdir
73
+ if defined?(Rails)
74
+ Rails.root.join("tmp/foreman").to_s
75
+ else
76
+ require 'tmpdir'
77
+ "#{Dir.tmpdir}/foreman"
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,48 @@
1
+ module ForemanApiClient
2
+ class Host
3
+ attr_accessor :manager_ref
4
+ attr_accessor :connection
5
+
6
+ def initialize(connection, manager_ref)
7
+ @connection = connection
8
+ @manager_ref = manager_ref
9
+ end
10
+
11
+ def building?
12
+ attributes["build"]
13
+ end
14
+
15
+ def start
16
+ power_state("on")
17
+ end
18
+
19
+ def stop
20
+ power_state("off")
21
+ end
22
+
23
+ # valid actions are (on/start), (off/stop), (soft/reboot), (cycle/reset), (state/status)
24
+ def power_state(action = "status")
25
+ connection.fetch(:hosts, :power, "id" => manager_ref, "power_action" => action).first["power"]
26
+ end
27
+
28
+ def powered_off?
29
+ power_state == "off"
30
+ end
31
+
32
+ def powered_on?
33
+ power_state == "on"
34
+ end
35
+
36
+ def set_boot_mode(mode = "pxe")
37
+ connection.fetch(:hosts, :boot, "id" => manager_ref, "device" => mode).first["boot"]
38
+ end
39
+
40
+ def attributes
41
+ connection.fetch(:hosts, :show, "id" => manager_ref).first
42
+ end
43
+
44
+ def update(params)
45
+ connection.fetch(:hosts, :update, "id" => manager_ref, "host" => params)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,23 @@
1
+ require "foreman_api_client/null_logger"
2
+
3
+ module ForemanApiClient
4
+ extend self
5
+ attr_accessor :logger
6
+
7
+ module Logging
8
+ def logger
9
+ ForemanApiClient.logger ||= NullLogger.new
10
+ end
11
+
12
+ def logger=(new_logger)
13
+ ForemanApiClient.logger = new_logger
14
+ end
15
+
16
+ def dump_hash(hash)
17
+ filtered_keys = ["root_pass"]
18
+ new_hash = hash.dup
19
+ filtered_keys.each { |k| new_hash[k] = "<FILTERED>" }
20
+ new_hash.inspect
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ require 'logger'
2
+
3
+ module ForemanApiClient
4
+ class NullLogger < Logger
5
+ def initialize(*_args)
6
+ end
7
+
8
+ def add(*_args, &_block)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,52 @@
1
+ module ForemanApiClient
2
+ # like the WillPaginate collection
3
+ class PagedResponse
4
+ include Enumerable
5
+ extend Forwardable
6
+
7
+ attr_accessor :page
8
+ attr_accessor :total
9
+ attr_accessor :results
10
+
11
+ # per_page, search, sort
12
+ def initialize(json)
13
+ if json.kind_of?(Hash) && json["results"]
14
+ @results = json["results"]
15
+ @total = json["total"].to_i
16
+ @page = json["page"]
17
+ else
18
+ @results = json.kind_of?(Array) ? json : Array[json]
19
+ @total = json.size
20
+ @page = 1
21
+ end
22
+ end
23
+
24
+ def_delegators :results, :each, :[], :empty?, :size
25
+
26
+ # modify the structure inline
27
+ def map!(&block)
28
+ self.results = results.map(&block)
29
+ self
30
+ end
31
+
32
+ def ==(other)
33
+ results == other.results
34
+ end
35
+
36
+ def denormalize
37
+ self.class.new(
38
+ results.collect do |record|
39
+ ancestors(results, record["ancestry"]).each_with_object({}) do |ancestor, h|
40
+ h.merge!(ancestor.select { |_n, v| !v.nil? && v != "" })
41
+ end.merge!(record.select { |_n, v| !v.nil? && v != "" })
42
+ end
43
+ )
44
+ end
45
+
46
+ private
47
+
48
+ def ancestors(records, ancestry)
49
+ (ancestry || "").split("/").collect(&:to_i).collect { |id| records.detect { |r| r["id"] == id } }
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module ForemanApiClient
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foreman_api_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Keenan Brock
8
+ - Brandon Dunne
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2020-02-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: apipie-bindings
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 0.0.15
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '='
26
+ - !ruby/object:Gem::Version
27
+ version: 0.0.15
28
+ - !ruby/object:Gem::Dependency
29
+ name: rest-client
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.0.0.rc1
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 2.0.0.rc1
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.3'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.3'
56
+ - !ruby/object:Gem::Dependency
57
+ name: codeclimate-test-reporter
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 1.0.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.0
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: vcr
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: 3.0.2
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: 3.0.2
112
+ - !ruby/object:Gem::Dependency
113
+ name: webmock
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: 2.3.1
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: 2.3.1
126
+ description: Foreman apipie-bindings wrapper
127
+ email:
128
+ - keenan@thebrocks.net
129
+ - bdunne@redhat.com
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - ".rspec"
136
+ - ".travis.yml"
137
+ - CHANGELOG.md
138
+ - Gemfile
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - bin/console
143
+ - bin/setup
144
+ - foreman_api_client.gemspec
145
+ - lib/foreman_api_client.rb
146
+ - lib/foreman_api_client/connection.rb
147
+ - lib/foreman_api_client/host.rb
148
+ - lib/foreman_api_client/logging.rb
149
+ - lib/foreman_api_client/null_logger.rb
150
+ - lib/foreman_api_client/paged_response.rb
151
+ - lib/foreman_api_client/version.rb
152
+ homepage: https://github.com/ManageIQ/foreman_api_client
153
+ licenses:
154
+ - Apache-2.0
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubygems_version: 3.0.6
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Foreman apipie-bindings wrapper
175
+ test_files: []