vault 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +41 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +6 -0
  5. data/CHANGELOG.md +5 -0
  6. data/Gemfile +3 -0
  7. data/Gemfile.lock +32 -0
  8. data/LICENSE +362 -0
  9. data/README.md +80 -54
  10. data/Rakefile +4 -40
  11. data/lib/vault.rb +33 -46
  12. data/lib/vault/api.rb +9 -0
  13. data/lib/vault/api/auth_token.rb +90 -0
  14. data/lib/vault/api/help.rb +23 -0
  15. data/lib/vault/api/logical.rb +66 -0
  16. data/lib/vault/api/secret.rb +23 -0
  17. data/lib/vault/api/sys.rb +24 -0
  18. data/lib/vault/api/sys/audit.rb +60 -0
  19. data/lib/vault/api/sys/auth.rb +58 -0
  20. data/lib/vault/api/sys/init.rb +46 -0
  21. data/lib/vault/api/sys/leader.rb +25 -0
  22. data/lib/vault/api/sys/lease.rb +51 -0
  23. data/lib/vault/api/sys/mount.rb +75 -0
  24. data/lib/vault/api/sys/policy.rb +76 -0
  25. data/lib/vault/api/sys/seal.rb +49 -0
  26. data/lib/vault/client.rb +285 -0
  27. data/lib/vault/configurable.rb +48 -0
  28. data/lib/vault/defaults.rb +68 -0
  29. data/lib/vault/errors.rb +48 -0
  30. data/lib/vault/request.rb +19 -0
  31. data/lib/vault/response.rb +20 -0
  32. data/lib/vault/version.rb +1 -6
  33. data/vault.gemspec +25 -0
  34. metadata +97 -98
  35. data/MIT-LICENSE +0 -20
  36. data/lib/vault/associations.rb +0 -39
  37. data/lib/vault/attribute_accessors.rb +0 -29
  38. data/lib/vault/bulk_attributes.rb +0 -17
  39. data/lib/vault/dirty.rb +0 -37
  40. data/lib/vault/finders.rb +0 -24
  41. data/lib/vault/persistance.rb +0 -47
  42. data/lib/vault/properties.rb +0 -68
  43. data/lib/vault/scoping.rb +0 -64
  44. data/lib/vault/storage.rb +0 -4
  45. data/lib/vault/storage/in_memory_store.rb +0 -14
  46. data/lib/vault/storage/yaml_store.rb +0 -52
  47. data/lib/vault/validations.rb +0 -13
  48. data/spec/active_model_compliance_spec.rb +0 -33
  49. data/spec/spec_helper.rb +0 -8
  50. data/spec/support/helpers.rb +0 -16
  51. data/spec/support/storage_api.rb +0 -14
  52. data/spec/vault/associations_spec.rb +0 -73
  53. data/spec/vault/finders_spec.rb +0 -69
  54. data/spec/vault/persistance_spec.rb +0 -126
  55. data/spec/vault/properties_spec.rb +0 -59
  56. data/spec/vault/scoping_spec.rb +0 -53
  57. data/spec/vault/storage/in_memory_store_spec.rb +0 -5
  58. data/spec/vault/storage/yaml_store_spec.rb +0 -29
  59. data/spec/vault_spec.rb +0 -33
@@ -1,37 +0,0 @@
1
- module Vault
2
- module Dirty
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- include ActiveModel::Dirty
7
- end
8
-
9
- def save(*)
10
- super.tap do |saved|
11
- if saved
12
- if attribute_changed?(self.class.key)
13
- self.class.store.delete(attribute_was(self.class.key))
14
- end
15
-
16
- @previously_changed = changes
17
- changed_attributes.clear
18
- end
19
- end
20
- end
21
-
22
- def write_attribute(name, value)
23
- name = name.to_s
24
-
25
- if attribute_changed?(name)
26
- old = changed_attributes[name]
27
- changed_attributes.delete(name) if old == value
28
- else
29
- old = read_attribute(name)
30
- old = old.dup if old.duplicable?
31
- changed_attributes[name] = old if old != value
32
- end
33
-
34
- super(name, value)
35
- end
36
- end
37
- end
@@ -1,24 +0,0 @@
1
- module Vault
2
- module Finders
3
- delegate :size, :to => :store
4
- alias_method :count, :size
5
-
6
- def all(query={})
7
- query.delete(key)
8
- store.filter(query).map do |key_value, properties|
9
- build(key_value, properties)
10
- end
11
- end
12
-
13
- def [](key_value)
14
- properties = store[key_value]
15
- build(key_value, properties) if properties
16
- end
17
-
18
- private
19
-
20
- def build(key_value, properties)
21
- new(properties.update(key => key_value))
22
- end
23
- end
24
- end
@@ -1,47 +0,0 @@
1
- module Vault
2
- module Persistance
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- cattr_accessor :store
7
- extend Storage
8
-
9
- store_objects_in Vault::Storage::InMemoryStore.new
10
- end
11
-
12
- module Storage
13
- def store_objects_in(store)
14
- self.store = store
15
- end
16
- end
17
-
18
- def initialize(*)
19
- @_new = true
20
- @_destroyed = false
21
- super
22
- end
23
-
24
- def persisted?
25
- !@_new && !@_destroyed
26
- end
27
-
28
- def save(run_validations=true)
29
- return false if run_validations && !valid?
30
- self.class.store[key] = attributes_except_key
31
- @_new = false
32
- true
33
- end
34
-
35
- def destroy
36
- self.class.store.delete(key)
37
- @_destroyed = true
38
- freeze
39
- end
40
-
41
- private
42
-
43
- def attributes_except_key
44
- attributes.except(self.class.key)
45
- end
46
- end
47
- end
@@ -1,68 +0,0 @@
1
- module Vault
2
- module Properties
3
- def key(key=nil)
4
- return @_key if key.nil?
5
- @_key = property(key, true).name
6
- end
7
-
8
- def property(name, primary=false, &block)
9
- Property.new(name, primary, &block).tap do |prop|
10
- properties << prop
11
- define_property_methods(prop.name)
12
-
13
- # FIXME: Ugh, ActiveModel fails with this, I can't do incremental method
14
- # definition, you have to define them all at once (so undefine/define
15
- # each time if you don't know all the properties upfront, like here.)
16
- undefine_attribute_methods
17
- define_attribute_methods(property_names)
18
- end
19
- end
20
-
21
- def properties
22
- @_properties ||= Set.new
23
- end
24
-
25
- def property_names
26
- properties.map(&:name)
27
- end
28
-
29
- def define_property_methods(name)
30
- class_eval <<-ruby, __FILE__, __LINE__
31
- def #{name}
32
- read_attribute(:#{name})
33
- end
34
-
35
- def #{name}=(value)
36
- write_attribute(:#{name}, value)
37
- end
38
- ruby
39
- end
40
-
41
- class Property
42
- attr_reader :name
43
-
44
- def initialize(name, primary=false, &default)
45
- @name = name.to_s
46
- @default = default || lambda {}
47
- @primary = primary
48
- end
49
-
50
- def primary?
51
- @primary
52
- end
53
-
54
- def default
55
- @default.call
56
- end
57
-
58
- # Set requires both #hash and #eql? to check for inclusion
59
- def hash # :nodoc:
60
- name.hash
61
- end
62
-
63
- def eql?(other) # :nodoc:
64
- name == other.name
65
- end
66
- end
67
- end
68
- end
@@ -1,64 +0,0 @@
1
- module Vault
2
- module Scoping
3
- extend ActiveSupport::Concern
4
-
5
- def scopes
6
- @_scopes ||= Hash.new
7
- end
8
-
9
- def scope(name, &conditions)
10
- name = name.to_s
11
- scopes[name] = Scope.new(self, conditions.call)
12
- define_scope_method(name)
13
- end
14
-
15
- private
16
-
17
- def define_scope_method(name)
18
- singleton_class.instance_eval do
19
- define_method name do
20
- scopes[name]
21
- end
22
- end
23
- end
24
-
25
- class Scope
26
- include Finders
27
-
28
- delegate :new, :key, :model_name, :to => :model
29
-
30
- attr_reader :conditions, :model
31
-
32
- def initialize(model, conditions)
33
- @model = model
34
- @conditions = conditions.stringify_keys
35
- end
36
-
37
- def store
38
- @store ||= @model.store.filter(conditions)
39
- end
40
-
41
- def method_missing(method, *)
42
- if model_has_scope?(method)
43
- merge(model.scopes[method.to_s])
44
- else
45
- super
46
- end
47
- end
48
-
49
- def respond_to?(method, include_private=false)
50
- model_has_scope?(method) || super
51
- end
52
-
53
- private
54
-
55
- def model_has_scope?(name)
56
- model.scopes.include?(name.to_s)
57
- end
58
-
59
- def merge(scope)
60
- Scope.new(model, conditions.merge(scope.conditions))
61
- end
62
- end
63
- end
64
- end
@@ -1,4 +0,0 @@
1
- module Vault
2
- module Storage
3
- end
4
- end
@@ -1,14 +0,0 @@
1
- module Vault
2
- module Storage
3
- class InMemoryStore < Hash
4
- def filter(query)
5
- return self if query.blank?
6
-
7
- inject(InMemoryStore.new) do |result, (key, properties)|
8
- result[key] = properties if properties.merge(query) == properties
9
- result
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,52 +0,0 @@
1
- require "yaml"
2
- require "active_support/core_ext/module/delegation"
3
-
4
- module Vault
5
- module Storage
6
- class YamlStore
7
- include Enumerable
8
-
9
- delegate :[], :[]=, :size, :each, :delete, :to => :doc
10
-
11
- def initialize(file=nil)
12
- @file = file
13
- at_exit { flush if @file.present? }
14
- end
15
-
16
- def initialize_copy(*)
17
- @file = nil
18
- end
19
-
20
- def filter(query)
21
- return filtered_copy(@doc) if query.blank?
22
-
23
- results = doc.inject(ActiveSupport::OrderedHash.new) do |result, (key, properties)|
24
- result[key] = properties if properties.merge(query) == properties
25
- result
26
- end
27
-
28
- filtered_copy(results)
29
- end
30
-
31
- def flush
32
- File.open(@file, "w+") {|f| YAML.dump(@doc, f) }
33
- end
34
-
35
- protected
36
-
37
- def doc=(doc)
38
- @doc = doc
39
- end
40
-
41
- private
42
-
43
- def filtered_copy(doc)
44
- dup.tap {|store| store.doc = doc }
45
- end
46
-
47
- def doc
48
- @doc ||= ActiveSupport::OrderedHash.new(YAML.load_file(@file))
49
- end
50
- end
51
- end
52
- end
@@ -1,13 +0,0 @@
1
- module Vault
2
- module Validations
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- include ActiveModel::Validations
7
- end
8
-
9
- def errors
10
- @_errors ||= ActiveModel::Errors.new
11
- end
12
- end
13
- end
@@ -1,33 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "ActiveModel compliance" do
4
- class Person
5
- include Vault
6
-
7
- key :id
8
- property :first_name
9
- property :last_name
10
- end
11
-
12
- include ActiveModel::Lint::Tests
13
-
14
- instance_methods.grep(/^test_/).each do |method|
15
- it method.gsub("_", " ").gsub(/to (\w+)/, 'to_\1') do
16
- send method
17
- end
18
- end
19
-
20
- private
21
-
22
- def model
23
- Person.new
24
- end
25
-
26
- def assert(cond, msg=nil)
27
- flunk msg unless cond
28
- end
29
-
30
- def assert_kind_of(kind, object, msg=nil)
31
- flunk msg unless object.kind_of?(kind)
32
- end
33
- end
@@ -1,8 +0,0 @@
1
- require "spec"
2
- require "vault"
3
-
4
- Dir["spec/support/**/*.rb"].each {|f| require f }
5
-
6
- Spec::Runner.configure do |config|
7
- config.include SpecHelpers
8
- end
@@ -1,16 +0,0 @@
1
- module SpecHelpers
2
- def model(&block)
3
- Class.new do
4
- include Vault
5
- class_eval(&block) if block
6
- end
7
- end
8
-
9
- def named_model(name, &block)
10
- model = model(&block)
11
- self.class.class_eval do
12
- remove_const(name) if const_defined?(name)
13
- const_set(name, model)
14
- end
15
- end
16
- end
@@ -1,14 +0,0 @@
1
- shared_examples_for "A storage adapter" do
2
- it { should respond_to(:size) }
3
- it { should respond_to(:delete) }
4
- it { should respond_to(:[]) }
5
- it { should respond_to(:[]=) }
6
-
7
- it { should respond_to(:each) }
8
- it { should be_an(Enumerable) }
9
-
10
- it { should respond_to(:filter) }
11
- it "is closed under #filter" do
12
- subject.filter({}).should be_a(described_class)
13
- end
14
- end
@@ -1,73 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Vault, "model" do
4
- class Book
5
- include Vault
6
- key :title
7
- has_many :authors
8
- end
9
-
10
- class Author
11
- include Vault
12
- key :name
13
- belongs_to :book
14
- end
15
-
16
- let(:pickaxe_book) { Book.new(:title => "Programming Ruby") }
17
-
18
- let(:dave_thomas) { Author.new(:name => "Dave Thomas") }
19
- let(:chad_fowler) { Author.new(:name => "Chad Fowler") }
20
- let(:andy_hunt) { Author.new(:name => "Andy Hunt") }
21
- let(:sam_ruby) { Author.new(:name => "Sam Ruby") }
22
-
23
- describe ".belongs_to" do
24
- before do
25
- dave_thomas.save
26
- pickaxe_book.save
27
- end
28
-
29
- it "can assign the associated object directly" do
30
- dave_thomas.book = pickaxe_book
31
- dave_thomas.book.should == pickaxe_book
32
- end
33
-
34
- it "can assign the key" do
35
- dave_thomas.book_key = pickaxe_book.key
36
- dave_thomas.book.should == pickaxe_book
37
- end
38
- end
39
-
40
- describe ".has_many" do
41
- before do
42
- dave_thomas.book = pickaxe_book
43
- chad_fowler.book = pickaxe_book
44
-
45
- dave_thomas.save
46
- chad_fowler.save
47
-
48
- pickaxe_book.save
49
- end
50
-
51
- subject { pickaxe_book.authors.all }
52
-
53
- it "can find all associated objects" do
54
- should include(dave_thomas, chad_fowler)
55
- end
56
-
57
- it "doesn't find objects that haven't been associated to the model" do
58
- should_not include(sam_ruby)
59
- end
60
-
61
- context "adding objects directly to the association" do
62
- it "persists both the container and containee" do
63
- pickaxe_book.authors << andy_hunt
64
- should include(andy_hunt)
65
- end
66
-
67
- it "can chain additions" do
68
- pickaxe_book.authors << andy_hunt << sam_ruby
69
- should include(andy_hunt, sam_ruby)
70
- end
71
- end
72
- end
73
- end