soar_customer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2cfe5f645ce2138447b712ef3c71bdc2852cf292
4
+ data.tar.gz: 3e78e03791c9c1ddd5ae69834f44b1e771a2486e
5
+ SHA512:
6
+ metadata.gz: 0f388bdd8ffae786e92c35e2b40109eebab3cdd92592d05572ab5b5c2dd78f1baa629f9de4628cb1d220923bd2de267861e433cc23d5a0b4d09a41b8d1fc811f
7
+ data.tar.gz: b1919b2356290d63b27cc716932c9001c4d8baea12c645612536ac9aa8208d96ab5d9168893b7e75f850f9137bef3ddac87e8f2daaf67828de2f42b2fa0ffb6c
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .byebug_history
11
+ nohup.out
12
+ sinatra.log
13
+ /.gem/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,32 @@
1
+ sudo: required
2
+
3
+ services:
4
+ - docker
5
+
6
+ env:
7
+ global:
8
+ - DOCKER_VERSION=1.10.1-0~trusty
9
+ - DOCKER_COMPOSE_VERSION=1.6.0
10
+ rvm:
11
+ - 2.2.0
12
+
13
+ before_install:
14
+ # list docker-engine versions
15
+ - apt-cache madison docker-engine
16
+
17
+ # upgrade docker-engine to specific version
18
+ - sudo apt-get -o Dpkg::Options::="--force-confnew" install -y docker-engine=${DOCKER_VERSION}
19
+
20
+ # reinstall docker-compose at specific version
21
+ - sudo rm /usr/local/bin/docker-compose
22
+ - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
23
+ - chmod +x docker-compose
24
+ - sudo mv docker-compose /usr/local/bin
25
+ - gem install bundler -v 1.11.2
26
+
27
+ script:
28
+ - docker version
29
+ - docker-compose version
30
+ - docker-compose up -d
31
+ - rake
32
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in soar_customer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 daneb
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # SoarCustomer
2
+ This is a Hetzner API provider for Customer data.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'soar_customer'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install soar_customer
19
+
20
+ ## Testing
21
+ If you desire to run docker locally without needing the Fake Service you, you can set your container IP here below and have the tests run against it.
22
+
23
+ ```bash
24
+ set -x TEST_HOST 192.168.99.100
25
+ export TEST_HOST=192.168.99.100
26
+ bundle
27
+ rake docker
28
+ ```
29
+
30
+ To run tests as per usual (which will startup a local sinatra service to be a fake service)
31
+
32
+ ```bash
33
+ bundle
34
+ rake
35
+ ```
36
+
37
+ ##### Travis CI requires Docker unfortunately for the Fake Service to run.
38
+ The fake service can be found in spec/mock_hapi/
39
+
40
+ ## Usage
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
45
+
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ $pid = 0
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task :default => :local
8
+
9
+ task :local do
10
+ begin
11
+ sh 'nohup rackup -p 9292 spec/mock_hapi/app.rb > sinatra.log 2>&1&'
12
+ puts "Firing up mock HAPI server"
13
+ $pid = `ps -ef | grep [a]pp.rb | grep 9292 | awk '{ print $2 }'`
14
+ puts "Pid found: #{$pid}"
15
+ sh 'rspec spec/'
16
+ ensure # Rake will abort when tests fail
17
+ puts "Tests done - shutting down mock HAPI server"
18
+ `kill #{$pid}`
19
+ end
20
+ end
21
+
22
+ task :docker => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "soar_customer"
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,9 @@
1
+ sinatra:
2
+ build: ./spec/mock_hapi
3
+ command: bundle exec rackup -o 0.0.0.0 -p 9292
4
+ volumes:
5
+ - ./spec/mock_hapi:/app
6
+ ports:
7
+ - "9292:9292"
8
+ expose:
9
+ - "9292"
@@ -0,0 +1,3 @@
1
+ module SoarCustomer
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,136 @@
1
+ require "soar_customer/version"
2
+ require 'soar_idm/directory_provider'
3
+
4
+ module SoarCustomer
5
+ # Custom Error Handling for Provider
6
+ class SoarHapiError < StandardError
7
+ end
8
+
9
+ # Directory Provider to HAPI for all things related to Customer Data
10
+ #
11
+ # @author Dane-Garrin Balia
12
+ class HapiProvider < SoarIdm::DirectoryProvider
13
+ # Passed in at initialization with connection details, username and password etc
14
+ attr_reader :configuration
15
+ # URL for HAPI
16
+ attr_reader :server_url
17
+ # Credentials is both the username and password
18
+ attr_reader :credentials
19
+ # Username for HAPI
20
+ attr_reader :username
21
+ # Password for HAPI
22
+ attr_reader :password
23
+ # Faraday initialized
24
+ attr_reader :connection
25
+
26
+ # Constructor
27
+ # @param configuration [Hash] contains the configuration details for connecting to HAPI
28
+ # @note Cannot bootstrap without these details
29
+ def initialize(configuration)
30
+ bootstrap(configuration)
31
+ end
32
+
33
+ # Used to authenticate against HAPI
34
+ # @return [Boolean] Returns true if authentication details are passed in
35
+ # @note Must be called first prior to any use
36
+ def authenticate(credentials)
37
+ @credentials = credentials
38
+ validate_credentials(credentials)
39
+ remember_credentials(credentials)
40
+ end
41
+
42
+ # Used to create a profile through HAPI
43
+ # @return [String] Returns body of message (JSON string) from HAPI response
44
+ # @note This is how you create a customer profile (not an account)
45
+ def create_profile(customer)
46
+ post('/profile', customer)
47
+ end
48
+
49
+ # Confirms if the class is instantiated with some form of configuration information
50
+ def bootstrapped?
51
+ not @configuration.nil?
52
+ end
53
+
54
+ protected
55
+
56
+ # Bootstrapping the application via configuration
57
+ def bootstrap(configuration)
58
+ @configuration = configuration
59
+ validate_configuration(@configuration)
60
+ remember_configuration(@configuration)
61
+ end
62
+
63
+ # Generic Method for Posting to HAPI
64
+ # @param endpoint [String] used for what resource to access on HAPI
65
+ # @param data [JSON] customer details
66
+ def post(endpoint, data)
67
+ raise SoarHapiError.new('Missing data') if data.nil? or data.empty?
68
+ setup_connection
69
+ response = submit_to_hapi(endpoint, data)
70
+ raise SoarHapiError.new('Endpoint Not Found') if response.status > 200
71
+ response.body
72
+ rescue Faraday::Error::ConnectionFailed => e
73
+ raise SoarHapiError.new('Connection failed to HAPI')
74
+ end
75
+
76
+ private
77
+
78
+ # Submit information to HAPI (only post)
79
+ #
80
+ # @note Raises exception to Method post(endpoint, data)
81
+ def submit_to_hapi(endpoint, data)
82
+ output = @connection.post do |req|
83
+ req.url endpoint
84
+ req.headers['Content-Type'] = 'application/json'
85
+ req.body = data
86
+ end
87
+ output
88
+ rescue Exception => e
89
+ raise
90
+ end
91
+
92
+ # Sets up the connection by instantiating Faraday
93
+ #
94
+ # @note Raises exception to Method post(endpoint, data)
95
+ def setup_connection
96
+ @connection = Faraday.new(:url => @server_url)
97
+ @connection.basic_auth(@username, @password)
98
+ rescue Exception => e
99
+ raise
100
+ end
101
+
102
+ # Validation for configuration hash
103
+ #
104
+ # @note Returns a SoarHapiError if validation fails
105
+ def validate_configuration(configuration)
106
+ raise SoarHapiError.new('No configuration') if configuration.nil?
107
+ raise SoarHapiError.new('Empty configuration') if configuration == {}
108
+ raise SoarHapiError.new('Invalid configuration') if not configuration.is_a?(Hash)
109
+ raise SoarHapiError.new('Missing server url') if configuration['server_url'].nil?
110
+ end
111
+
112
+ # Validation for credentials
113
+ #
114
+ # @note Returns a SoarHapiError if validation fails
115
+ def validate_credentials(credentials)
116
+ raise SoarHapiError.new('Missing credentials') if credentials.nil?
117
+ raise SoarHapiError.new('Empty credentials') if credentials == {}
118
+ raise SoarHapiError.new('Invalid credentials') if not credentials.is_a?(Hash)
119
+ raise SoarHapiError.new('Missing username') if credentials['username'].nil?
120
+ raise SoarHapiError.new('Missing password') if credentials['password'].nil?
121
+ end
122
+
123
+ # Ensures configuration is bound for re-use
124
+ def remember_configuration(configuration)
125
+ @configuration = configuration
126
+ @server_url = @configuration['server_url']
127
+ end
128
+
129
+ # Ensure credential is bound for re-use
130
+ def remember_credentials(credentials)
131
+ @credentials = credentials
132
+ @username = @credentials['username']
133
+ @password = @credentials['password']
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soar_customer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "soar_customer"
8
+ spec.version = SoarCustomer::VERSION
9
+ spec.authors = ["daneb"]
10
+ spec.email = ["dane.balia@hetzner.co.za"]
11
+
12
+ spec.summary = %q{Customer client library allowing easy access to customer data}
13
+ spec.description = %q{Customer client library allowing easy access to customer data}
14
+ #spec.homepage = "TODO: Put your gem's website or public repo URL here."
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
33
+ spec.add_development_dependency "rspec"
34
+ spec.add_development_dependency "byebug"
35
+ spec.add_development_dependency "sinatra"
36
+ spec.add_development_dependency "rack"
37
+ spec.add_development_dependency "yard"
38
+ spec.add_dependency "faraday", "~> 0.9"
39
+ spec.add_dependency "faraday_middleware", "~>0.10"
40
+ spec.add_dependency "soar_idm", "~> 0.0.2"
41
+ end
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soar_customer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - daneb
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sinatra
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rack
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: faraday
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.9'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.9'
139
+ - !ruby/object:Gem::Dependency
140
+ name: faraday_middleware
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.10'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.10'
153
+ - !ruby/object:Gem::Dependency
154
+ name: soar_idm
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.0.2
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.0.2
167
+ description: Customer client library allowing easy access to customer data
168
+ email:
169
+ - dane.balia@hetzner.co.za
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".travis.yml"
177
+ - Gemfile
178
+ - LICENSE.txt
179
+ - README.md
180
+ - Rakefile
181
+ - bin/console
182
+ - bin/setup
183
+ - docker-compose.yml
184
+ - lib/soar_customer.rb
185
+ - lib/soar_customer/version.rb
186
+ - soar_customer.gemspec
187
+ homepage:
188
+ licenses:
189
+ - MIT
190
+ metadata: {}
191
+ post_install_message:
192
+ rdoc_options: []
193
+ require_paths:
194
+ - lib
195
+ required_ruby_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ requirements: []
206
+ rubyforge_project:
207
+ rubygems_version: 2.4.5
208
+ signing_key:
209
+ specification_version: 4
210
+ summary: Customer client library allowing easy access to customer data
211
+ test_files: []
212
+ has_rdoc: