openstack_bridge 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 08604b7f2726a5f117c345b3fe24a859d4712321
4
+ data.tar.gz: 3a5b888a3b2dfd9a23555ba932bca4504634a735
5
+ SHA512:
6
+ metadata.gz: f01740d139ccc4cf57a9743e3a756727eeece19211bb8df19e8bea9de27a55326a68c2654cc9164249baaeb5a6a152bd75ade40e9bba126e434227aeb84450eb
7
+ data.tar.gz: c50bacda14fc501618ae580ad256c913ee7d1d98ef9f5fb5d059db0790a550108e5e402a05ac889666c8a357d192acbe78f3c82e3c7193851f44ba0fa79949b4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in openstack_bridge.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Krzysztof Kotlarek
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # OpenstackBridge
2
+
3
+ Basic integration with Openstack Swift. Implemented simple operation like exists?, read, create and delete.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'openstack_bridge'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install openstack_bridge
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ swift = OpenstackBridge::Swift.new('localhost', 'lis2', 'password', 'dev', 'container_name')
23
+ swift.exists?('readme.txt')
24
+ swift.read('readme.txt')
25
+ swift.delete('readme.txt')
26
+ swift.create('readme.txt', 'new content')
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ module OpenstackBridge
2
+ class Authentication < Struct.new(:host, :username, :password, :tenant)
3
+ attr_accessor :response
4
+
5
+ def initialize(*)
6
+ super
7
+ request = HTTPI::Request.new
8
+ request.url = host
9
+ request.body = auth_hash.to_json
10
+ request.headers['Content-Type'] = 'application/json'
11
+ self.response = JSON.parse(HTTPI.post(request, :curb).body)
12
+ end
13
+
14
+ def auth_hash
15
+ {
16
+ "auth" => {
17
+ "passwordCredentials" =>{
18
+ "username" => username,
19
+ "password" => password
20
+ },
21
+ "tenantName" => tenant
22
+ }
23
+ }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,49 @@
1
+ module OpenstackBridge
2
+ class Swift < Struct.new(:host, :user, :password, :tenant, :container)
3
+ attr_accessor :authentication_response
4
+
5
+ def initialize(*)
6
+ super
7
+ self.authentication_response = OpenstackBridge::Authentication.new(host, user, password, tenant).response
8
+ end
9
+
10
+ def token
11
+ self.authentication_response['access']['token']['id']
12
+ end
13
+
14
+ def end_point
15
+ self.authentication_response['access']['serviceCatalog'].detect {|s| s['name'] == 'swift'}['endpoints'].first['publicURL']
16
+ end
17
+
18
+ def file_path(path)
19
+ "#{end_point}/#{container}/#{path}"
20
+ end
21
+
22
+ def exists?(path)
23
+ request(:head, file_path(path)).code == 200
24
+ end
25
+
26
+ def read(path)
27
+ request(:get, file_path(path)).raw_body
28
+ end
29
+
30
+ def delete(path)
31
+ request(:delete, file_path(path))
32
+ end
33
+
34
+ def create(path, content)
35
+ request(:put, file_path(path), content)
36
+ end
37
+
38
+
39
+ def request(method, path, params={}.to_json, httpclient = false)
40
+ request = HTTPI::Request.new
41
+ request.url = path
42
+ request.body = params
43
+ request.headers['Content-Type'] = 'application/json'
44
+ request.headers['X-Auth-Token'] = token
45
+ HTTPI.send(method, request, (httpclient ? :httpclient : :curb))
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,3 @@
1
+ module OpenstackBridge
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "openstack_bridge/version"
2
+ require "openstack_bridge/authentication"
3
+ require "openstack_bridge/swift"
4
+
5
+ module OpenstackBridge
6
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'openstack_bridge/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "openstack_bridge"
8
+ spec.version = OpenstackBridge::VERSION
9
+ spec.authors = ["lis2", "morhekil"]
10
+ spec.email = ["kotlarek.krzysztof@gmail.com"]
11
+ spec.description = %q{Openstack ruby integration}
12
+ spec.summary = %q{Ruby integration with openstack, especially swift}
13
+ spec.homepage = "https://github.com/lis2/openstack_bridge"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_runtime_dependency "httpi"
24
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openstack_bridge
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - lis2
8
+ - morhekil
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-06-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: httpi
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: Openstack ruby integration
57
+ email:
58
+ - kotlarek.krzysztof@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/openstack_bridge.rb
68
+ - lib/openstack_bridge/authentication.rb
69
+ - lib/openstack_bridge/swift.rb
70
+ - lib/openstack_bridge/version.rb
71
+ - openstack_bridge.gemspec
72
+ homepage: https://github.com/lis2/openstack_bridge
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Ruby integration with openstack, especially swift
96
+ test_files: []