bone 0.2.1
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.
- data/CHANGES.txt +23 -0
- data/LICENSE.txt +19 -0
- data/README.md +62 -0
- data/Rakefile +55 -0
- data/Rudyfile +227 -0
- data/bin/bone +89 -0
- data/bone.gemspec +48 -0
- data/lib/bone.rb +150 -0
- data/lib/bone/cli.rb +69 -0
- data/try/bone.rb +9 -0
- data/vendor/drydock-0.6.8/CHANGES.txt +159 -0
- data/vendor/drydock-0.6.8/LICENSE.txt +22 -0
- data/vendor/drydock-0.6.8/README.rdoc +92 -0
- data/vendor/drydock-0.6.8/Rakefile +74 -0
- data/vendor/drydock-0.6.8/bin/example +210 -0
- data/vendor/drydock-0.6.8/drydock.gemspec +38 -0
- data/vendor/drydock-0.6.8/lib/drydock.rb +961 -0
- data/vendor/drydock-0.6.8/lib/drydock/console.rb +313 -0
- data/vendor/drydock-0.6.8/lib/drydock/mixins.rb +4 -0
- data/vendor/drydock-0.6.8/lib/drydock/mixins/object.rb +23 -0
- data/vendor/drydock-0.6.8/lib/drydock/mixins/string.rb +66 -0
- data/vendor/drydock-0.6.8/lib/drydock/screen.rb +33 -0
- metadata +91 -0
data/bone.gemspec
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
@spec = Gem::Specification.new do |s|
|
2
|
+
s.name = "bone"
|
3
|
+
s.rubyforge_project = 'bone'
|
4
|
+
s.version = "0.2.1"
|
5
|
+
s.summary = "Get Bones"
|
6
|
+
s.description = s.summary
|
7
|
+
s.author = "Delano Mandelbaum"
|
8
|
+
s.email = "delano@solutious.com"
|
9
|
+
s.homepage = ""
|
10
|
+
|
11
|
+
s.extra_rdoc_files = %w[README.md LICENSE.txt CHANGES.txt]
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.rdoc_options = ["--line-numbers", "--title", s.summary, "--main", "README.rdoc"]
|
14
|
+
s.require_paths = %w[lib]
|
15
|
+
|
16
|
+
s.executables = %w[bone]
|
17
|
+
|
18
|
+
s.add_dependency 'boned', '= 0.2.0'
|
19
|
+
|
20
|
+
# = MANIFEST =
|
21
|
+
# git ls-files
|
22
|
+
s.files = %w(
|
23
|
+
CHANGES.txt
|
24
|
+
LICENSE.txt
|
25
|
+
README.md
|
26
|
+
Rakefile
|
27
|
+
Rudyfile
|
28
|
+
bin/bone
|
29
|
+
bone.gemspec
|
30
|
+
lib/bone.rb
|
31
|
+
lib/bone/cli.rb
|
32
|
+
try/bone.rb
|
33
|
+
vendor/drydock-0.6.8/CHANGES.txt
|
34
|
+
vendor/drydock-0.6.8/LICENSE.txt
|
35
|
+
vendor/drydock-0.6.8/README.rdoc
|
36
|
+
vendor/drydock-0.6.8/Rakefile
|
37
|
+
vendor/drydock-0.6.8/bin/example
|
38
|
+
vendor/drydock-0.6.8/drydock.gemspec
|
39
|
+
vendor/drydock-0.6.8/lib/drydock.rb
|
40
|
+
vendor/drydock-0.6.8/lib/drydock/console.rb
|
41
|
+
vendor/drydock-0.6.8/lib/drydock/mixins.rb
|
42
|
+
vendor/drydock-0.6.8/lib/drydock/mixins/object.rb
|
43
|
+
vendor/drydock-0.6.8/lib/drydock/mixins/string.rb
|
44
|
+
vendor/drydock-0.6.8/lib/drydock/screen.rb
|
45
|
+
)
|
46
|
+
|
47
|
+
|
48
|
+
end
|
data/lib/bone.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
unless defined?(BONE_HOME)
|
5
|
+
BONE_HOME = File.expand_path(File.join(File.dirname(__FILE__), '..') )
|
6
|
+
end
|
7
|
+
|
8
|
+
module Bone
|
9
|
+
extend self
|
10
|
+
VERSION = "0.2.1"
|
11
|
+
APIVERSION = 'v1'.freeze
|
12
|
+
|
13
|
+
class Problem < RuntimeError; end
|
14
|
+
class BadBone < Problem; end
|
15
|
+
|
16
|
+
@digest_type = nil # set at the end
|
17
|
+
@debug = false
|
18
|
+
class << self
|
19
|
+
attr_accessor :digest_type
|
20
|
+
def enable_debug() @debug = true end
|
21
|
+
def disable_debug() @debug = false end
|
22
|
+
def debug?() @debug == true end
|
23
|
+
def ld(*msg)
|
24
|
+
return unless Bone.debug?
|
25
|
+
prefix = "D(#{Thread.current.object_id}): "
|
26
|
+
STDERR.puts "#{prefix}" << msg.join("#{$/}#{prefix}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
SOURCE = (ENV['BONE_SOURCE'] || "localhost:6043").freeze
|
31
|
+
TOKEN = ENV['BONE_TOKEN'].freeze
|
32
|
+
|
33
|
+
def get(key, opts={})
|
34
|
+
token = opts[:token] || ENV['BONE_TOKEN'] || TOKEN
|
35
|
+
request(:get, token, key) # returns the response body
|
36
|
+
end
|
37
|
+
|
38
|
+
def set(key, value, opts={})
|
39
|
+
token = opts[:token] || ENV['BONE_TOKEN'] || TOKEN
|
40
|
+
opts[:value] = value
|
41
|
+
request(:set, token, key, opts)
|
42
|
+
key # return the key b/c it could be a binary file
|
43
|
+
end
|
44
|
+
|
45
|
+
def del(key, opts={})
|
46
|
+
token = opts[:token] || ENV['BONE_TOKEN'] || TOKEN
|
47
|
+
request(:del, token, key, opts) # returns the response body
|
48
|
+
end
|
49
|
+
|
50
|
+
def [](keyname)
|
51
|
+
get(keyname)
|
52
|
+
end
|
53
|
+
|
54
|
+
def []=(keyname, value)
|
55
|
+
set(keyname, value)
|
56
|
+
end
|
57
|
+
|
58
|
+
def keys(keyname=nil, opts={})
|
59
|
+
token = opts[:token] || ENV['BONE_TOKEN'] || TOKEN
|
60
|
+
request(:keys, token, keyname, opts)
|
61
|
+
end
|
62
|
+
|
63
|
+
# <tt>require</tt> a library from the vendor directory.
|
64
|
+
# The vendor directory should be organized such
|
65
|
+
# that +name+ and +version+ can be used to create
|
66
|
+
# the path to the library.
|
67
|
+
#
|
68
|
+
# e.g.
|
69
|
+
#
|
70
|
+
# vendor/httpclient-2.1.5.2/httpclient
|
71
|
+
#
|
72
|
+
def require_vendor(name, version)
|
73
|
+
path = File.join(BONE_HOME, 'vendor', "#{name}-#{version}", 'lib')
|
74
|
+
$:.unshift path
|
75
|
+
Bone.ld "REQUIRE VENDOR: ", path
|
76
|
+
require name
|
77
|
+
end
|
78
|
+
|
79
|
+
def valid_token?(val)
|
80
|
+
is_sha256? val
|
81
|
+
end
|
82
|
+
|
83
|
+
def is_sha1?(val)
|
84
|
+
val.to_s.match /\A[0-9a-f]{40}\z/
|
85
|
+
end
|
86
|
+
|
87
|
+
def is_sha256?(val)
|
88
|
+
val.to_s.match /\A[0-9a-f]{64}\z/
|
89
|
+
end
|
90
|
+
|
91
|
+
def digest(val)
|
92
|
+
@digest_type.hexdigest val
|
93
|
+
end
|
94
|
+
|
95
|
+
def generate_token
|
96
|
+
srand
|
97
|
+
digest [`hostname`, `w`, Time.now, rand].join(':')
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def request(action, token, key, params={})
|
103
|
+
params[:token] = token
|
104
|
+
path = "/#{APIVERSION}/#{action}/#{key}"
|
105
|
+
host, port = *SOURCE.split(':')
|
106
|
+
port ||= 6043
|
107
|
+
|
108
|
+
Bone.ld "URI: #{path}"
|
109
|
+
Bone.ld "PARAMS: " << params.inspect
|
110
|
+
|
111
|
+
case action
|
112
|
+
when :del
|
113
|
+
headers = { 'X-BONE_TOKEN' => token }
|
114
|
+
req = Net::HTTP::Delete.new(path, headers)
|
115
|
+
when :set
|
116
|
+
query = {}
|
117
|
+
params.each_pair {|n,v| query[n.to_s] = v }
|
118
|
+
req = Net::HTTP::Post.new(path)
|
119
|
+
req.set_form_data query
|
120
|
+
when :get, :keys
|
121
|
+
args = []
|
122
|
+
params.each_pair {|n,v| args << "#{n}=#{URI.encode(v.to_s)}" }
|
123
|
+
query = [path, args.join('&')].join('?')
|
124
|
+
Bone.ld "GET: #{query}"
|
125
|
+
req = Net::HTTP::Get.new(query)
|
126
|
+
else
|
127
|
+
raise Bone::Problem, "Unknown action: #{action}"
|
128
|
+
end
|
129
|
+
res = Net::HTTP.start(host, port) {|http| http.request(req) }
|
130
|
+
case res
|
131
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
132
|
+
res.body
|
133
|
+
else
|
134
|
+
raise Bone::Problem, "#{res.body} (#{res.code} #{res.message})"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def determine_digest_type
|
139
|
+
if RUBY_PLATFORM == "java"
|
140
|
+
require 'openssl'
|
141
|
+
Bone.digest_type = OpenSSL::Digest::SHA256
|
142
|
+
else
|
143
|
+
require 'digest'
|
144
|
+
Bone.digest_type = Digest::SHA256
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
@digest_type = determine_digest_type
|
149
|
+
end
|
150
|
+
|
data/lib/bone/cli.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'bone'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
class Bone::CLI < Drydock::Command
|
5
|
+
|
6
|
+
def check!
|
7
|
+
@token = @global.t || ENV['BONE_TOKEN']
|
8
|
+
raise Bone::BadBone, @token unless Bone.valid_token?(@token)
|
9
|
+
end
|
10
|
+
|
11
|
+
def get
|
12
|
+
check!
|
13
|
+
@argv.unshift @alias unless @alias == 'get'
|
14
|
+
raise "No key specified" unless @argv.first
|
15
|
+
puts Bone.get(@argv.first)
|
16
|
+
end
|
17
|
+
|
18
|
+
def del
|
19
|
+
check!
|
20
|
+
raise "No key specified" unless @argv.first
|
21
|
+
puts Bone.del(@argv.first)
|
22
|
+
end
|
23
|
+
|
24
|
+
def set
|
25
|
+
check!
|
26
|
+
opts = {:token => @token }
|
27
|
+
keyname, value = *(@argv.size == 1 ? @argv.first.split('=') : @argv)
|
28
|
+
raise "No key specified" unless keyname
|
29
|
+
raise "No value specified" unless value
|
30
|
+
if File.exists?(value) && !@option.string
|
31
|
+
value = File.readlines(value).join
|
32
|
+
opts[:file] = true
|
33
|
+
end
|
34
|
+
puts Bone.set(keyname, value, opts)
|
35
|
+
end
|
36
|
+
|
37
|
+
def keys
|
38
|
+
check!
|
39
|
+
list = Bone.keys(@argv[0])
|
40
|
+
if list.empty?
|
41
|
+
return if @global.quiet
|
42
|
+
puts "No keys"
|
43
|
+
puts "Try: bone set keyname=keyvalue"
|
44
|
+
else
|
45
|
+
puts list
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def token
|
50
|
+
check!
|
51
|
+
if @option.force
|
52
|
+
generate_token_dialog
|
53
|
+
else
|
54
|
+
puts @token
|
55
|
+
end
|
56
|
+
rescue Bone::BadBone => ex
|
57
|
+
generate_token_dialog
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def generate_token_dialog
|
63
|
+
newtoken = Bone.generate_token
|
64
|
+
puts newtoken and return if @global.quiet
|
65
|
+
puts "Set the BONE_TOKEN environment variable with the following token"
|
66
|
+
puts newtoken
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
data/try/bone.rb
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
DRYDOCK, CHANGES
|
2
|
+
|
3
|
+
#### 0.6.9 (2009-10-??) #############################
|
4
|
+
|
5
|
+
* CHANGE: Using autoload where appropriate.
|
6
|
+
|
7
|
+
#### 0.6.8 (2009-09-15) #############################
|
8
|
+
|
9
|
+
* FIXED: require 'thread' added to Drydock::Screen
|
10
|
+
* FIXED: require 'drydock/console'
|
11
|
+
|
12
|
+
|
13
|
+
#### 0.6.7 (2009-09-15) #############################
|
14
|
+
|
15
|
+
* ADDED: Drydock::Screen
|
16
|
+
|
17
|
+
#### 0.6.6 (2009-06-24) #############################
|
18
|
+
|
19
|
+
NOTE: Because at_exit has been removed, Drydock scripts will no longer
|
20
|
+
run automatically. You can explicitly call the following at the bottom
|
21
|
+
of your scripts:
|
22
|
+
|
23
|
+
Drydock.run!(ARGV, STDIN) if Drydock.run?
|
24
|
+
|
25
|
+
* CHANGE: Removed at_exit
|
26
|
+
* CHANGE: Drydock.run? will now return false if Drydock hasl already run
|
27
|
+
|
28
|
+
|
29
|
+
#### 0.6.5 (2009-05-21) #############################
|
30
|
+
|
31
|
+
* ADDED: "with_args" support for default command. When specified,
|
32
|
+
arguments can be passed to the default command with run in the
|
33
|
+
short form. e.g. "script arg1 arg2" == "script cmdname arg1 arg2"
|
34
|
+
|
35
|
+
#### 0.6.3 (2009-05-10) #############################
|
36
|
+
|
37
|
+
* ADDED: show-commands now displays a note about which command is the default
|
38
|
+
* CHANGE: Moved mixins to lib/drydock/mixins (so other projects can require 'drydock/mixins')
|
39
|
+
* FIXED: Support for inline command aliases when specifying a class:
|
40
|
+
command [:name, :alias1, :alias2] => SomeClass
|
41
|
+
|
42
|
+
|
43
|
+
#### 0.6.2 (2009-05-07) #############################
|
44
|
+
|
45
|
+
* ADDED: drydock/console.rb to start a new wing in the drydock
|
46
|
+
* ADDED: mixins for String and Object (for Console)
|
47
|
+
|
48
|
+
|
49
|
+
#### 0.6.1 (2009-05-03) #############################
|
50
|
+
|
51
|
+
* FIXED: @@trawler raises an error in Ruby 1.8 if it's a Symbol
|
52
|
+
|
53
|
+
|
54
|
+
#### 0.6.0 (2009-04-30) #############################
|
55
|
+
|
56
|
+
* CHANGE: Cleaner default error message for UnknownCommand exceptions
|
57
|
+
* CHANGE: 'desc' is now 'about' (desc works, but it prints a notice)
|
58
|
+
* CHANGE: I now recommend implementing the Drydock DSL in a module.
|
59
|
+
bin/example was updated to reflect the change. This prevents Drydock
|
60
|
+
keywords from being included in the global namespace.
|
61
|
+
* ADDED: Inline commands aliases. command :cmd1, :cmd2 do; ...; end
|
62
|
+
* ADDED: Unknown commands can be directed to a trawler.
|
63
|
+
|
64
|
+
|
65
|
+
#### 0.5.6 (2009-04-22) #############################
|
66
|
+
|
67
|
+
* CHANGED: Interrupts now handled in rescue rather than a trap.
|
68
|
+
* ADDED: Drydock::ArgError and Drydock::OptError are rescued at runtime by default
|
69
|
+
|
70
|
+
#### 0.5.5 (2009-04-19) #############################
|
71
|
+
|
72
|
+
* CHANGED: Improved help screen formatting.
|
73
|
+
|
74
|
+
#### 0.5.4 (2009-04-15) #############################
|
75
|
+
|
76
|
+
* ADDED: Better error handling with new Drydock::ArgError and Drydock::OptError
|
77
|
+
|
78
|
+
#### 0.5.3 (2009-04-05) #############################
|
79
|
+
|
80
|
+
* FIXED: Command actions were not being handled correctly. Added rdocs to
|
81
|
+
clarify the code.
|
82
|
+
|
83
|
+
#### 0.5.2 (2009-04-04) #############################
|
84
|
+
|
85
|
+
* ADDED: before and after blocks now receive a primed reference to the
|
86
|
+
command object (which gives them access to the globals and options)
|
87
|
+
* CHANGE: The prep stuff in Drydock::Command#call is now split into a
|
88
|
+
separate method: prepare so call no longer takes arguments.
|
89
|
+
* FIXED: Drydock#capture_io was using yield. It now accepts a block instead.
|
90
|
+
|
91
|
+
|
92
|
+
#### 0.5.1 (2009-03-15) #############################
|
93
|
+
|
94
|
+
* FIXED: Prevent calling default command in at_exit when there's a LoadError.
|
95
|
+
* FIXED: Exit gracefully when the application exits.
|
96
|
+
* FIXED: Print command names with dashes rather than underscores
|
97
|
+
|
98
|
+
|
99
|
+
#### 0.5 (2009-03-11) ###############################
|
100
|
+
|
101
|
+
* ADDED: Checks that the command class is a subclass of Drydock::Command
|
102
|
+
* CHANGE: Cleaned up show-commands screen
|
103
|
+
* FIXED: Help didn't work when using command alias
|
104
|
+
* ADDED: Named argv values.
|
105
|
+
* CHANGE: argv are now part of the Command class (not passed to command blocks)
|
106
|
+
* CHANGE: "project" now automatically requires the lowercase name of the project
|
107
|
+
and gracefully continues if the require failed.
|
108
|
+
* CHANGE: Drydock will look for different validation method, based on the method
|
109
|
+
being executed. If a validation method is found it's executed and
|
110
|
+
must return a true valid (it can also raise its own exceptions).
|
111
|
+
* ADDED: command actions. These are boolean switches with a twist. Drydock looks
|
112
|
+
for command_action or action_command methods. Saves checking the switches
|
113
|
+
and sending to other methods manually.
|
114
|
+
|
115
|
+
|
116
|
+
#### 0.4 (2009-02-28) ###############################
|
117
|
+
|
118
|
+
* FIXED: "interning empty string" error when bare "option" is used
|
119
|
+
* ADDED: Calls valid? method (if present) before calling command block.
|
120
|
+
* ADDED: "capture" method. Auto capture STDOUT to obj.stdout etc...
|
121
|
+
* ADDED: Automatically calls init and print_header methods before the command
|
122
|
+
and print_footer after the command (if available)
|
123
|
+
* ADDED: Tries to call obj.command if available when no block is supplied
|
124
|
+
* ADDED: "show_commands" command built-in. Displays commands with descriptions
|
125
|
+
* ADDED: A default usage help msg for every command: "#{$0} command-name"
|
126
|
+
* ADDED: "usage" work multiple times for the same command.
|
127
|
+
* ADDED: "desc" method for per command descriptions
|
128
|
+
* CHANGE: options are now stored as obj.option.name instead of obj.name
|
129
|
+
* CHANGE: global options are now stored as obj.globals.name
|
130
|
+
* CHANGE: removed auto importing methods
|
131
|
+
OLD: require 'drydock'
|
132
|
+
ADDED: require 'drydock'
|
133
|
+
extend Drydock
|
134
|
+
|
135
|
+
|
136
|
+
#### 0.3.3 (2009-02-14) ###############################
|
137
|
+
|
138
|
+
* ADDED: init method hook for subclasses of Drydock::Command
|
139
|
+
* UPDATED: Rdocs
|
140
|
+
* CHANGE: added method command_aliaz to mirror aliaz_command
|
141
|
+
|
142
|
+
|
143
|
+
#### 0.3 (2009-02-05) ###############################
|
144
|
+
|
145
|
+
* Added support for custom Drydock::Commands objects
|
146
|
+
* Global and command-specific options are now available as
|
147
|
+
attributes of the Drydock::Commands class instance.
|
148
|
+
* Automatic execution
|
149
|
+
* Now in a single file (lib/drydock.rb)
|
150
|
+
* Started adding tests
|
151
|
+
* Improved documentation
|
152
|
+
|
153
|
+
|
154
|
+
#### 0.2 (2008-12-27) ###############################
|
155
|
+
|
156
|
+
* Initial release
|
157
|
+
* Forked from bmizerany/frylock
|
158
|
+
|
159
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2008-2009 Delano Mandelbaum, Solutious Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|