niftycloud-restful-read-api 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +67 -0
- data/LICENSE.txt +1 -0
- data/README.md +87 -0
- data/Rakefile +34 -0
- data/VERSION +1 -0
- data/bin/niftycloud-restful-read-api +4 -0
- data/lib/niftycloud-restful-read-api.rb +98 -0
- data/test/helper.rb +18 -0
- data/test/test_nifty-cloud-restful-read-api.rb +7 -0
- metadata +106 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "bundler"
|
10
|
+
gem "jeweler"
|
11
|
+
end
|
12
|
+
|
13
|
+
gem 'sinatra'
|
14
|
+
gem 'nifty-cloud-sdk'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.6)
|
5
|
+
builder (3.2.2)
|
6
|
+
descendants_tracker (0.0.4)
|
7
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
8
|
+
faraday (0.9.0)
|
9
|
+
multipart-post (>= 1.2, < 3)
|
10
|
+
git (1.2.7)
|
11
|
+
github_api (0.11.3)
|
12
|
+
addressable (~> 2.3)
|
13
|
+
descendants_tracker (~> 0.0.1)
|
14
|
+
faraday (~> 0.8, < 0.10)
|
15
|
+
hashie (>= 1.2)
|
16
|
+
multi_json (>= 1.7.5, < 2.0)
|
17
|
+
nokogiri (~> 1.6.0)
|
18
|
+
oauth2
|
19
|
+
hashie (3.0.0)
|
20
|
+
highline (1.6.21)
|
21
|
+
jeweler (2.0.1)
|
22
|
+
builder
|
23
|
+
bundler (>= 1.0)
|
24
|
+
git (>= 1.2.5)
|
25
|
+
github_api
|
26
|
+
highline (>= 1.6.15)
|
27
|
+
nokogiri (>= 1.5.10)
|
28
|
+
rake
|
29
|
+
rdoc
|
30
|
+
json (1.8.1)
|
31
|
+
jwt (1.0.0)
|
32
|
+
mini_portile (0.6.0)
|
33
|
+
multi_json (1.10.1)
|
34
|
+
multi_xml (0.5.5)
|
35
|
+
multipart-post (2.0.0)
|
36
|
+
nifty-cloud-sdk (1.7)
|
37
|
+
xml-simple (>= 1.0.12)
|
38
|
+
nokogiri (1.6.2.1)
|
39
|
+
mini_portile (= 0.6.0)
|
40
|
+
oauth2 (0.9.4)
|
41
|
+
faraday (>= 0.8, < 0.10)
|
42
|
+
jwt (~> 1.0)
|
43
|
+
multi_json (~> 1.3)
|
44
|
+
multi_xml (~> 0.5)
|
45
|
+
rack (~> 1.2)
|
46
|
+
rack (1.5.2)
|
47
|
+
rack-protection (1.5.3)
|
48
|
+
rack
|
49
|
+
rake (10.3.2)
|
50
|
+
rdoc (4.1.1)
|
51
|
+
json (~> 1.4)
|
52
|
+
sinatra (1.4.5)
|
53
|
+
rack (~> 1.4)
|
54
|
+
rack-protection (~> 1.4)
|
55
|
+
tilt (~> 1.3, >= 1.3.4)
|
56
|
+
thread_safe (0.3.4)
|
57
|
+
tilt (1.4.1)
|
58
|
+
xml-simple (1.1.3)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
ruby
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
bundler
|
65
|
+
jeweler
|
66
|
+
nifty-cloud-sdk
|
67
|
+
sinatra
|
data/LICENSE.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Public Domain
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# NIFTYCloud RESTful Read API
|
2
|
+
|
3
|
+
## 概要
|
4
|
+
|
5
|
+
ニフティクラウドの情報取得系 API を REST っぽく取得できるようにする Sinatra アプリです。
|
6
|
+
|
7
|
+
## インストール
|
8
|
+
|
9
|
+
gem install niftycloud-restful-read-api
|
10
|
+
|
11
|
+
## 使い方
|
12
|
+
|
13
|
+
### コマンドライン
|
14
|
+
|
15
|
+
環境変数で認証情報を指定し、niftycloud-restful-read-api コマンドを実行すると、
|
16
|
+
|
17
|
+
$ export ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX
|
18
|
+
$ export SECRET_ACCESS_KEY=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
|
19
|
+
$ niftycloud-restful-read-api
|
20
|
+
[2014-06-26 01:15:24] INFO WEBrick 1.3.1
|
21
|
+
[2014-06-26 01:15:24] INFO ruby 2.0.0 (2014-02-24) [universal.x86_64-darwin13]
|
22
|
+
== Sinatra/1.4.5 has taken the stage on 4567 for development with backup from WEBrick
|
23
|
+
[2014-06-26 01:15:24] INFO WEBrick::HTTPServer#start: pid=18326 port=4567
|
24
|
+
|
25
|
+
http://localhost:4567 からいい感じの JSON が取得できるようになります。
|
26
|
+
|
27
|
+
$ curl -X POST -d "hoge" http://localhost:4567/computing/key_pairs | python -m json.tool
|
28
|
+
% Total % Received % Xferd Average Speed Time Time Time Current
|
29
|
+
Dload Upload Total Spent Left Speed
|
30
|
+
100 309 100 305 100 4 383 5 --:--:-- --:--:-- --:--:-- 383
|
31
|
+
[
|
32
|
+
{
|
33
|
+
"keyFingerprint": "1f:e7:bb:c1:c8:a1:32:d1:7d:b5:db:e9:ac:12:37:3a:69:e9:ee:50",
|
34
|
+
"keyName": "JTFJTF"
|
35
|
+
},
|
36
|
+
{
|
37
|
+
"keyFingerprint": "9c:a9:04:9f:e1:8b:36:ca:b3:91:49:6a:fd:d4:47:9f:0f:a5:99:40",
|
38
|
+
"keyName": "default"
|
39
|
+
},
|
40
|
+
{
|
41
|
+
"keyFingerprint": "36:30:be:c6:47:f6:bd:be:38:c9:cd:d1:55:61:aa:0c:c1:ff:a3:00",
|
42
|
+
"keyName": "something"
|
43
|
+
}
|
44
|
+
]
|
45
|
+
|
46
|
+
### config.ru
|
47
|
+
|
48
|
+
config.ru から require して使うこともできます。
|
49
|
+
|
50
|
+
$ cat config.ru
|
51
|
+
require 'niftycloud-restful-read-api'
|
52
|
+
run NiftycloudRestfulReadApi
|
53
|
+
$ rackup
|
54
|
+
[2014-06-26 01:19:34] INFO WEBrick 1.3.1
|
55
|
+
[2014-06-26 01:19:34] INFO ruby 2.0.0 (2014-02-24) [universal.x86_64-darwin13]
|
56
|
+
[2014-06-26 01:19:34] INFO WEBrick::HTTPServer#start: pid=18378 port=9292
|
57
|
+
|
58
|
+
## 対応リソース
|
59
|
+
|
60
|
+
### Computing
|
61
|
+
|
62
|
+
* /computing/regions
|
63
|
+
* リージョン一覧を取得できます
|
64
|
+
* /computing/instances
|
65
|
+
* サーバー一覧を取得できます
|
66
|
+
* /computing/volumes
|
67
|
+
* ディスク一覧を取得できます
|
68
|
+
* /computing/key_pairs
|
69
|
+
* SSH キー一覧を取得できます
|
70
|
+
* /computing/images
|
71
|
+
* イメージ一覧を取得できます
|
72
|
+
* /computing/load_balancers
|
73
|
+
* ロードバランサー一覧を取得できます
|
74
|
+
* /computing/security_groups
|
75
|
+
* ファイアウォール一覧を取得できます
|
76
|
+
* /computing/ssl_certificates
|
77
|
+
* SSL 証明書一覧を取得できます
|
78
|
+
* /computing/addresses
|
79
|
+
* 付替アドレス一覧を取得できます
|
80
|
+
|
81
|
+
## TODO
|
82
|
+
|
83
|
+
* ニフティクラウド RDB/MQ/ESS/DNS/Automation
|
84
|
+
|
85
|
+
## ライセンス
|
86
|
+
|
87
|
+
* パブリックドメイン
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "niftycloud-restful-read-api"
|
18
|
+
gem.homepage = "http://github.com/tily/niftycloud-restful-read-api"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{NIFTYCloud の情報取得系 API を RESTful に利用できるようにする Sinatra アプリ}
|
21
|
+
gem.description = %Q{NIFTYCloud の情報取得系 API を RESTful に利用できるようにする Sinatra アプリ}
|
22
|
+
gem.email = "tily05@gmail.com"
|
23
|
+
gem.authors = ["tily"]
|
24
|
+
gem.executables = ['niftycloud-restful-read-api']
|
25
|
+
# dependencies defined in Gemfile
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'json'
|
3
|
+
require 'NIFTY'
|
4
|
+
|
5
|
+
class NiftycloudRestfulReadApi < Sinatra::Base
|
6
|
+
class NiftyCloud
|
7
|
+
class Computing
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
@api = NIFTY::Cloud::Base.new(
|
11
|
+
:access_key => options[:access_key_id],
|
12
|
+
:secret_key => options[:secret_access_key],
|
13
|
+
:endpoint => "{options[:region]}.cp.cloud.nifty.com",
|
14
|
+
:path => '/api'
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def regions
|
19
|
+
response = @api.send(:response_generator, 'Action' => 'DescribeRegions')
|
20
|
+
response.regionInfo.item.to_a rescue []
|
21
|
+
end
|
22
|
+
|
23
|
+
def instances
|
24
|
+
response = @api.describe_instances
|
25
|
+
|
26
|
+
return [] if response.reservationSet.nil?
|
27
|
+
|
28
|
+
items = response.reservationSet.item
|
29
|
+
instances = items.map do |item|
|
30
|
+
security_groups = item.groupSet.item.flatten.map {|item| item.groupId }
|
31
|
+
instances = item.instancesSet.item.to_a
|
32
|
+
instances.each do |instance|
|
33
|
+
instance['securityGroups'] = security_groups
|
34
|
+
end
|
35
|
+
instances
|
36
|
+
end
|
37
|
+
instances.flatten
|
38
|
+
end
|
39
|
+
|
40
|
+
def volumes
|
41
|
+
response = @api.describe_volumes
|
42
|
+
response.volumeSet.item.to_a rescue []
|
43
|
+
end
|
44
|
+
|
45
|
+
def key_pairs
|
46
|
+
response = @api.describe_key_pairs
|
47
|
+
response.keySet.item.to_a rescue []
|
48
|
+
end
|
49
|
+
|
50
|
+
def images
|
51
|
+
response = @api.describe_images
|
52
|
+
response.imagesSet.item.to_a rescue []
|
53
|
+
end
|
54
|
+
|
55
|
+
def load_balancers
|
56
|
+
response = @api.describe_load_balancers
|
57
|
+
response.DescribeLoadBalancersResult.LoadBalancerDescriptions.member.to_a rescue []
|
58
|
+
end
|
59
|
+
|
60
|
+
def security_groups
|
61
|
+
response = @api.describe_security_groups
|
62
|
+
response.securityGroupInfo.item.to_a rescue []
|
63
|
+
end
|
64
|
+
|
65
|
+
def ssl_certificates
|
66
|
+
response = @api.describe_ssl_certificates
|
67
|
+
response.certsSet.item.to_a rescue []
|
68
|
+
[]
|
69
|
+
end
|
70
|
+
|
71
|
+
def addresses
|
72
|
+
response = @api.send(:response_generator, 'Action' => 'DescribeAddresses')
|
73
|
+
response.addressesSet.item.to_a rescue []
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
helpers do
|
79
|
+
def compute
|
80
|
+
@compute ||= NiftyCloud::Computing.new(
|
81
|
+
:region => @region,
|
82
|
+
:access_key_id => @access_key_id,
|
83
|
+
:secret_access_key => @secret_access_key
|
84
|
+
)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
before do
|
89
|
+
content_type 'text/plain'
|
90
|
+
@region = params[:region] || 'east-1'
|
91
|
+
@access_key_id = params[:access_key_id] || ENV['ACCESS_KEY_ID']
|
92
|
+
@secret_access_key = params[:secret_access_key] || ENV['SECRET_ACCESS_KEY']
|
93
|
+
end
|
94
|
+
|
95
|
+
post '/computing/:resources' do
|
96
|
+
compute.send(params[:resources]).to_json
|
97
|
+
end
|
98
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'niftycloud-restful-read-api'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: niftycloud-restful-read-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- tily
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-25 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: &41097780 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *41097780
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: nifty-cloud-sdk
|
27
|
+
requirement: &41097180 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *41097180
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &41096580 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *41096580
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: &41095980 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *41095980
|
58
|
+
description: NIFTYCloud の情報取得系 API を RESTful に利用できるようにする Sinatra アプリ
|
59
|
+
email: tily05@gmail.com
|
60
|
+
executables:
|
61
|
+
- niftycloud-restful-read-api
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files:
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
files:
|
67
|
+
- .document
|
68
|
+
- Gemfile
|
69
|
+
- Gemfile.lock
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- VERSION
|
74
|
+
- bin/niftycloud-restful-read-api
|
75
|
+
- lib/niftycloud-restful-read-api.rb
|
76
|
+
- test/helper.rb
|
77
|
+
- test/test_nifty-cloud-restful-read-api.rb
|
78
|
+
homepage: http://github.com/tily/niftycloud-restful-read-api
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
hash: 2482087528386462282
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.13
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: NIFTYCloud の情報取得系 API を RESTful に利用できるようにする Sinatra アプリ
|
106
|
+
test_files: []
|