winton-secret_key 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2009 Winton Welsh
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,19 @@
1
+ Secret Key
2
+ ==========
3
+
4
+ Provides an accessor for a secret key stored in <code>tmp</code>.
5
+
6
+ Setup
7
+ -----
8
+
9
+ <pre>
10
+ gem sources -a http://gems.github.com
11
+ sudo gem install winton-secret_key
12
+ </pre>
13
+
14
+ Usage
15
+ -----
16
+
17
+ <pre>
18
+ key = SecretKey.new(File.dirname("__FILE__")).read
19
+ </pre>
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/gempackagetask'
4
+ require 'spec/rake/spectask'
5
+ require 'gemspec'
6
+
7
+ desc "Generate gemspec"
8
+ task :gemspec do
9
+ File.open("#{Dir.pwd}/#{GEM_NAME}.gemspec", 'w') do |f|
10
+ f.write(GEM_SPEC.to_ruby)
11
+ end
12
+ end
13
+
14
+ desc "Install gem"
15
+ task :install do
16
+ Rake::Task['gem'].invoke
17
+ `sudo gem uninstall #{GEM_NAME} -x`
18
+ `sudo gem install pkg/#{GEM_NAME}*.gem`
19
+ `rm -Rf pkg`
20
+ end
21
+
22
+ desc "Package gem"
23
+ Rake::GemPackageTask.new(GEM_SPEC) do |pkg|
24
+ pkg.gem_spec = GEM_SPEC
25
+ end
26
+
27
+ desc "Run specs"
28
+ Spec::Rake::SpecTask.new do |t|
29
+ t.rcov = true
30
+ t.spec_opts = ["--format", "specdoc", "--colour"]
31
+ t.spec_files = FileList["spec/**/*_spec.rb"]
32
+ end
data/gemspec.rb ADDED
@@ -0,0 +1,17 @@
1
+ GEM_NAME = 'secret_key'
2
+ GEM_FILES = FileList['**/*'] - FileList['coverage', 'coverage/**/*', 'pkg', 'pkg/**/*', 'spec/tmp', 'spec/tmp/**/*']
3
+ GEM_SPEC = Gem::Specification.new do |s|
4
+ # == CONFIGURE ==
5
+ s.author = "Winton Welsh"
6
+ s.email = "mail@wintoni.us"
7
+ s.homepage = "http://github.com/winton/#{GEM_NAME}"
8
+ s.summary = "Provides an accessor for a secret key stored in tmp"
9
+ # == CONFIGURE ==
10
+ s.extra_rdoc_files = [ "README.markdown" ]
11
+ s.files = GEM_FILES.to_a
12
+ s.has_rdoc = false
13
+ s.name = GEM_NAME
14
+ s.platform = Gem::Platform::RUBY
15
+ s.require_path = "lib"
16
+ s.version = "0.1.0"
17
+ end
data/lib/secret_key.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'digest/sha1'
2
+
3
+ class SecretKey
4
+
5
+ attr_reader :key
6
+
7
+ def initialize(base_dir)
8
+ tmp = "#{base_dir}/tmp"
9
+ tmp = File.expand_path(tmp)
10
+ FileUtils.mkdir_p(tmp)
11
+ @path = "#{tmp}/secret_key"
12
+ end
13
+
14
+ def read
15
+ if @key
16
+ @key
17
+ elsif exists?
18
+ @key = File.read(@path).strip
19
+ else
20
+ write
21
+ end
22
+ end
23
+
24
+ def write
25
+ File.open(@path, 'w') do |f|
26
+ @key = RUBY_PLATFORM + rand(10000000000000).to_s
27
+ @key = Digest::SHA1.hexdigest(@key)
28
+ f.write(@key)
29
+ end
30
+ @key
31
+ end
32
+
33
+ private
34
+
35
+ def exists?
36
+ File.exists?(@path)
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{secret_key}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Winton Welsh"]
9
+ s.date = %q{2009-07-18}
10
+ s.email = %q{mail@wintoni.us}
11
+ s.extra_rdoc_files = ["README.markdown"]
12
+ s.files = ["gemspec.rb", "lib", "lib/secret_key.rb", "MIT-LICENSE", "Rakefile", "README.markdown", "secret_key.gemspec", "spec", "spec/secret_key_spec.rb", "spec/spec.opts", "spec/spec_helper.rb"]
13
+ s.homepage = %q{http://github.com/winton/secret_key}
14
+ s.require_paths = ["lib"]
15
+ s.rubygems_version = %q{1.3.1}
16
+ s.summary = %q{Provides an accessor for a secret key stored in tmp}
17
+
18
+ if s.respond_to? :specification_version then
19
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
20
+ s.specification_version = 2
21
+
22
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
23
+ else
24
+ end
25
+ else
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
2
+
3
+ describe SecretKey do
4
+
5
+ before(:all) do
6
+ reset
7
+ @secret_key = SecretKey.new(File.dirname(__FILE__))
8
+ @key = @secret_key.read
9
+ end
10
+
11
+ context "first read" do
12
+
13
+ it "should generate the key" do
14
+ @key.length.should == 40
15
+ end
16
+ end
17
+
18
+ context "second read" do
19
+
20
+ it "should already have the key stored" do
21
+ @secret_key.key.length.should == 40
22
+ end
23
+ end
24
+
25
+ context "first read with temp file present" do
26
+
27
+ before(:all) do
28
+ @secret_key = SecretKey.new(File.dirname(__FILE__))
29
+ end
30
+
31
+ it "should read the key from the temp file" do
32
+ @secret_key.read.length.should == 40
33
+ @secret_key.read.should == @key
34
+ end
35
+ end
36
+
37
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,20 @@
1
+ $TESTING=true
2
+ SPEC = File.dirname(__FILE__)
3
+ $:.unshift File.expand_path("#{SPEC}/../lib")
4
+
5
+ require 'secret_key'
6
+ require 'pp'
7
+
8
+ Spec::Runner.configure do |config|
9
+ end
10
+
11
+ # For use with rspec textmate bundle
12
+ def debug(object)
13
+ puts "<pre>"
14
+ puts object.pretty_inspect.gsub('<', '&lt;').gsub('>', '&gt;')
15
+ puts "</pre>"
16
+ end
17
+
18
+ def reset
19
+ FileUtils.rm_rf File.dirname(__FILE__) + "/tmp"
20
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: winton-secret_key
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Winton Welsh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: mail@wintoni.us
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.markdown
24
+ files:
25
+ - gemspec.rb
26
+ - lib
27
+ - lib/secret_key.rb
28
+ - MIT-LICENSE
29
+ - Rakefile
30
+ - README.markdown
31
+ - secret_key.gemspec
32
+ - spec
33
+ - spec/secret_key_spec.rb
34
+ - spec/spec.opts
35
+ - spec/spec_helper.rb
36
+ has_rdoc: false
37
+ homepage: http://github.com/winton/secret_key
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: Provides an accessor for a secret key stored in tmp
62
+ test_files: []
63
+