a9s_swift 0.1.4 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 159c003cd8be577850f303edba533d675aced635
4
- data.tar.gz: 4606240725e7e0e9549eeea56f49e981b04b89b4
3
+ metadata.gz: 7a953008977d2f7da209bd6c2d4efb9b556880c9
4
+ data.tar.gz: 08295eb8f96eb724ac53a853a49a368a8b256707
5
5
  SHA512:
6
- metadata.gz: a7c5759be960afd8ad5418449f1ee5eaf3f2b2884bf70df5ef3cd945dacd4f0b0ae1971d4309fcb6a05c65613eb9adce797ab53e0d8d41b2fcdc6d8945876e59
7
- data.tar.gz: 44367b251e3e8fcca22922ff8358318e50fbf0904613d821597a62905849a565a86a7bc6f550eeb80c6c35e14e18ae2f0b53ff6ff67800705a4df289d13e3f77
6
+ metadata.gz: a876a6e47927483f0d20c22f07924a828d749d277cbb8685f7a3f1cc373f97ecb71de42eeae8cf628029e6fda4859ecb525c151ebed1a8122b4867abce5ef0f2
7
+ data.tar.gz: bf4cfd81d33a3b8e90af0381d673525195bcdfe7d1742690483b1845125978b7468d24e310d346c6ad2ca28f836cf7a1450ef0011a0c379ca79085d5859480f6
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # v0.2.0
2
+
3
+ * adds support for the OpenStack fog provider
data/Gemfile.lock CHANGED
@@ -12,27 +12,33 @@ GEM
12
12
  builder (3.2.2)
13
13
  descendants_tracker (0.0.3)
14
14
  docile (1.1.3)
15
- excon (0.32.1)
15
+ excon (0.39.5)
16
16
  faraday (0.9.0)
17
17
  multipart-post (>= 1.2, < 3)
18
- fog (1.21.0)
18
+ fog (1.23.0)
19
19
  fog-brightbox
20
- fog-core (~> 1.21, >= 1.21.1)
20
+ fog-core (~> 1.23)
21
21
  fog-json
22
+ fog-softlayer
23
+ ipaddress (~> 0.5)
22
24
  nokogiri (~> 1.5, >= 1.5.11)
23
- fog-brightbox (0.0.1)
24
- fog-core
25
+ fog-brightbox (0.3.0)
26
+ fog-core (~> 1.22)
25
27
  fog-json
26
- fog-core (1.21.1)
28
+ inflecto
29
+ fog-core (1.24.0)
27
30
  builder
28
- excon (~> 0.32)
29
- formatador (~> 0.2.0)
31
+ excon (~> 0.38)
32
+ formatador (~> 0.2)
30
33
  mime-types
31
34
  net-scp (~> 1.1)
32
35
  net-ssh (>= 2.1.3)
33
36
  fog-json (1.0.0)
34
37
  multi_json (~> 1.0)
35
- formatador (0.2.4)
38
+ fog-softlayer (0.3.15)
39
+ fog-core
40
+ fog-json
41
+ formatador (0.2.5)
36
42
  git (1.2.6)
37
43
  github_api (0.11.3)
38
44
  addressable (~> 2.3)
@@ -45,6 +51,8 @@ GEM
45
51
  hashie (2.0.5)
46
52
  highline (1.6.21)
47
53
  i18n (0.6.9)
54
+ inflecto (0.0.2)
55
+ ipaddress (0.8.0)
48
56
  jeweler (2.0.1)
49
57
  builder
50
58
  bundler (>= 1.0)
@@ -57,17 +65,17 @@ GEM
57
65
  json (1.8.1)
58
66
  jwt (0.1.11)
59
67
  multi_json (>= 1.5)
60
- mime-types (2.0)
61
- mini_portile (0.5.3)
68
+ mime-types (2.3)
69
+ mini_portile (0.6.0)
62
70
  minitest (4.7.5)
63
- multi_json (1.9.2)
71
+ multi_json (1.10.1)
64
72
  multi_xml (0.5.5)
65
73
  multipart-post (2.0.0)
66
- net-scp (1.1.2)
74
+ net-scp (1.2.1)
67
75
  net-ssh (>= 2.6.5)
68
- net-ssh (2.8.0)
69
- nokogiri (1.6.1)
70
- mini_portile (~> 0.5.0)
76
+ net-ssh (2.9.1)
77
+ nokogiri (1.6.3.1)
78
+ mini_portile (= 0.6.0)
71
79
  oauth2 (0.9.3)
72
80
  faraday (>= 0.8, < 0.10)
73
81
  jwt (~> 0.1.8)
data/Rakefile CHANGED
@@ -56,3 +56,4 @@ task :irb_console do
56
56
  end
57
57
 
58
58
  task irb: :irb_console
59
+ task c: :irb_console
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.0
data/a9s_swift.gemspec CHANGED
@@ -2,16 +2,14 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: a9s_swift 0.1.4 ruby lib
6
5
 
7
6
  Gem::Specification.new do |s|
8
7
  s.name = "a9s_swift"
9
- s.version = "0.1.4"
8
+ s.version = "0.2.0"
10
9
 
11
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
11
  s.authors = ["Julian Weber"]
14
- s.date = "2014-07-14"
12
+ s.date = "2014-08-28"
15
13
  s.description = "anynines.com swift service utility library for simplifying app acces to the a9s swift service."
16
14
  s.email = "jweber@anynines.com"
17
15
  s.extra_rdoc_files = [
@@ -20,6 +18,7 @@ Gem::Specification.new do |s|
20
18
  ]
21
19
  s.files = [
22
20
  ".document",
21
+ "CHANGELOG.md",
23
22
  "Gemfile",
24
23
  "Gemfile.lock",
25
24
  "LICENSE.txt",
@@ -36,7 +35,8 @@ Gem::Specification.new do |s|
36
35
  ]
37
36
  s.homepage = "http://github.com/anynines/a9s_swift"
38
37
  s.licenses = ["MIT"]
39
- s.rubygems_version = "2.2.2"
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = "2.0.6"
40
40
  s.summary = "anynines.com swift service utility library for simplifying app acces to the a9s swift service."
41
41
 
42
42
  if s.respond_to? :specification_version then
@@ -6,26 +6,27 @@ class Anynines::Swift::Utility
6
6
 
7
7
  # Returns a fog storage connection to the swift service
8
8
  # @return [Fog::Storage] a fog storage connection
9
- def self.fog_connection
10
- Fog::Storage.new fog_credentials_hash
9
+ def self.fog_connection(provider = "hp")
10
+ Fog::Storage.new fog_credentials_hash(provider)
11
11
  end
12
12
 
13
13
  # Sets up paperclip for the usage with the anynines service.
14
14
  # Creates a bucket with the given name if not already present.
15
15
  # @param image_bucket_name [String] the bucket name to use
16
16
  # @param options [Hash] a hash of additional options
17
- def self.configure_paperclip(image_bucket_name, options = {})
17
+ def self.configure_paperclip(image_bucket_name, options = {}, provider = "hp")
18
18
  raise "Paperclip wasn't found in your environment! Please verify that paperclip is included within your Gemfile and loaded correctly." if defined?(Paperclip).nil?
19
19
 
20
20
  opts = initialize_options options
21
- create_new_bucket(image_bucket_name, opts[:fog_public])
21
+ create_new_bucket(image_bucket_name, opts[:fog_public], provider)
22
+ fog_hash = self.fog_credentials_hash(provider)
22
23
 
23
- # configure paperclip to use the credentials provided by the anynines environment
24
+ # configure paperclip to use the credentials provided by the anynines environment
24
25
  Paperclip::Attachment.default_options.update(
25
26
  {
26
27
  :path => ":class/:id/:attachment/:style/img_:fingerprint",
27
28
  :storage => :fog,
28
- :fog_credentials => self.fog_credentials_hash,
29
+ :fog_credentials => fog_hash,
29
30
  :fog_directory => image_bucket_name,
30
31
  :fog_public => opts[:fog_public],
31
32
  :fog_host => "#{SWIFT_HOST}/v1/AUTH_#{fog_hash[:hp_tenant_id]}/#{image_bucket_name}"
@@ -36,14 +37,15 @@ class Anynines::Swift::Utility
36
37
  # Creates a bucket with the given name if not already present.
37
38
  # @param image_bucket_name [String] the bucket name to use
38
39
  # @param options [Hash] a hash of additional options
39
- def self.configure_carrierwave(image_bucket_name, options = {})
40
+ # @param provider [String] 'hp' or 'openstack'
41
+ def self.configure_carrierwave(image_bucket_name, options = {}, provider = "hp")
40
42
  raise "CarrierWave wasn't found in your environment! Please verify that carrierwave is included within your Gemfile and loaded correctly." if defined?(CarrierWave).nil?
41
43
 
42
44
  opts = initialize_options options
43
- create_new_bucket(image_bucket_name, opts[:fog_public])
45
+ create_new_bucket(image_bucket_name, opts[:fog_public], provider)
44
46
 
45
47
  CarrierWave.configure do |config|
46
- config.fog_credentials = fog_credentials_hash
48
+ config.fog_credentials = fog_credentials_hash(provider)
47
49
 
48
50
  config.storage = :fog
49
51
  config.fog_directory = image_bucket_name
@@ -52,30 +54,30 @@ class Anynines::Swift::Utility
52
54
  end
53
55
 
54
56
  # Returns a fog compatible credentials hash for the swift service
55
- def self.fog_credentials_hash
57
+ # @param provider [String] 'hp' or 'openstack'
58
+ def self.fog_credentials_hash(provider = "hp")
59
+ provider = provider.downcase
56
60
  # parse the VCAP_SERVICES environment variable
57
61
  services = JSON.parse(ENV["VCAP_SERVICES"])
58
62
  raise "Couldn't find the VCAP_SERVICE env variable! Are you running within an anynines environment?" if services.nil?
59
63
  raise "Couldn't access the a9s swift service credentials from env! Have you bound a swift service instance to the application?" if services["swift-1.0"].nil?
60
64
  swift_service = services["swift-1.0"].first
61
65
 
62
- return {
63
- :provider => 'HP',
64
- :hp_access_key => swift_service["credentials"]["user_name"],
65
- :hp_secret_key => swift_service["credentials"]["password"],
66
- :hp_tenant_id => swift_service["credentials"]["tenant_id"],
67
- :hp_auth_uri => swift_service["credentials"]["authentication_uri"],
68
- :hp_use_upass_auth_style => true,
69
- :hp_avl_zone => swift_service["credentials"]["availability_zone"],
70
- :os_account_meta_temp_url_key => swift_service["credentials"]["account_meta_key"]
71
- }
66
+ if provider == "hp"
67
+ fog_credentials_hash_hp_provider swift_service
68
+ elsif provider == "openstack"
69
+ fog_credentials_hash_openstack_provider swift_service
70
+ else
71
+ raise "No recognized provider. Please use 'hp' or 'openstack' as provider choice."
72
+ end
72
73
  end
73
74
 
74
75
  # Creates a new bucket with the given name if not already present
75
76
  # @param bucket_name [String] a name for the bucket
76
77
  # @param public_access [Boolean] should the bucket be publicly accessible?
77
- def self.create_new_bucket(bucket_name, public_access)
78
- connection = fog_connection
78
+ # @param provider [String] 'hp' or 'openstack'
79
+ def self.create_new_bucket(bucket_name, public_access, provider = "hp")
80
+ connection = fog_connection provider
79
81
  if connection.directories.get(bucket_name).nil?
80
82
  puts "The bucket with key=#{bucket_name} wasn't found. Creating bucket with key=#{bucket_name} ."
81
83
  bucket = connection.directories.create key: bucket_name
@@ -99,4 +101,38 @@ class Anynines::Swift::Utility
99
101
  options[:fog_public] = true if options[:fog_public].nil?
100
102
  return options
101
103
  end
104
+
105
+ def self.fog_credentials_hash_openstack_provider(vcap_service_subhash)
106
+ auth_uri = vcap_service_subhash["credentials"]["authentication_uri"]
107
+ last_route = auth_uri[auth_uri.length - 6, auth_uri.length - 1]
108
+ if last_route != "tokens"
109
+ last_char = auth_uri[auth_uri.length - 1]
110
+ if last_char == "/"
111
+ auth_uri = "#{auth_uri}tokens"
112
+ else
113
+ auth_uri = "#{auth_uri}/tokens"
114
+ end
115
+ end
116
+
117
+ {
118
+ :provider => 'OpenStack',
119
+ :openstack_auth_url => auth_uri,
120
+ :openstack_username => vcap_service_subhash["credentials"]["user_name"],
121
+ :openstack_api_key => vcap_service_subhash["credentials"]["password"],
122
+ :openstack_temp_url_key => vcap_service_subhash["credentials"]["account_meta_key"]
123
+ }
124
+ end
125
+
126
+ def self.fog_credentials_hash_hp_provider(vcap_service_subhash)
127
+ {
128
+ :provider => 'HP',
129
+ :hp_access_key => vcap_service_subhash["credentials"]["user_name"],
130
+ :hp_secret_key => vcap_service_subhash["credentials"]["password"],
131
+ :hp_tenant_id => vcap_service_subhash["credentials"]["tenant_id"],
132
+ :hp_auth_uri => vcap_service_subhash["credentials"]["authentication_uri"],
133
+ :hp_use_upass_auth_style => true,
134
+ :hp_avl_zone => vcap_service_subhash["credentials"]["availability_zone"],
135
+ :os_account_meta_temp_url_key => vcap_service_subhash["credentials"]["account_meta_key"]
136
+ }
137
+ end
102
138
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: a9s_swift
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Weber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-14 00:00:00.000000000 Z
11
+ date: 2014-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda
@@ -90,6 +90,7 @@ extra_rdoc_files:
90
90
  - README.md
91
91
  files:
92
92
  - .document
93
+ - CHANGELOG.md
93
94
  - Gemfile
94
95
  - Gemfile.lock
95
96
  - LICENSE.txt
@@ -123,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
124
  version: '0'
124
125
  requirements: []
125
126
  rubyforge_project:
126
- rubygems_version: 2.2.2
127
+ rubygems_version: 2.0.6
127
128
  signing_key:
128
129
  specification_version: 4
129
130
  summary: anynines.com swift service utility library for simplifying app acces to the