bone 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ # try try/20_instance_try.rb
2
+
3
+ # To prevent from loading the HTTP lib
4
+ ENV['BONE_SOURCE'] = 'memory://localhost'
5
+ require 'bone'
6
+ Bone.debug = true
7
+ Bone.source = 'memory://localhost'
8
+
9
+ ## Bone.generate (to see the values)
10
+ @t, @s = *Bone.generate
11
+ [@t, @s]
12
+ #=> [@t, @s]
13
+
14
+ ## Bone.generate
15
+ t, s = *Bone.generate
16
+ [t.size, s.size]
17
+ #=> [24, 64]
@@ -0,0 +1,73 @@
1
+ # try try/20_instance_try.rb
2
+
3
+ require 'bone'
4
+ #Bone.debug = true
5
+ Bone.token = 'atoken'
6
+ Bone.source = 'memory://localhost'
7
+
8
+ @secret = "wHLJ3PskyzcxN9A9fYdQKltxDhsw2E%2B%2BUoL%2BbfOp2DM"
9
+ @path = "/#{Bone::APIVERSION}/#{Bone.token}/keys"
10
+ @query = {
11
+ :token => Bone.token,
12
+ :zang => :excellent,
13
+ :a_nil_value => nil,
14
+ :arbitrary => '&+ ~ *%'
15
+ }
16
+ @body = 'nuprin'
17
+ @now = Bone::API::HTTP.canonical_time Time.at(1292396472)
18
+
19
+ ## Check Bone::API::HTTP.canonical_time
20
+ @now
21
+ #=> 1292396472
22
+
23
+ ## Bone::API::HTTP.canonical_host
24
+ Bone::API::HTTP.canonical_host Bone.source
25
+ #=> 'localhost:80'
26
+
27
+ ## Bone::API::HTTP.canonical_sig_string (arbitrary query)
28
+ Bone::API::HTTP.canonical_sig_string Bone.source, :get, @path, @query
29
+ #=> "get\nlocalhost:80\n/v2/atoken/keys\na_nil_value=&arbitrary=%26%2B%20~%20%2A%25&token=atoken&zang=excellent"
30
+
31
+ ## Bone::API::HTTP.encode (arbitrary query)
32
+ str = Bone::API::HTTP.canonical_sig_string Bone.source, :get, @path, @query
33
+ Bone::API::HTTP.encode @secret, str
34
+ #=> 'rfJY5F3j2Ndq9inSbbA2%2FKzvd%2By5eGqR5kMu4HCDM4I%3D'
35
+
36
+ ## Bone::API::HTTP.encode (arbitrary query, no escape)
37
+ str = Bone::API::HTTP.canonical_sig_string Bone.source, :get, @path, @query
38
+ Bone::API::HTTP.encode @secret, str, false
39
+ #=> 'rfJY5F3j2Ndq9inSbbA2/Kzvd+y5eGqR5kMu4HCDM4I='
40
+
41
+ ## Bone::API::HTTP.generate_signature (arbitrary query)
42
+ Bone::API::HTTP.generate_signature @secret, Bone.source, :get, @path, @query
43
+ #=> 'rfJY5F3j2Ndq9inSbbA2%2FKzvd%2By5eGqR5kMu4HCDM4I%3D'
44
+
45
+ ## Bone::API::HTTP.sign_query (arbitrary query)
46
+ Bone::API::HTTP.sign_query(Bone.token, @secret, :get, @path, @query)
47
+ #=> {:token=>"atoken", :a_nil_value=>nil, :arbitrary=>"&+ ~ *%", "sig"=>"rfJY5F3j2Ndq9inSbbA2%2FKzvd%2By5eGqR5kMu4HCDM4I%3D", :zang=>:excellent}
48
+
49
+ ## Bone::API::HTTP.encode (arbitrary query, with body)
50
+ str = Bone::API::HTTP.canonical_sig_string Bone.source, :get, @path, @query, @body
51
+ Bone::API::HTTP.encode @secret, str
52
+ #=> 'LK%2FghZKcGwNl7tSnEnr0pKGdBe%2BMwAjl5cl1ZBpT%2F%2F0%3D'
53
+
54
+ ## Bone::API::HTTP.prepare_query
55
+ query = Bone::API::HTTP.prepare_query @query, Bone.token, @now
56
+ #=> {:token=>"atoken", :a_nil_value=>nil, "token"=>"atoken", :arbitrary=>"&+ ~ *%", "stamp"=>1292396472, "sigversion"=>"v2", :zang=>:excellent, "apiversion"=>"v2"}
57
+
58
+ ## Bone::API::HTTP.generate_signature (prepared query)
59
+ query = Bone::API::HTTP.prepare_query @query, Bone.token, @now
60
+ Bone::API::HTTP.generate_signature @secret, Bone.source, :get, @path, query
61
+ #=> 'UY8s7hbquwWedOpr0g%2B4SyioKTbYSLalCjgvfUhl7eo%3D'
62
+
63
+ ## Bone::API::HTTP.sign_query (prepared query)
64
+ query = Bone::API::HTTP.prepare_query @query, Bone.token, @now
65
+ Bone::API::HTTP.sign_query Bone.token, @secret, :get, @path, query
66
+ #=> {:token=>"atoken", "token"=>"atoken", :a_nil_value=>nil, :arbitrary=>"&+ ~ *%", "sig"=>"UY8s7hbquwWedOpr0g%2B4SyioKTbYSLalCjgvfUhl7eo%3D", "stamp"=>1292396472, "sigversion"=>"v2", "apiversion"=>"v2", :zang=>:excellent}
67
+
68
+ ## Bone::API::HTTP.generate_signature (an example of unique signatures)
69
+ query = Bone::API::HTTP.prepare_query @query, Bone.token
70
+ @sig = Bone::API::HTTP.generate_signature @secret, Bone.source, :get, @path, query
71
+ #=> @sig
72
+
73
+ ## Bone::API::HTTP.
@@ -0,0 +1,29 @@
1
+ # try try/20_instance_try.rb
2
+
3
+ require 'bone'
4
+ #Bone.debug = true
5
+ Bone.source = 'memory://localhost'
6
+
7
+ @token, @secret = *Bone.generate
8
+
9
+ ## create bone instance
10
+ @bone = Bone.new @token
11
+ @bone.class
12
+ #=> Bone
13
+
14
+ ## set
15
+ @bone.set :nerve, :centre
16
+ #=> 'centre'
17
+
18
+ ## get
19
+ @bone.get :nerve
20
+ #=> 'centre'
21
+
22
+ ## []=
23
+ @bone[:nasty] = :fine
24
+ #=> :fine
25
+
26
+ ## []
27
+ @bone[:nasty]
28
+ #=> 'fine'
29
+
@@ -0,0 +1,67 @@
1
+
2
+ require 'bone'
3
+ #Bone.debug = true
4
+ Bone.source = 'redis://localhost:8045'
5
+
6
+ ## Bone::API::Redis::Token.redis_objects
7
+ Bone::API::Redis::Token.redis_objects.keys.collect(&:to_s).sort
8
+ #=> ['keys', 'secret']
9
+
10
+ ## Bone::API::Redis::Token.redis_objects
11
+ Bone::API::Redis::Token.class_redis_objects.keys
12
+ #=> [:tokens]
13
+
14
+ ## Bone::API::Redis::Token.new
15
+ @tobj = Bone::API::Redis::Token.new :atoken
16
+ @tobj.rediskey
17
+ #=> 'v2:bone:token:atoken:object'
18
+
19
+ ## Bone::API::Redis::Token#secret
20
+ @tobj.secret.class
21
+ #=> Familia::Object::String
22
+
23
+ ## Bone::API::Redis::Token#secret= doesn't exist
24
+ @tobj.secret = :poop
25
+ #=> :poop
26
+
27
+ ## Bone::API::Redis::Token#secret isn't affected by secret=
28
+ @tobj.secret.class
29
+ #=> Familia::Object::String
30
+
31
+ ## Bone::API::Redis::Token#secret to_s
32
+ @tobj.secret.to_s
33
+ #=> 'poop'
34
+
35
+ ## Bone::API::Redis::Key.redis_objects
36
+ Bone::API::Redis::Key.redis_objects.keys
37
+ #=> [:value]
38
+
39
+ ## Bone::API::Redis::Key.new
40
+ @kobj = Bone::API::Redis::Key.new :atoken, :akey
41
+ @kobj.rediskey
42
+ #=> 'v2:bone:key:atoken:global:akey:object'
43
+
44
+ ## Bone::API::Redis::Key#value
45
+ @kobj.value.class
46
+ #=> Familia::Object::String
47
+
48
+ ## Bone::API::Redis::Key#value to_s returns empty string
49
+ @kobj.value.to_s
50
+ #=> ''
51
+
52
+ ## Bone::API::Redis::Key#value get returns nil
53
+ @kobj.value.get
54
+ #=> nil
55
+
56
+ ## Bone::API::Redis::Key#value=
57
+ @kobj.value = 'avalue1'
58
+ #=> 'avalue1'
59
+
60
+ ## Bone::API::Redis::Key#value set
61
+ @kobj.value.set 'avalue2'
62
+ #=> 'avalue2'
63
+
64
+ ## Bone::API::Redis::Key#value clear
65
+ @kobj.value.clear
66
+ #=> 1
67
+
@@ -0,0 +1,74 @@
1
+ # try try/30_api_redis_try.rb
2
+
3
+ require 'bone'
4
+ #Bone.debug = true
5
+ Bone.source = 'memory://localhost'
6
+
7
+ ## Can set the base uri via ENV
8
+ ## (NOTE: must be set before the require)
9
+ Bone.source.to_s
10
+ #=> 'memory://localhost'
11
+
12
+ ## Knows to use the redis API
13
+ Bone.api
14
+ #=> Bone::API::Memory
15
+
16
+ ## Can generate a token
17
+ @generated_token, secret = *Bone.generate
18
+ @generated_token.size
19
+ #=> 24
20
+
21
+ ## Can register a token
22
+ @token = Bone.register 'atoken', 'secret1'
23
+ @token
24
+ #=> 'atoken'
25
+
26
+ ## Can check secret via API
27
+ Bone.api.secret 'atoken'
28
+ #=> 'secret1'
29
+
30
+ ## Can set token directly
31
+ Bone.token = @token
32
+ Bone.token
33
+ #=> @token
34
+
35
+ ## Knows a valid token
36
+ Bone.token? @token
37
+ #=> true
38
+
39
+ ## Knows an invalid token
40
+ Bone.token? 'bogustoken'
41
+ #=> false
42
+
43
+ ## Empty key returns nil
44
+ Bone['bogus']
45
+ #=> nil
46
+
47
+ ## Make request to API directly
48
+ Bone.api.get Bone.token, Bone.secret, 'bogus'
49
+ #=> nil
50
+
51
+ ## Set a value
52
+ Bone['valid'] = true
53
+ Bone['valid']
54
+ #=> 'true'
55
+
56
+ ## Get a value
57
+ Bone['valid']
58
+ #=> 'true'
59
+
60
+ ## Knows all keys
61
+ Bone.keys
62
+ #=> ["v2:bone:#{@token}:valid"]
63
+
64
+ ## Knows when a key exists
65
+ Bone.key? :valid
66
+ #=> true
67
+
68
+ ## Knows when a key doesn't exist
69
+ Bone.key? :bogus
70
+ #=> false
71
+
72
+ Bone.destroy @token
73
+ Bone.destroy @generated_token
74
+
@@ -0,0 +1,73 @@
1
+ # try try/31_api_redis_try.rb
2
+
3
+ require 'bone'
4
+ #Bone.debug = true
5
+ @token = 'atoken'
6
+ @secret = Bone.random_secret
7
+
8
+ ## Can set the base uri without a token
9
+ Bone.source = 'redis://localhost:8045'
10
+ #=> 'redis://localhost:8045'
11
+
12
+ ## Knows to use the redis API
13
+ Bone.api
14
+ #=> Bone::API::Redis
15
+
16
+ ## Can generate a token
17
+ @generated_token, secret = *Bone.generate
18
+ @generated_token.size
19
+ #=> 24
20
+
21
+ ## Can register a token
22
+ token = Bone.register @token, @secret
23
+ #=> 'atoken'
24
+
25
+ ## Can set token directly
26
+ Bone.token = @token
27
+ Bone.token
28
+ #=> @token
29
+
30
+ ## Can check secret via API
31
+ Bone.api.secret @token
32
+ #=> @secret
33
+
34
+ ## Knows a valid token
35
+ Bone.token? @token
36
+ #=> true
37
+
38
+ ## Knows an invalid token
39
+ Bone.token? 'bogustoken'
40
+ #=> false
41
+
42
+ ## Empty key returns nil
43
+ Bone['bogus']
44
+ #=> nil
45
+
46
+ ## Make request to API directly
47
+ Bone.api.get Bone.token, Bone.secret, 'bogus'
48
+ #=> nil
49
+
50
+ ## Set a value
51
+ Bone['akey1'] = 'value1'
52
+ Bone['akey1']
53
+ #=> 'value1'
54
+
55
+ ## Get a value
56
+ Bone['akey1']
57
+ #=> 'value1'
58
+
59
+ ## Knows all keys
60
+ Bone.keys
61
+ #=> ["akey1"]
62
+
63
+ ## Knows when a key exists
64
+ Bone.key? :akey1
65
+ #=> true
66
+
67
+ ## Knows when a key doesn't exist
68
+ Bone.key? :bogus
69
+ #=> false
70
+
71
+
72
+ Bone.destroy @token
73
+ Bone.destroy @generated_token
@@ -0,0 +1,68 @@
1
+ # try try/32_api_http_try.rb
2
+
3
+ require 'bone'
4
+ #Bone.debug = true
5
+ Bone.token = 'atoken'
6
+ Bone.secret = 'crystal'
7
+
8
+ ## Can set the base uri directly
9
+ Bone.source = "http://localhost:3073"
10
+ Bone.source.to_s
11
+ #=> "http://localhost:3073"
12
+
13
+ ## Knows to use the redis HTTP
14
+ Bone.api
15
+ #=> Bone::API::HTTP
16
+
17
+ ## Bone.register
18
+ Bone.register Bone.token, Bone.secret
19
+ #=> 'atoken'
20
+
21
+ ## Bone.token? knows when a token exists
22
+ Bone.token? Bone.token
23
+ #=> true
24
+
25
+ ## Bone.token? returns false when it doesn't exist
26
+ Bone.token? 'bogus'
27
+ #=> false
28
+
29
+ ## Empty key returns nil
30
+ Bone['bogus']
31
+ #=> nil
32
+
33
+ ## Make request to API directly
34
+ Bone.api.get Bone.token, Bone.secret, 'bogus'
35
+ #=> nil
36
+
37
+ ## Set a value
38
+ Bone['akey1'] = 'value1'
39
+ Bone['akey1']
40
+ #=> 'value1'
41
+
42
+ ## Get a value
43
+ Bone['akey1']
44
+ #=> 'value1'
45
+
46
+ ## Knows all keys
47
+ Bone.keys
48
+ #=> ["akey1"]
49
+
50
+ ## Knows when a key exists
51
+ Bone.key? :akey1
52
+ #=> true
53
+
54
+ ## Knows when a key doesn't exist
55
+ Bone.key? :bogus
56
+ #=> false
57
+
58
+ ## Bone.generate
59
+ @token2, @secret2 = *Bone.generate
60
+ @token2.size
61
+ #=> 24
62
+
63
+ Bone.destroy Bone.token
64
+
65
+ if @token2
66
+ bone = Bone.new @token2, @secret2
67
+ bone.destroy @token2
68
+ end
@@ -0,0 +1,24 @@
1
+
2
+ sources = ['redis://localhost:8045', 'http://localhost:3073/']
3
+ execs = ['/usr/bin/ruby', '/usr/local/bin/ruby']
4
+
5
+ def run_command *args
6
+ cmd = '%s -rubygems %s %s' % args
7
+ ret, status = `#{cmd}`, $?.exitstatus
8
+ puts cmd, "(#{status}) #{ret}", $/
9
+ [status, ret]
10
+ end
11
+
12
+ sources.each do |source|
13
+ ENV['BONE_SOURCE'] = source
14
+ puts '-' * 20, source, '-' * 20
15
+ execs.each do |ruby|
16
+ status, token = *run_command(ruby, 'bin/bone', :generate)
17
+ next unless status.zero?
18
+ ENV['BONE_TOKEN'] = token
19
+ status, ret = *run_command(ruby, 'bin/bone', :token)
20
+ next unless token == ret
21
+ p 1
22
+ break
23
+ end
24
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Delano Mandelbaum
@@ -9,31 +15,71 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-02-20 00:00:00 -05:00
13
- default_executable:
14
- dependencies: []
15
-
16
- description: Get Bones
18
+ date: 2010-12-17 00:00:00 -05:00
19
+ default_executable: bone
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: familia
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 0
32
+ - 6
33
+ - 0
34
+ version: 0.6.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: em-http-request
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: A simple store for remote environment variables
17
52
  email: delano@solutious.com
18
53
  executables:
19
54
  - bone
20
55
  extensions: []
21
56
 
22
57
  extra_rdoc_files:
23
- - README.md
24
58
  - LICENSE.txt
25
- - CHANGES.txt
59
+ - README.md
26
60
  files:
27
61
  - CHANGES.txt
62
+ - Gemfile
63
+ - Gemfile.lock
28
64
  - LICENSE.txt
29
65
  - README.md
30
66
  - Rakefile
31
67
  - Rudyfile
68
+ - VERSION.yml
32
69
  - bin/bone
33
70
  - bone.gemspec
71
+ - config/redis-server.conf
34
72
  - lib/bone.rb
73
+ - lib/bone/api.rb
35
74
  - lib/bone/cli.rb
36
- - try/bone.rb
75
+ - try/10_generate_try.rb
76
+ - try/16_http_try.rb
77
+ - try/20_instance_try.rb
78
+ - try/25_key_token_object_try.rb
79
+ - try/30_api_memory_try.rb
80
+ - try/31_api_redis_try.rb
81
+ - try/32_api_http_try.rb
82
+ - try/manual_cli.rb
37
83
  - vendor/drydock-0.6.8/CHANGES.txt
38
84
  - vendor/drydock-0.6.8/LICENSE.txt
39
85
  - vendor/drydock-0.6.8/README.rdoc
@@ -47,36 +93,38 @@ files:
47
93
  - vendor/drydock-0.6.8/lib/drydock/mixins/string.rb
48
94
  - vendor/drydock-0.6.8/lib/drydock/screen.rb
49
95
  has_rdoc: true
50
- homepage: http://github.com/solutious/bone
96
+ homepage: https://github.com/solutious/bone
51
97
  licenses: []
52
98
 
53
99
  post_install_message:
54
100
  rdoc_options:
55
- - --line-numbers
56
- - --title
57
- - Get Bones
58
- - --main
59
- - README.md
101
+ - --charset=UTF-8
60
102
  require_paths:
61
103
  - lib
62
104
  required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
63
106
  requirements:
64
107
  - - ">="
65
108
  - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
66
112
  version: "0"
67
- version:
68
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
69
115
  requirements:
70
116
  - - ">="
71
117
  - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
72
121
  version: "0"
73
- version:
74
122
  requirements: []
75
123
 
76
124
  rubyforge_project: bone
77
- rubygems_version: 1.3.5
125
+ rubygems_version: 1.3.7
78
126
  signing_key:
79
127
  specification_version: 3
80
- summary: Get Bones
128
+ summary: A simple store for remote environment variables
81
129
  test_files: []
82
130