bastille 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ module Bastille
2
+ class Space
3
+
4
+ def initialize(space)
5
+ @space = space
6
+ end
7
+
8
+ def all
9
+ redis.keys
10
+ end
11
+
12
+ def get(vault)
13
+ redis.get(vault)
14
+ end
15
+
16
+ def set(vault, contents)
17
+ redis.set(vault, contents)
18
+ end
19
+
20
+ def delete(vault)
21
+ redis.del(vault)
22
+ end
23
+
24
+ def redis
25
+ host = ENV['REDIS_HOST'] || 'localhost'
26
+ port = ENV['REDIS_PORT'] || 6379
27
+ @redis ||= Redis::Namespace.new("BASTILLE:#{@space}", :redis => Redis.new(:host => host, :port => port))
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,123 @@
1
+ module Bastille
2
+ class Store
3
+
4
+ def generate(username, password, domain, name)
5
+ @client = Octokit::Client.new(:login => username, :password => password)
6
+ auth = @client.create_authorization(:scopes => [], :note => name, :note_url => domain)
7
+ self.username = username
8
+ self.token = auth['token']
9
+ self.domain = domain
10
+ self.name = name
11
+ freeze!
12
+ true
13
+ rescue Octokit::Unauthorized
14
+ false
15
+ end
16
+
17
+ def generate_key_for(space, vault)
18
+ new_ciphers = ciphers.dup
19
+ cipher = Gibberish::SHA512("#{username}#{space}#{vault}#{Time.now}")
20
+ new_ciphers["#{space}:#{vault}"] = cipher
21
+ self.ciphers = new_ciphers
22
+ freeze!
23
+ cipher
24
+ end
25
+
26
+ def authenticate
27
+ response = Client.new(self).authenticate!
28
+ response.success?
29
+ end
30
+
31
+ def username
32
+ store.fetch(:username) { raise_key_error :username }
33
+ end
34
+
35
+ def username=(username)
36
+ store[:username] = username
37
+ end
38
+
39
+ def token
40
+ store.fetch(:token) { raise_key_error :token }
41
+ end
42
+
43
+ def token=(token)
44
+ store[:token] = token
45
+ end
46
+
47
+ def domain
48
+ store.fetch(:domain) { raise_key_error :domain }
49
+ end
50
+
51
+ def domain=(domain)
52
+ store[:domain] = domain
53
+ end
54
+
55
+ def name
56
+ store.fetch(:name) { raise_key_error :name }
57
+ end
58
+
59
+ def name=(name)
60
+ store[:name] = name
61
+ end
62
+
63
+ def key(space, vault, type = :autogenerated)
64
+ ciphers.fetch("#{space}:#{vault}") do
65
+ if type == :autogenerated
66
+ generate_key_for(space, vault)
67
+ end
68
+ end
69
+ end
70
+
71
+ def ciphers
72
+ store.fetch(:ciphers) { Hash.new }
73
+ end
74
+
75
+ def ciphers=(ciphers)
76
+ store[:ciphers] = ciphers
77
+ end
78
+
79
+ def freeze!
80
+ pathname.open('w+') do |f|
81
+ f.write(YAML.dump(@store))
82
+ end
83
+ @store = nil
84
+ end
85
+
86
+ def thaw!
87
+ exist? ? pathname.open('r') { |f| YAML.load(f.read) } : {}
88
+ end
89
+
90
+ def delete!
91
+ pathname.delete
92
+ end
93
+
94
+ def raise_key_error(key)
95
+ raise KeyError, "There is no :#{key} key in the ~/.bastille store. Try running `bastille tokenize` to generate a new store with the correct tokens."
96
+ end
97
+
98
+ def store
99
+ @store ||= thaw!
100
+ end
101
+
102
+ def each(&block)
103
+ store.sort { |(a, _), (b, _)| a.to_s <=> b.to_s }.each(&block)
104
+ end
105
+
106
+ def keys
107
+ store.keys
108
+ end
109
+
110
+ def pathname
111
+ @pathname ||= Pathname.new(path)
112
+ end
113
+
114
+ def exist?
115
+ pathname.exist?
116
+ end
117
+
118
+ def path
119
+ ENV['BASTILLE_STORE'] || "#{ENV['HOME']}/.bastille"
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,3 @@
1
+ module Bastille
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,271 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bastille
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Moran
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ none: false
21
+ name: gibberish
22
+ type: :runtime
23
+ prerelease: false
24
+ requirement: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ none: false
37
+ name: highline
38
+ type: :runtime
39
+ prerelease: false
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ none: false
46
+ - !ruby/object:Gem::Dependency
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ none: false
53
+ name: httparty
54
+ type: :runtime
55
+ prerelease: false
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ none: false
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ none: false
69
+ name: multi_json
70
+ type: :runtime
71
+ prerelease: false
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ none: false
78
+ - !ruby/object:Gem::Dependency
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ none: false
85
+ name: octokit
86
+ type: :runtime
87
+ prerelease: false
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ none: false
94
+ - !ruby/object:Gem::Dependency
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ none: false
101
+ name: redis
102
+ type: :runtime
103
+ prerelease: false
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ none: false
110
+ - !ruby/object:Gem::Dependency
111
+ version_requirements: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ none: false
117
+ name: redis-namespace
118
+ type: :runtime
119
+ prerelease: false
120
+ requirement: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ none: false
126
+ - !ruby/object:Gem::Dependency
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ none: false
133
+ name: sinatra
134
+ type: :runtime
135
+ prerelease: false
136
+ requirement: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ none: false
142
+ - !ruby/object:Gem::Dependency
143
+ version_requirements: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ none: false
149
+ name: thor
150
+ type: :runtime
151
+ prerelease: false
152
+ requirement: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ none: false
158
+ - !ruby/object:Gem::Dependency
159
+ version_requirements: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ none: false
165
+ name: aruba
166
+ type: :development
167
+ prerelease: false
168
+ requirement: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ none: false
174
+ - !ruby/object:Gem::Dependency
175
+ version_requirements: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ! '>='
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ none: false
181
+ name: mimic
182
+ type: :development
183
+ prerelease: false
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ! '>='
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ none: false
190
+ - !ruby/object:Gem::Dependency
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ! '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ none: false
197
+ name: fakeredis
198
+ type: :development
199
+ prerelease: false
200
+ requirement: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ! '>='
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ none: false
206
+ description: KV Storage As a Service, LOLz
207
+ email:
208
+ - ryan.moran@gmail.com
209
+ executables:
210
+ - bastille
211
+ extensions: []
212
+ extra_rdoc_files: []
213
+ files:
214
+ - .gitignore
215
+ - .travis.yml
216
+ - Gemfile
217
+ - Gemfile.lock
218
+ - LICENSE.txt
219
+ - README.md
220
+ - Rakefile
221
+ - bastille.gemspec
222
+ - bin/bastille
223
+ - config.ru
224
+ - features/bastille.feature
225
+ - features/support/aruba.rb
226
+ - features/support/octokit.rb
227
+ - features/support/server.rb
228
+ - features/token.feature
229
+ - features/vault.feature
230
+ - lib/bastille.rb
231
+ - lib/bastille/cli.rb
232
+ - lib/bastille/cli/common.rb
233
+ - lib/bastille/cli/token.rb
234
+ - lib/bastille/cli/vault.rb
235
+ - lib/bastille/client.rb
236
+ - lib/bastille/hub.rb
237
+ - lib/bastille/server.rb
238
+ - lib/bastille/space.rb
239
+ - lib/bastille/store.rb
240
+ - lib/bastille/version.rb
241
+ homepage: https://github.com/ryanmoran/bastille
242
+ licenses: []
243
+ post_install_message:
244
+ rdoc_options: []
245
+ require_paths:
246
+ - lib
247
+ required_ruby_version: !ruby/object:Gem::Requirement
248
+ requirements:
249
+ - - ! '>='
250
+ - !ruby/object:Gem::Version
251
+ version: '0'
252
+ none: false
253
+ required_rubygems_version: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ! '>='
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ none: false
259
+ requirements: []
260
+ rubyforge_project:
261
+ rubygems_version: 1.8.23
262
+ signing_key:
263
+ specification_version: 3
264
+ summary: KV Storage As a Service, LOLz
265
+ test_files:
266
+ - features/bastille.feature
267
+ - features/support/aruba.rb
268
+ - features/support/octokit.rb
269
+ - features/support/server.rb
270
+ - features/token.feature
271
+ - features/vault.feature