micro_service-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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/generators/micro_service/client/active_record_generator.rb +24 -0
- data/lib/generators/micro_service/client/client_generator.rb +11 -0
- data/lib/generators/micro_service/client/next_migration_version.rb +16 -0
- data/lib/generators/micro_service/client/templates/migration_0.0.1.rb +17 -0
- data/lib/micro_service/client.rb +19 -0
- data/lib/micro_service/client/class_methods.rb +24 -0
- data/lib/micro_service/client/compatibility.rb +25 -0
- data/lib/micro_service/client/configuration.rb +11 -0
- data/lib/micro_service/client/exceptions.rb +9 -0
- data/lib/micro_service/client/instance_methods.rb +42 -0
- data/lib/micro_service/client/version.rb +7 -0
- data/micro_service-active_record-client.gemspec +39 -0
- metadata +209 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5bcdb9cd3b92f77bfbaf9b9251898a968bcd6533
|
4
|
+
data.tar.gz: 6d48f2bdd617f74b70dfd4be887c55472aeac731
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 60229e94737932f8f44fc6cf3a422cb002701e5ad0960e5aa230b3e0d3fd5cd9b884c4a110fef86d3bfa0341fe42936e130a4516a6212042868153b613c341b6
|
7
|
+
data.tar.gz: eac2349acfa93270995c0923c609887d80e28bb8357b1a8eb641e7b383c0c3f2d88ebe8ccc7670f913310385d30825a60645df01118dac4cbf8af8108aa8cfd6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
[](http://badge.fury.io/rb/micro_service-client)
|
2
|
+
[](https://travis-ci.org/butchmarshall/ruby-micro_service-client)
|
3
|
+
|
4
|
+
# MicroService::Client
|
5
|
+
|
6
|
+
ActiveRecord MicroService implementation that persists the details of client installations.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'micro_service-client'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install micro_service-client
|
23
|
+
|
24
|
+
then run
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
rails generate micro_service:client:active_record
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
To the ActiveRecord model:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
MicroService::Client.new(...)
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/butchmarshall/ruby-micro_service-client.
|
41
|
+
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
46
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "micro_service/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,24 @@
|
|
1
|
+
require "generators/micro_service/client/client_generator"
|
2
|
+
require "generators/micro_service/client/next_migration_version"
|
3
|
+
require "rails/generators/migration"
|
4
|
+
require "rails/generators/active_record"
|
5
|
+
|
6
|
+
# Extend the HasDynamicColumnsGenerator so that it creates an AR migration
|
7
|
+
module MicroService
|
8
|
+
class Client < ::ActiveRecord::Base
|
9
|
+
class ActiveRecordGenerator < ::MicroService::Client::Generator
|
10
|
+
include Rails::Generators::Migration
|
11
|
+
extend NextMigrationVersion
|
12
|
+
|
13
|
+
source_paths << File.join(File.dirname(__FILE__), "templates")
|
14
|
+
|
15
|
+
def create_migration_file
|
16
|
+
migration_template "migration_0.0.1.rb", "db/migrate/add_micro_service_client_0_0_1_migration.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.next_migration_number(dirname)
|
20
|
+
::ActiveRecord::Generators::Base.next_migration_number dirname
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
require 'micro_service/client/compatibility'
|
3
|
+
|
4
|
+
module MicroService
|
5
|
+
class Client < ::ActiveRecord::Base
|
6
|
+
class Generator < Rails::Generators::Base
|
7
|
+
source_paths << File.join(File.dirname(__FILE__), 'templates')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module MicroService
|
2
|
+
class Client < ::ActiveRecord::Base
|
3
|
+
module NextMigrationVersion
|
4
|
+
# while methods have moved around this has been the implementation
|
5
|
+
# since ActiveRecord 3.0
|
6
|
+
def next_migration_number(dirname)
|
7
|
+
next_migration_number = current_migration_number(dirname) + 1
|
8
|
+
if ::ActiveRecord::Base.timestamped_migrations
|
9
|
+
[Time.now.utc.strftime("%Y%m%d%H%M%S"), format("%.14d", next_migration_number)].max
|
10
|
+
else
|
11
|
+
format("%.3d", next_migration_number)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class AddMicroServiceClient001Migration < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :micro_service_clients do |t|
|
4
|
+
t.string :secret # Secret to be used
|
5
|
+
t.string :install_url # POST here when install successful
|
6
|
+
t.string :uninstall_url # POST here when uninstall successful
|
7
|
+
t.integer :attempt, default: 0
|
8
|
+
t.boolean :uninstalled, default: 0
|
9
|
+
|
10
|
+
t.timestamps null: false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
drop_table :micro_service_clients
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/dependencies"
|
3
|
+
require "active_record"
|
4
|
+
|
5
|
+
require "micro_service/client/version"
|
6
|
+
require "micro_service/client/compatibility"
|
7
|
+
require "micro_service/client/configuration"
|
8
|
+
require "micro_service/client/class_methods"
|
9
|
+
require "micro_service/client/instance_methods"
|
10
|
+
|
11
|
+
require "micro_service/client/exceptions"
|
12
|
+
|
13
|
+
module MicroService
|
14
|
+
class Client < ::ActiveRecord::Base
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
MicroService::Client.send :include, MicroService::Client::InstanceMethods
|
19
|
+
MicroService::Client.send :extend, MicroService::Client::ClassMethods
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "validate_url"
|
2
|
+
|
3
|
+
module MicroService
|
4
|
+
class Client < ::ActiveRecord::Base
|
5
|
+
module ClassMethods
|
6
|
+
def self.extended(base)
|
7
|
+
base.send(:attr_accessor, :configuration)
|
8
|
+
base.validates :secret, :presence => true
|
9
|
+
base.validates :install_url, :presence => true, url: true
|
10
|
+
base.after_initialize :initialize_secret
|
11
|
+
base.after_create :after_create_notify_client_service
|
12
|
+
end
|
13
|
+
|
14
|
+
def configuration
|
15
|
+
@configuration
|
16
|
+
end
|
17
|
+
|
18
|
+
def configure
|
19
|
+
@configuration ||= MicroService::Client::Configuration.new
|
20
|
+
yield(@configuration)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'micro_service/client/version'
|
2
|
+
|
3
|
+
module MicroService
|
4
|
+
class Client < ::ActiveRecord::Base
|
5
|
+
module Compatibility
|
6
|
+
if ActiveSupport::VERSION::MAJOR >= 4
|
7
|
+
require 'active_support/proxy_object'
|
8
|
+
def self.executable_prefix
|
9
|
+
'bin'
|
10
|
+
end
|
11
|
+
def self.proxy_object_class
|
12
|
+
ActiveSupport::ProxyObject
|
13
|
+
end
|
14
|
+
else
|
15
|
+
require 'active_support/basic_object'
|
16
|
+
def self.executable_prefix
|
17
|
+
'script'
|
18
|
+
end
|
19
|
+
def self.proxy_object_class
|
20
|
+
ActiveSupport::BasicObject
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module MicroService
|
2
|
+
class Client < ::ActiveRecord::Base
|
3
|
+
module InstanceMethods
|
4
|
+
def self.included(base)
|
5
|
+
base.table_name = "micro_service_clients"
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
def initialize_secret
|
10
|
+
require 'securerandom'
|
11
|
+
self.secret ||= "#{SecureRandom.base64(24)}.s"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Notifies the client service the install was successful
|
15
|
+
def after_create_notify_client_service
|
16
|
+
require "open-uri"
|
17
|
+
require "net/http"
|
18
|
+
require "openssl"
|
19
|
+
|
20
|
+
uri = URI.parse(self.install_url)
|
21
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
22
|
+
http.use_ssl = true if uri.scheme == "https"
|
23
|
+
|
24
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
25
|
+
request["Content-Type"] = "application/json"
|
26
|
+
request.body = {
|
27
|
+
client_id: self.id,
|
28
|
+
secret: self.secret,
|
29
|
+
url: ((MicroService::Client.configuration)? MicroService::Client.configuration.url : ""),
|
30
|
+
timestamp: self.created_at.to_i,
|
31
|
+
}.to_json
|
32
|
+
|
33
|
+
response = http.request(request)
|
34
|
+
|
35
|
+
# Failed to register with external service
|
36
|
+
if !response.kind_of? Net::HTTPSuccess
|
37
|
+
raise ::MicroService::Client::InstallError
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'micro_service/client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "micro_service-client"
|
8
|
+
spec.version = MicroService::Client::VERSION
|
9
|
+
spec.authors = ["Butch Marshall"]
|
10
|
+
spec.email = ["butch.a.marshall@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "ActiveRecord implementation to store MicroService Clients"
|
13
|
+
spec.description = "Stores MicroService Clients so that installs can be tracked"
|
14
|
+
spec.homepage = "https://github.com/butchmarshall/micro_service-client"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activerecord", [">= 3.0", "<= 5.0"]
|
22
|
+
spec.add_dependency "validate_url"
|
23
|
+
|
24
|
+
if RUBY_PLATFORM == 'java'
|
25
|
+
spec.add_development_dependency "jdbc-sqlite3", "> 0"
|
26
|
+
spec.add_development_dependency "activerecord-jdbcsqlite3-adapter", "> 0"
|
27
|
+
else
|
28
|
+
spec.add_development_dependency "sqlite3", "> 0"
|
29
|
+
end
|
30
|
+
|
31
|
+
spec.add_development_dependency "bigdecimal", "~> 1.1"
|
32
|
+
spec.add_development_dependency "database_cleaner"
|
33
|
+
spec.add_development_dependency "factory_girl", "> 4.0"
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
|
37
|
+
spec.add_development_dependency "rspec"
|
38
|
+
spec.add_development_dependency "webmock"
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: micro_service-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Butch Marshall
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
- - "<="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- - "<="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: validate_url
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: sqlite3
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: bigdecimal
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.1'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.1'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: database_cleaner
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: factory_girl
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '4.0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '4.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: bundler
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.7'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '1.7'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: rake
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '10.0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '10.0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: rspec
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: webmock
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
description: Stores MicroService Clients so that installs can be tracked
|
160
|
+
email:
|
161
|
+
- butch.a.marshall@gmail.com
|
162
|
+
executables: []
|
163
|
+
extensions: []
|
164
|
+
extra_rdoc_files: []
|
165
|
+
files:
|
166
|
+
- ".gitignore"
|
167
|
+
- ".rspec"
|
168
|
+
- ".travis.yml"
|
169
|
+
- Gemfile
|
170
|
+
- README.md
|
171
|
+
- Rakefile
|
172
|
+
- bin/console
|
173
|
+
- bin/setup
|
174
|
+
- lib/generators/micro_service/client/active_record_generator.rb
|
175
|
+
- lib/generators/micro_service/client/client_generator.rb
|
176
|
+
- lib/generators/micro_service/client/next_migration_version.rb
|
177
|
+
- lib/generators/micro_service/client/templates/migration_0.0.1.rb
|
178
|
+
- lib/micro_service/client.rb
|
179
|
+
- lib/micro_service/client/class_methods.rb
|
180
|
+
- lib/micro_service/client/compatibility.rb
|
181
|
+
- lib/micro_service/client/configuration.rb
|
182
|
+
- lib/micro_service/client/exceptions.rb
|
183
|
+
- lib/micro_service/client/instance_methods.rb
|
184
|
+
- lib/micro_service/client/version.rb
|
185
|
+
- micro_service-active_record-client.gemspec
|
186
|
+
homepage: https://github.com/butchmarshall/micro_service-client
|
187
|
+
licenses: []
|
188
|
+
metadata: {}
|
189
|
+
post_install_message:
|
190
|
+
rdoc_options: []
|
191
|
+
require_paths:
|
192
|
+
- lib
|
193
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
194
|
+
requirements:
|
195
|
+
- - ">="
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - ">="
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0'
|
203
|
+
requirements: []
|
204
|
+
rubyforge_project:
|
205
|
+
rubygems_version: 2.4.6
|
206
|
+
signing_key:
|
207
|
+
specification_version: 4
|
208
|
+
summary: ActiveRecord implementation to store MicroService Clients
|
209
|
+
test_files: []
|