fog-riakcs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.hound.yml +20 -0
  4. data/.rubocop.yml +20 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +17 -0
  8. data/CONTRIBUTING.md +18 -0
  9. data/CONTRIBUTORS.md +10 -0
  10. data/Gemfile +4 -0
  11. data/LICENSE.md +20 -0
  12. data/README.md +38 -0
  13. data/Rakefile +18 -0
  14. data/fog-riakcs.gemspec +36 -0
  15. data/gemfiles/Gemfile.1.9.2- +8 -0
  16. data/gemfiles/Gemfile.1.9.3+ +7 -0
  17. data/lib/fog/riakcs.rb +17 -0
  18. data/lib/fog/riakcs/multipart_utils.rb +45 -0
  19. data/lib/fog/riakcs/multipart_utils/headers.rb +33 -0
  20. data/lib/fog/riakcs/provisioning.rb +97 -0
  21. data/lib/fog/riakcs/provisioning/create_user.rb +77 -0
  22. data/lib/fog/riakcs/provisioning/disable_user.rb +23 -0
  23. data/lib/fog/riakcs/provisioning/enable_user.rb +23 -0
  24. data/lib/fog/riakcs/provisioning/get_user.rb +41 -0
  25. data/lib/fog/riakcs/provisioning/list_users.rb +43 -0
  26. data/lib/fog/riakcs/provisioning/regrant_secret.rb +23 -0
  27. data/lib/fog/riakcs/provisioning/update_user.rb +23 -0
  28. data/lib/fog/riakcs/usage.rb +61 -0
  29. data/lib/fog/riakcs/usage/get_usage.rb +68 -0
  30. data/lib/fog/riakcs/user_utils.rb +34 -0
  31. data/lib/fog/riakcs/utils.rb +16 -0
  32. data/lib/fog/riakcs/version.rb +5 -0
  33. data/spec/minitest_helper.rb +31 -0
  34. data/tests/helper.rb +34 -0
  35. data/tests/helpers/collection_helper.rb +97 -0
  36. data/tests/helpers/flavors_helper.rb +32 -0
  37. data/tests/helpers/formats_helper.rb +98 -0
  38. data/tests/helpers/formats_helper_tests.rb +110 -0
  39. data/tests/helpers/mock_helper.rb +15 -0
  40. data/tests/helpers/model_helper.rb +29 -0
  41. data/tests/helpers/responds_to_helper.rb +11 -0
  42. data/tests/helpers/schema_validator_tests.rb +107 -0
  43. data/tests/helpers/server_helper.rb +25 -0
  44. data/tests/helpers/servers_helper.rb +10 -0
  45. data/tests/helpers/succeeds_helper.rb +9 -0
  46. data/tests/riakcs/provisioning/provisioning_tests.rb +174 -0
  47. data/tests/riakcs/usage/usage_tests.rb +29 -0
  48. metadata +233 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2f072ee73f421491492b34219fa0e3dff42d2c2
4
+ data.tar.gz: edc9cb56611a1101628abdef0d3d1ed9729704ae
5
+ SHA512:
6
+ metadata.gz: f0c8a336f6249b03b67d2f092f17e2aafd4596f53da976708de35c14b84031012c4cbd594e7948489e0cc208b5363300a8189c5b89c278a26a10dc2b1655cc86
7
+ data.tar.gz: 01bbdba1d8594023660569b84b5e1c5425ad4637cea4a7ad17e650d9528b43ae5de8f904db14e97f4da509bb2b87b0bfa983f8551197b7a46dc669a179cc7679
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ gemfiles/*.lock
data/.hound.yml ADDED
@@ -0,0 +1,20 @@
1
+ Metrics/LineLength:
2
+ Enabled: false
3
+
4
+ Style/EachWithObject:
5
+ Enabled: false
6
+
7
+ Style/Encoding:
8
+ EnforcedStyle: when_needed
9
+
10
+ Style/FormatString:
11
+ Enabled: false
12
+
13
+ Style/HashSyntax:
14
+ EnforcedStyle: hash_rockets
15
+
16
+ Style/SignalException:
17
+ EnforcedStyle: only_raise
18
+
19
+ Style/StringLiterals:
20
+ EnforcedStyle: double_quotes
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ Metrics/LineLength:
2
+ Enabled: false
3
+
4
+ Style/EachWithObject:
5
+ Enabled: false
6
+
7
+ Style/Encoding:
8
+ EnforcedStyle: when_needed
9
+
10
+ Style/FormatString:
11
+ Enabled: false
12
+
13
+ Style/HashSyntax:
14
+ EnforcedStyle: hash_rockets
15
+
16
+ Style/SignalException:
17
+ EnforcedStyle: only_raise
18
+
19
+ Style/StringLiterals:
20
+ EnforcedStyle: double_quotes
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ fog-riakcs
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.5
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ matrix:
2
+ include:
3
+ - rvm: 1.8.7
4
+ gemfile: gemfiles/Gemfile.1.9.2-
5
+ - rvm: 1.9.2
6
+ gemfile: gemfiles/Gemfile.1.9.2-
7
+ - rvm: 1.9.3
8
+ gemfile: gemfiles/Gemfile.1.9.3+
9
+ - rvm: 2.0.0
10
+ gemfile: gemfiles/Gemfile.1.9.3+
11
+ - rvm: 2.1.4
12
+ gemfile: gemfiles/Gemfile.1.9.3+
13
+ env: COVERAGE=true
14
+ - rvm: ree
15
+ gemfile: gemfiles/Gemfile.1.9.2-
16
+ - rvm: jruby
17
+ gemfile: gemfiles/Gemfile.1.9.3+
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,18 @@
1
+ ## Getting Involved
2
+
3
+ New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another.
4
+
5
+ ### Coding
6
+
7
+ * Pick a task:
8
+ * Offer feedback on open [pull requests](https://github.com/fog/fog-riakcs/pulls).
9
+ * Review open [issues](https://github.com/fog/fog-riakcs/issues) for things to help on.
10
+ * [Create an issue](https://github.com/fog/fog-riakcs/issues/new) to start a discussion on additions or features.
11
+ * Fork the project, add your changes and tests to cover them in a topic branch.
12
+ * Commit your changes and rebase against `fog/fog-riakcs` to ensure everything is up to date.
13
+ * [Submit a pull request](https://github.com/fog/fog-riakcs/compare/)
14
+
15
+ ### Non-Coding
16
+
17
+ * Offer feedback on open [issues](https://github.com/fog/fog-riakcs/issues).
18
+ * Organize or volunteer at events.
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1,10 @@
1
+ * Brian D. Burns <iosctr@gmail.com>
2
+ * Christopher Meiklejohn <christopher.meiklejohn@gmail.com>
3
+ * Derek Richard and Karen Wang <pair+drichard+khwang@pivotallabs.com>
4
+ * Eric Hodel <drbrain@segment7.net>
5
+ * Erik Michaels-Ober <sferik@gmail.com>
6
+ * Hector Castro <hectcastro@gmail.com>
7
+ * Lance Ivy <lance@cainlevy.net>
8
+ * Kyle Rames <kyle.rames@rackspace.com>
9
+ * Paul Thornthwaite <tokengeek@gmail.com>
10
+ * Paulo Henrique Lopes Ribeiro <plribeiro3000@gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fog-riakcs.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2014 [CONTRIBUTORS.md](https://github.com/fog/fog-riakcs/blob/master/CONTRIBUTORS.md)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Fog::Riakcs
2
+
3
+ ![Gem Version](https://badge.fury.io/rb/fog-riakcs.svg) [![Build Status](https://travis-ci.org/fog/fog-riakcs.svg?branch=master)](https://travis-ci.org/fog/fog-riakcs) [![Dependency Status](https://gemnasium.com/fog/fog-riakcs.svg)](https://gemnasium.com/fog/fog-riakcs) [![Coverage Status](https://img.shields.io/coveralls/fog/fog-riakcs.svg)](https://coveralls.io/r/fog/fog-riakcs?branch=master) [![Code Climate](https://codeclimate.com/github/fog/fog-riakcs.png)](https://codeclimate.com/github/fog/fog-riakcs)
4
+
5
+ Module for the 'fog' gem to support Riakcs
6
+
7
+ ## Help Needed
8
+
9
+ This gem needs a maintainer. If you want to work on it, please contact
10
+ [@geemus](mailto:geemus@gmail.com) or [@plribeiro3000](mailto:plribeiro3000@gmail.com)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'fog-riakcs'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install fog-riakcs
27
+
28
+ ## Usage
29
+
30
+ TODO: Write usage instructions here
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/fog/fog-riakcs/fork )
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push %w(spec)
6
+ t.test_files = FileList['spec/**/*_spec.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ desc 'Default Task'
11
+ task :default => [ :test, 'test:travis' ]
12
+
13
+ namespace :test do
14
+ mock = ENV['FOG_MOCK'] || 'true'
15
+ task :travis do
16
+ sh("export FOG_MOCK=#{mock} && bundle exec shindont")
17
+ end
18
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fog/riakcs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fog-riakcs"
8
+ spec.version = Fog::Riakcs::VERSION
9
+ spec.authors = ["Paulo Henrique Lopes Ribeiro"]
10
+ spec.email = ["plribeiro3000@gmail.com"]
11
+ spec.summary = %q{Module for the 'fog' gem to support Riakcs.}
12
+ spec.description = %q{This library can be used as a module for `fog` or as standalone provider
13
+ to use the Riakcs in applications.}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "fog-core"
23
+ spec.add_dependency "fog-json"
24
+ spec.add_dependency "fog-xml"
25
+
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "minitest"
28
+ spec.add_development_dependency "shindo"
29
+ spec.add_development_dependency "turn"
30
+ spec.add_development_dependency "pry"
31
+
32
+ if RUBY_VERSION.to_f > 1.9
33
+ spec.add_development_dependency "coveralls"
34
+ spec.add_development_dependency "rubocop"
35
+ end
36
+ end
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+
3
+ gem 'mime-types', '< 2.0'
4
+ gem 'nokogiri', '< 1.6'
5
+ gem 'rest-client', '~> 1.6.8'
6
+ gem 'fog-core'
7
+
8
+ gemspec :path => '../'
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gem 'activesupport', '>= 3.0', '< 4'
4
+ gem 'mime-types', '< 2.0'
5
+ gem 'fog-core'
6
+
7
+ gemspec :path => '../'
data/lib/fog/riakcs.rb ADDED
@@ -0,0 +1,17 @@
1
+ require "fog/riakcs/version"
2
+ require "fog/core"
3
+
4
+ module Fog
5
+ module RiakCS
6
+ extend Fog::Provider
7
+
8
+ autoload :MultipartUtils, 'fog/riakcs/multipart_utils'
9
+ autoload :Provisioning, 'fog/riakcs/provisioning'
10
+ autoload :Utils, 'fog/riakcs/utils'
11
+ autoload :UserUtils, 'fog/riakcs/user_utils'
12
+ autoload :Usage, 'fog/riakcs/usage'
13
+
14
+ service(:provisioning, 'Provisioning')
15
+ service(:usage, 'Usage')
16
+ end
17
+ end
@@ -0,0 +1,45 @@
1
+ module Fog
2
+ module RiakCS
3
+ module MultipartUtils
4
+ autoload :Headers, 'fog/riakcs/multipart_utils/headers'
5
+
6
+ def parse(data, boundary)
7
+ contents = data.match(end_boundary_regex(boundary)).pre_match rescue ""
8
+ contents.split(inner_boundary_regex(boundary)).reject(&:empty?).map do |part|
9
+ parse_multipart_section(part)
10
+ end.compact
11
+ end
12
+
13
+ def extract_boundary(header_string)
14
+ $1 if header_string =~ /boundary=([A-Za-z0-9\'()+_,-.\/:=?]+)/
15
+ end
16
+
17
+ private
18
+
19
+ def end_boundary_regex(boundary)
20
+ /\r?\n--#{Regexp.escape(boundary)}--\r?\n?/
21
+ end
22
+
23
+ def inner_boundary_regex(boundary)
24
+ /\r?\n--#{Regexp.escape(boundary)}\r?\n/
25
+ end
26
+
27
+ def parse_multipart_section(part)
28
+ headers = Headers.new
29
+ if md = part.match(/\r?\n\r?\n/)
30
+ body = md.post_match
31
+ md.pre_match.split(/\r?\n/).each do |line|
32
+ headers.parse(line)
33
+ end
34
+
35
+ if headers["content-type"] =~ /multipart\/mixed/
36
+ boundary = extract_boundary(headers.to_hash["content-type"].first)
37
+ parse(body, boundary)
38
+ else
39
+ {:headers => headers.to_hash, :body => body}
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,33 @@
1
+ require 'net/http'
2
+
3
+ module Fog
4
+ module RiakCS
5
+ module MultipartUtils
6
+ class Headers
7
+ include Net::HTTPHeader
8
+
9
+ def initialize
10
+ initialize_http_header({})
11
+ end
12
+
13
+ # Parse a single header line into its key and value
14
+ # @param [String] chunk a single header line
15
+ def self.parse(chunk)
16
+ line = chunk.strip
17
+ # thanks Net::HTTPResponse
18
+ return [nil,nil] if chunk =~ /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)\s*(.*)\z/in
19
+ m = /\A([^:]+):\s*/.match(line)
20
+ [m[1], m.post_match] rescue [nil, nil]
21
+ end
22
+
23
+ # Parses a header line and adds it to the header collection
24
+ # @param [String] chunk a single header line
25
+ def parse(chunk)
26
+ key, value = self.class.parse(chunk)
27
+ add_field(key, value) if key && value
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,97 @@
1
+ module Fog
2
+ module RiakCS
3
+ class Provisioning < Fog::Service
4
+ class UserAlreadyExists < Fog::RiakCS::Provisioning::Error; end
5
+ class ServiceUnavailable < Fog::RiakCS::Provisioning::Error; end
6
+
7
+ requires :riakcs_access_key_id, :riakcs_secret_access_key
8
+ recognizes :host, :path, :port, :scheme, :persistent, :path_style
9
+
10
+ request_path 'fog/riakcs/provisioning'
11
+
12
+ request :create_user
13
+ request :update_user
14
+ request :disable_user
15
+ request :enable_user
16
+ request :list_users
17
+ request :get_user
18
+ request :regrant_secret
19
+
20
+ class Mock
21
+ include Fog::RiakCS::Utils
22
+
23
+ def self.data
24
+ @data ||= Hash.new({})
25
+ end
26
+
27
+ def self.reset
28
+ @data = nil
29
+ end
30
+
31
+ def initialize(options = {})
32
+ configure_uri_options(options)
33
+ end
34
+
35
+ def data
36
+ self.class.data[riakcs_uri]
37
+ end
38
+
39
+ def reset_data
40
+ self.class.data.delete(riakcs_uri)
41
+ end
42
+ end
43
+
44
+ class Real
45
+ include Fog::RiakCS::Utils
46
+
47
+ def initialize(options = {})
48
+ configure_uri_options(options)
49
+ @riakcs_access_key_id = options[:riakcs_access_key_id]
50
+ @riakcs_secret_access_key = options[:riakcs_secret_access_key]
51
+ @connection_options = options[:connection_options] || {}
52
+ @persistent = options[:persistent] || false
53
+ @path_style = options[:path_style] || false
54
+
55
+ @raw_connection = Fog::XML::Connection.new(riakcs_uri, @persistent, @connection_options)
56
+
57
+ @s3_connection = Fog::Storage.new(
58
+ :provider => 'AWS',
59
+ :aws_access_key_id => @riakcs_access_key_id,
60
+ :aws_secret_access_key => @riakcs_secret_access_key,
61
+ :host => @host,
62
+ :port => @port,
63
+ :scheme => @scheme,
64
+ :path_style => @path_style,
65
+ :connection_options => @connection_options
66
+ )
67
+ end
68
+
69
+ def request(params, parse_response = true, &block)
70
+ begin
71
+ response = @raw_connection.request(params.merge({
72
+ :host => @host,
73
+ :path => "#{@path}/#{params[:path]}",
74
+ }), &block)
75
+ rescue Excon::Errors::HTTPStatusError => error
76
+ if match = error.message.match(/<Code>(.*?)<\/Code>(?:.*<Message>(.*?)<\/Message>)?/m)
77
+ case match[1]
78
+ when 'UserAlreadyExists'
79
+ raise Fog::RiakCS::Provisioning.const_get(match[1]).new
80
+ when 'ServiceUnavailable'
81
+ raise Fog::RiakCS::Provisioning.const_get(match[1]).new
82
+ else
83
+ raise error
84
+ end
85
+ else
86
+ raise error
87
+ end
88
+ end
89
+ if !response.body.empty? && parse_response
90
+ response.body = Fog::JSON.decode(response.body)
91
+ end
92
+ response
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end