rhosync 2.0.0.beta9 → 2.0.0.beta10

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.
@@ -4,10 +4,11 @@ module RhosyncApi
4
4
  class << self
5
5
 
6
6
  def get_token(server,login,password)
7
- res = RestClient.post("#{server}/login",
8
- {:login => login, :password => password}.to_json, :content_type => :json)
9
- res.cookies['rhosync_session'] = CGI.escape(res.cookies['rhosync_session'])
10
- RestClient.post("#{server}/api/get_api_token",'',{:cookies => res.cookies})
7
+ # res = RestClient.post("#{server}/login",
8
+ # {:login => login, :password => password}.to_json, :content_type => :json)
9
+ # RestClient.post("#{server}/api/get_api_token",'',{:cookies => res.cookies})
10
+ cookie = login(server,login,password)
11
+ RestClient.post("#{server}/api/get_api_token",'',{:cookies => cookie})
11
12
  end
12
13
 
13
14
  def list_users(server,token)
@@ -100,5 +101,18 @@ module RhosyncApi
100
101
  {:api_token => token}.to_json, :content_type => :json).body)
101
102
  end
102
103
 
104
+ private
105
+
106
+ # TODO: Kill this code when rest-client properly
107
+ # escapes cookie strings on MAC/LINUX AND WINDOWS
108
+ def login(server,login,password)
109
+ uri = URI.parse(server)
110
+ http = Net::HTTP.new(uri.host,uri.port)
111
+ res,data = http.post( '/login',
112
+ {:login => login, :password => password}.to_json,
113
+ {'Content-Type' => 'application/json'} )
114
+ cookie = res.response['set-cookie'].split('; ')[0].split('=')
115
+ {cookie[0] => cookie[1]}
116
+ end
103
117
  end
104
118
  end
@@ -59,9 +59,9 @@ module Rhosync
59
59
 
60
60
  db.transaction do |database|
61
61
  # Create a table with columns specified by 'property' array in settings
62
- schema['property'].each do |column|
63
- create_table << "#{column.keys[0]} varchar default NULL"
64
- columns << column.keys[0]
62
+ schema['property'].each do |key,value|
63
+ create_table << "#{key} varchar default NULL"
64
+ columns << key
65
65
  qm << '?'
66
66
  end
67
67
  database.execute("CREATE TABLE #{source.name}(
@@ -80,13 +80,13 @@ module Rhosync
80
80
  end
81
81
 
82
82
  # Create indexes for specified columns in settings 'index'
83
- schema['index'].each do |index|
84
- database.execute("CREATE INDEX #{index.keys[0]} on #{source.name} (#{index.values[0]});")
83
+ schema['index'].each do |key,value|
84
+ database.execute("CREATE INDEX #{key} on #{source.name} (#{value});")
85
85
  end if schema['index']
86
86
 
87
87
  # Create unique indexes for specified columns in settings 'unique_index'
88
- schema['unique_index'].each do |index|
89
- database.execute("CREATE UNIQUE INDEX #{index.keys[0]} on #{source.name} (#{index.values[0]});")
88
+ schema['unique_index'].each do |key,value|
89
+ database.execute("CREATE UNIQUE INDEX #{key} on #{source.name} (#{value});")
90
90
  end if schema['unique_index']
91
91
  end
92
92
 
@@ -58,7 +58,7 @@ module Rhosync
58
58
  end
59
59
 
60
60
  def login
61
- if params[:login] == 'admin'
61
+ if params[:login] == 'rhoadmin'
62
62
  user = User.authenticate(params[:login], params[:password])
63
63
  elsif current_app and current_app.can_authenticate?
64
64
  user = current_app.authenticate(params[:login], params[:password], session)
@@ -10,6 +10,7 @@ module Rhosync
10
10
  field :poll_interval,:integer
11
11
  field :partition_type,:string
12
12
  field :sync_type,:string
13
+ field :belongs_to,:string
13
14
  field :queue,:string
14
15
  field :query_queue,:string
15
16
  field :cud_queue,:string
@@ -28,6 +29,7 @@ module Rhosync
28
29
  fields[:partition_type] ||= :user
29
30
  fields[:poll_interval] ||= 300
30
31
  fields[:sync_type] ||= :incremental
32
+ fields[:belongs_to] = fields[:belongs_to].to_json if fields[:belongs_to]
31
33
  fields[:schema] = fields[:schema].to_json if fields[:schema]
32
34
  end
33
35
 
@@ -48,8 +50,9 @@ module Rhosync
48
50
  return '' unless self.schema
49
51
  schema = JSON.parse(self.schema)
50
52
  blob_attribs = []
51
- schema['property'].each do |property|
52
- blob_attribs << property.keys[0] if property.values[0] == 'blob'
53
+ schema['property'].each do |key,value|
54
+ values = value ? value.split(',') : []
55
+ blob_attribs << key if values.include?('blob')
53
56
  end
54
57
  blob_attribs.sort.join(',')
55
58
  end
data/lib/rhosync/tasks.rb CHANGED
@@ -59,13 +59,13 @@ namespace :rhosync do
59
59
 
60
60
  task :config do
61
61
  $settings = load_settings(File.join('settings','settings.yml'))
62
- env = (ENV['RHO_ENV'] || :development).to_sym
63
- uri = URI.parse($settings[env][:syncserver])
62
+ $env = (ENV['RHO_ENV'] || :development).to_sym
63
+ uri = URI.parse($settings[$env][:syncserver])
64
64
  $url = "#{uri.scheme}://#{uri.host}"
65
65
  $url = "#{$url}:#{uri.port}" if uri.port && uri.port != 80
66
66
  $host = uri.host
67
67
  $port = uri.port
68
- $appname = $settings[env][:syncserver].split('/').last
68
+ $appname = $settings[$env][:syncserver].split('/').last
69
69
  $token_file = File.join(ENV['HOME'],'.rhosync_token')
70
70
  $token = File.read($token_file) if File.exist?($token_file)
71
71
  end
@@ -187,6 +187,18 @@ namespace :rhosync do
187
187
  task :web => :config do
188
188
  windows? ? sh("start #{$url}") : sh("open #{$url}")
189
189
  end
190
+
191
+ desc "Flush data store - WARNING: THIS REMOVES ALL DATA IN RHOSYNC"
192
+ task :flushdb => :config do
193
+ puts "*** WARNING: THIS WILL REMOVE ALL DATA FROM YOUR REDIS STORE ***"
194
+ confirm = ask "Are you sure (please answer yes/no)? "
195
+ if confirm == 'yes'
196
+ Redis.new.flushdb
197
+ puts "Database flushed..."
198
+ else
199
+ puts "Aborted..."
200
+ end
201
+ end
190
202
  end
191
203
 
192
204
  load File.join(File.dirname(__FILE__),'..','..','tasks','redis.rake')
@@ -1,3 +1,3 @@
1
1
  module Rhosync
2
- VERSION = '2.0.0.beta9'
2
+ VERSION = '2.0.0.beta10'
3
3
  end
data/lib/rhosync.rb CHANGED
@@ -105,8 +105,8 @@ module Rhosync
105
105
 
106
106
  # Generate admin user on first load
107
107
  def create_admin_user
108
- unless User.is_exist?('admin')
109
- admin = User.create({:login => 'admin', :admin => 1})
108
+ unless User.is_exist?('rhoadmin')
109
+ admin = User.create({:login => 'rhoadmin', :admin => 1})
110
110
  admin.password = ''
111
111
  admin.create_token
112
112
  end
@@ -22,7 +22,7 @@ describe "ApiHelper", :shared => true do
22
22
  :run => false,
23
23
  :secret => "secure!"
24
24
  )
25
- @api_token = User.load('admin').token_id
25
+ @api_token = User.load('rhoadmin').token_id
26
26
  end
27
27
 
28
28
  def app
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__),'api_helper')
3
3
  describe "RhosyncApiCreateUser" do
4
4
  it_should_behave_like "ApiHelper"
5
5
 
6
- it "should create user as admin" do
6
+ it "should create user" do
7
7
  params = {:api_token => @api_token,
8
8
  :attributes => {:login => 'testuser1', :password => 'testpass1'}}
9
9
  post "/api/create_user", params
@@ -4,12 +4,12 @@ describe "RhosyncApiGetApiToken" do
4
4
  it_should_behave_like "ApiHelper"
5
5
 
6
6
  it "should get token string" do
7
- post "/login", :login => 'admin',:password => ''
7
+ post "/login", :login => 'rhoadmin',:password => ''
8
8
  post "/api/get_api_token"
9
9
  last_response.body.should == @api_token
10
10
  end
11
11
 
12
- it "should fail to get token if user is not admin" do
12
+ it "should fail to get token if user is not rhoadmin" do
13
13
  post "/login", :login => @u_fields[:login],:password => 'testpass'
14
14
  post "/api/get_api_token"
15
15
  last_response.status.should == 422
@@ -17,6 +17,7 @@ describe "RhosyncApiGetSourceParams" do
17
17
  {"name"=>"poll_interval", "value"=>300, "type"=>"integer"},
18
18
  {"name"=>"partition_type", "value"=>"user", "type"=>"string"},
19
19
  {"name"=>"sync_type", "value"=>"incremental", "type"=>"string"},
20
+ {"name"=>"belongs_to", "type"=>"string", "value"=>nil},
20
21
  {"name"=>"queue", "value"=>nil, "type"=>"string"},
21
22
  {"name"=>"query_queue", "value"=>nil, "type"=>"string"},
22
23
  {"name"=>"cud_queue", "value"=>nil, "type"=>"string"},
@@ -3,20 +3,20 @@ require File.join(File.dirname(__FILE__),'api_helper')
3
3
  describe "RhosyncApiReset" do
4
4
  it_should_behave_like "ApiHelper"
5
5
 
6
- it "should reset and re-create admin user with bootstrap" do
6
+ it "should reset and re-create rhoadmin user with bootstrap" do
7
7
  Store.put_data('somedoc',{'foo'=>'bar'})
8
8
  post "/api/reset", :api_token => @api_token
9
9
  App.is_exist?(@test_app_name).should == true
10
10
  Store.get_data('somedoc').should == {}
11
- User.authenticate('admin','').should_not be_nil
11
+ User.authenticate('rhoadmin','').should_not be_nil
12
12
  end
13
13
 
14
- it "should reset and re-create admin user with initializer" do
14
+ it "should reset and re-create rhoadmin user with initializer" do
15
15
  Store.put_data('somedoc',{'foo'=>'bar'})
16
16
  post "/api/reset", :api_token => @api_token
17
17
  App.is_exist?(@test_app_name).should == true
18
18
  Store.get_data('somedoc').should == {}
19
- User.authenticate('admin','').should_not be_nil
19
+ User.authenticate('rhoadmin','').should_not be_nil
20
20
  load File.join(Rhosync.base_directory,@test_app_name+'.rb')
21
21
  end
22
22
  end
@@ -7,8 +7,8 @@ describe "RhosyncApiUpdateUser" do
7
7
  post "/api/update_user", :api_token => @api_token,
8
8
  :attributes => {:new_password => '123'}
9
9
  last_response.should be_ok
10
- user = User.authenticate('admin','123')
11
- user.login.should == 'admin'
10
+ user = User.authenticate('rhoadmin','123')
11
+ user.login.should == 'rhoadmin'
12
12
  user.admin.should == 1
13
13
  end
14
14
 
@@ -23,8 +23,8 @@ describe "RhosyncApiUpdateUser" do
23
23
  post "/api/update_user", :api_token => @api_token,
24
24
  :attributes => {:new_password => '123', :login => 'admin1'}
25
25
  last_response.should be_ok
26
- user = User.authenticate('admin','123')
27
- user.login.should == 'admin'
26
+ user = User.authenticate('rhoadmin','123')
27
+ user.login.should == 'rhoadmin'
28
28
  user.admin.should == 1
29
29
  User.is_exist?('admin1').should == false
30
30
  end
@@ -3,20 +3,24 @@
3
3
  poll_interval: 300
4
4
  SimpleAdapter:
5
5
  poll_interval: 600
6
- partition_type: app
6
+ partition_type: 'app'
7
7
  FixedSchemaAdapter:
8
8
  poll_interval: 300
9
+ sync_type: 'incremental'
10
+ belongs_to:
11
+ brand: 'Customer'
9
12
  schema:
10
13
  version: '1.0'
11
14
  property:
12
- - name: string
13
- - brand: string
14
- - price: string
15
- - image_url: blob
15
+ name: 'string'
16
+ brand: 'string'
17
+ price: 'string'
18
+ image_url_cropped: 'blob,overwrite'
19
+ image_url: 'blob'
16
20
  index:
17
- - by_name_brand: 'name,brand'
21
+ by_name_brand: 'name,brand'
18
22
  unique_index:
19
- - by_price: 'price'
23
+ by_price: 'price'
20
24
 
21
25
  :development:
22
26
  :licensefile: settings/license.key
@@ -43,8 +43,8 @@ describe "Server" do
43
43
  last_response.should be_ok
44
44
  end
45
45
 
46
- it "should login as admin user" do
47
- post "/login", "login" => 'admin', "password" => ''
46
+ it "should login as rhoadmin user" do
47
+ post "/login", "login" => 'rhoadmin', "password" => ''
48
48
  last_response.should be_ok
49
49
  end
50
50
 
@@ -117,17 +117,23 @@ describe "Server" do
117
117
  before(:each) do
118
118
  do_post "/application/clientlogin", "login" => @u.login, "password" => 'testpass'
119
119
  @source_config = {
120
- "sources"=> {
121
- "FixedSchemaAdapter"=>
122
- {"schema"=>{"property"=>[{"name"=>"string"},
123
- {"brand"=>"string"}, {"price"=>"string"},
124
- {"image_url"=>"blob"}], "version"=>"1.0",
125
- "unique_index"=>[{"by_price"=>"price"}],
126
- "index"=>[{"by_name_brand"=>"name,brand"}]},
127
- "poll_interval"=>300},
128
- "SampleAdapter"=>{"poll_interval"=>300},
129
- "SimpleAdapter"=>{"partition_type"=>"app",
130
- "poll_interval"=>600}}
120
+ "sources"=>
121
+ {"FixedSchemaAdapter"=>
122
+ {"schema"=>
123
+ {"property"=>
124
+ {"image_url_cropped"=>"blob,overwrite",
125
+ "price"=>"string",
126
+ "brand"=>"string",
127
+ "name"=>"string",
128
+ "image_url"=>"blob"},
129
+ "unique_index"=>{"by_price"=>"price"},
130
+ "version"=>"1.0",
131
+ "index"=>{"by_name_brand"=>"name,brand"}},
132
+ "poll_interval"=>300,
133
+ "sync_type"=>"incremental",
134
+ "belongs_to"=>{"brand"=>"Customer"}},
135
+ "SampleAdapter"=>{"poll_interval"=>300},
136
+ "SimpleAdapter"=>{"partition_type"=>"app", "poll_interval"=>600}}
131
137
  }
132
138
  end
133
139
 
data/spec/spec_helper.rb CHANGED
@@ -129,8 +129,8 @@ module TestHelpers
129
129
  if s.schema
130
130
  schema = JSON.parse(s.schema)
131
131
  columns = ['object']
132
- schema['property'].each do |column|
133
- columns << column.keys[0]
132
+ schema['property'].each do |key,value|
133
+ columns << key
134
134
  end
135
135
  db.execute("select #{columns.join(',')} from #{s.name}") do |row|
136
136
  obj = data[row[0]]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhosync
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1848230043
4
+ hash: -1967355490
5
5
  prerelease: true
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
9
  - 0
10
- - beta9
11
- version: 2.0.0.beta9
10
+ - beta10
11
+ version: 2.0.0.beta10
12
12
  platform: ruby
13
13
  authors:
14
14
  - Rhomobile
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-05-28 00:00:00 -07:00
19
+ date: 2010-06-02 00:00:00 -07:00
20
20
  default_executable: rhosync
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency