kanmon 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/exe/kanmon +3 -4
- data/kanmon.gemspec +1 -1
- data/lib/kanmon.rb +25 -1
- data/lib/kanmon/cli.rb +74 -0
- data/lib/kanmon/myip.rb +11 -0
- data/lib/kanmon/version.rb +1 -1
- metadata +7 -11
- data/Gemfile.lock +0 -55
- data/lib/kanmon/commands.rb +0 -11
- data/lib/kanmon/commands/base.rb +0 -30
- data/lib/kanmon/commands/close.rb +0 -43
- data/lib/kanmon/commands/open.rb +0 -30
- data/lib/kanmon/commands/version.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e7a715138c4ecc5d5d10a150bfca964d497e937839f6b66a9d05e514b90053b
|
4
|
+
data.tar.gz: 5ccf83c54ea6098279fe7029a7f09f46e4da9f214669ed18168e272dd77bfa87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d594dcb84cd1bf89431bcf8f78f4e5e24203adb0bb8b64ee274df6afab7f910a193660ae59630890110966eea4209a6308b26dc25c4dcaeb17612aeebff767c
|
7
|
+
data.tar.gz: 386aacf6e68e101384882f23ae909719ec4717b52b254d4e6a285123a71fccebe7bf2e58e0531181211f2bf8e7099acc729c9f58bcb192f12aeaad898656add9
|
data/.gitignore
CHANGED
@@ -9,6 +9,8 @@
|
|
9
9
|
/test/tmp/
|
10
10
|
/test/version_tmp/
|
11
11
|
/tmp/
|
12
|
+
/*.yml
|
13
|
+
/*.yaml
|
12
14
|
|
13
15
|
# Used by dotenv library to load environment variables.
|
14
16
|
# .env
|
@@ -21,6 +23,7 @@ build/
|
|
21
23
|
build-iPhoneOS/
|
22
24
|
build-iPhoneSimulator/
|
23
25
|
.rspec_status
|
26
|
+
/Gemfile.lock
|
24
27
|
|
25
28
|
## Specific to RubyMotion (use of CocoaPods):
|
26
29
|
#
|
data/exe/kanmon
CHANGED
data/kanmon.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
23
|
spec.add_dependency "yao", ">= 0.4.1"
|
24
|
-
spec.add_dependency "
|
24
|
+
spec.add_dependency "thor", ">= 0.20.0"
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.16"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/kanmon.rb
CHANGED
@@ -1,4 +1,28 @@
|
|
1
|
-
require "
|
1
|
+
require "yao"
|
2
|
+
require "yaml"
|
3
|
+
|
4
|
+
require "kanmon/cli"
|
2
5
|
|
3
6
|
module Kanmon
|
7
|
+
|
8
|
+
def self.init_yao
|
9
|
+
Yao.configure do
|
10
|
+
auth_url ENV['OS_AUTH_URL']
|
11
|
+
tenant_name ENV['OS_TENANT_NAME']
|
12
|
+
username ENV['OS_USERNAME']
|
13
|
+
password ENV['OS_PASSWORD']
|
14
|
+
client_cert ENV['OS_CERT']
|
15
|
+
client_key ENV['OS_KEY']
|
16
|
+
region_name ENV['OS_REGION_NAME']
|
17
|
+
identity_api_version ENV['OS_IDENTITY_API_VERSION']
|
18
|
+
user_domain_name ENV['OS_USER_DOMAIN_NAME']
|
19
|
+
project_domain_name ENV['OS_PROJECT_DOMAIN_NAME']
|
20
|
+
debug ENV['YAO_DEBUG']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.load_config(file_name)
|
25
|
+
YAML.load_file(file_name)
|
26
|
+
end
|
27
|
+
|
4
28
|
end
|
data/lib/kanmon/cli.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
require "kanmon/myip"
|
4
|
+
|
5
|
+
module Kanmon
|
6
|
+
class CLI < Thor
|
7
|
+
class_option :file, aliases: "f", type: :string, default: "kanmon.yml", banner: "FILE", desc: "Load configure from FILE"
|
8
|
+
|
9
|
+
desc "open", "Commands about add rules to SecurityGroup"
|
10
|
+
def open
|
11
|
+
myip = Kanmon::MyIP.get
|
12
|
+
rule = {
|
13
|
+
direction: "ingress",
|
14
|
+
port_range_min: 22,
|
15
|
+
port_range_max: 22,
|
16
|
+
ethertype: "IPv4",
|
17
|
+
protocol: "tcp",
|
18
|
+
remote_ip_prefix: "#{myip}/32",
|
19
|
+
security_group_id: @config["security_group"],
|
20
|
+
}
|
21
|
+
|
22
|
+
Yao::SecurityGroupRule.create(rule)
|
23
|
+
puts "Success!!"
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "close", "Commands about delete rules from SecurityGroup"
|
27
|
+
def close
|
28
|
+
myip = Kanmon::MyIP.get
|
29
|
+
tenant_id = Yao.current_tenant_id
|
30
|
+
|
31
|
+
rule = {
|
32
|
+
direction: "ingress",
|
33
|
+
port_range_min: 22,
|
34
|
+
port_range_max: 22,
|
35
|
+
ethertype: "IPv4",
|
36
|
+
protocol: "tcp",
|
37
|
+
security_group_id: @config["security_group"],
|
38
|
+
tenant_id: tenant_id,
|
39
|
+
remote_ip_prefix: "#{myip}/32"
|
40
|
+
}
|
41
|
+
|
42
|
+
result = Yao::SecurityGroupRule.list(rule)
|
43
|
+
|
44
|
+
if result.empty?
|
45
|
+
puts "Not found"
|
46
|
+
exit(1)
|
47
|
+
end
|
48
|
+
|
49
|
+
result.each do |rule|
|
50
|
+
id = rule.id
|
51
|
+
puts "Delete #{id}"
|
52
|
+
Yao::SecurityGroupRule.destroy(id)
|
53
|
+
end
|
54
|
+
|
55
|
+
puts "Success!!"
|
56
|
+
end
|
57
|
+
|
58
|
+
desc "version", "Commands about show version"
|
59
|
+
def version
|
60
|
+
puts Kanmon::VERSION
|
61
|
+
end
|
62
|
+
|
63
|
+
no_commands do
|
64
|
+
def invoke_command(command, *args)
|
65
|
+
unless %w(help version).include?(command.name)
|
66
|
+
Kanmon.init_yao
|
67
|
+
@config = Kanmon.load_config(options[:file])
|
68
|
+
end
|
69
|
+
|
70
|
+
super
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/kanmon/myip.rb
ADDED
data/lib/kanmon/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kanmon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuki Koya
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yao
|
@@ -25,19 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.4.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: thor
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.20.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.20.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,7 +92,6 @@ files:
|
|
92
92
|
- ".rspec"
|
93
93
|
- ".travis.yml"
|
94
94
|
- Gemfile
|
95
|
-
- Gemfile.lock
|
96
95
|
- LICENSE
|
97
96
|
- README.md
|
98
97
|
- Rakefile
|
@@ -101,11 +100,8 @@ files:
|
|
101
100
|
- exe/kanmon
|
102
101
|
- kanmon.gemspec
|
103
102
|
- lib/kanmon.rb
|
104
|
-
- lib/kanmon/
|
105
|
-
- lib/kanmon/
|
106
|
-
- lib/kanmon/commands/close.rb
|
107
|
-
- lib/kanmon/commands/open.rb
|
108
|
-
- lib/kanmon/commands/version.rb
|
103
|
+
- lib/kanmon/cli.rb
|
104
|
+
- lib/kanmon/myip.rb
|
109
105
|
- lib/kanmon/version.rb
|
110
106
|
homepage: https://github.com/buty4649/kanmon/
|
111
107
|
licenses: []
|
data/Gemfile.lock
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
kanmon (0.1.0)
|
5
|
-
hanami-cli (>= 0.1.1)
|
6
|
-
yao (>= 0.4.1)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
concurrent-ruby (1.0.5)
|
12
|
-
diff-lcs (1.3)
|
13
|
-
faraday (0.12.2)
|
14
|
-
multipart-post (>= 1.2, < 3)
|
15
|
-
faraday_middleware (0.12.2)
|
16
|
-
faraday (>= 0.7.4, < 1.0)
|
17
|
-
hanami-cli (0.2.0)
|
18
|
-
concurrent-ruby (~> 1.0)
|
19
|
-
hanami-utils (~> 1.2)
|
20
|
-
hanami-utils (1.2.0)
|
21
|
-
concurrent-ruby (~> 1.0)
|
22
|
-
transproc (~> 1.0)
|
23
|
-
json (2.1.0)
|
24
|
-
multipart-post (2.0.0)
|
25
|
-
rake (10.5.0)
|
26
|
-
rspec (3.7.0)
|
27
|
-
rspec-core (~> 3.7.0)
|
28
|
-
rspec-expectations (~> 3.7.0)
|
29
|
-
rspec-mocks (~> 3.7.0)
|
30
|
-
rspec-core (3.7.1)
|
31
|
-
rspec-support (~> 3.7.0)
|
32
|
-
rspec-expectations (3.7.0)
|
33
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
-
rspec-support (~> 3.7.0)
|
35
|
-
rspec-mocks (3.7.0)
|
36
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (~> 3.7.0)
|
38
|
-
rspec-support (3.7.1)
|
39
|
-
transproc (1.0.2)
|
40
|
-
yao (0.4.1)
|
41
|
-
faraday (~> 0.12.0)
|
42
|
-
faraday_middleware
|
43
|
-
json
|
44
|
-
|
45
|
-
PLATFORMS
|
46
|
-
ruby
|
47
|
-
|
48
|
-
DEPENDENCIES
|
49
|
-
bundler (~> 1.16)
|
50
|
-
kanmon!
|
51
|
-
rake (~> 10.0)
|
52
|
-
rspec (~> 3.0)
|
53
|
-
|
54
|
-
BUNDLED WITH
|
55
|
-
1.16.1
|
data/lib/kanmon/commands.rb
DELETED
data/lib/kanmon/commands/base.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require "net/http"
|
2
|
-
require "uri"
|
3
|
-
|
4
|
-
module Kanmon
|
5
|
-
module Commands
|
6
|
-
class Base < Hanami::CLI::Command
|
7
|
-
|
8
|
-
def initialize(*)
|
9
|
-
Yao.configure do
|
10
|
-
auth_url ENV['OS_AUTH_URL']
|
11
|
-
tenant_name ENV['OS_TENANT_NAME']
|
12
|
-
username ENV['OS_USERNAME']
|
13
|
-
password ENV['OS_PASSWORD']
|
14
|
-
client_cert ENV['OS_CERT']
|
15
|
-
client_key ENV['OS_KEY']
|
16
|
-
region_name ENV['OS_REGION_NAME']
|
17
|
-
identity_api_version ENV['OS_IDENTITY_API_VERSION']
|
18
|
-
user_domain_name ENV['OS_USER_DOMAIN_NAME']
|
19
|
-
project_domain_name ENV['OS_PROJECT_DOMAIN_NAME']
|
20
|
-
debug ENV['YAO_DEBUG']
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def myip
|
25
|
-
res = Net::HTTP.get URI.parse('https://checkip.amazonaws.com/')
|
26
|
-
res.chomp
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require "yao"
|
2
|
-
require "yaml"
|
3
|
-
require "kanmon/commands/base"
|
4
|
-
|
5
|
-
module Kanmon
|
6
|
-
module Commands
|
7
|
-
class Close < Base
|
8
|
-
option :file, default: "kanmon.yml", desc: "config file path"
|
9
|
-
|
10
|
-
def call(**options)
|
11
|
-
id = YAML.load_file(options.fetch(:file))["security_group"]
|
12
|
-
tenant_id = Yao.current_tenant_id
|
13
|
-
|
14
|
-
rule = {
|
15
|
-
direction: "ingress",
|
16
|
-
port_range_min: 22,
|
17
|
-
port_range_max: 22,
|
18
|
-
ethertype: "IPv4",
|
19
|
-
protocol: "tcp",
|
20
|
-
security_group_id: id,
|
21
|
-
tenant_id: tenant_id,
|
22
|
-
}
|
23
|
-
|
24
|
-
result = Yao::SecurityGroupRule.list(rule)
|
25
|
-
|
26
|
-
if result.empty?
|
27
|
-
puts "Not found"
|
28
|
-
exit(1)
|
29
|
-
end
|
30
|
-
|
31
|
-
result.each do |rule|
|
32
|
-
id = rule.id
|
33
|
-
puts "Delete #{id}"
|
34
|
-
Yao::SecurityGroupRule.destroy(id)
|
35
|
-
end
|
36
|
-
|
37
|
-
puts "Success!!"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
register "close", Close
|
42
|
-
end
|
43
|
-
end
|
data/lib/kanmon/commands/open.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require "yao"
|
2
|
-
require "yaml"
|
3
|
-
require "kanmon/commands/base"
|
4
|
-
|
5
|
-
module Kanmon
|
6
|
-
module Commands
|
7
|
-
class Open < Base
|
8
|
-
option :file, default: "kanmon.yml", desc: "config file path"
|
9
|
-
|
10
|
-
def call(**options)
|
11
|
-
id = YAML.load_file(options.fetch(:file))["security_group"]
|
12
|
-
ip = myip
|
13
|
-
rule = {
|
14
|
-
direction: "ingress",
|
15
|
-
port_range_min: 22,
|
16
|
-
port_range_max: 22,
|
17
|
-
ethertype: "IPv4",
|
18
|
-
protocol: "tcp",
|
19
|
-
remote_ip_prefix: "#{ip}/32",
|
20
|
-
security_group_id: id,
|
21
|
-
}
|
22
|
-
|
23
|
-
Yao::SecurityGroupRule.create(rule)
|
24
|
-
puts "Success!!"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
register "open", Open
|
29
|
-
end
|
30
|
-
end
|