restpack_core_service 0.0.4 → 0.0.5
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 +4 -4
- data/Rakefile +0 -2
- data/db/migrate/20130807103945_create_applications.rb +2 -1
- data/db/migrate/20130808135549_create_hosts.rb +16 -0
- data/db/migrate/{20130807104142_create_domains.rb → 20130808135613_create_domains.rb} +2 -2
- data/lib/restpack_core_service.rb +5 -0
- data/lib/restpack_core_service/models/application.rb +5 -1
- data/lib/restpack_core_service/models/domain.rb +4 -4
- data/lib/restpack_core_service/models/host.rb +17 -0
- data/lib/restpack_core_service/serializers/user_serializer.rb +11 -0
- data/lib/restpack_core_service/services.rb +5 -0
- data/lib/restpack_core_service/services/application/verify_api_token.rb +17 -0
- data/lib/restpack_core_service/tasks/db.rake +1 -1
- data/lib/restpack_core_service/version.rb +1 -1
- data/restpack_core_service.gemspec +4 -3
- data/spec/factories/application_factory.rb +6 -0
- data/spec/factories/domain_factory.rb +6 -0
- data/spec/factories/host_factory.rb +6 -0
- data/spec/models/application_spec.rb +11 -1
- data/spec/models/domain_spec.rb +3 -3
- data/spec/models/host_spec.rb +22 -0
- data/spec/services/application/verify_api_token_spec.rb +49 -0
- data/spec/spec_helper.rb +6 -6
- metadata +44 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2bee426ae4a23da2add15e79d02eeb7c4c0cc0a
|
4
|
+
data.tar.gz: f68631c3b3ce233431fa1e0691abce208c946e22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96ed4b9255544b9333a26498e0bfe5065056b53cff908637e6b7d662d59dce04b7bf2e9f4dae72cf4a786d9ed1ed821114afe6fc726b01fb843e0f2079cabd4a
|
7
|
+
data.tar.gz: 508c2670a7be016519b23039a89ee842ebd5faa16c5dec65e99e5ba2f944efe6e058aed768421aa3d163c9b4a0df724485fae375b22daf5da60a34571edf0491
|
data/Rakefile
CHANGED
@@ -5,7 +5,8 @@ class CreateApplications < ActiveRecord::Migration
|
|
5
5
|
|
6
6
|
def change
|
7
7
|
create_table table_name do |t|
|
8
|
-
t.string
|
8
|
+
t.string :name, :null => false, :limit => 256
|
9
|
+
t.string :api_token, :null => false, :limit => 512
|
9
10
|
t.integer :account_id, :null => false
|
10
11
|
|
11
12
|
t.timestamps
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateHosts < ActiveRecord::Migration
|
2
|
+
def table_name
|
3
|
+
RestPack::Core::Service.config.prefix_db_table(:hosts)
|
4
|
+
end
|
5
|
+
|
6
|
+
def change
|
7
|
+
create_table table_name do |t|
|
8
|
+
t.string :name, :null => false, :limit => 256
|
9
|
+
t.integer :application_id, :null => false
|
10
|
+
t.string :session_secret, :null => false, :limit => 128
|
11
|
+
t.json :oauth_providers, :null => false
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -5,8 +5,8 @@ class CreateDomains < ActiveRecord::Migration
|
|
5
5
|
|
6
6
|
def change
|
7
7
|
create_table table_name do |t|
|
8
|
-
t.string :
|
9
|
-
t.integer :
|
8
|
+
t.string :identifier, :null => false, :limit => 512
|
9
|
+
t.integer :host_id, :null => false
|
10
10
|
|
11
11
|
t.timestamps
|
12
12
|
end
|
@@ -6,7 +6,12 @@ require "restpack_core_service/configuration"
|
|
6
6
|
|
7
7
|
require "restpack_core_service/models/base"
|
8
8
|
require "restpack_core_service/models/application"
|
9
|
+
require "restpack_core_service/models/host"
|
9
10
|
require "restpack_core_service/models/domain"
|
10
11
|
|
12
|
+
require "restpack_core_service/services"
|
11
13
|
require "restpack_core_service/tasks"
|
12
14
|
|
15
|
+
Models = RestPack::Core::Service::Models
|
16
|
+
Commands = RestPack::Core::Service::Commands
|
17
|
+
# Serializers = RestPack::Core::Service::Serializers
|
@@ -6,6 +6,10 @@ module RestPack::Core::Service::Models
|
|
6
6
|
validates_presence_of :name, :account_id
|
7
7
|
validates :name, :length => { :maximum => 256 }
|
8
8
|
|
9
|
-
has_many :
|
9
|
+
has_many :hosts
|
10
|
+
|
11
|
+
before_save -> {
|
12
|
+
self.api_token ||= SecureRandom.hex(50)[0..31]
|
13
|
+
}
|
10
14
|
end
|
11
15
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module RestPack::Core::Service::Models
|
2
2
|
class Domain < Base
|
3
3
|
restpack_table_name :domains
|
4
|
-
attr_accessible :
|
4
|
+
attr_accessible :identifier, :host
|
5
5
|
|
6
|
-
validates_presence_of :
|
7
|
-
validates :
|
6
|
+
validates_presence_of :identifier
|
7
|
+
validates :identifier, :length => { :maximum => 512 }
|
8
8
|
|
9
|
-
belongs_to :
|
9
|
+
belongs_to :host
|
10
10
|
end
|
11
11
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RestPack::Core::Service::Models
|
2
|
+
class Host < Base
|
3
|
+
restpack_table_name :hosts
|
4
|
+
attr_accessible :name, :application_id, :session_secret, :oauth_providers
|
5
|
+
|
6
|
+
validates_presence_of :name, :application_id
|
7
|
+
validates :name, :length => { :maximum => 256 }
|
8
|
+
|
9
|
+
has_many :domains
|
10
|
+
belongs_to :application
|
11
|
+
|
12
|
+
before_save -> {
|
13
|
+
self.oauth_providers ||= {}
|
14
|
+
self.session_secret ||= SecureRandom.hex(16)
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module RestPack::Core::Service::Serializers
|
2
|
+
class UserSerializer
|
3
|
+
include RestPack::Serializer
|
4
|
+
|
5
|
+
self.model_class = RestPack::User::Service::Models::User
|
6
|
+
self.key = :users
|
7
|
+
|
8
|
+
# attributes :id, :application_id, :user_id, :title, :content, :latitude, :longitude,
|
9
|
+
# :tags, :access, :data, :href, :updated_at, :created_at
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RestPack::Core::Service::Commands::Application
|
2
|
+
class VerifyApiToken < RestPack::Service::Command
|
3
|
+
required do
|
4
|
+
integer :id
|
5
|
+
string :api_token
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
application = Models::Application.find_by_id_and_api_token(
|
10
|
+
inputs[:id],
|
11
|
+
inputs[:api_token]
|
12
|
+
)
|
13
|
+
|
14
|
+
status :forbidden if !application
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -33,7 +33,7 @@ namespace :restpack do
|
|
33
33
|
task :configuration do
|
34
34
|
p "RestPack::Core::Service Configuration"
|
35
35
|
p "--------------------------------"
|
36
|
-
p "
|
36
|
+
p "db_table_prefix: #{RestPack::Core::Service.config.db_table_prefix}"
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "restpack_service"
|
22
|
-
spec.add_dependency "restpack_serializer"
|
23
|
-
spec.add_dependency "restpack_gem"
|
21
|
+
spec.add_dependency "restpack_service"
|
22
|
+
spec.add_dependency "restpack_serializer"
|
23
|
+
spec.add_dependency "restpack_gem"
|
24
24
|
spec.add_dependency "sinatra", "~> 1.4.3"
|
25
25
|
spec.add_dependency "pg", "~> 0.16"
|
26
26
|
|
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "rspec"
|
31
31
|
spec.add_development_dependency "bump"
|
32
32
|
spec.add_development_dependency "shoulda-matchers", "~> 1.4.2"
|
33
|
+
spec.add_development_dependency "factory_girl", "~> 4.0"
|
33
34
|
end
|
@@ -2,6 +2,16 @@ describe RestPack::Core::Service::Models::Application do
|
|
2
2
|
it { should validate_presence_of(:name) }
|
3
3
|
it { should validate_presence_of(:account_id) }
|
4
4
|
it { should ensure_length_of(:name).is_at_most(256) }
|
5
|
-
it { should have_many(:
|
5
|
+
it { should have_many(:hosts) }
|
6
6
|
it { subject.class.table_name.should == 'restpack_applications' }
|
7
|
+
|
8
|
+
context "default values" do
|
9
|
+
it "has a random api_token" do
|
10
|
+
app1 = create(:application)
|
11
|
+
app2 = create(:application)
|
12
|
+
|
13
|
+
app1.api_token.length.should == 32
|
14
|
+
app1.api_token.should_not == app2.api_token
|
15
|
+
end
|
16
|
+
end
|
7
17
|
end
|
data/spec/models/domain_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
describe RestPack::Core::Service::Models::Domain do
|
2
|
-
it { should validate_presence_of(:
|
3
|
-
it { should ensure_length_of(:
|
4
|
-
it { should belong_to(:
|
2
|
+
it { should validate_presence_of(:identifier) }
|
3
|
+
it { should ensure_length_of(:identifier).is_at_most(512) }
|
4
|
+
it { should belong_to(:host) }
|
5
5
|
it { subject.class.table_name.should == 'restpack_domains' }
|
6
6
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
describe RestPack::Core::Service::Models::Host do
|
2
|
+
it { should validate_presence_of(:name) }
|
3
|
+
it { should validate_presence_of(:application_id) }
|
4
|
+
it { should ensure_length_of(:name).is_at_most(256) }
|
5
|
+
it { should belong_to(:application) }
|
6
|
+
it { should have_many(:domains) }
|
7
|
+
it { subject.class.table_name.should == 'restpack_hosts' }
|
8
|
+
|
9
|
+
context "default values" do
|
10
|
+
it "has a random session_secret" do
|
11
|
+
host1 = create(:host)
|
12
|
+
host2 = create(:host)
|
13
|
+
|
14
|
+
host1.session_secret.should_not == nil
|
15
|
+
host1.session_secret.should_not == host2.session_secret
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has empty oauth_providers as default" do
|
19
|
+
create(:host).oauth_providers.should == {}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe Commands::Application::VerifyApiToken do
|
4
|
+
is_required :id, :api_token
|
5
|
+
|
6
|
+
let(:response) { subject.class.run(params) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
@application = create(:application)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with valid params' do
|
13
|
+
let(:params) { {
|
14
|
+
id: @application.id,
|
15
|
+
api_token: @application.api_token
|
16
|
+
} }
|
17
|
+
|
18
|
+
it 'is valid' do
|
19
|
+
response.success?.should == true
|
20
|
+
response.result.should == {}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with invalid :id' do
|
25
|
+
let(:params) { {
|
26
|
+
id: 142857,
|
27
|
+
api_token: @application.api_token
|
28
|
+
}}
|
29
|
+
|
30
|
+
it 'is forbidden' do
|
31
|
+
response.success?.should == false
|
32
|
+
response.result.should == {}
|
33
|
+
response.status.should == :forbidden
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with invalid :api_token' do
|
38
|
+
let(:params) { {
|
39
|
+
id: @application.id,
|
40
|
+
api_token: 'invalid_token'
|
41
|
+
}}
|
42
|
+
|
43
|
+
it 'is forbidden' do
|
44
|
+
response.success?.should == false
|
45
|
+
response.result.should == {}
|
46
|
+
response.status.should == :forbidden
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require '
|
2
|
-
require 'rspec'
|
3
|
-
require 'database_cleaner'
|
4
|
-
require 'yaml'
|
5
|
-
require 'shoulda-matchers'
|
1
|
+
require 'restpack_service/support/spec_helper'
|
6
2
|
require 'restpack_core_service'
|
7
3
|
|
8
4
|
config = YAML.load_file('./config/database.yml')
|
9
5
|
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'] || config['test'])
|
10
6
|
|
11
|
-
migrations_path = File.dirname(__FILE__) + "/../db/
|
7
|
+
migrations_path = File.dirname(__FILE__) + "/../db/migratore"
|
12
8
|
migrator = ActiveRecord::Migrator.new(:up, migrations_path)
|
13
9
|
migrator.migrate
|
14
10
|
|
11
|
+
FactoryGirl.find_definitions
|
12
|
+
|
15
13
|
DatabaseCleaner.strategy = :transaction
|
16
14
|
|
17
15
|
RSpec.configure do |config|
|
16
|
+
config.include FactoryGirl::Syntax::Methods
|
17
|
+
|
18
18
|
config.before(:each) do
|
19
19
|
DatabaseCleaner.start
|
20
20
|
end
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restpack_core_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Joyce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: restpack_service
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: restpack_serializer
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: restpack_gem
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0
|
47
|
+
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sinatra
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - ~>
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: 1.4.2
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: factory_girl
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '4.0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ~>
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '4.0'
|
167
181
|
description: Applications, Domains and Configurations service
|
168
182
|
email:
|
169
183
|
- gavinjoyce@gmail.com
|
@@ -179,19 +193,29 @@ files:
|
|
179
193
|
- Rakefile
|
180
194
|
- config/database.yml
|
181
195
|
- db/migrate/20130807103945_create_applications.rb
|
182
|
-
- db/migrate/
|
196
|
+
- db/migrate/20130808135549_create_hosts.rb
|
197
|
+
- db/migrate/20130808135613_create_domains.rb
|
183
198
|
- lib/restpack_core_service.rb
|
184
199
|
- lib/restpack_core_service/configuration.rb
|
185
200
|
- lib/restpack_core_service/models/application.rb
|
186
201
|
- lib/restpack_core_service/models/base.rb
|
187
202
|
- lib/restpack_core_service/models/domain.rb
|
203
|
+
- lib/restpack_core_service/models/host.rb
|
204
|
+
- lib/restpack_core_service/serializers/user_serializer.rb
|
205
|
+
- lib/restpack_core_service/services.rb
|
206
|
+
- lib/restpack_core_service/services/application/verify_api_token.rb
|
188
207
|
- lib/restpack_core_service/tasks.rb
|
189
208
|
- lib/restpack_core_service/tasks/db.rake
|
190
209
|
- lib/restpack_core_service/version.rb
|
191
210
|
- restpack_core_service.gemspec
|
192
211
|
- spec/configuration_spec.rb
|
212
|
+
- spec/factories/application_factory.rb
|
213
|
+
- spec/factories/domain_factory.rb
|
214
|
+
- spec/factories/host_factory.rb
|
193
215
|
- spec/models/application_spec.rb
|
194
216
|
- spec/models/domain_spec.rb
|
217
|
+
- spec/models/host_spec.rb
|
218
|
+
- spec/services/application/verify_api_token_spec.rb
|
195
219
|
- spec/spec_helper.rb
|
196
220
|
homepage: https://github.com/RestPack
|
197
221
|
licenses:
|
@@ -219,6 +243,11 @@ specification_version: 4
|
|
219
243
|
summary: Applications, Domains and Configurations
|
220
244
|
test_files:
|
221
245
|
- spec/configuration_spec.rb
|
246
|
+
- spec/factories/application_factory.rb
|
247
|
+
- spec/factories/domain_factory.rb
|
248
|
+
- spec/factories/host_factory.rb
|
222
249
|
- spec/models/application_spec.rb
|
223
250
|
- spec/models/domain_spec.rb
|
251
|
+
- spec/models/host_spec.rb
|
252
|
+
- spec/services/application/verify_api_token_spec.rb
|
224
253
|
- spec/spec_helper.rb
|