Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 1d75bf4a911e1d97f68f711b3f3e9f5f672b1fa1 @larsburgess larsburgess committed Dec 22, 2011
Showing with 500 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +33 −0 Gemfile
  3. +93 −0 Gemfile.lock
  4. +22 −0 Rakefile
  5. +20 −0 application.rb
  6. +43 −0 config.ru
  7. +1 −0 settings/license.key
  8. +21 −0 settings/settings.yml
  9. +12 −0 sources/blob_test.rb
  10. +12 −0 sources/blob_test_s.rb
  11. +12 −0 sources/image.rb
  12. +36 −0 sources/image_base.rb
  13. +166 −0 sources/metadata.rb
  14. +25 −0 spec/sources/blob_test_spec.rb
@@ -0,0 +1,4 @@
+coverage
+log
+
+*.rdb
33 Gemfile
@@ -0,0 +1,33 @@
+source 'http://rubygems.org'
+
+gem 'rhoconnect', '3.0.6'
+gem 'aws-s3'
+
+# Helps with some of the limitations of green threads, not needed in ruby 1.9.x
+gem 'SystemTimer', '~> 1.2.3', :platforms => :ruby_18
+
+platforms :jruby do
+ gem 'jdbc-sqlite3', ">= 3.7.2"
+ gem 'dbi', ">= 0.4.5"
+ gem 'dbd-jdbc', ">= 0.1.4"
+ gem 'jruby-openssl', ">= 0.7.4"
+ gem 'warbler'
+end
+
+gem 'sqlite3', ">= 1.3.3", :platforms => [:ruby, :mswin, :mingw]
+
+# For jruby trinidad JRuby web server is used
+gem 'trinidad', :platforms => :jruby
+
+group :development do
+ # By default to run application thin web server is used
+ gem 'thin', :platforms => [:ruby, :mswin, :mingw]
+ gem 'rhomobile-debug', ">= 1.0.2"
+end
+
+group :test do
+ gem 'rack-test', '>= 0.5.3', :require => "rack/test"
+ gem 'rspec', '~> 2.6.0'
+ gem 'rcov', '>= 0.9.8'
+ gem 'rhomobile-debug', ">= 1.0.2"
+end
@@ -0,0 +1,93 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ SystemTimer (1.2.3)
+ aws-s3 (0.6.2)
+ builder
+ mime-types
+ xml-simple
+ builder (3.0.0)
+ daemons (1.1.4)
+ diff-lcs (1.1.3)
+ eventmachine (0.12.10)
+ extlib (0.9.15)
+ highline (1.6.5)
+ json (1.5.4)
+ mime-types (1.17.2)
+ multi_json (1.0.3)
+ rack (1.3.5)
+ rack-protection (1.1.4)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rake (0.9.2.2)
+ rcov (0.9.11)
+ redis (2.2.2)
+ redis-namespace (1.0.3)
+ redis (< 3.0.0)
+ resque (1.19.0)
+ multi_json (~> 1.0)
+ redis-namespace (~> 1.0.2)
+ sinatra (>= 0.9.2)
+ vegas (~> 0.1.2)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ rhoconnect (3.0.6)
+ bundler (~> 1.0)
+ json (~> 1.5.0)
+ rake (~> 0.9.2)
+ redis (>= 2.2.0)
+ resque (~> 1.19.0)
+ rest-client (~> 1.6.1)
+ rubyzip (~> 0.9.4)
+ sinatra (~> 1.3)
+ templater (~> 1.0.0)
+ uuidtools (>= 2.1.1)
+ rhomobile-debug (1.0.5)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+ rubyzip (0.9.4)
+ sinatra (1.3.1)
+ rack (~> 1.3, >= 1.3.4)
+ rack-protection (~> 1.1, >= 1.1.2)
+ tilt (~> 1.3, >= 1.3.3)
+ sqlite3 (1.3.4)
+ templater (1.0.0)
+ diff-lcs (>= 1.1.2)
+ extlib (>= 0.9.5)
+ highline (>= 1.4.0)
+ thin (1.2.11)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ tilt (1.3.3)
+ uuidtools (2.1.2)
+ vegas (0.1.8)
+ rack (>= 1.0.0)
+ xml-simple (1.1.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ SystemTimer (~> 1.2.3)
+ aws-s3
+ dbd-jdbc (>= 0.1.4)
+ dbi (>= 0.4.5)
+ jdbc-sqlite3 (>= 3.7.2)
+ jruby-openssl (>= 0.7.4)
+ rack-test (>= 0.5.3)
+ rcov (>= 0.9.8)
+ rhoconnect (= 3.0.6)
+ rhomobile-debug (>= 1.0.2)
+ rspec (~> 2.6.0)
+ sqlite3 (>= 1.3.3)
+ thin
+ trinidad
+ warbler
@@ -0,0 +1,22 @@
+require 'rubygems'
+require 'bundler/setup'
+
+begin
+ require 'vendor/rhoconnect/lib/rhoconnect/tasks'
+ require 'vendor/rhoconnect/lib/rhoconnect'
+rescue LoadError
+ require 'rhoconnect/tasks'
+ require 'rhoconnect'
+end
+
+ROOT_PATH = File.expand_path(File.dirname(__FILE__))
+
+begin
+ require 'resque/tasks'
+ task "resque:setup" do
+ require 'application'
+ end
+rescue LoadError
+ puts "Resque not available. Install it with: "
+ puts "gem install resque\n\n"
+end
@@ -0,0 +1,20 @@
+class Application < Rhoconnect::Base
+ class << self
+ def authenticate(login,password,session)
+ true
+ end
+
+ # Add hooks for application startup here
+ # Don't forget to call super at the end!
+ def initializer(path)
+ super
+ end
+
+ def store_blob(obj,field_name,blob)
+ obj['filename'] = blob[:filename]
+ super
+ end
+ end
+end
+
+Application.initializer(ROOT_PATH)
@@ -0,0 +1,43 @@
+#!/usr/bin/env ruby
+require 'rubygems'
+require 'bundler'
+Bundler.require
+
+ROOT_PATH = File.expand_path(File.dirname(__FILE__))
+
+if ENV['DEBUG'] == 'yes'
+ ENV['APP_TYPE'] = 'rhoconnect'
+ ENV['ROOT_PATH'] = ROOT_PATH
+ require 'debugger'
+end
+
+# Try to load vendor-ed rhoconnect, otherwise load the gem
+begin
+ require 'vendor/rhoconnect/lib/rhoconnect/server'
+ require 'vendor/rhoconnect/lib/rhoconnect/console/server'
+rescue LoadError
+ require 'rhoconnect/server'
+ require 'rhoconnect/console/server'
+end
+
+# By default, turn on the resque web console
+require 'resque/server'
+
+
+# Rhoconnect server flags
+Rhoconnect::Server.disable :run
+Rhoconnect::Server.disable :clean_trace
+Rhoconnect::Server.enable :raise_errors
+Rhoconnect::Server.set :secret, 'c700fa2474075a0d0549208004012f33f86e2d5d97962b9c53003d364eab1fe3e13c3faa32822228ff53e10bc0b0f22f8944f1ed32fce0528c0ee79c8027f47d'
+Rhoconnect::Server.set :root, ROOT_PATH
+Rhoconnect::Server.use Rack::Static, :urls => ["/data"], :root => Rhoconnect::Server.root
+
+# Load our rhoconnect application
+$:.unshift ROOT_PATH if RUBY_VERSION =~ /1.9/ # FIXME: see PT story #16682771
+require 'application'
+
+# Setup the url map
+run Rack::URLMap.new \
+ "/" => Rhoconnect::Server.new,
+ "/resque" => Resque::Server.new, # If you don't want resque frontend, disable it here
+ "/console" => RhoconnectConsole::Server.new # If you don't want rhoconnect frontend, disable it here
@@ -0,0 +1 @@
+858fc60fadfde40273d0ac505906969318aa4931d1a2c4aeb24d98393c74379f60e226651601969874257f7f1fbda9b099ecd551a641519aa46819947fda0191
@@ -0,0 +1,21 @@
+:sources:
+ BlobTest:
+ :poll_interval: 0
+ BlobTest_s:
+ :poll_interval: 0
+ Image:
+ :poll_interval: 0
+ Metadata:
+ :poll_interval: 0
+
+:test:
+ :licensefile: settings/license.key
+ :syncserver: http://localhost:9292/application/
+ :redis: localhost:6379
+:production:
+ :licensefile: settings/license.key
+ :syncserver: http://localhost:9292/application/
+:development:
+ :licensefile: settings/license.key
+ :syncserver: http://localhost:9292/application/
+ :redis: localhost:6379
@@ -0,0 +1,12 @@
+require 'image_base'
+class BlobTest < ImageBase
+ def initialize(source,credential)
+ AWS::S3::Base.establish_connection!(
+ :access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
+ :secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']
+ )
+ @baseurl = 'http://s3.amazonaws.com/'
+ @bucket = 'rhodes-system-samples-images-auto'
+ super(source,credential)
+ end
+end
@@ -0,0 +1,12 @@
+require 'image_base'
+class BlobTest_s < ImageBase
+ def initialize(source,credential)
+ AWS::S3::Base.establish_connection!(
+ :access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
+ :secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']
+ )
+ @baseurl = 'http://s3.amazonaws.com/'
+ @bucket = 'rhodes-system-samples-images-auto'
+ super(source,credential)
+ end
+end
@@ -0,0 +1,12 @@
+require 'image_base'
+class Image < ImageBase
+ def initialize(source,credential)
+ AWS::S3::Base.establish_connection!(
+ :access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
+ :secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']
+ )
+ @baseurl = 'http://s3.amazonaws.com/'
+ @bucket = 'rhodes-system-samples-images'
+ super(source,credential)
+ end
+end
@@ -0,0 +1,36 @@
+require 'aws/s3'
+
+class ImageBase < SourceAdapter
+ include AWS::S3
+
+ def query(params=nil)
+ @result={}
+ Bucket.find(@bucket).objects.each do |entry|
+ new_item = {
+ 'image_uri-rhoblob' => @baseurl+@bucket+'/'+File.basename(entry.key),
+ 'name' => entry.key
+ }
+ puts "Found: #{new_item.inspect}"
+ @result[entry.key] = new_item
+ end
+ @result
+ end
+
+ def create(name_value_list)
+ puts "Creating: #{name_value_list.inspect}"
+ name = name_value_list["image_uri"]
+ basename = name_value_list["filename"]
+ S3Object.store(
+ basename,
+ open(name),
+ @bucket,
+ :access => :public_read
+ )
+ basename
+ end
+
+ def delete(name_value_list)
+ puts "Removing: #{name_value_list.inspect}"
+ S3Object.delete name_value_list['id'], @bucket
+ end
+end
Oops, something went wrong.

0 comments on commit 1d75bf4

Please sign in to comment.