rapis 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +33 -0
- data/.travis.yml +7 -1
- data/CHANGELOG.md +10 -1
- data/README.md +9 -3
- data/exe/rapis +1 -1
- data/lib/rapis/actions.rb +19 -25
- data/lib/rapis/cli.rb +34 -23
- data/lib/rapis/client.rb +15 -21
- data/lib/rapis/converter.rb +62 -47
- data/lib/rapis/exceptions.rb +1 -0
- data/lib/rapis/logger.rb +12 -34
- data/lib/rapis/utils.rb +27 -29
- data/lib/rapis/version.rb +1 -1
- data/lib/rapis.rb +20 -7
- data/rapis.gemspec +2 -0
- metadata +32 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bfe276fcc78b153847606180a18cbfd4731b8cb
|
4
|
+
data.tar.gz: 54dfe4b9be39e7a1622f38d6455e544a899c3adf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb8e8141386c47650ffaff1e316729567a0e820ea53179a52adbe6e6e5c1aba85af223e82c2e329764ba3a54a2688219f01975220753b68245f6089c7ed55a07
|
7
|
+
data.tar.gz: fa300290d3d070fef9f0dfb32e7af774fa8e21211a50473a9f3a1bb524a205b686d38db110bc81ad991cfed8b46cf665a15aabe702d3d1bcc74855dca5f9d2b8
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'bin/**'
|
4
|
+
- 'exe/**'
|
5
|
+
- Rakefile
|
6
|
+
- rapis.gemspec
|
7
|
+
|
8
|
+
LineLength:
|
9
|
+
Max: 120
|
10
|
+
|
11
|
+
Metrics/ClassLength:
|
12
|
+
Max: 150
|
13
|
+
|
14
|
+
Metrics/MethodLength:
|
15
|
+
Max: 30
|
16
|
+
|
17
|
+
Metrics/AbcSize:
|
18
|
+
Max: 30
|
19
|
+
|
20
|
+
Metrics/PerceivedComplexity:
|
21
|
+
Max: 10
|
22
|
+
|
23
|
+
Metrics/CyclomaticComplexity:
|
24
|
+
Max: 10
|
25
|
+
|
26
|
+
Style/Documentation:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/MutableConstant:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/RedundantBegin:
|
33
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Rapis
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rapis.svg)](https://badge.fury.io/rb/rapis)
|
4
|
+
[![Build Status](https://travis-ci.org/marcy-terui/rapis.svg?branch=master)](https://travis-ci.org/marcy-terui/rapis)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/github/marcy-terui/rapis/badge.svg?branch=master)](https://coveralls.io/github/marcy-terui/rapis?branch=master)
|
6
|
+
|
7
|
+
|
3
8
|
Swagger as Ruby DSL and its deployment tool for Amazon API Gateway
|
4
9
|
|
5
10
|
## Installation
|
@@ -24,7 +29,7 @@ Or install it yourself as:
|
|
24
29
|
Commands:
|
25
30
|
rapis apply -r, --rest-api=REST_API # Apply the REST API configuration
|
26
31
|
rapis convert -F, --format=FORMAT # Convert the REST API configuration to the specified format
|
27
|
-
rapis create
|
32
|
+
rapis create -n, --name=NAME # Create REST API
|
28
33
|
rapis deploy -r, --rest-api=REST_API -s, --stage=STAGE # Deploy the current REST API configuration to the stage
|
29
34
|
rapis diff -r, --rest-api=REST_API -s, --stage=STAGE # Diff the local configuration and the remote configuration
|
30
35
|
rapis export -r, --rest-api=REST_API -s, --stage=STAGE # Export the configuration as Ruby DSL
|
@@ -43,9 +48,10 @@ Create REST API
|
|
43
48
|
|
44
49
|
```sh
|
45
50
|
Usage:
|
46
|
-
rapis create
|
51
|
+
rapis create -n, --name=NAME
|
47
52
|
|
48
53
|
Options:
|
54
|
+
-n, --name=NAME # Name
|
49
55
|
-d, [--description=DESCRIPTION] # Description
|
50
56
|
-f, [--file=FILE] # Configuration file
|
51
57
|
# Default: Apifile
|
@@ -91,7 +97,7 @@ Options:
|
|
91
97
|
-s, --stage=STAGE # The name of the stage
|
92
98
|
-d, [--description=DESCRIPTION] # The description for the deployment
|
93
99
|
-D, [--stage-description=STAGE_DESCRIPTION] # The description of the stage
|
94
|
-
-c, [--cache=CACHE] # Size of the cache cluster
|
100
|
+
-c, [--cache=CACHE] # Size of the cache cluster
|
95
101
|
# Default: 0.0
|
96
102
|
-v, [--variables=key:value] # A map that defines the stage variables
|
97
103
|
-f, [--file=FILE] # Configuration file
|
data/exe/rapis
CHANGED
data/lib/rapis/actions.rb
CHANGED
@@ -1,25 +1,16 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'json'
|
3
|
-
require 'rapis/client'
|
4
|
-
require 'rapis/converter'
|
5
|
-
require 'rapis/logger'
|
6
|
-
require 'rapis/utils'
|
7
|
-
|
8
1
|
module Rapis
|
9
2
|
class Actions
|
10
|
-
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@client = Rapis::Client.new
|
3
|
+
def initialize(client)
|
4
|
+
@client = client
|
14
5
|
@converter = Rapis::Converter.new
|
15
6
|
end
|
16
7
|
|
17
|
-
def create(
|
18
|
-
ret = @client.create(name, options['description'])
|
19
|
-
info("API id: #{ret.id}")
|
20
|
-
info("API name: #{ret.name}")
|
21
|
-
info("API description: #{ret.description}")
|
22
|
-
ret.warnings.each {|w| warn("WARNING: #{w}") } unless ret.warnings.nil?
|
8
|
+
def create(options)
|
9
|
+
ret = @client.create(options['name'], options['description'])
|
10
|
+
Rapis.logger.info("API id: #{ret.id}")
|
11
|
+
Rapis.logger.info("API name: #{ret.name}")
|
12
|
+
Rapis.logger.info("API description: #{ret.description}")
|
13
|
+
ret.warnings.each { |w| Rapis.logger.warn("WARNING: #{w}") } unless ret.warnings.nil?
|
23
14
|
end
|
24
15
|
|
25
16
|
def convert(options)
|
@@ -32,30 +23,33 @@ module Rapis
|
|
32
23
|
output = YAML.dump(output)
|
33
24
|
Rapis::Utils.print_yaml(output)
|
34
25
|
else
|
35
|
-
raise "\"#{options['format']}\" format is not supported."
|
26
|
+
raise OperationError, "\"#{options['format']}\" format is not supported."
|
36
27
|
end
|
37
28
|
File.write(options['output'], output) unless options['output'].empty?
|
38
29
|
end
|
39
30
|
|
40
31
|
def list(options)
|
32
|
+
apis = []
|
41
33
|
@client.get_apis.each do |a|
|
42
34
|
if options['verbose']
|
43
35
|
api = Rapis::Utils.struct_to_hash(a)
|
44
36
|
api['stages'] = []
|
45
37
|
else
|
46
38
|
a_key = "#{a.id} (#{a.name})"
|
47
|
-
api = {a_key => []}
|
39
|
+
api = { a_key => [] }
|
48
40
|
end
|
49
41
|
|
50
42
|
@client.get_stages(a.id).each do |s|
|
51
43
|
if options['verbose']
|
52
44
|
api['stages'] << Rapis::Utils.struct_to_hash(s)
|
53
45
|
else
|
54
|
-
api[a_key]
|
46
|
+
api[a_key] << s.stage_name
|
55
47
|
end
|
56
48
|
end
|
57
49
|
Rapis::Utils.print_yaml(YAML.dump(api))
|
50
|
+
apis << api
|
58
51
|
end
|
52
|
+
apis
|
59
53
|
end
|
60
54
|
|
61
55
|
def export(options)
|
@@ -78,8 +72,8 @@ module Rapis
|
|
78
72
|
options['rest_api'],
|
79
73
|
@converter.to_h(File.read(options['file']))
|
80
74
|
)
|
81
|
-
info("Applied the REST API configuration to \"#{ret.id}\" (#{ret.name})")
|
82
|
-
ret.warnings.each {|w| warn("WARNING: #{w}") } unless ret.warnings.nil?
|
75
|
+
Rapis.logger.info("Applied the REST API configuration to \"#{ret.id}\" (#{ret.name})")
|
76
|
+
ret.warnings.each { |w| Rapis.logger.warn("WARNING: #{w}") } unless ret.warnings.nil?
|
83
77
|
end
|
84
78
|
|
85
79
|
def deploy(options)
|
@@ -94,9 +88,9 @@ module Rapis
|
|
94
88
|
|
95
89
|
ret = @client.deploy(args)
|
96
90
|
summary = YAML.dump(Rapis::Utils.struct_to_hash(ret.api_summary))
|
97
|
-
info("Deployment id: #{ret.id}")
|
98
|
-
info("Deployment description: #{ret.description}")
|
99
|
-
info("API summary :\n#{summary}")
|
91
|
+
Rapis.logger.info("Deployment id: #{ret.id}")
|
92
|
+
Rapis.logger.info("Deployment description: #{ret.description}")
|
93
|
+
Rapis.logger.info("API summary :\n#{summary}")
|
100
94
|
end
|
101
95
|
end
|
102
96
|
end
|
data/lib/rapis/cli.rb
CHANGED
@@ -1,64 +1,75 @@
|
|
1
|
-
require 'thor'
|
2
|
-
require 'rapis/actions'
|
3
|
-
|
4
1
|
module Rapis
|
5
2
|
class Cli < Thor
|
6
3
|
class_option :file, aliases: '-f', desc: 'Configuration file', type: :string, default: 'Apifile'
|
7
4
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
5
|
+
def self.start(*args)
|
6
|
+
begin
|
7
|
+
super(*args)
|
8
|
+
rescue OperationError => e
|
9
|
+
Rapis.logger.fatal(e.message)
|
10
|
+
rescue => e
|
11
|
+
Rapis.logger.error(e.message, e.backtrace)
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
|
-
desc
|
14
|
-
option :
|
15
|
-
|
16
|
-
|
15
|
+
desc 'create', 'Create REST API'
|
16
|
+
option :name, aliases: '-n', desc: 'Name', type: :string, required: true
|
17
|
+
option :description, aliases: '-d', desc: 'Description', type: :string, default: nil
|
18
|
+
def create
|
19
|
+
actions.create(options)
|
17
20
|
end
|
18
21
|
|
19
|
-
desc
|
22
|
+
desc 'convert', 'Convert the REST API configuration to the specified format'
|
20
23
|
option :format, aliases: '-F', desc: 'Output format # accepts json, yaml', type: :string, required: true
|
21
24
|
option :output, aliases: '-o', desc: 'Output path', type: :string, default: ''
|
22
25
|
def convert
|
23
|
-
|
26
|
+
actions.convert(options)
|
24
27
|
end
|
25
28
|
|
26
|
-
desc
|
29
|
+
desc 'list', 'List the REST APIs and the stages'
|
27
30
|
option :verbose, aliases: '-V', desc: 'Verbose mode', type: :boolean, default: false
|
28
31
|
def list
|
29
|
-
|
32
|
+
actions.list(options)
|
30
33
|
end
|
31
34
|
|
32
|
-
desc
|
35
|
+
desc 'export', 'Export the configuration as Ruby DSL'
|
33
36
|
option :rest_api, aliases: '-r', desc: 'The id of the REST API', type: :string, required: true
|
34
37
|
option :stage, aliases: '-s', desc: 'The name of the stage', type: :string, required: true
|
35
38
|
option :write, aliases: '-w', desc: 'Write the configuration to the file', type: :boolean, default: false
|
36
39
|
def export
|
37
|
-
|
40
|
+
actions.export(options)
|
38
41
|
end
|
39
42
|
|
40
|
-
desc
|
43
|
+
desc 'diff', 'Diff the local configuration and the remote configuration'
|
41
44
|
option :rest_api, aliases: '-r', desc: 'The id of the REST API', type: :string, required: true
|
42
45
|
option :stage, aliases: '-s', desc: 'The name of the stage', type: :string, required: true
|
43
46
|
def diff
|
44
|
-
|
47
|
+
actions.diff(options)
|
45
48
|
end
|
46
49
|
|
47
|
-
desc
|
50
|
+
desc 'apply', 'Apply the REST API configuration'
|
48
51
|
option :rest_api, aliases: '-r', desc: 'The id of the REST API', type: :string, required: true
|
49
52
|
def apply
|
50
|
-
|
53
|
+
actions.apply(options)
|
51
54
|
end
|
52
55
|
|
53
|
-
desc
|
56
|
+
desc 'deploy', 'Deploy the current REST API configuration to the stage'
|
54
57
|
option :rest_api, aliases: '-r', desc: 'The id of the REST API', type: :string, required: true
|
55
58
|
option :stage, aliases: '-s', desc: 'The name of the stage', type: :string, required: true
|
56
59
|
option :description, aliases: '-d', desc: 'The description for the deployment', type: :string, default: ''
|
57
60
|
option :stage_description, aliases: '-D', desc: 'The description of the stage', type: :string, default: ''
|
58
|
-
option :cache, aliases: '-c', desc: 'Size of the cache cluster
|
61
|
+
option :cache, aliases: '-c', desc: 'Size of the cache cluster', type: :string, default: '0.0'
|
59
62
|
option :variables, aliases: '-v', desc: 'A map that defines the stage variables', type: :hash, default: {}
|
60
63
|
def deploy
|
61
|
-
|
64
|
+
actions.deploy(options)
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def actions
|
70
|
+
Rapis::Actions.new(
|
71
|
+
Rapis::Client.new
|
72
|
+
)
|
62
73
|
end
|
63
74
|
end
|
64
75
|
end
|
data/lib/rapis/client.rb
CHANGED
@@ -1,58 +1,52 @@
|
|
1
|
-
require 'aws-sdk'
|
2
|
-
require 'base64'
|
3
|
-
require 'json'
|
4
|
-
require 'rapis/utils'
|
5
|
-
|
6
1
|
module Rapis
|
7
2
|
class Client
|
8
|
-
|
9
|
-
|
10
|
-
@api = Aws::APIGateway::Client.new
|
3
|
+
def api
|
4
|
+
Aws::APIGateway::Client.new
|
11
5
|
end
|
12
6
|
|
13
7
|
def create(name, desc)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
opt = {}
|
9
|
+
opt[:name] = name
|
10
|
+
opt[:description] = desc unless desc.nil?
|
11
|
+
api.create_rest_api(opt)
|
18
12
|
end
|
19
13
|
|
20
|
-
def get_apis(pos=nil)
|
14
|
+
def get_apis(pos = nil)
|
21
15
|
opt = {}
|
22
16
|
opt[:limit] = 500
|
23
17
|
opt[:position] = pos unless pos.nil?
|
24
18
|
|
25
|
-
ret =
|
19
|
+
ret = api.get_rest_apis(opt)
|
26
20
|
ret.items.concat(get_apis(ret.posision)) unless ret.position.nil?
|
27
21
|
ret.items
|
28
22
|
end
|
29
23
|
|
30
|
-
def get_stages(api_id
|
31
|
-
|
24
|
+
def get_stages(api_id)
|
25
|
+
api.get_stages(rest_api_id: api_id).item
|
32
26
|
end
|
33
27
|
|
34
28
|
def export_api(api_id, stage_name)
|
35
|
-
ret =
|
29
|
+
ret = api.get_export(
|
36
30
|
rest_api_id: api_id,
|
37
31
|
stage_name: stage_name,
|
38
32
|
export_type: 'swagger',
|
39
33
|
parameters: { extensions: 'integrations' }
|
40
|
-
|
34
|
+
)
|
41
35
|
|
42
36
|
JSON.load(ret.body.read)
|
43
37
|
end
|
44
38
|
|
45
39
|
def put_api(api_id, data)
|
46
|
-
|
40
|
+
api.put_rest_api(
|
47
41
|
rest_api_id: api_id,
|
48
42
|
mode: 'overwrite',
|
49
43
|
parameters: { extensions: 'integrations' },
|
50
44
|
body: JSON.dump(data)
|
51
|
-
|
45
|
+
)
|
52
46
|
end
|
53
47
|
|
54
48
|
def deploy(args)
|
55
|
-
|
49
|
+
api.create_deployment(args)
|
56
50
|
end
|
57
51
|
end
|
58
52
|
end
|
data/lib/rapis/converter.rb
CHANGED
@@ -1,30 +1,56 @@
|
|
1
|
-
require 'dslh'
|
2
|
-
require 'rapis/utils'
|
3
|
-
require 'pp'
|
4
|
-
|
5
|
-
CHANGE_SETS = {
|
6
|
-
'x-amazon-apigateway-integration' => 'amazon_apigateway_integration',
|
7
|
-
'$ref' => 'ref'
|
8
|
-
}
|
9
|
-
|
10
1
|
module Rapis
|
11
2
|
class Converter
|
3
|
+
CHANGE_SETS = {
|
4
|
+
'x-amazon-apigateway-integration' => 'amazon_apigateway_integration',
|
5
|
+
'$ref' => 'ref'
|
6
|
+
}
|
7
|
+
|
12
8
|
def to_dsl(hash)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
dsl = Dslh.deval(
|
10
|
+
hash,
|
11
|
+
exclude_key: to_dsl_exclude_key,
|
12
|
+
key_conv: to_dsl_key_conv,
|
13
|
+
value_conv: to_dsl_value_conv
|
14
|
+
)
|
15
|
+
dsl.gsub!(/^/, ' ').strip!
|
16
|
+
<<-EOS
|
17
|
+
rest_api do
|
18
|
+
#{dsl}
|
19
|
+
end
|
20
|
+
EOS
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_h(dsl)
|
24
|
+
instance_eval(dsl)
|
25
|
+
@apis
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def to_dsl_exclude_key
|
31
|
+
proc do |k|
|
32
|
+
if !k.is_a?(String)
|
33
|
+
false
|
34
|
+
elsif ['in'].include?(k)
|
17
35
|
true
|
18
|
-
elsif
|
36
|
+
elsif k.include?('/')
|
37
|
+
if k =~ %r{^\/}
|
38
|
+
false
|
39
|
+
else
|
40
|
+
true
|
41
|
+
end
|
42
|
+
elsif ['-', '.'].any? { |i| k.include?(i) } && k != 'x-amazon-apigateway-integration'
|
19
43
|
true
|
20
44
|
else
|
21
45
|
false
|
22
46
|
end
|
23
47
|
end
|
48
|
+
end
|
24
49
|
|
25
|
-
|
50
|
+
def to_dsl_key_conv
|
51
|
+
proc do |k|
|
26
52
|
k = k.to_s
|
27
|
-
if k =~
|
53
|
+
if k =~ %r{^\/}
|
28
54
|
proc do |v, nested|
|
29
55
|
if nested
|
30
56
|
"path #{k.inspect} #{v}"
|
@@ -41,51 +67,38 @@ module Rapis
|
|
41
67
|
end
|
42
68
|
end
|
43
69
|
else
|
44
|
-
CHANGE_SETS.each { |f,t| k = k.gsub(f,t) }
|
70
|
+
CHANGE_SETS.each { |f, t| k = k.gsub(f, t) }
|
45
71
|
k
|
46
72
|
end
|
47
73
|
end
|
74
|
+
end
|
48
75
|
|
49
|
-
|
50
|
-
|
76
|
+
def to_dsl_value_conv
|
77
|
+
proc do |v|
|
78
|
+
if v.is_a?(String) && v =~ /\A(?:0|[1-9]\d*)\Z/
|
51
79
|
v.to_i
|
52
80
|
else
|
53
81
|
v
|
54
82
|
end
|
55
83
|
end
|
56
|
-
|
57
|
-
dsl = Dslh.deval(
|
58
|
-
hash,
|
59
|
-
exclude_key: exclude_key,
|
60
|
-
key_conv: key_conv,
|
61
|
-
value_conv: value_conv)
|
62
|
-
dsl.gsub!(/^/, ' ').strip!
|
63
|
-
<<-EOS
|
64
|
-
rest_api do
|
65
|
-
#{dsl}
|
66
|
-
end
|
67
|
-
EOS
|
68
84
|
end
|
69
85
|
|
70
|
-
def
|
71
|
-
|
72
|
-
@apis
|
73
|
-
end
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
def rest_api(value = nil, &block)
|
78
|
-
exclude_key = proc do |k|
|
86
|
+
def to_h_exclude_key
|
87
|
+
proc do |_|
|
79
88
|
false
|
80
89
|
end
|
90
|
+
end
|
81
91
|
|
82
|
-
|
92
|
+
def to_h_key_conv
|
93
|
+
proc do |k|
|
83
94
|
k = k.to_s
|
84
|
-
CHANGE_SETS.each { |f,t| k = k.gsub(t,f) }
|
95
|
+
CHANGE_SETS.each { |f, t| k = k.gsub(t, f) }
|
85
96
|
k
|
86
97
|
end
|
98
|
+
end
|
87
99
|
|
88
|
-
|
100
|
+
def to_h_value_conv
|
101
|
+
proc do |v|
|
89
102
|
case v
|
90
103
|
when Hash, Array
|
91
104
|
v
|
@@ -93,13 +106,15 @@ EOS
|
|
93
106
|
v.to_s
|
94
107
|
end
|
95
108
|
end
|
109
|
+
end
|
96
110
|
|
111
|
+
def rest_api(&block)
|
97
112
|
@apis = Dslh.eval(
|
98
|
-
exclude_key:
|
99
|
-
key_conv:
|
100
|
-
value_conv:
|
113
|
+
exclude_key: to_h_exclude_key,
|
114
|
+
key_conv: to_h_key_conv,
|
115
|
+
value_conv: to_h_value_conv,
|
101
116
|
allow_empty_args: true,
|
102
|
-
scope_hook: proc {|scope| define_template_func(scope)},
|
117
|
+
scope_hook: proc { |scope| define_template_func(scope) },
|
103
118
|
&block
|
104
119
|
)
|
105
120
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
class OperationError < StandardError; end
|
data/lib/rapis/logger.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
require 'logger'
|
2
|
-
require 'singleton'
|
3
|
-
|
4
1
|
module Rapis
|
5
2
|
class TermColor
|
6
3
|
class << self
|
7
|
-
|
8
4
|
def green(msg)
|
9
5
|
colorize 32, msg
|
10
6
|
end
|
@@ -20,24 +16,30 @@ module Rapis
|
|
20
16
|
def colorize(num, msg)
|
21
17
|
"\e[#{num}m#{msg}\e[0m"
|
22
18
|
end
|
23
|
-
|
24
19
|
end
|
25
20
|
end
|
26
21
|
|
22
|
+
def self.logger
|
23
|
+
Rapis::Logger.instance
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Default logger
|
28
|
+
#
|
27
29
|
class Logger < Logger
|
28
30
|
include Singleton
|
29
31
|
|
30
32
|
def initialize
|
31
33
|
super(STDERR)
|
32
34
|
|
33
|
-
self.formatter = proc do |
|
35
|
+
self.formatter = proc do |_severity, _datetime, _progname, msg|
|
34
36
|
"#{msg}\n"
|
35
37
|
end
|
36
38
|
|
37
39
|
self.level = Logger::INFO
|
38
40
|
end
|
39
41
|
|
40
|
-
def debug(progname = nil, method_name = nil
|
42
|
+
def debug(msg, progname = nil, method_name = nil)
|
41
43
|
super(progname) { { method_name: method_name, message: msg } }
|
42
44
|
end
|
43
45
|
|
@@ -53,34 +55,10 @@ module Rapis
|
|
53
55
|
super { Rapis::TermColor.red(msg) }
|
54
56
|
end
|
55
57
|
|
56
|
-
def error(progname = nil, method_name = nil
|
57
|
-
super(progname)
|
58
|
-
|
59
|
-
|
60
|
-
module Helper
|
61
|
-
|
62
|
-
def log(level, message)
|
63
|
-
logger = Rapis::Logger.instance
|
64
|
-
logger.send(level, message)
|
58
|
+
def error(msg, backtrace, progname = nil, method_name = nil)
|
59
|
+
super(progname) do
|
60
|
+
{ method_name: method_name, message: msg, backtrace: backtrace }
|
65
61
|
end
|
66
|
-
|
67
|
-
def info(msg)
|
68
|
-
log(:info, msg)
|
69
|
-
end
|
70
|
-
|
71
|
-
def warn(msg)
|
72
|
-
log(:warn, msg)
|
73
|
-
end
|
74
|
-
|
75
|
-
def fatal(msg)
|
76
|
-
log(:error, msg)
|
77
|
-
end
|
78
|
-
|
79
|
-
def debug(msg)
|
80
|
-
log(:debug, msg)
|
81
|
-
end
|
82
|
-
|
83
|
-
module_function :log, :info, :warn, :fatal, :debug
|
84
62
|
end
|
85
63
|
end
|
86
64
|
end
|
data/lib/rapis/utils.rb
CHANGED
@@ -1,38 +1,36 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'diffy'
|
3
|
-
require 'coderay'
|
4
|
-
|
5
1
|
module Rapis
|
6
2
|
class Utils
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
class << self
|
4
|
+
def struct_to_hash(val)
|
5
|
+
val = val.to_h if val.is_a?(Struct) || val.is_a?(OpenStruct)
|
6
|
+
val = val.to_s if val.is_a?(Symbol)
|
7
|
+
val = Hash[val.map { |k, v| [k.to_s, struct_to_hash(v)] }] if val.is_a?(Hash)
|
8
|
+
val = val.map! { |v| struct_to_hash(v) } if val.is_a?(Array)
|
9
|
+
val
|
10
|
+
end
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
def diff(hash1, hash2)
|
13
|
+
Diffy::Diff.new(
|
14
|
+
JSON.pretty_generate(hash1),
|
15
|
+
JSON.pretty_generate(hash2),
|
16
|
+
diff: '-u'
|
17
|
+
).to_s(:color)
|
18
|
+
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
def print_yaml(yaml)
|
21
|
+
CodeRay::Encoders::Terminal::TOKEN_COLORS[:key] = {
|
22
|
+
self: "\e[32m"
|
23
|
+
}
|
24
|
+
puts CodeRay.scan(yaml, :yaml).terminal
|
25
|
+
end
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
def print_ruby(ruby)
|
28
|
+
puts CodeRay.scan(ruby, :ruby).terminal
|
29
|
+
end
|
33
30
|
|
34
|
-
|
35
|
-
|
31
|
+
def print_json(json)
|
32
|
+
puts CodeRay.scan(json, :json).terminal
|
33
|
+
end
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
data/lib/rapis/version.rb
CHANGED
data/lib/rapis.rb
CHANGED
@@ -1,7 +1,20 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
|
7
|
-
require
|
1
|
+
require 'json'
|
2
|
+
require 'yaml'
|
3
|
+
require 'logger'
|
4
|
+
require 'singleton'
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
require 'thor'
|
8
|
+
require 'aws-sdk'
|
9
|
+
require 'dslh'
|
10
|
+
require 'diffy'
|
11
|
+
require 'coderay'
|
12
|
+
|
13
|
+
require 'rapis/version'
|
14
|
+
require 'rapis/actions'
|
15
|
+
require 'rapis/cli'
|
16
|
+
require 'rapis/client'
|
17
|
+
require 'rapis/converter'
|
18
|
+
require 'rapis/exceptions'
|
19
|
+
require 'rapis/logger'
|
20
|
+
require 'rapis/utils'
|
data/rapis.gemspec
CHANGED
@@ -28,4 +28,6 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency "bundler", "~> 1.12"
|
29
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
30
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
spec.add_development_dependency "coveralls"
|
32
|
+
spec.add_development_dependency "rubocop"
|
31
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rapis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masashi Terui
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -122,6 +122,34 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '3.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: coveralls
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
125
153
|
description: Swagger as Ruby DSL and its deployment tool for Amazon API Gateway
|
126
154
|
email:
|
127
155
|
- marcy9114@gmail.com
|
@@ -132,6 +160,7 @@ extra_rdoc_files: []
|
|
132
160
|
files:
|
133
161
|
- ".gitignore"
|
134
162
|
- ".rspec"
|
163
|
+
- ".rubocop.yml"
|
135
164
|
- ".travis.yml"
|
136
165
|
- Apifile
|
137
166
|
- CHANGELOG.md
|
@@ -147,6 +176,7 @@ files:
|
|
147
176
|
- lib/rapis/cli.rb
|
148
177
|
- lib/rapis/client.rb
|
149
178
|
- lib/rapis/converter.rb
|
179
|
+
- lib/rapis/exceptions.rb
|
150
180
|
- lib/rapis/logger.rb
|
151
181
|
- lib/rapis/utils.rb
|
152
182
|
- lib/rapis/version.rb
|