nimbussecure 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
+ .idea
2
3
  .bundle
3
4
  Gemfile.lock
4
5
  binstubs
data/README.md CHANGED
@@ -70,34 +70,34 @@ setup service, you can dynamically grab all your sensitive credentials
70
70
  and data needed to run your application. This typically happens during
71
71
  your application boot up process.
72
72
 
73
- # Setting up your .nibmussecure.yml file:
74
- The easiest way to setup Nimbus Secure is to setup a configuration file in your home directory.
75
- This file will contain sensitive information, so it should be marked as readable to you only
76
- (permission mode 400). The following is a sample configuration file:
73
+ # Setup
74
+ For a complete set of instructions on how to setup and use Nimbus Secure,
75
+ please go to https://www.nimbussecure.com, login, and click on "Instructions"
76
+ in the top menu bar.
77
77
 
78
- account: <my_account_id>
79
- apikey: <my_accounts_apikey>
80
- crypt_keys:
81
- key1: <my_secret_value_for_key1>
82
- key2: <my_secret_value_for_key2>
78
+ # Command Line
79
+ You must complete the set of instructions under 'Setup' above for this to work
80
+ properly.
83
81
 
84
- The value "<my_account_id>" is the same value that appears in the base part of your URL you use to
85
- access Nmbus Secure. So, for example, if the URL you use to access Nimbus Secure is this:
82
+ Once ready, you can do things like this:
86
83
 
87
- https://www.nimbussecure.com/myaccount
84
+ nimbussecure account
88
85
 
89
- Then your account id is "myaccount". Your "apikey" can be retrieved from the "Api Keys" tab in
90
- Nimbus Secure.
86
+ will return a list of information about your account.
91
87
 
92
- For each encryption key you have in your account and you wish to use, you must have a line in the
93
- "crypt_keys:"" section of the config file. In the above example, "key1" is the name assigned to the
94
- first encryption key, and "<my_secret_value_for_key1>" is the secret value you assigned when
95
- you created this encryption key.
88
+ Assuming you have a stored key with a name "testmessage" setup, with an approprate encryption key.
89
+ Then the following can be used to retrieve and decrypt a stored key:
90
+
91
+ nimbussecure lookup testmessage
92
+
93
+ The decrypted value in the stored key will be sent to stdout.
96
94
 
97
95
  # Using in Ruby
96
+ You must complete the set of instructions under 'Setup' above for this to work
97
+ properly.
98
+
98
99
  Assuming you have a stored key with a name "testmessage" setup, with an approprate encryption key.
99
- Also assuming your ~/.nimbussecure.yml file is setup with your account identifier, API Key,
100
- and the encryption key value. Then the following can be used to retrieve and decrypt a stored key:
100
+ Then the following can be used to retrieve and decrypt a stored key:
101
101
 
102
102
  require 'nimbussecure'
103
103
  stored_value=nimbussecure.lookup_value "testmessage"
data/Rakefile CHANGED
@@ -1,6 +1,21 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
- desc "Run all tests"
4
- task :test do
5
- require "#{File.dirname(Pathname.new(File.expand_path(__FILE__)).realpath.to_s).to_s}/test/run_tests.rb"
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Default: run specs.'
7
+ task :default => :spec
8
+
9
+ desc "Run specs"
10
+ RSpec::Core::RakeTask.new do |t|
11
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
12
+ # Put spec opts in a file named .rspec in root
6
13
  end
14
+
15
+ desc "Generate code coverage"
16
+ RSpec::Core::RakeTask.new(:coverage) do |t|
17
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
18
+ t.rcov = true
19
+ t.rcov_opts = ['--exclude', 'spec']
20
+ end
21
+
data/bin/nimbussecure CHANGED
@@ -42,6 +42,8 @@ NOTE:
42
42
  This is a set of key/value pairs. The key is the name as defined in your
43
43
  Nimbus Secure \"Encryption Keys\" section, and the value is the secret value
44
44
  you used when you created your encryption key.
45
+
46
+ Version: #{NimbusSecure::VERSION}
45
47
  "
46
48
  exit 1
47
49
  end
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
4
+ require 'nimbussecure'
5
+ #
6
+ #
7
+ # This program will create a new ~/.nimbussecure.yml file (or equivalent in a different filename).
8
+ #
9
+ #
10
+ def usage
11
+ puts "
12
+ Usage:
13
+ nimbussecure_setup <account_id> <apikey> [filename]
14
+
15
+ This program will generate a default ~/.nimbussecure.yml file for use by the Nimbus Secure
16
+ Gem. It will fill in all the basic information needed, and will access Nimbus Secure to get
17
+ a complete list of your encryption keys, adding a line for each.
18
+
19
+ See https://www.nimbussecure.com for more information.
20
+
21
+ NOTE:
22
+ account_id:
23
+ The account ident can be found based on the URL you use to access Nimbus Secure. If your URL is:
24
+
25
+ https://www.nimbussecure.com/my_acct/
26
+
27
+ Then the <account_id> value to use should be \"my_acct\"
28
+ apikey:
29
+ You can find your API Key by clicking on \"API Keys\" when you are logged into
30
+ the Nimbus Secure website.
31
+ filename:
32
+ Optional filename to store the configuration file to. The default is ~/.nimbussecure.yml.
33
+ "
34
+ exit 1
35
+ end
36
+
37
+
38
+ def main
39
+ usage unless (ARGV.size==2) or (ARGV.size==3)
40
+ filename="~/.nimbussecure.yml"
41
+ filename=ARGV[2] if ARGV.size==3
42
+
43
+ expand_file=File.expand_path filename
44
+ setup_file expand_file,ARGV[0],ARGV[1]
45
+ end
46
+
47
+ #
48
+ # Create New File
49
+ #
50
+ def setup_file filename,account_id,apikey
51
+ crypt_key_hash_list={}
52
+ existing_content=read_old_config_file filename
53
+ if existing_content
54
+ if existing_content["account"]!=account_id or existing_content["apikey"]!=apikey
55
+ puts "ERROR: There is an existing file that refers to a different account or API Key."
56
+ exit 1
57
+ end
58
+ crypt_key_hash_list=existing_content["crypt_keys"]
59
+ end
60
+
61
+
62
+ ns=NimbusSecure.new account: account_id,apikey: apikey
63
+ crypt_keys=ns.crypt_keys
64
+ unless ns.success? and crypt_keys
65
+ puts "Error: #{ns.last_error_message}"
66
+ exit 1
67
+ end
68
+
69
+ ns.crypt_keys.each do |ck|
70
+ crypt_key_hash_list[ck.ident.to_s]||=nil
71
+ end
72
+
73
+
74
+
75
+ content=config_file_contents account_id,apikey,crypt_key_hash_list
76
+ if File.exists?(filename)
77
+ newfilename=filename+"_old#{Time.now.to_i}"
78
+ puts "Moved existing file to #{newfilename}"
79
+ File.rename filename,newfilename
80
+ end
81
+ File.open filename, File::CREAT|File::TRUNC|File::RDWR, 0644 do |f|
82
+ f.write content+"\n"
83
+ end
84
+ puts "Created #{filename}"
85
+ end
86
+
87
+
88
+ #
89
+ # Get old content if it exists
90
+ #
91
+ def read_old_config_file filename
92
+ return nil unless File.exist?(filename)
93
+ content=File.read(filename)
94
+ unless content
95
+ puts "The Configuration file is invalid: #{filename}"
96
+ exit 1
97
+ end
98
+ YAML.load(content)
99
+ end
100
+
101
+ #
102
+ # Create a configuration file from specified parameters
103
+ #
104
+ def config_file_contents account_id,apikey,crypt_key_hash_list
105
+ content=[]
106
+ content<<"#"
107
+ content<<"# Nimbus Secure Configuration File"
108
+ content<<"# https://www.nimbussecure.com"
109
+ content<<"# This file was auto-generated on: #{Time.now.strftime '%b %e, %Y %H:%M:%S %Z'}"
110
+ content<<"# Nimbus Secure Client Version Number: #{NimbusSecure::VERSION}"
111
+ content<<"#"
112
+ content<<"account: #{account_id}"
113
+ content<<"apikey: #{apikey}"
114
+ #
115
+ # See if we have any secret values setup...
116
+ #
117
+ any_values=false
118
+ crypt_key_hash_list.each do |key,value|
119
+ any_values=true unless value.nil?
120
+ end
121
+ if any_values
122
+ content<<"#"
123
+ content<<"# Note: Please fill in any remaining crypt key secret values yourself."
124
+ content<<"#"
125
+ else
126
+ content<<"#"
127
+ content<<"# Note: The crypt key names are filled in here, but you must add the"
128
+ content<<"# crypt key secret values yourself."
129
+ content<<"#"
130
+ end
131
+ content<<"crypt_keys:"
132
+ crypt_key_hash_list.each do |key,value|
133
+ content<<" #{key}: #{value||"<put secret value here>"}"
134
+ end
135
+ content.join("\n")
136
+ end
137
+
138
+ main
@@ -7,7 +7,7 @@ class NimbusSecure
7
7
  @endpoint="https://www.nimbussecure.com"
8
8
  end
9
9
  def invalid?
10
- endpoint.nil? || account.nil? || apikey.nil? || crypt_keys.size==0
10
+ endpoint.nil? || account.nil? || apikey.nil?
11
11
  end
12
12
  def valid?
13
13
  !invalid?
@@ -57,6 +57,7 @@ class NimbusSecure
57
57
  #
58
58
  def crypt_keys
59
59
  res=request_get "/crypt_keys"
60
+ return nil unless res
60
61
  @cached_crypt_keys=res["crypt_keys"].map{|key|NimbusSecure::CryptKey.new self,key}
61
62
  end
62
63
  def crypt_keys_from_cache
@@ -1,3 +1,3 @@
1
1
  class NimbusSecure
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
data/nimbussecure.gemspec CHANGED
@@ -18,7 +18,9 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_development_dependency "minitest"
21
+ #s.add_development_dependency "minitest"
22
+ #s.add_development_dependency "minitest-reporters"
23
+ s.add_development_dependency "rspec"
22
24
  s.add_development_dependency "vcr"
23
25
  s.add_development_dependency "fakeweb"
24
26
  s.add_runtime_dependency "faraday"
@@ -1,6 +1,6 @@
1
- require 'minitest_helper'
1
+ require 'spec_helper'
2
2
 
3
- describe NimbusSecure::Account do
3
+ describe "NimbusSecure::Account" do
4
4
  before do
5
5
  @ns=NimbusSecure.new({endpoint: "http://localhost:3000",
6
6
  account: "vcrtest",
@@ -10,9 +10,9 @@ describe NimbusSecure::Account do
10
10
  it "should get a list of all accounts (when there is just one)" do
11
11
  VCR.use_cassette "accounts/test" do
12
12
  acct=@ns.account
13
- acct.name.must_equal "VCR Account"
14
- acct.num_crypt_keys.must_equal 23
15
- acct.num_stored_keys.must_equal 34
13
+ acct.name.should eq "VCR Account"
14
+ acct.num_crypt_keys.should eq 23
15
+ acct.num_stored_keys.should eq 34
16
16
  end
17
17
  end
18
18
  end
@@ -1,4 +1,4 @@
1
- require 'minitest_helper'
1
+ require 'spec_helper'
2
2
  describe "Key Lookup" do
3
3
  before do
4
4
  @ns=NimbusSecure.new({endpoint: "http://localhost:3000",
@@ -8,22 +8,22 @@ describe "Key Lookup" do
8
8
  end
9
9
  it "should be able to lookup a key and decrypt it" do
10
10
  VCR.use_cassette "lookup/key1" do
11
- @ns.lookup_value(:test1).must_equal "This is a test stored key"
11
+ @ns.lookup_value(:test1).should eq "This is a test stored key"
12
12
  end
13
13
  end
14
14
  it "should be able to lookup a second key and decrypt it" do
15
15
  VCR.use_cassette "lookup/key2" do
16
- code=@ns.lookup_value(:test1).must_equal "This is a test stored key"
17
- code=@ns.lookup_value(:test2).must_equal "This is another test stored key"
16
+ code=@ns.lookup_value(:test1).should eq "This is a test stored key"
17
+ code=@ns.lookup_value(:test2).should eq "This is another test stored key"
18
18
  end
19
19
  end
20
20
  it "should be able to fail gracefully if key is not found" do
21
21
  VCR.use_cassette "lookup/key3" do
22
22
  code=@ns.lookup_value :invalidkey
23
- code.must_be_nil
24
- @ns.success?.must_equal false
25
- @ns.last_error_message.must_equal "Could not locate Stored Key invalidkey"
26
- @ns.last_error_details.must_be_nil
23
+ code.should be_nil
24
+ @ns.success?.should eq false
25
+ @ns.last_error_message.should eq "Could not locate Stored Key invalidkey"
26
+ @ns.last_error_details.should be_nil
27
27
  end
28
28
  end
29
29
  end
@@ -0,0 +1,17 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require 'vcr'
4
+ require 'nimbussecure'
5
+
6
+ root_dir=File.expand_path("../..", __FILE__)
7
+ Dir["#{root_dir}spec/support/**/*.rb"].each {|f| require f}
8
+
9
+ RSpec.configure do |config|
10
+ config.mock_with :rspec
11
+ end
12
+
13
+ VCR.configure do |c|
14
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
15
+ c.hook_into :fakeweb
16
+ # c.stub_with :fakeweb
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nimbussecure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-02 00:00:00.000000000 Z
12
+ date: 2012-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: minitest
16
- requirement: &70236373001520 !ruby/object:Gem::Requirement
15
+ name: rspec
16
+ requirement: &70345215642340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70236373001520
24
+ version_requirements: *70345215642340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: vcr
27
- requirement: &70236373001100 !ruby/object:Gem::Requirement
27
+ requirement: &70345215641920 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70236373001100
35
+ version_requirements: *70345215641920
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: fakeweb
38
- requirement: &70236373000680 !ruby/object:Gem::Requirement
38
+ requirement: &70345215641480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70236373000680
46
+ version_requirements: *70345215641480
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: faraday
49
- requirement: &70236373000240 !ruby/object:Gem::Requirement
49
+ requirement: &70345215641000 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70236373000240
57
+ version_requirements: *70345215641000
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: gibberish
60
- requirement: &70236372999780 !ruby/object:Gem::Requirement
60
+ requirement: &70345215640540 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,12 +65,13 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70236372999780
68
+ version_requirements: *70345215640540
69
69
  description: Client library for NimbusSecure
70
70
  email:
71
71
  - lee@nimbussecure.com
72
72
  executables:
73
73
  - nimbussecure
74
+ - nimbussecure_setup
74
75
  extensions: []
75
76
  extra_rdoc_files: []
76
77
  files:
@@ -79,6 +80,7 @@ files:
79
80
  - README.md
80
81
  - Rakefile
81
82
  - bin/nimbussecure
83
+ - bin/nimbussecure_setup
82
84
  - lib/nimbussecure.rb
83
85
  - lib/nimbussecure/accounts.rb
84
86
  - lib/nimbussecure/attr_accessor.rb
@@ -92,14 +94,13 @@ files:
92
94
  - lib/nimbussecure/version.rb
93
95
  - nimbussecure.gemspec
94
96
  - pry_load.rb
95
- - test/accounts_spec.rb
96
- - test/basic_key_lookup_spec.rb
97
- - test/fixtures/vcr_cassettes/accounts/test.yml
98
- - test/fixtures/vcr_cassettes/lookup/key1.yml
99
- - test/fixtures/vcr_cassettes/lookup/key2.yml
100
- - test/fixtures/vcr_cassettes/lookup/key3.yml
101
- - test/minitest_helper.rb
102
- - test/run_tests.rb
97
+ - spec/fixtures/vcr_cassettes/accounts/test.yml
98
+ - spec/fixtures/vcr_cassettes/lookup/key1.yml
99
+ - spec/fixtures/vcr_cassettes/lookup/key2.yml
100
+ - spec/fixtures/vcr_cassettes/lookup/key3.yml
101
+ - spec/requests/accounts_spec.rb
102
+ - spec/requests/basic_key_lookup_spec.rb
103
+ - spec/spec_helper.rb
103
104
  homepage: ''
104
105
  licenses: []
105
106
  post_install_message:
@@ -125,11 +126,10 @@ signing_key:
125
126
  specification_version: 3
126
127
  summary: Client library for NimbusSecure
127
128
  test_files:
128
- - test/accounts_spec.rb
129
- - test/basic_key_lookup_spec.rb
130
- - test/fixtures/vcr_cassettes/accounts/test.yml
131
- - test/fixtures/vcr_cassettes/lookup/key1.yml
132
- - test/fixtures/vcr_cassettes/lookup/key2.yml
133
- - test/fixtures/vcr_cassettes/lookup/key3.yml
134
- - test/minitest_helper.rb
135
- - test/run_tests.rb
129
+ - spec/fixtures/vcr_cassettes/accounts/test.yml
130
+ - spec/fixtures/vcr_cassettes/lookup/key1.yml
131
+ - spec/fixtures/vcr_cassettes/lookup/key2.yml
132
+ - spec/fixtures/vcr_cassettes/lookup/key3.yml
133
+ - spec/requests/accounts_spec.rb
134
+ - spec/requests/basic_key_lookup_spec.rb
135
+ - spec/spec_helper.rb
@@ -1,10 +0,0 @@
1
- $LOAD_PATH << File.dirname(File.expand_path(__FILE__).to_s).to_s+"/../lib/"
2
- require 'minitest/autorun'
3
- require 'vcr'
4
- require 'nimbussecure'
5
-
6
- VCR.configure do |c|
7
- c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
8
- c.hook_into :fakeweb
9
- # c.stub_with :fakeweb
10
- end
data/test/run_tests.rb DELETED
@@ -1,6 +0,0 @@
1
- require 'minitest/autorun'
2
- test_dir_root=File.dirname(Pathname.new(File.expand_path(__FILE__)).realpath.to_s).to_s
3
- $LOAD_PATH << test_dir_root
4
- FileList["#{test_dir_root}/*_spec.rb"].each do |file|
5
- require file
6
- end