niftycloud-restful-read-api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -12,3 +12,4 @@ end
12
12
 
13
13
  gem 'sinatra'
14
14
  gem 'nifty-cloud-sdk'
15
+ gem 'aws-sdk'
data/Gemfile.lock CHANGED
@@ -2,6 +2,9 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  addressable (2.3.6)
5
+ aws-sdk (1.44.0)
6
+ json (~> 1.4)
7
+ nokogiri (>= 1.4.4)
5
8
  builder (3.2.2)
6
9
  descendants_tracker (0.0.4)
7
10
  thread_safe (~> 0.3, >= 0.3.1)
@@ -61,6 +64,7 @@ PLATFORMS
61
64
  ruby
62
65
 
63
66
  DEPENDENCIES
67
+ aws-sdk
64
68
  bundler
65
69
  jeweler
66
70
  nifty-cloud-sdk
data/README.md CHANGED
@@ -96,9 +96,19 @@ config.ru から require して使うこともできます。
96
96
  * /mq/queues
97
97
  * キュー一覧を取得できます
98
98
 
99
+ ### DNS
100
+
101
+ * /dns/zones
102
+ * ゾーン一覧を取得できます
103
+
104
+ ### Storage
105
+
106
+ * /storage/buckets
107
+ * バケット一覧を取得できます
108
+
99
109
  ## TODO
100
110
 
101
- * ニフティクラウド MQ/ESS/DNS/Automation
111
+ * ニフティクラウド ESS/Automation
102
112
 
103
113
  ## ライセンス
104
114
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -1,7 +1,13 @@
1
1
  require 'logger'
2
+ require 'openssl'
3
+ require 'base64'
4
+ require 'time'
5
+
6
+ require 'httparty'
2
7
  require 'sinatra'
3
8
  require 'json'
4
9
  require 'NIFTY'
10
+ require 'aws-sdk'
5
11
 
6
12
  NIFTY::LOG.level = Logger::DEBUG
7
13
 
@@ -15,12 +21,13 @@ end
15
21
  class NiftycloudRestfulReadApi < Sinatra::Base
16
22
  class NiftyCloud
17
23
  class Computing
24
+ VERSION = '1.18'
18
25
 
19
26
  def initialize(options)
20
27
  @api = NIFTY::Cloud::Base.new(
21
28
  :access_key => options[:access_key_id],
22
29
  :secret_key => options[:secret_access_key],
23
- :server => "{options[:region]}.cp.cloud.nifty.com",
30
+ :server => "#{options[:region]}.cp.cloud.nifty.com",
24
31
  :path => '/api'
25
32
  )
26
33
  end
@@ -84,6 +91,8 @@ class NiftycloudRestfulReadApi < Sinatra::Base
84
91
  end
85
92
 
86
93
  class Rdb
94
+ VERSION = '2013-05-15N2013-12-16'
95
+
87
96
  def initialize(options)
88
97
  @api = NIFTY::Cloud::Base.new(
89
98
  :access_key => options[:access_key_id],
@@ -95,39 +104,40 @@ class NiftycloudRestfulReadApi < Sinatra::Base
95
104
 
96
105
  def db_instances
97
106
  response = @api.send(:response_generator, 'Action' => 'DescribeDBInstances')
98
- [response.DescribeDBInstancesResult.DBInstances.DBInstance.to_a].flatten rescue []
107
+ [response.DescribeDBInstancesResult.DBInstances.DBInstance].flatten rescue []
99
108
  end
100
109
 
101
110
  def db_security_groups
102
111
  response = @api.send(:response_generator, 'Action' => 'DescribeDBSecurityGroups')
103
- [response.DescribeDBSecurityGroupsResult.DBSecurityGroups.DBSecurityGroup.to_a].flatten rescue []
112
+ [response.DescribeDBSecurityGroupsResult.DBSecurityGroups.DBSecurityGroup].flatten rescue []
104
113
  end
105
114
 
106
115
  def db_parameter_groups
107
116
  response = @api.send(:response_generator, 'Action' => 'DescribeDBParameterGroups')
108
- [response.DescribeDBParameterGroupsResult.DBParameterGroups.DBParameterGroup.to_a].flatten rescue []
117
+ [response.DescribeDBParameterGroupsResult.DBParameterGroups.DBParameterGroup].flatten rescue []
109
118
  end
110
119
 
111
120
  def db_snapshots
112
121
  response = @api.send(:response_generator, 'Action' => 'DescribeDBSnapshots')
113
- p response
114
- [response.DescribeDBSnapshotsResult.DBSnapshots.DBSnapshot.to_a].flatten rescue []
122
+ [response.DescribeDBSnapshotsResult.DBSnapshots.DBSnapshot].flatten rescue []
115
123
  end
116
124
 
117
125
  def db_engine_versions
118
126
  response = @api.send(:response_generator, 'Action' => 'DescribeDBEngineVersions')
119
- [response.DescribeDBEngineVersionsResult.DBEngineVersions.DBEngineVersion.to_a].flatten rescue []
127
+ [response.DescribeDBEngineVersionsResult.DBEngineVersions.DBEngineVersion].flatten rescue []
120
128
  end
121
129
 
122
130
  # TODO: Engine
123
131
  #def orderable_db_instance_options
124
132
  # response = @api.send(:response_generator, 'Action' => 'DescribeOrderableDBInstanceOptions')
125
133
  # p response
126
- # [response.DescribeOrderableDBInstanceOptionsResult.OrderableDBInstanceOptions.OrderableDBInstanceOption.to_a].flatten rescue []
134
+ # [response.DescribeOrderableDBInstanceOptionsResult.OrderableDBInstanceOptions.OrderableDBInstanceOption].flatten rescue []
127
135
  #end
128
136
  end
129
137
 
130
138
  class Mq
139
+ VERSION = '2012-11-05N2013-12-16'
140
+
131
141
  def initialize(options)
132
142
  @api = NIFTY::Cloud::Base.new(
133
143
  :access_key => options[:access_key_id],
@@ -143,27 +153,95 @@ class NiftycloudRestfulReadApi < Sinatra::Base
143
153
  [response.ListQueuesResult.QueueUrl].flatten.map {|queue_url| {'QueueUrl' => queue_url} } rescue []
144
154
  end
145
155
  end
146
- end
147
-
148
- helpers do
149
- def compute
150
- @compute ||= NiftyCloud::Computing.new(
151
- :region => @region,
152
- :access_key_id => @access_key_id,
153
- :secret_access_key => @secret_access_key
154
- )
156
+
157
+ class Dns
158
+ include HTTParty
159
+ $debug_output = true
160
+ base_uri 'https://dns.api.cloud.nifty.com'
161
+
162
+ VERSION = '2012-12-12N2013-12-16'
163
+
164
+ def initialize(options)
165
+ @access_key_id = options[:access_key_id]
166
+ @secret_access_key = options[:secret_access_key]
167
+ end
168
+
169
+ def zones
170
+ @date = Time.now.rfc2822.gsub(/(\-|\+)\d{4}$/, 'GMT')
171
+ response = self.class.get("/#{Dns::VERSION}/hostedzone", :headers => headers)
172
+ [response['ListHostedZonesResponse']['HostedZones']['HostedZone']].flatten rescue []
173
+ end
174
+
175
+ def headers
176
+ {
177
+ 'x-nifty-authorization' => "NIFTY3-HTTPS NIFTYAccessKeyId=#{@access_key_id},ALgorithm=HmacSHA256,Signature=#{signature}",
178
+ 'x-nifty-date' => @date
179
+ }
180
+ end
181
+
182
+ def signature
183
+ signature = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), @secret_access_key, @date)).strip
184
+ end
155
185
  end
156
186
 
157
- def rdb
158
- @rdb ||= NiftyCloud::Rdb.new(
159
- :region => @region,
160
- :access_key_id => @access_key_id,
161
- :secret_access_key => @secret_access_key
162
- )
187
+ class Storage
188
+ include HTTParty
189
+ $debug_output = true
190
+
191
+ VERSION = '0'
192
+
193
+ def initialize(options)
194
+ @access_key_id = options[:access_key_id]
195
+ @secret_access_key = options[:secret_access_key]
196
+ if options[:region] == 'east-1'
197
+ self.class.base_uri "https://ncss.nifty.com"
198
+ else
199
+ self.class.base_uri "https://#{options[:region]}-ncss.nifty.com"
200
+ end
201
+ end
202
+
203
+ def buckets
204
+ @date = Time.now.rfc2822.gsub(/(\-|\+)\d{4}$/, 'GMT')
205
+ response = self.class.get("/", :headers => headers)
206
+ [response['ListAllMyBucketsResult']['Buckets']['Bucket']].flatten rescue []
207
+ end
208
+
209
+ def headers
210
+ {
211
+ 'authorization' => "NIFTY #{@access_key_id}:#{signature}",
212
+ 'date' => @date,
213
+ 'content-type' => 'text/plain'
214
+ }
215
+ end
216
+
217
+ def signature
218
+ signature = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), @secret_access_key, string_to_sign)).strip
219
+ end
220
+
221
+ def string_to_sign
222
+ str = []
223
+ str << 'GET'
224
+ str << ''
225
+ str << 'text/plain'
226
+ str << @date
227
+ str << '/'
228
+ str.join("\n")
229
+ end
163
230
  end
231
+ end
232
+
233
+ helpers do
234
+ SERVICE_CLASS = {
235
+ :computing => NiftyCloud::Computing,
236
+ :rdb => NiftyCloud::Rdb,
237
+ :mq => NiftyCloud::Mq,
238
+ :dns => NiftyCloud::Dns,
239
+ :storage => NiftyCloud::Storage
240
+ }
164
241
 
165
- def mq
166
- @rdb ||= NiftyCloud::Mq.new(
242
+ def service(service)
243
+ NIFTY::VERSION.gsub!(/^.+$/) { SERVICE_CLASS[service]::VERSION }
244
+ SERVICE_CLASS[service].new(
167
245
  :region => @region,
168
246
  :access_key_id => @access_key_id,
169
247
  :secret_access_key => @secret_access_key
@@ -178,17 +256,7 @@ class NiftycloudRestfulReadApi < Sinatra::Base
178
256
  @secret_access_key = params[:secret_access_key] || ENV['SECRET_ACCESS_KEY']
179
257
  end
180
258
 
181
- post '/computing/:resources' do
182
- compute.send(params[:resources]).to_json
183
- end
184
-
185
- post '/rdb/:resources' do
186
- NIFTY::VERSION = '2013-05-15N2013-12-16'
187
- rdb.send(params[:resources]).to_json
188
- end
189
-
190
- post '/mq/:resources' do
191
- NIFTY::VERSION = '2012-11-05N2013-12-16'
192
- mq.send(params[:resources]).to_json
259
+ get '/:service/:resources' do
260
+ service(params[:service].to_sym).send(params[:resources]).to_json
193
261
  end
194
262
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: niftycloud-restful-read-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-25 00:00:00.000000000Z
12
+ date: 2014-06-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &227443700 !ruby/object:Gem::Requirement
16
+ requirement: &144182160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *227443700
24
+ version_requirements: *144182160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nifty-cloud-sdk
27
- requirement: &227462700 !ruby/object:Gem::Requirement
27
+ requirement: &144181320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,21 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *227462700
35
+ version_requirements: *144181320
36
+ - !ruby/object:Gem::Dependency
37
+ name: aws-sdk
38
+ requirement: &144180180 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *144180180
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: bundler
38
- requirement: &227462220 !ruby/object:Gem::Requirement
49
+ requirement: &144178260 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: '0'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *227462220
57
+ version_requirements: *144178260
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: jeweler
49
- requirement: &227461740 !ruby/object:Gem::Requirement
60
+ requirement: &144177380 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,7 +65,7 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *227461740
68
+ version_requirements: *144177380
58
69
  description: NIFTYCloud の情報取得系 API を RESTful に利用できるようにする Sinatra アプリ
59
70
  email: tily05@gmail.com
60
71
  executables:
@@ -63,7 +74,6 @@ extensions: []
63
74
  extra_rdoc_files:
64
75
  - LICENSE.txt
65
76
  - README.md
66
- - TODO
67
77
  files:
68
78
  - .document
69
79
  - Gemfile
@@ -76,7 +86,6 @@ files:
76
86
  - lib/niftycloud-restful-read-api.rb
77
87
  - test/helper.rb
78
88
  - test/test_nifty-cloud-restful-read-api.rb
79
- - TODO
80
89
  homepage: http://github.com/tily/niftycloud-restful-read-api
81
90
  licenses:
82
91
  - MIT
@@ -92,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
101
  version: '0'
93
102
  segments:
94
103
  - 0
95
- hash: 801768762339487333
104
+ hash: 3637886189179613779
96
105
  required_rubygems_version: !ruby/object:Gem::Requirement
97
106
  none: false
98
107
  requirements:
data/TODO DELETED
@@ -1 +0,0 @@
1
- RDB, to_a が要らない