fog-atmos 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rubocop.yml +20 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +17 -0
  7. data/CONTRIBUTING.md +18 -0
  8. data/CONTRIBUTORS.md +10 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE.md +20 -0
  11. data/README.md +38 -0
  12. data/Rakefile +18 -0
  13. data/fog-atmos.gemspec +35 -0
  14. data/gemfiles/Gemfile.1.9.2- +8 -0
  15. data/gemfiles/Gemfile.1.9.3+ +7 -0
  16. data/lib/fog/atmos.rb +15 -0
  17. data/lib/fog/atmos/storage.rb +0 -0
  18. data/lib/fog/atmos/version.rb +5 -0
  19. data/lib/fog/storage/atmos.rb +187 -0
  20. data/lib/fog/storage/atmos/models/directories.rb +41 -0
  21. data/lib/fog/storage/atmos/models/directory.rb +46 -0
  22. data/lib/fog/storage/atmos/models/file.rb +106 -0
  23. data/lib/fog/storage/atmos/models/files.rb +71 -0
  24. data/lib/fog/storage/atmos/requests/delete_namespace.rb +17 -0
  25. data/lib/fog/storage/atmos/requests/get_namespace.rb +23 -0
  26. data/lib/fog/storage/atmos/requests/head_namespace.rb +18 -0
  27. data/lib/fog/storage/atmos/requests/post_namespace.rb +18 -0
  28. data/lib/fog/storage/atmos/requests/put_namespace.rb +18 -0
  29. data/tests/helper.rb +36 -0
  30. data/tests/helpers/collection_helper.rb +97 -0
  31. data/tests/helpers/compute/flavors_helper.rb +32 -0
  32. data/tests/helpers/compute/server_helper.rb +25 -0
  33. data/tests/helpers/compute/servers_helper.rb +10 -0
  34. data/tests/helpers/formats_helper.rb +98 -0
  35. data/tests/helpers/formats_helper_tests.rb +110 -0
  36. data/tests/helpers/mock_helper.rb +117 -0
  37. data/tests/helpers/model_helper.rb +31 -0
  38. data/tests/helpers/responds_to_helper.rb +11 -0
  39. data/tests/helpers/schema_validator_tests.rb +107 -0
  40. data/tests/helpers/succeeds_helper.rb +9 -0
  41. data/tests/models/storage/file_update_tests.rb +19 -0
  42. data/tests/models/storage/nested_directories_tests.rb +23 -0
  43. metadata +213 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d7e815031060e57ab291ec0bdd2221ada13324f
4
+ data.tar.gz: 0ad7bec208526d9ea31aaab2b71bdc8b36f457ca
5
+ SHA512:
6
+ metadata.gz: 1da084b73ea114a253d6e8164b70fcc0a6a6c836cfaaeb2ec8cee56e7c8fe78a64e3e67227e4181386455bd4fc146c65a18bb7d4356dad745d747c69c51c602a
7
+ data.tar.gz: 26d6baf734d62030ef1489ee64a729dd43eadc9258137de7f67acd13b191b88beb9fea76394976d211bf8d8cca19ae31d810da47119678d0062ed8db5a1b2dc5
@@ -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
@@ -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
@@ -0,0 +1 @@
1
+ fog-atmos
@@ -0,0 +1 @@
1
+ 2.1.5
@@ -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+
@@ -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-atmos/pulls).
9
+ * Review open [issues](https://github.com/fog/fog-atmos/issues) for things to help on.
10
+ * [Create an issue](https://github.com/fog/fog-atmos/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-atmos` to ensure everything is up to date.
13
+ * [Submit a pull request](https://github.com/fog/fog-atmos/compare/)
14
+
15
+ ### Non-Coding
16
+
17
+ * Offer feedback on open [issues](https://github.com/fog/fog-atmos/issues).
18
+ * Organize or volunteer at events.
@@ -0,0 +1,10 @@
1
+ * Brian D. Burns <iosctr@gmail.com>
2
+ * David Prater <dprater@cisco.com>
3
+ * Lance Ivy <lance@cainlevy.net>
4
+ * Michael Harrison <michael@ntechmedia.com>
5
+ * Paul Thornthwaite <tokengeek@gmail.com>
6
+ * Paulo Henrique Lopes Ribeiro <plribeiro3000@gmail.com>
7
+ * Peter Vawser <peter@catapult-elearning.com>
8
+ * Tim <tim.lawrence1984@gmail.com>
9
+ * Timur Alperovich <timur@maginatics.com>
10
+ * Toby Hede <tobyhede@info-architects.net>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fog-atmos.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2014 [CONTRIBUTORS.md](https://github.com/fog/fog-atmos/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.
@@ -0,0 +1,38 @@
1
+ # Fog::Atmos
2
+
3
+ ![Gem Version](https://badge.fury.io/rb/fog-atmos.svg) [![Build Status](https://travis-ci.org/fog/fog-atmos.svg?branch=master)](https://travis-ci.org/fog/fog-atmos) [![Dependency Status](https://gemnasium.com/fog/fog-atmos.svg)](https://gemnasium.com/fog/fog-atmos) [![Coverage Status](https://img.shields.io/coveralls/fog/fog-atmos.svg)](https://coveralls.io/r/fog/fog-atmos?branch=master) [![Code Climate](https://codeclimate.com/github/fog/fog-atmos.png)](https://codeclimate.com/github/fog/fog-atmos)
4
+
5
+ Module for the 'fog' gem to support Atmos
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-atmos'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install fog-atmos
27
+
28
+ ## Usage
29
+
30
+ TODO: Write usage instructions here
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/fog/fog-atmos/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
@@ -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,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fog/atmos/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fog-atmos"
8
+ spec.version = Fog::Atmos::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 Atmos.}
12
+ spec.description = %q{This library can be used as a module for `fog` or as standalone provider
13
+ to use the Atmos 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-xml"
24
+
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "minitest"
27
+ spec.add_development_dependency "shindo"
28
+ spec.add_development_dependency "turn"
29
+ spec.add_development_dependency "pry"
30
+
31
+ if RUBY_VERSION.to_f > 1.9
32
+ spec.add_development_dependency "coveralls"
33
+ spec.add_development_dependency "rubocop"
34
+ end
35
+ 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 => '../'
@@ -0,0 +1,15 @@
1
+ require 'fog/atmos/version'
2
+ require 'fog/core'
3
+ require 'fog/xml'
4
+
5
+ module Fog
6
+ module Atmos
7
+ extend Fog::Provider
8
+
9
+ service(:storage, 'Storage')
10
+ end
11
+
12
+ module Storage
13
+ autoload :Atmos, 'fog/storage/atmos'
14
+ end
15
+ end
File without changes
@@ -0,0 +1,5 @@
1
+ module Fog
2
+ module Atmos
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,187 @@
1
+ module Fog
2
+ module Storage
3
+ class Atmos < Fog::Service
4
+ autoload :Directory, 'fog/storage/atmos/models/directory'
5
+ autoload :Directories, 'fog/storage/atmos/models/directories'
6
+ autoload :File, 'fog/storage/atmos/models/file'
7
+ autoload :Files, 'fog/storage/atmos/models/files'
8
+
9
+ requires :atmos_storage_endpoint,
10
+ :atmos_storage_secret,
11
+ :atmos_storage_token
12
+ recognizes :persistent
13
+
14
+ model_path 'fog/storage/atmos/models'
15
+ model :directory
16
+ collection :directories
17
+ model :file
18
+ collection :files
19
+
20
+ request_path 'fog/storage/atmos/requests'
21
+ # request :delete_container
22
+ request :get_namespace
23
+ request :head_namespace
24
+ request :post_namespace
25
+ request :put_namespace
26
+ request :delete_namespace
27
+
28
+ module Utils
29
+ ENDPOINT_REGEX = /(https*):\/\/([a-zA-Z0-9\.\-]+)(:[0-9]+)?(\/.*)?/
30
+
31
+ def ssl?
32
+ protocol = @endpoint.match(ENDPOINT_REGEX)[1]
33
+ raise ArgumentError, 'Invalid endpoint URL' if protocol.nil?
34
+
35
+ return true if protocol == 'https'
36
+ return false if protocol == 'http'
37
+
38
+ raise ArgumentError, "Unknown protocol #{protocol}"
39
+ end
40
+
41
+ def port
42
+ port = @endpoint.match(ENDPOINT_REGEX)[3]
43
+ return ssl? ? 443 : 80 if port.nil?
44
+ port.split(':')[1].to_i
45
+ end
46
+
47
+ def host
48
+ @endpoint.match(ENDPOINT_REGEX)[2]
49
+ end
50
+
51
+ def api_path
52
+ @endpoint.match(ENDPOINT_REGEX)[4]
53
+ end
54
+
55
+ def setup_credentials(options)
56
+ @storage_token = options[:atmos_storage_token]
57
+ @storage_secret = options[:atmos_storage_secret]
58
+ @storage_secret_decoded = Base64.decode64(@storage_secret)
59
+ @endpoint = options[:atmos_storage_endpoint]
60
+ @prefix = self.ssl? ? 'https' : 'http'
61
+ @storage_host = self.host
62
+ @storage_port = self.port
63
+ @api_path = self.api_path
64
+ end
65
+ end
66
+
67
+ class Mock
68
+ include Utils
69
+
70
+ def initialize(options={})
71
+ setup_credentials(options)
72
+ end
73
+
74
+ def request(options)
75
+ raise "Atmos Storage mocks not implemented"
76
+ end
77
+ end
78
+
79
+ class Real
80
+ include Utils
81
+
82
+ def initialize(options={})
83
+ setup_credentials(options)
84
+ @connection_options = options[:connection_options] || {}
85
+ @hmac = Fog::HMAC.new('sha1', @storage_secret_decoded)
86
+ @persistent = options.fetch(:persistent, false)
87
+
88
+ @connection = Fog::XML::Connection.new("#{@prefix}://#{@storage_host}:#{@storage_port}",
89
+ @persistent, @connection_options)
90
+ end
91
+
92
+ def uid
93
+ @storage_token#.split('/')[-1]
94
+ end
95
+
96
+ def sign(string)
97
+ value = @hmac.sign(string)
98
+ Base64.encode64( value ).chomp()
99
+ end
100
+
101
+ def reload
102
+ @connection.reset
103
+ end
104
+
105
+ def request(params, &block)
106
+ req_path = params[:path]
107
+ # Force set host and port
108
+ params.merge!({
109
+ :host => @storage_host,
110
+ :path => "#{@api_path}/rest/#{params[:path]}",
111
+ })
112
+ # Set default method and headers
113
+ params = {:method => 'GET', :headers => {}}.merge params
114
+
115
+ params[:headers]["Content-Type"] ||= "application/octet-stream"
116
+
117
+ # Add request date
118
+ params[:headers]["date"] = Time.now().httpdate()
119
+ params[:headers]["x-emc-uid"] = @storage_token
120
+
121
+ # Build signature string
122
+ signstring = ""
123
+ signstring += params[:method]
124
+ signstring += "\n"
125
+ signstring += params[:headers]["Content-Type"]
126
+ signstring += "\n"
127
+ if( params[:headers]["range"] )
128
+ signstring += params[:headers]["range"]
129
+ end
130
+ signstring += "\n"
131
+ signstring += params[:headers]["date"]
132
+ signstring += "\n"
133
+
134
+ signstring += "/rest/" + URI.unescape( req_path ).downcase
135
+ query_str = params[:query].map{|k,v| "#{k}=#{v}"}.join('&')
136
+ signstring += '?' + query_str unless query_str.empty?
137
+ signstring += "\n"
138
+
139
+ customheaders = {}
140
+ params[:headers].each { |key,value|
141
+ case key
142
+ when 'x-emc-date', 'x-emc-signature'
143
+ #skip
144
+ when /^x-emc-/
145
+ customheaders[ key.downcase ] = value
146
+ end
147
+ }
148
+ header_arr = customheaders.sort()
149
+
150
+ header_arr.each { |key,value|
151
+ # Values are lowercase and whitespace-normalized
152
+ signstring += key + ":" + value.strip.chomp.squeeze( " " ) + "\n"
153
+ }
154
+
155
+ digest = @hmac.sign(signstring.chomp())
156
+ signature = Base64.encode64( digest ).chomp()
157
+ params[:headers]["x-emc-signature"] = signature
158
+
159
+ params.delete(:host) #invalid excon request parameter
160
+
161
+ parse = params.delete(:parse)
162
+
163
+ begin
164
+ response = @connection.request(params, &block)
165
+ rescue Excon::Errors::HTTPStatusError => error
166
+ raise case error
167
+ when Excon::Errors::NotFound
168
+ Fog::Storage::Atmos::NotFound.slurp(error)
169
+ else
170
+ error
171
+ end
172
+ end
173
+ unless response.body.empty?
174
+ if parse
175
+ document = Fog::ToHashDocument.new
176
+ parser = Nokogiri::XML::SAX::PushParser.new(document)
177
+ parser << response.body
178
+ parser.finish
179
+ response.body = document.body
180
+ end
181
+ end
182
+ response
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end