marketplace-kit 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/marketplace_kit.rb +3 -0
- data/lib/marketplace_kit/command_dispatcher.rb +5 -10
- data/lib/marketplace_kit/commands/base_authorized_command.rb +41 -0
- data/lib/marketplace_kit/commands/base_command.rb +2 -10
- data/lib/marketplace_kit/commands/deploy.rb +2 -4
- data/lib/marketplace_kit/commands/pull.rb +2 -4
- data/lib/marketplace_kit/commands/show_help.rb +12 -0
- data/lib/marketplace_kit/commands/show_version.rb +11 -0
- data/lib/marketplace_kit/commands/sync.rb +1 -5
- data/lib/marketplace_kit/services/api_driver.rb +3 -1
- data/lib/marketplace_kit/services/args_parser.rb +0 -17
- data/lib/marketplace_kit/services/config.rb +14 -6
- data/lib/marketplace_kit/services/logger.rb +24 -9
- data/lib/marketplace_kit/version.rb +1 -1
- data/marketplace_builder/.builder +2 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cf0ff59d61afee0ea9b0805086835383abd268a
|
4
|
+
data.tar.gz: d19b7935d2593fd5bfd6ad6099a99998c704093a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 507de84b9c1ba794a37bef6804e50ea26cf9c0babb3867d9fa0ab46d04d1de5a1848b6dfcfbe11df66c6c618d43d79f9d0e16f0995350fd9ab6c2e75c06f886f
|
7
|
+
data.tar.gz: d8c2d35a7d153a06725b2b23d9b74fa8627587cc9e6043f5c6813987162cbf9512db0285d7230c00213eb9e7839c3a55e1686cdd196fdb7f017b65385ea48c58
|
data/lib/marketplace_kit.rb
CHANGED
@@ -17,9 +17,12 @@ require 'marketplace_kit/services/config'
|
|
17
17
|
require 'marketplace_kit/services/api_driver'
|
18
18
|
require 'marketplace_kit/services/api_gateway'
|
19
19
|
require 'marketplace_kit/commands/base_command'
|
20
|
+
require 'marketplace_kit/commands/base_authorized_command'
|
20
21
|
require 'marketplace_kit/commands/sync'
|
21
22
|
require 'marketplace_kit/commands/deploy'
|
22
23
|
require 'marketplace_kit/commands/pull'
|
24
|
+
require 'marketplace_kit/commands/show_version'
|
25
|
+
require 'marketplace_kit/commands/show_help'
|
23
26
|
|
24
27
|
module MarketplaceKit
|
25
28
|
MARKETPLACE_BUILDER_FOLDER = 'marketplace_builder'.freeze
|
@@ -1,16 +1,13 @@
|
|
1
1
|
module MarketplaceKit
|
2
2
|
class CommandDispatcher
|
3
3
|
extend Forwardable
|
4
|
-
def_delegators :args_parser, :command_name, :command_args
|
4
|
+
def_delegators :args_parser, :command_name, :command_args
|
5
5
|
|
6
6
|
def initialize(args)
|
7
7
|
@args = args
|
8
8
|
end
|
9
9
|
|
10
10
|
def execute
|
11
|
-
MarketplaceKit.config.load current_env
|
12
|
-
user_authentication.authenticate
|
13
|
-
|
14
11
|
command.new(command_args).execute
|
15
12
|
rescue Errors::MarketplaceError => e
|
16
13
|
puts e.message.red
|
@@ -23,16 +20,14 @@ module MarketplaceKit
|
|
23
20
|
when 'sync' then Commands::Sync
|
24
21
|
when 'deploy' then Commands::Deploy
|
25
22
|
when 'pull' then Commands::Pull
|
26
|
-
|
27
|
-
|
23
|
+
when '--version', '-v' then Commands::ShowVersion
|
24
|
+
when '--help', '-h' then Commands::ShowHelp
|
25
|
+
else Commands::ShowHelp
|
26
|
+
end
|
28
27
|
end
|
29
28
|
|
30
29
|
def args_parser
|
31
30
|
@args_parse ||= Services::ArgsParser.new @args
|
32
31
|
end
|
33
|
-
|
34
|
-
def user_authentication
|
35
|
-
@user_authentication ||= Services::UserAuthentication.new
|
36
|
-
end
|
37
32
|
end
|
38
33
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module MarketplaceKit
|
2
|
+
module Commands
|
3
|
+
class BaseAuthorizedCommand < BaseCommand
|
4
|
+
def initialize(command_args)
|
5
|
+
@command_args = command_args
|
6
|
+
authenticate
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def ensure_tmp_folder_exist
|
12
|
+
Dir.mkdir('tmp') unless File.exist?('tmp')
|
13
|
+
end
|
14
|
+
|
15
|
+
def gateway
|
16
|
+
@gateway ||= Services::ApiGateway.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def authenticate
|
20
|
+
MarketplaceKit.config.load current_env
|
21
|
+
user_authentication.authenticate
|
22
|
+
end
|
23
|
+
|
24
|
+
def current_env
|
25
|
+
endpoint_arg_value
|
26
|
+
end
|
27
|
+
|
28
|
+
def endpoint_arg_index
|
29
|
+
@endpoint_arg_index ||= @command_args.find_index { |arg| arg == '-e' }
|
30
|
+
end
|
31
|
+
|
32
|
+
def endpoint_arg_value
|
33
|
+
endpoint_arg_index && @command_args[endpoint_arg_index + 1]
|
34
|
+
end
|
35
|
+
|
36
|
+
def user_authentication
|
37
|
+
@user_authentication ||= Services::UserAuthentication.new
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,19 +1,11 @@
|
|
1
1
|
module MarketplaceKit
|
2
2
|
module Commands
|
3
3
|
class BaseCommand
|
4
|
+
include Services::Loggable
|
5
|
+
|
4
6
|
def initialize(command_args)
|
5
7
|
@command_args = command_args
|
6
8
|
end
|
7
|
-
|
8
|
-
protected
|
9
|
-
|
10
|
-
def ensure_tmp_folder_exist
|
11
|
-
Dir.mkdir('tmp') unless File.exist?('tmp')
|
12
|
-
end
|
13
|
-
|
14
|
-
def gateway
|
15
|
-
@gateway ||= Services::ApiGateway.new
|
16
|
-
end
|
17
9
|
end
|
18
10
|
end
|
19
11
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module MarketplaceKit
|
2
2
|
module Commands
|
3
|
-
class Deploy <
|
4
|
-
include Services::Loggable
|
5
|
-
|
3
|
+
class Deploy < BaseAuthorizedCommand
|
6
4
|
def execute
|
7
5
|
log :deploy_started
|
8
6
|
ensure_tmp_folder_exist
|
@@ -57,7 +55,7 @@ module MarketplaceKit
|
|
57
55
|
def handle_deploy_result(deploy_response)
|
58
56
|
print "\n"
|
59
57
|
if deploy_response.body['status'] == 'success'
|
60
|
-
|
58
|
+
log :deploy_succeeded
|
61
59
|
else
|
62
60
|
parsed_error = JSON.parse(deploy_response.body['error'])
|
63
61
|
log :api_error, parsed_error['message'], parsed_error['details']
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module MarketplaceKit
|
2
2
|
module Commands
|
3
|
-
class Pull <
|
4
|
-
include Services::Loggable
|
5
|
-
|
3
|
+
class Pull < BaseAuthorizedCommand
|
6
4
|
def execute
|
7
5
|
log :pull_started
|
8
6
|
ensure_tmp_folder_exist
|
@@ -48,7 +46,7 @@ module MarketplaceKit
|
|
48
46
|
def handle_deploy_result(deploy_response)
|
49
47
|
print "\n"
|
50
48
|
if deploy_response.body['status'] == 'success'
|
51
|
-
|
49
|
+
log :pull_succeeded
|
52
50
|
deploy_response
|
53
51
|
else
|
54
52
|
parsed_error = JSON.parse(deploy_response.body['error'])
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module MarketplaceKit
|
2
2
|
module Commands
|
3
|
-
class Sync <
|
4
|
-
include Services::Loggable
|
5
|
-
|
3
|
+
class Sync < BaseAuthorizedCommand
|
6
4
|
def execute
|
7
5
|
log :sync_command_started
|
8
6
|
|
@@ -23,8 +21,6 @@ module MarketplaceKit
|
|
23
21
|
def on_file_change(file_path)
|
24
22
|
log :sync_updating, file_path
|
25
23
|
response = gateway.send_file_change relative_file_path(file_path), File.read(file_path)
|
26
|
-
|
27
|
-
log :sync_done if response.success?
|
28
24
|
end
|
29
25
|
|
30
26
|
def relative_file_path(file_path)
|
@@ -72,7 +72,9 @@ module MarketplaceKit
|
|
72
72
|
'UserTemporaryToken' => MarketplaceKit.config.token,
|
73
73
|
'Accept' => 'application/vnd.nearme.v4+json'
|
74
74
|
}
|
75
|
-
}
|
75
|
+
}.tap do |config|
|
76
|
+
config[:ssl] = { verify: false } unless MarketplaceKit.config.endpoint == 'production'
|
77
|
+
end
|
76
78
|
end
|
77
79
|
|
78
80
|
def fix_font_file_encoding
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module MarketplaceKit
|
2
2
|
module Services
|
3
3
|
class ArgsParser
|
4
|
-
DEFAULT_ENV = 'localhost'
|
5
|
-
|
6
4
|
def initialize(args)
|
7
5
|
@args = args
|
8
6
|
end
|
@@ -14,21 +12,6 @@ module MarketplaceKit
|
|
14
12
|
def command_args
|
15
13
|
@args[1..-1] || []
|
16
14
|
end
|
17
|
-
|
18
|
-
def current_env
|
19
|
-
return DEFAULT_ENV unless e_arg_index
|
20
|
-
env_arg_value || DEFAULT_ENV
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def e_arg_index
|
26
|
-
@e_arg_index ||= command_args.find_index { |arg| arg == '-e' }
|
27
|
-
end
|
28
|
-
|
29
|
-
def env_arg_value
|
30
|
-
command_args[e_arg_index + 1]
|
31
|
-
end
|
32
15
|
end
|
33
16
|
end
|
34
17
|
end
|
@@ -1,13 +1,17 @@
|
|
1
1
|
module MarketplaceKit
|
2
2
|
module Services
|
3
3
|
class Config
|
4
|
+
def endpoint
|
5
|
+
@endpoint
|
6
|
+
end
|
7
|
+
|
4
8
|
def load(endpoint_name)
|
5
9
|
@config = {}
|
6
|
-
@endpoint = endpoint_name
|
7
10
|
|
8
11
|
load_config_from '.builder'
|
9
12
|
load_config_from '.builder-autogenerated', required: false
|
10
13
|
|
14
|
+
@endpoint = endpoint_name || default_endpoint
|
11
15
|
raise Errors::MarketplaceError.new 'Error: Invalid env passed!' if @config[@endpoint].nil?
|
12
16
|
rescue Errno::ENOENT
|
13
17
|
raise Errors::MarketplaceError.new 'Please create .builder file in order to continue.'
|
@@ -26,6 +30,10 @@ module MarketplaceKit
|
|
26
30
|
@config[@endpoint]['url'].to_s
|
27
31
|
end
|
28
32
|
|
33
|
+
def default_endpoint
|
34
|
+
@config.select { |_k, config| config['default']}.keys.first || 'localhost'.freeze
|
35
|
+
end
|
36
|
+
|
29
37
|
private
|
30
38
|
|
31
39
|
def load_config_from(file_name, options = {})
|
@@ -40,12 +48,12 @@ module MarketplaceKit
|
|
40
48
|
File.write("#{MarketplaceKit.builder_folder}.builder-autogenerated", config.to_json)
|
41
49
|
end
|
42
50
|
|
43
|
-
|
44
|
-
|
51
|
+
def autogenerated_config
|
52
|
+
return {} unless File.exist?("#{MarketplaceKit.builder_folder}.builder-autogenerated")
|
45
53
|
|
46
|
-
|
47
|
-
|
48
|
-
|
54
|
+
raw_config = File.read("#{MarketplaceKit.builder_folder}.builder-autogenerated")
|
55
|
+
JSON.parse raw_config
|
56
|
+
end
|
49
57
|
end
|
50
58
|
end
|
51
59
|
end
|
@@ -2,7 +2,7 @@ module MarketplaceKit
|
|
2
2
|
module Services
|
3
3
|
class Logger
|
4
4
|
def deploy_started
|
5
|
-
puts 'Deploy command started
|
5
|
+
puts 'Deploy command started'.green
|
6
6
|
end
|
7
7
|
|
8
8
|
def compressing_folder
|
@@ -10,15 +10,19 @@ module MarketplaceKit
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def sending_zip
|
13
|
-
puts 'Sending zip to the server'.yellow
|
13
|
+
puts 'Sending zip file to the server'.yellow
|
14
14
|
end
|
15
15
|
|
16
16
|
def wait_for_deploy_finish
|
17
17
|
puts 'Waiting for deploy to finish'.yellow
|
18
18
|
end
|
19
19
|
|
20
|
+
def deploy_succeeded
|
21
|
+
puts 'Deploy command succeded'.green
|
22
|
+
end
|
23
|
+
|
20
24
|
def pull_started
|
21
|
-
puts 'Pull command started
|
25
|
+
puts 'Pull command started'.green
|
22
26
|
end
|
23
27
|
|
24
28
|
def request_backup
|
@@ -29,6 +33,10 @@ module MarketplaceKit
|
|
29
33
|
puts 'Waiting for backup to finish'.yellow
|
30
34
|
end
|
31
35
|
|
36
|
+
def pull_succeeded
|
37
|
+
puts 'Pull command succeded'.green
|
38
|
+
end
|
39
|
+
|
32
40
|
def sync_command_started
|
33
41
|
puts 'Sync mode enabled'.green
|
34
42
|
end
|
@@ -37,22 +45,29 @@ module MarketplaceKit
|
|
37
45
|
puts "Updating: #{file_path}".green
|
38
46
|
end
|
39
47
|
|
40
|
-
def sync_done
|
41
|
-
puts 'Done!'.green
|
42
|
-
end
|
43
|
-
|
44
48
|
def ask_for_email
|
45
|
-
puts 'Enter your email'
|
49
|
+
puts 'Enter your email:'.yellow
|
46
50
|
end
|
47
51
|
|
48
52
|
def ask_for_password
|
49
|
-
puts 'Enter your password'
|
53
|
+
puts 'Enter your password:'.yellow
|
50
54
|
end
|
51
55
|
|
52
56
|
def redirect_tip
|
53
57
|
puts 'Server returned redirect code (possible a wrong domain in config file?)'.yellow
|
54
58
|
end
|
55
59
|
|
60
|
+
def version(version)
|
61
|
+
puts "marketplace-kit #{version}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def usage
|
65
|
+
puts ''
|
66
|
+
puts 'Usage: marketplace-kit sync | deploy | pull'
|
67
|
+
puts ' -e endpoint endpoint from your config file'
|
68
|
+
puts ' -v show current version'
|
69
|
+
end
|
70
|
+
|
56
71
|
def json_error(source)
|
57
72
|
puts '```'.red
|
58
73
|
puts 'Error while parsing JSON'.red
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marketplace-kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Janeczek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -198,9 +198,12 @@ files:
|
|
198
198
|
- bin/setup
|
199
199
|
- lib/marketplace_kit.rb
|
200
200
|
- lib/marketplace_kit/command_dispatcher.rb
|
201
|
+
- lib/marketplace_kit/commands/base_authorized_command.rb
|
201
202
|
- lib/marketplace_kit/commands/base_command.rb
|
202
203
|
- lib/marketplace_kit/commands/deploy.rb
|
203
204
|
- lib/marketplace_kit/commands/pull.rb
|
205
|
+
- lib/marketplace_kit/commands/show_help.rb
|
206
|
+
- lib/marketplace_kit/commands/show_version.rb
|
204
207
|
- lib/marketplace_kit/commands/sync.rb
|
205
208
|
- lib/marketplace_kit/errors/api_error.rb
|
206
209
|
- lib/marketplace_kit/errors/marketplace_error.rb
|