dbag 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rvmrc +1 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +20 -0
- data/README.md +42 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/dbag/client.rb +82 -0
- data/lib/dbag.rb +7 -0
- data/test/helper.rb +18 -0
- data/test/test_dbag.rb +8 -0
- metadata +197 -0
data/.document
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ree-1.8.7-2012.02@dbag --create
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.7)
|
5
|
+
i18n (~> 0.6)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
git (1.2.5)
|
8
|
+
httparty (0.8.3)
|
9
|
+
multi_json (~> 1.0)
|
10
|
+
multi_xml
|
11
|
+
i18n (0.6.0)
|
12
|
+
jeweler (1.8.4)
|
13
|
+
bundler (~> 1.0)
|
14
|
+
git (>= 1.2.5)
|
15
|
+
rake
|
16
|
+
rdoc
|
17
|
+
json (1.7.4)
|
18
|
+
multi_json (1.3.6)
|
19
|
+
multi_xml (0.5.1)
|
20
|
+
rake (0.9.2.2)
|
21
|
+
rcov (1.0.0)
|
22
|
+
rdoc (3.12)
|
23
|
+
json (~> 1.4)
|
24
|
+
shoulda (3.1.1)
|
25
|
+
shoulda-context (~> 1.0)
|
26
|
+
shoulda-matchers (~> 1.2)
|
27
|
+
shoulda-context (1.0.0)
|
28
|
+
shoulda-matchers (1.2.0)
|
29
|
+
activesupport (>= 3.0.0)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
bundler (~> 1.1.3)
|
36
|
+
httparty
|
37
|
+
jeweler (~> 1.8.4)
|
38
|
+
rcov
|
39
|
+
rdoc (~> 3.12)
|
40
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Oliver Kiessler
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# dbag
|
2
|
+
|
3
|
+
Client library to fetch and manage data bags from a server. Databags can be used for settings, app configurations and arbitrary json data.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install dbag
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
require "lib/dbag";
|
12
|
+
client = Dbag::Client.new("http://YOUR_ENDPOINT", "YOUR AUTH TOKEN")
|
13
|
+
|
14
|
+
data_bag = client.find("YOUR DATA BAG KEY")
|
15
|
+
data_bags = client.all
|
16
|
+
|
17
|
+
client.to_file(data_bag, "/your/path/your_file.json")
|
18
|
+
client.to_file(data_bag, "/your/path/your_file.yml", :yaml)
|
19
|
+
|
20
|
+
encrypted_on_server = false
|
21
|
+
|
22
|
+
new_data_bag = {"foo" => "bar", "baz" => "foo"}
|
23
|
+
client.create("NEW DATA BAG KEY", new_data_bag, encrypted_on_server)
|
24
|
+
new_data_bag["foo"] = "bar2"
|
25
|
+
client.update("NEW DATA BAG KEY", new_data_bag, encrypted_on_server)
|
26
|
+
|
27
|
+
data_bag2 = client.from_file("NEW DATA BAG KEY 2", "/your/path/the_file_to_store.json", encrypted_on_server)
|
28
|
+
data_bag3 = client.from_file("NEW DATA BAG KEY 3", "/path/some.yml", encrypted_on_server, :yaml)
|
29
|
+
|
30
|
+
## Contributing to dbag
|
31
|
+
|
32
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
33
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
34
|
+
* Fork the project.
|
35
|
+
* Start a feature/bugfix branch.
|
36
|
+
* Commit and push until you are happy with your contribution.
|
37
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
38
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
39
|
+
|
40
|
+
## Copyright
|
41
|
+
|
42
|
+
Copyright (c) 2012 Oliver Kiessler. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "dbag"
|
18
|
+
gem.homepage = "http://github.com/okiess/dbag"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "Client for a Data Bag server"
|
21
|
+
gem.description = "Client library to fetch and manage data bags from a server. Databags can be used for settings, app configurations and arbitrary json data."
|
22
|
+
gem.email = "kiessler@inceedo.com"
|
23
|
+
gem.authors = ["Oliver Kiessler"]
|
24
|
+
gem.add_dependency "httparty", ">= 0.8.3"
|
25
|
+
gem.add_dependency "multi_json", ">= 1.3.6"
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
test.rcov_opts << '--exclude "gems/*"'
|
42
|
+
end
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rdoc/task'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "dbag #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/dbag/client.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
module Dbag
|
2
|
+
class Client
|
3
|
+
include HTTParty
|
4
|
+
attr_accessor :base_url, :auth_token, :logger, :log_level
|
5
|
+
|
6
|
+
def initialize(base_url, auth_token)
|
7
|
+
self.base_url = base_url
|
8
|
+
self.auth_token = auth_token
|
9
|
+
self.logger = Logger.new(STDOUT)
|
10
|
+
self.logger.level = (self.log_level || Logger::DEBUG)
|
11
|
+
end
|
12
|
+
|
13
|
+
def all
|
14
|
+
if (response = get_response(:get, '/data_bags.json')).response.is_a?(Net::HTTPOK)
|
15
|
+
response.parsed_response
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def find(key)
|
20
|
+
if (response = get_response(:get, "/data_bags/#{key}.json")).response.is_a?(Net::HTTPOK)
|
21
|
+
JSON.parse(response.parsed_response["bag_string"])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def create(key, data_bag = {}, encrypted = false)
|
26
|
+
raise "Invalid Databag!" unless key or data_bag
|
27
|
+
response = get_response(:post, '/data_bags.json',
|
28
|
+
{:body => {:data_bag => {:key => key, :bag_string_clear => data_bag.to_json,
|
29
|
+
:encrypted => encrypted}}})
|
30
|
+
end
|
31
|
+
|
32
|
+
def update(key, data_bag = {}, encrypted = false)
|
33
|
+
raise "Invalid Databag!" unless key or data_bag
|
34
|
+
response = get_response(:put, "/data_bags/#{key}.json",
|
35
|
+
{:body => {:data_bag => {:bag_string_clear => data_bag.to_json,
|
36
|
+
:encrypted => encrypted}}})
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_file(hash, path, format = :json)
|
40
|
+
File.open(path, "w") do |f|
|
41
|
+
if format == :json
|
42
|
+
f.write(JSON.pretty_generate(hash))
|
43
|
+
elsif format == :yaml
|
44
|
+
f.write(hash.to_yaml)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def from_file(new_key, path, encrypted = false, format = :json)
|
50
|
+
File.open(path, "r" ) do |f|
|
51
|
+
if format == :json
|
52
|
+
if (json = JSON.load(f))
|
53
|
+
create(new_key, json, encrypted)
|
54
|
+
end
|
55
|
+
elsif format == :yaml
|
56
|
+
if (yaml = YAML.load_file(path))
|
57
|
+
create(new_key, yaml, encrypted)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
def get_response(http_verb, endpoint, options = {})
|
65
|
+
begin
|
66
|
+
endpoint_value = "#{self.base_url}#{URI.escape(endpoint)}?auth_token=#{self.auth_token}"
|
67
|
+
logger.debug("Using endpoint: #{endpoint_value}")
|
68
|
+
body = {}; body.merge!(options) if options and options.any?
|
69
|
+
if http_verb == :post or http_verb == :put
|
70
|
+
logger.debug("Body: #{body.inspect}")
|
71
|
+
response = HTTParty.send(http_verb, endpoint_value, body)
|
72
|
+
else
|
73
|
+
response = HTTParty.send(http_verb, endpoint_value)
|
74
|
+
end
|
75
|
+
logger.debug("Response: #{response.inspect}") if response
|
76
|
+
response
|
77
|
+
rescue => e
|
78
|
+
logger.error("Could not connect to backend: #{e.message}")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/dbag.rb
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'dbag'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
data/test/test_dbag.rb
ADDED
metadata
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dbag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Oliver Kiessler
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-08-04 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
version_requirements: *id001
|
31
|
+
name: httparty
|
32
|
+
prerelease: false
|
33
|
+
type: :runtime
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 3
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
version_requirements: *id002
|
45
|
+
name: shoulda
|
46
|
+
prerelease: false
|
47
|
+
type: :development
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 31
|
55
|
+
segments:
|
56
|
+
- 3
|
57
|
+
- 12
|
58
|
+
version: "3.12"
|
59
|
+
version_requirements: *id003
|
60
|
+
name: rdoc
|
61
|
+
prerelease: false
|
62
|
+
type: :development
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 21
|
70
|
+
segments:
|
71
|
+
- 1
|
72
|
+
- 1
|
73
|
+
- 3
|
74
|
+
version: 1.1.3
|
75
|
+
version_requirements: *id004
|
76
|
+
name: bundler
|
77
|
+
prerelease: false
|
78
|
+
type: :development
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 63
|
86
|
+
segments:
|
87
|
+
- 1
|
88
|
+
- 8
|
89
|
+
- 4
|
90
|
+
version: 1.8.4
|
91
|
+
version_requirements: *id005
|
92
|
+
name: jeweler
|
93
|
+
prerelease: false
|
94
|
+
type: :development
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
version_requirements: *id006
|
106
|
+
name: rcov
|
107
|
+
prerelease: false
|
108
|
+
type: :development
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: 57
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
- 8
|
119
|
+
- 3
|
120
|
+
version: 0.8.3
|
121
|
+
version_requirements: *id007
|
122
|
+
name: httparty
|
123
|
+
prerelease: false
|
124
|
+
type: :runtime
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 23
|
132
|
+
segments:
|
133
|
+
- 1
|
134
|
+
- 3
|
135
|
+
- 6
|
136
|
+
version: 1.3.6
|
137
|
+
version_requirements: *id008
|
138
|
+
name: multi_json
|
139
|
+
prerelease: false
|
140
|
+
type: :runtime
|
141
|
+
description: Client library to fetch and manage data bags from a server. Databags can be used for settings, app configurations and arbitrary json data.
|
142
|
+
email: kiessler@inceedo.com
|
143
|
+
executables: []
|
144
|
+
|
145
|
+
extensions: []
|
146
|
+
|
147
|
+
extra_rdoc_files:
|
148
|
+
- LICENSE.txt
|
149
|
+
- README.md
|
150
|
+
files:
|
151
|
+
- .document
|
152
|
+
- .rvmrc
|
153
|
+
- Gemfile
|
154
|
+
- Gemfile.lock
|
155
|
+
- LICENSE.txt
|
156
|
+
- README.md
|
157
|
+
- Rakefile
|
158
|
+
- VERSION
|
159
|
+
- lib/dbag.rb
|
160
|
+
- lib/dbag/client.rb
|
161
|
+
- test/helper.rb
|
162
|
+
- test/test_dbag.rb
|
163
|
+
homepage: http://github.com/okiess/dbag
|
164
|
+
licenses:
|
165
|
+
- MIT
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
none: false
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
hash: 3
|
177
|
+
segments:
|
178
|
+
- 0
|
179
|
+
version: "0"
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
none: false
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
hash: 3
|
186
|
+
segments:
|
187
|
+
- 0
|
188
|
+
version: "0"
|
189
|
+
requirements: []
|
190
|
+
|
191
|
+
rubyforge_project:
|
192
|
+
rubygems_version: 1.8.24
|
193
|
+
signing_key:
|
194
|
+
specification_version: 3
|
195
|
+
summary: Client for a Data Bag server
|
196
|
+
test_files: []
|
197
|
+
|