rb-gae-support 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,11 @@ A gem that wraps GAE functionality.
5
5
  Currently provides easier access to the User service, Monkey Patches Net::HTTP
6
6
  to work on google app engine, and provides a simple wrapper for the Memcache service.
7
7
 
8
- This is very early work, so not very complete, and not production ready.
8
+ This is very early work, so not very complete, and not production ready. If you come across
9
+ any issues, please report them at http://github.com/lstoll/rb-gae-support/issues
10
+
11
+ <b>Note: do not use jruby-openssl in your app engine application - it'll break it!</b>. It
12
+ uses native code, which is not supported on app engine.
9
13
 
10
14
  == Usage
11
15
 
@@ -63,7 +67,11 @@ call email, nickname and auth_domain on to get those details.
63
67
 
64
68
  === GAE::Memcache
65
69
 
66
- Allows you to store & retrieve items in Memcache. Resembles a hash
70
+ Allows you to store & retrieve items in Memcache. Resembles a hash. Note, the type
71
+ must be Serializable in Java. Strings etc. are OK, for arrays you will need to do
72
+ something like this (for a array of strings)
73
+
74
+ @array.to_java(:String)
67
75
 
68
76
  <b>Storing data</b>
69
77
 
@@ -3,6 +3,7 @@ require 'net/http'
3
3
  require 'net/https'
4
4
  require 'net/protocol'
5
5
  require 'java'
6
+ require 'yaml'
6
7
 
7
8
  module Net
8
9
 
@@ -29,6 +30,27 @@ module Net
29
30
  url = @use_ssl ? 'https://' : 'http://' + address + req.path
30
31
  jurl = java.net.URL.new(url)
31
32
  urlconn = jurl.openConnection()
33
+ #puts "METHOD: #{req.method}"
34
+ #puts "REQ: #{req.to_yaml}"
35
+
36
+ req.each_header do |k,v|
37
+ urlconn.addRequestProperty(k,v)
38
+ #puts "#{k}; #{v}"
39
+ end
40
+
41
+
42
+ #p req.header
43
+ urlconn.setRequestMethod(req.method)
44
+ if req.method == 'POST' || req.method == 'PUT'
45
+ urlconn.setDoOutput(true)
46
+ urlconn.connect()
47
+ if req.body
48
+ out=urlconn.getOutputStream()
49
+
50
+ out.write(req.body.to_java_bytes)
51
+ out.close
52
+ end
53
+ end
32
54
  inStream = java.io.InputStreamReader.new(urlconn.getInputStream())
33
55
  buff = java.io.BufferedReader.new(inStream)
34
56
  result = ''
@@ -54,11 +76,9 @@ module Net
54
76
  @use_ssl = flag
55
77
  end
56
78
 
57
- # Does nothing at the moment - avoiding OpenSSL
58
- def verify_mode=(mode)
59
- # TODO - check the verify mode, and make sure
60
- # the URL fetcher uses it.
61
- end
79
+ # Override ssl context accessors
80
+ # TODO - check what we can implement
81
+ attr_accessor :ca_path, :verify_callback, :verify_depth, :cert_store, :ca_file, :key, :cert, :verify_mode
62
82
 
63
83
  end
64
84
 
@@ -1,4 +1,7 @@
1
- # This module mocks out OpenSSL functionality to stop net/http erroring.
1
+ require 'java'
2
+
3
+ # This module mocks out OpenSSL functionality to stop net/http erroring, and adds support
4
+ # for some basic openssl functionality
2
5
  module OpenSSL
3
6
  # Providing a dummy SSL module
4
7
  module SSL
@@ -7,4 +10,16 @@ module OpenSSL
7
10
  # Dummy value to prevent errors with Net::HTTP
8
11
  VERIFY_PEER = nil
9
12
  end
13
+
14
+ # Returns a string with a size number of secure random bytes
15
+ class Random
16
+ def self.random_bytes(size)
17
+ # TODO - bounds check input, see how openssl does it.
18
+ random = java.security.SecureRandom.new
19
+ bytes = Java::byte[size].new
20
+ random.nextBytes(bytes)
21
+ String.from_java_bytes(bytes)
22
+ end
23
+ end
24
+
10
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-gae-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lincoln Stoll