marketplace-kit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/README.md +17 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/marketplace-kit +3 -0
- data/bin/setup +8 -0
- data/lib/marketplace_kit/command_dispatcher.rb +38 -0
- data/lib/marketplace_kit/commands/base_command.rb +19 -0
- data/lib/marketplace_kit/commands/deploy.rb +62 -0
- data/lib/marketplace_kit/commands/pull.rb +60 -0
- data/lib/marketplace_kit/commands/sync.rb +35 -0
- data/lib/marketplace_kit/errors/api_error.rb +12 -0
- data/lib/marketplace_kit/errors/marketplace_error.rb +6 -0
- data/lib/marketplace_kit/services/api_driver.rb +78 -0
- data/lib/marketplace_kit/services/api_gateway.rb +42 -0
- data/lib/marketplace_kit/services/args_parser.rb +34 -0
- data/lib/marketplace_kit/services/config.rb +43 -0
- data/lib/marketplace_kit/services/loggable.rb +9 -0
- data/lib/marketplace_kit/services/logger.rb +78 -0
- data/lib/marketplace_kit/services/user_authentication.rb +41 -0
- data/lib/marketplace_kit/version.rb +3 -0
- data/lib/marketplace_kit.rb +42 -0
- data/marketplace_builder/.builder +8 -0
- data/marketplace_builder/.builder-autogenerated +1 -0
- data/marketplace_builder/liquid_views/index.liquid +1 -0
- data/marketplace_kit.gemspec +38 -0
- metadata +228 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f3f4a26994e8282c2ea46677fe0fc92811d6505d
|
4
|
+
data.tar.gz: 8d072cbeda1c0ce3aafa4939520cb1db082d1354
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd874cdaa01da2bd8ee81b2895ea0c789fd9f0a54058e29fcbb88fe379de7dd617d406730299f25d96f9d9039d2f8f8ab9753329cace23ff97638fd09154f19e
|
7
|
+
data.tar.gz: 138dd68143e724499635a278bb50666397b7d8e538bbb6ce41d6370bb3824a25226818a360134445334bd4ab0394f0bc3dc3b1e1cc07b9902c13b865dbd1bebf
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# MarketplaceKit [![Version](http://img.shields.io/gem/v/marketplace-kit.svg)](https://rubygems.org/gems/marketplace-kit) [![Build Status](https://travis-ci.org/mdyd-dev/marketplace-kit.svg?branch=master)](https://travis-ci.org/mdyd-dev/marketplace-kit) [![Code Climate](https://codeclimate.com/github/crashbreak/crashbreak/badges/gpa.svg)](https://codeclimate.com/github/mdyd-dev/marketplace-kit) [![Coverage Status](https://coveralls.io/repos/github/mdyd-dev/marketplace-kit/badge.svg?branch=master)](https://coveralls.io/github/mdyd-dev/marketplace-kit?branch=master)
|
2
|
+
|
3
|
+
MarketplaceKit is a gem for Marketplace Platform users.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install it yourself as:
|
8
|
+
|
9
|
+
$ gem install marketplace-kit
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
TODO: Write usage instructions here
|
14
|
+
|
15
|
+
## Contributing
|
16
|
+
|
17
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mdyd-dev/marketplace-kit.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'marketplace_kit'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/marketplace-kit
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module MarketplaceKit
|
2
|
+
class CommandDispatcher
|
3
|
+
extend Forwardable
|
4
|
+
def_delegators :args_parser, :command_name, :command_args, :current_env
|
5
|
+
|
6
|
+
def initialize(args)
|
7
|
+
@args = args
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute
|
11
|
+
MarketplaceKit.config.load current_env
|
12
|
+
user_authentication.authenticate
|
13
|
+
|
14
|
+
command.new(command_args).execute
|
15
|
+
rescue Errors::MarketplaceError => e
|
16
|
+
puts e.message.red
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def command
|
22
|
+
@command ||= case command_name
|
23
|
+
when 'sync' then Commands::Sync
|
24
|
+
when 'deploy' then Commands::Deploy
|
25
|
+
when 'pull' then Commands::Pull
|
26
|
+
else raise Errors::MarketplaceError.new('Usage: nearme-marketpalce sync | deploy | pull')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def args_parser
|
31
|
+
@args_parse ||= Services::ArgsParser.new @args
|
32
|
+
end
|
33
|
+
|
34
|
+
def user_authentication
|
35
|
+
@user_authentication ||= Services::UserAuthentication.new
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MarketplaceKit
|
2
|
+
module Commands
|
3
|
+
class BaseCommand
|
4
|
+
def initialize(command_args)
|
5
|
+
@command_args = command_args
|
6
|
+
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
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module MarketplaceKit
|
2
|
+
module Commands
|
3
|
+
class Deploy < BaseCommand
|
4
|
+
include Services::Loggable
|
5
|
+
|
6
|
+
def execute
|
7
|
+
log :deploy_started
|
8
|
+
ensure_tmp_folder_exist
|
9
|
+
|
10
|
+
log :compressing_folder
|
11
|
+
zip_marketplace_builder_directory
|
12
|
+
|
13
|
+
log :sending_zip
|
14
|
+
response = send_zip_to_server
|
15
|
+
return unless response.success?
|
16
|
+
|
17
|
+
log :wait_for_deploy_finish
|
18
|
+
wait_for_deploy(response[:body]['id'])
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def zip_marketplace_builder_directory
|
24
|
+
system "rm #{Dir.getwd}/tmp/marketplace_builder.zip"
|
25
|
+
system "cd #{MarketplaceKit::MARKETPLACE_BUILDER_FOLDER}; zip -r #{Dir.getwd}/tmp/marketplace_builder.zip ."
|
26
|
+
end
|
27
|
+
|
28
|
+
def send_zip_to_server
|
29
|
+
gateway.deploy("#{Dir.getwd}/tmp/marketplace_builder.zip", force: is_force_mode)
|
30
|
+
end
|
31
|
+
|
32
|
+
def wait_for_deploy(deploy_id)
|
33
|
+
deploy_response = gateway.get_deploy(deploy_id)
|
34
|
+
return handle_deploy_result(deploy_response) if deploy_finished?(deploy_response)
|
35
|
+
|
36
|
+
print '.'
|
37
|
+
sleep 5
|
38
|
+
wait_for_deploy(deploy_id)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def deploy_finished?(deploy_response)
|
44
|
+
%w(success error).include?(deploy_response.body['status'])
|
45
|
+
end
|
46
|
+
|
47
|
+
def handle_deploy_result(deploy_response)
|
48
|
+
print "\n"
|
49
|
+
if deploy_response.body['status'] == 'success'
|
50
|
+
puts 'success'.green
|
51
|
+
else
|
52
|
+
parsed_error = JSON.parse(deploy_response.body['error'])
|
53
|
+
log :api_error, parsed_error['message'], parsed_error['details']
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def is_force_mode
|
58
|
+
(@command_args & ['--force', '-f']).any?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module MarketplaceKit
|
2
|
+
module Commands
|
3
|
+
class Pull < BaseCommand
|
4
|
+
include Services::Loggable
|
5
|
+
|
6
|
+
def execute
|
7
|
+
log :pull_started
|
8
|
+
ensure_tmp_folder_exist
|
9
|
+
|
10
|
+
log :request_backup
|
11
|
+
response = send_backup_request
|
12
|
+
|
13
|
+
log :wait_for_backup_finish
|
14
|
+
success_response = wait_for_backup(response[:body]['id']) if response.success?
|
15
|
+
|
16
|
+
download_and_unzip_exported_zip(success_response) if success_response
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def send_backup_request
|
22
|
+
gateway.backup
|
23
|
+
end
|
24
|
+
|
25
|
+
def wait_for_backup(backup_id)
|
26
|
+
backup_response = gateway.get_deploy(backup_id)
|
27
|
+
return handle_deploy_result(backup_response) if deploy_finished?(backup_response)
|
28
|
+
|
29
|
+
print '.'
|
30
|
+
sleep 5
|
31
|
+
wait_for_backup(backup_id)
|
32
|
+
end
|
33
|
+
|
34
|
+
def download_and_unzip_exported_zip(release)
|
35
|
+
url = release.body['zip_file']['url']
|
36
|
+
url = url.prepend(MarketplaceKit.config.url) if url.start_with?('/')
|
37
|
+
|
38
|
+
system "curl -o marketplace_release.zip '#{url}'"
|
39
|
+
system 'unzip -o marketplace_release.zip -d marketplace_builder'
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def deploy_finished?(deploy_response)
|
45
|
+
%w(success error).include?(deploy_response.body['status'])
|
46
|
+
end
|
47
|
+
|
48
|
+
def handle_deploy_result(deploy_response)
|
49
|
+
print "\n"
|
50
|
+
if deploy_response.body['status'] == 'success'
|
51
|
+
puts 'success'.green
|
52
|
+
deploy_response
|
53
|
+
else
|
54
|
+
parsed_error = JSON.parse(deploy_response.body['error'])
|
55
|
+
log :api_error, parsed_error['message'], parsed_error['details']
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module MarketplaceKit
|
2
|
+
module Commands
|
3
|
+
class Sync < BaseCommand
|
4
|
+
include Services::Loggable
|
5
|
+
|
6
|
+
def execute
|
7
|
+
log :sync_command_started
|
8
|
+
|
9
|
+
listener = Listen.to(MARKETPLACE_BUILDER_FOLDER) do |modified, added, _removed|
|
10
|
+
changed_file_paths = added + modified
|
11
|
+
|
12
|
+
changed_file_paths.each do |changed_file_path|
|
13
|
+
on_file_change(changed_file_path)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
listener.start
|
18
|
+
sleep
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def on_file_change(file_path)
|
24
|
+
log :sync_updating, file_path
|
25
|
+
response = gateway.send_file_change relative_file_path(file_path), File.read(file_path)
|
26
|
+
|
27
|
+
log :sync_done if response.success?
|
28
|
+
end
|
29
|
+
|
30
|
+
def relative_file_path(file_path)
|
31
|
+
file_path.gsub("#{Dir.getwd}/#{MARKETPLACE_BUILDER_FOLDER}/", '')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module MarketplaceKit
|
2
|
+
module Services
|
3
|
+
class ApiDriver
|
4
|
+
include Loggable
|
5
|
+
|
6
|
+
def initialize(request_type, url, hash_body, options)
|
7
|
+
@request_type = request_type
|
8
|
+
@url = url
|
9
|
+
@hash_body = hash_body
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def send_request
|
14
|
+
url = "api/marketplace_builder/#{@url}"
|
15
|
+
body = prepare_body_to_send
|
16
|
+
|
17
|
+
response = connection.method(@request_type).call(url, body)
|
18
|
+
parsed_response = JSON.parse(response.body)
|
19
|
+
|
20
|
+
raise Errors::ApiError.new(parsed_response) unless response.success?
|
21
|
+
OpenStruct.new(status: response.status, body: parsed_response, success?: true)
|
22
|
+
rescue StandardError => e
|
23
|
+
log_error(e, response)
|
24
|
+
OpenStruct.new(status: (response && response.status), body: parsed_response, success?: false)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def log_error(error, response)
|
30
|
+
if error.is_a?(JSON::ParserError)
|
31
|
+
log :json_error, response.body
|
32
|
+
elsif error.is_a?(Errors::ApiError)
|
33
|
+
log :api_error, error.parsed_response['error'], error.parsed_response['details']
|
34
|
+
else
|
35
|
+
log :standard_error, error
|
36
|
+
end
|
37
|
+
|
38
|
+
log :redirect_tip if response && [301,302].include?(response.status)
|
39
|
+
end
|
40
|
+
|
41
|
+
def prepare_body_to_send
|
42
|
+
return @hash_body if @options[:multipart]
|
43
|
+
|
44
|
+
body_should_be_json? ? @hash_body.to_json : @hash_body
|
45
|
+
end
|
46
|
+
|
47
|
+
def body_should_be_json?
|
48
|
+
[:post, :put, :patch].include?(@request_type)
|
49
|
+
end
|
50
|
+
|
51
|
+
def connection
|
52
|
+
@options[:multipart] ? multipart_connection : json_connection
|
53
|
+
end
|
54
|
+
|
55
|
+
def json_connection
|
56
|
+
@json_connection ||= Faraday.new(basic_configuration.deeper_merge(headers: { 'Content-Type' => 'application/json' }))
|
57
|
+
end
|
58
|
+
|
59
|
+
def multipart_connection
|
60
|
+
@multipart_connection ||= Faraday.new(basic_configuration) do |connection|
|
61
|
+
connection.request :multipart
|
62
|
+
connection.request :url_encoded
|
63
|
+
connection.adapter :net_http
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def basic_configuration
|
68
|
+
{
|
69
|
+
url: MarketplaceKit.config.url,
|
70
|
+
headers: {
|
71
|
+
'UserTemporaryToken' => MarketplaceKit.config.token,
|
72
|
+
'Accept' => 'application/vnd.nearme.v4+json'
|
73
|
+
}
|
74
|
+
}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module MarketplaceKit
|
2
|
+
module Services
|
3
|
+
class ApiGateway
|
4
|
+
def login(email, password)
|
5
|
+
response = send(:post, 'sessions', email: email, password: password)
|
6
|
+
raise Errors::MarketplaceError.new('Error: Invalid email or password!') if response.status == 401
|
7
|
+
|
8
|
+
response.body['token']
|
9
|
+
end
|
10
|
+
|
11
|
+
def login_required?
|
12
|
+
response = send(:get, "sessions?temporary_token=#{MarketplaceKit.config.token}")
|
13
|
+
raise Errors::MarketplaceError.new('Login failed.') unless response.success?
|
14
|
+
|
15
|
+
response.body['login_required']
|
16
|
+
end
|
17
|
+
|
18
|
+
def send_file_change(file_path, file_content)
|
19
|
+
send(:put, 'marketplace_releases/sync', path: file_path, marketplace_builder_file_body: file_content)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_deploy(deploy_id)
|
23
|
+
send(:get, "marketplace_releases/#{deploy_id}")
|
24
|
+
end
|
25
|
+
|
26
|
+
def deploy(zip_file_path, deploy_options)
|
27
|
+
upload_file = Faraday::UploadIO.new(zip_file_path, 'application/zip')
|
28
|
+
send(:post, 'marketplace_releases', { marketplace_builder: { zip_file: upload_file, force_mode: deploy_options[:force] } }, multipart: true)
|
29
|
+
end
|
30
|
+
|
31
|
+
def backup
|
32
|
+
send(:post, 'marketplace_releases/backup', {})
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def send(request_type, url, body = {}, options = {})
|
38
|
+
ApiDriver.new(request_type, url, body, options).send_request
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module MarketplaceKit
|
2
|
+
module Services
|
3
|
+
class ArgsParser
|
4
|
+
DEFAULT_ENV = 'localhost'
|
5
|
+
|
6
|
+
def initialize(args)
|
7
|
+
@args = args
|
8
|
+
end
|
9
|
+
|
10
|
+
def command_name
|
11
|
+
@args[0]
|
12
|
+
end
|
13
|
+
|
14
|
+
def command_args
|
15
|
+
@args[1..-1] || []
|
16
|
+
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
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module MarketplaceKit
|
2
|
+
module Services
|
3
|
+
class Config
|
4
|
+
def load(endpoint_name)
|
5
|
+
@config = {}
|
6
|
+
@endpoint = endpoint_name
|
7
|
+
|
8
|
+
load_config_from '.builder'
|
9
|
+
load_config_from '.builder-autogenerated', required: false
|
10
|
+
|
11
|
+
raise Errors::MarketplaceError.new 'Error: Invalid env passed!' if @config[@endpoint].nil?
|
12
|
+
rescue Errno::ENOENT
|
13
|
+
raise Errors::MarketplaceError.new 'Please create .builder file in order to continue.'
|
14
|
+
end
|
15
|
+
|
16
|
+
def token
|
17
|
+
@config[@endpoint]['token'].to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
def set_token(value)
|
21
|
+
@config[@endpoint]['token'] = value
|
22
|
+
save_token(value)
|
23
|
+
end
|
24
|
+
|
25
|
+
def url
|
26
|
+
@config[@endpoint]['url'].to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def load_config_from(file_name, options = {})
|
32
|
+
return if options[:required] == false && !File.exist?("#{MarketplaceKit.builder_folder}.builder-autogenerated")
|
33
|
+
|
34
|
+
text_config = File.read("#{MarketplaceKit.builder_folder}#{file_name}")
|
35
|
+
@config.deeper_merge! JSON.parse(text_config)
|
36
|
+
end
|
37
|
+
|
38
|
+
def save_token(value)
|
39
|
+
File.write("#{MarketplaceKit.builder_folder}.builder-autogenerated", { @endpoint => { token: value } }.to_json)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module MarketplaceKit
|
2
|
+
module Services
|
3
|
+
class Logger
|
4
|
+
def deploy_started
|
5
|
+
puts 'Deploy command started!'.green
|
6
|
+
end
|
7
|
+
|
8
|
+
def compressing_folder
|
9
|
+
puts 'Compressing marketplace_builder folder'.yellow
|
10
|
+
end
|
11
|
+
|
12
|
+
def sending_zip
|
13
|
+
puts 'Sending zip to the server'.yellow
|
14
|
+
end
|
15
|
+
|
16
|
+
def wait_for_deploy_finish
|
17
|
+
puts 'Waiting for deploy to finish'.yellow
|
18
|
+
end
|
19
|
+
|
20
|
+
def pull_started
|
21
|
+
puts 'Pull command started!'.green
|
22
|
+
end
|
23
|
+
|
24
|
+
def request_backup
|
25
|
+
puts 'Requesting system backup...'.yellow
|
26
|
+
end
|
27
|
+
|
28
|
+
def wait_for_backup_finish
|
29
|
+
puts 'Waiting for backup to finish'.yellow
|
30
|
+
end
|
31
|
+
|
32
|
+
def sync_command_started
|
33
|
+
puts 'Sync mode enabled'.green
|
34
|
+
end
|
35
|
+
|
36
|
+
def sync_updating(file_path)
|
37
|
+
puts "Updating: #{file_path}".green
|
38
|
+
end
|
39
|
+
|
40
|
+
def sync_done
|
41
|
+
puts 'Done!'.green
|
42
|
+
end
|
43
|
+
|
44
|
+
def ask_for_email
|
45
|
+
puts 'Enter your email'
|
46
|
+
end
|
47
|
+
|
48
|
+
def ask_for_password
|
49
|
+
puts 'Enter your password'
|
50
|
+
end
|
51
|
+
|
52
|
+
def redirect_tip
|
53
|
+
puts 'Server returned redirect code (possible a wrong domain in config file?)'.yellow
|
54
|
+
end
|
55
|
+
|
56
|
+
def json_error(source)
|
57
|
+
puts '```'.red
|
58
|
+
puts 'Error while parsing JSON'.red
|
59
|
+
puts "Raw body:\n#{source}"
|
60
|
+
puts '```'.red
|
61
|
+
end
|
62
|
+
|
63
|
+
def api_error(message, details)
|
64
|
+
puts '```'.red
|
65
|
+
puts "Builder error: #{message}".red
|
66
|
+
puts 'Details:'
|
67
|
+
puts details
|
68
|
+
puts '```'.red
|
69
|
+
end
|
70
|
+
|
71
|
+
def standard_error(error)
|
72
|
+
puts '```'.red
|
73
|
+
puts "Error: #{error.message} (#{error.class})".red
|
74
|
+
puts '```'.red
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module MarketplaceKit
|
2
|
+
module Services
|
3
|
+
class UserAuthentication
|
4
|
+
include Services::Loggable
|
5
|
+
|
6
|
+
def authenticate
|
7
|
+
return unless requires_login?
|
8
|
+
|
9
|
+
credentials = ask_for_email_and_password
|
10
|
+
login_and_remember credentials
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def requires_login?
|
16
|
+
MarketplaceKit.config.token.empty? || gateway.login_required?
|
17
|
+
end
|
18
|
+
|
19
|
+
def ask_for_email_and_password
|
20
|
+
log :ask_for_email
|
21
|
+
email = STDIN.gets.chomp
|
22
|
+
|
23
|
+
log :ask_for_password
|
24
|
+
password = STDIN.noecho(&:gets).chomp
|
25
|
+
|
26
|
+
{ email: email, password: password }
|
27
|
+
end
|
28
|
+
|
29
|
+
def login_and_remember(credentials)
|
30
|
+
user_token = gateway.login credentials[:email], credentials[:password]
|
31
|
+
MarketplaceKit.config.set_token user_token
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def gateway
|
37
|
+
@gateway ||= Services::ApiGateway.new
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'listen'
|
3
|
+
require 'faraday'
|
4
|
+
require 'io/console'
|
5
|
+
require 'deep_merge/rails_compat'
|
6
|
+
require 'colorize'
|
7
|
+
|
8
|
+
require 'marketplace_kit/services/loggable'
|
9
|
+
require 'marketplace_kit/services/logger'
|
10
|
+
require 'marketplace_kit/version'
|
11
|
+
require 'marketplace_kit/command_dispatcher'
|
12
|
+
require 'marketplace_kit/errors/api_error'
|
13
|
+
require 'marketplace_kit/errors/marketplace_error'
|
14
|
+
require 'marketplace_kit/services/user_authentication'
|
15
|
+
require 'marketplace_kit/services/args_parser'
|
16
|
+
require 'marketplace_kit/services/config'
|
17
|
+
require 'marketplace_kit/services/api_driver'
|
18
|
+
require 'marketplace_kit/services/api_gateway'
|
19
|
+
require 'marketplace_kit/commands/base_command'
|
20
|
+
require 'marketplace_kit/commands/sync'
|
21
|
+
require 'marketplace_kit/commands/deploy'
|
22
|
+
require 'marketplace_kit/commands/pull'
|
23
|
+
|
24
|
+
module MarketplaceKit
|
25
|
+
MARKETPLACE_BUILDER_FOLDER = 'marketplace_builder'.freeze
|
26
|
+
|
27
|
+
def self.root
|
28
|
+
File.dirname __dir__
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.builder_folder
|
32
|
+
"#{Dir.getwd}/#{MARKETPLACE_BUILDER_FOLDER}/"
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.config
|
36
|
+
@config ||= Services::Config.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.logger
|
40
|
+
@logger ||= Services::Logger.new
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"localhost":{"token":"example-user-token"}, "staging":{"token":"example-user-token"}}
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Hello</h1>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'marketplace_kit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'marketplace-kit'
|
8
|
+
spec.version = MarketplaceKit::VERSION
|
9
|
+
spec.authors = ['Michal Janeczek']
|
10
|
+
spec.email = ['michal.janeczek@ymail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Marketplace Kit'
|
13
|
+
spec.description = 'Marketplace Kit'
|
14
|
+
spec.homepage = 'https://marketplaceplatform.com'
|
15
|
+
|
16
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.bindir = 'bin'
|
23
|
+
spec.executables = ['marketplace-kit']
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'rspec-mocks'
|
30
|
+
spec.add_development_dependency 'webmock'
|
31
|
+
spec.add_development_dependency 'simplecov'
|
32
|
+
spec.add_development_dependency 'coveralls'
|
33
|
+
|
34
|
+
spec.add_dependency 'listen'
|
35
|
+
spec.add_dependency 'faraday'
|
36
|
+
spec.add_dependency 'colorize'
|
37
|
+
spec.add_dependency 'deep_merge'
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,228 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: marketplace-kit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michal Janeczek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-mocks
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: listen
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: faraday
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
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: colorize
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: deep_merge
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: Marketplace Kit
|
168
|
+
email:
|
169
|
+
- michal.janeczek@ymail.com
|
170
|
+
executables:
|
171
|
+
- marketplace-kit
|
172
|
+
extensions: []
|
173
|
+
extra_rdoc_files: []
|
174
|
+
files:
|
175
|
+
- ".gitignore"
|
176
|
+
- ".rspec"
|
177
|
+
- ".travis.yml"
|
178
|
+
- Gemfile
|
179
|
+
- README.md
|
180
|
+
- Rakefile
|
181
|
+
- bin/console
|
182
|
+
- bin/marketplace-kit
|
183
|
+
- bin/setup
|
184
|
+
- lib/marketplace_kit.rb
|
185
|
+
- lib/marketplace_kit/command_dispatcher.rb
|
186
|
+
- lib/marketplace_kit/commands/base_command.rb
|
187
|
+
- lib/marketplace_kit/commands/deploy.rb
|
188
|
+
- lib/marketplace_kit/commands/pull.rb
|
189
|
+
- lib/marketplace_kit/commands/sync.rb
|
190
|
+
- lib/marketplace_kit/errors/api_error.rb
|
191
|
+
- lib/marketplace_kit/errors/marketplace_error.rb
|
192
|
+
- lib/marketplace_kit/services/api_driver.rb
|
193
|
+
- lib/marketplace_kit/services/api_gateway.rb
|
194
|
+
- lib/marketplace_kit/services/args_parser.rb
|
195
|
+
- lib/marketplace_kit/services/config.rb
|
196
|
+
- lib/marketplace_kit/services/loggable.rb
|
197
|
+
- lib/marketplace_kit/services/logger.rb
|
198
|
+
- lib/marketplace_kit/services/user_authentication.rb
|
199
|
+
- lib/marketplace_kit/version.rb
|
200
|
+
- marketplace_builder/.builder
|
201
|
+
- marketplace_builder/.builder-autogenerated
|
202
|
+
- marketplace_builder/liquid_views/index.liquid
|
203
|
+
- marketplace_kit.gemspec
|
204
|
+
homepage: https://marketplaceplatform.com
|
205
|
+
licenses: []
|
206
|
+
metadata:
|
207
|
+
allowed_push_host: https://rubygems.org
|
208
|
+
post_install_message:
|
209
|
+
rdoc_options: []
|
210
|
+
require_paths:
|
211
|
+
- lib
|
212
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
213
|
+
requirements:
|
214
|
+
- - ">="
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '0'
|
217
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
requirements: []
|
223
|
+
rubyforge_project:
|
224
|
+
rubygems_version: 2.5.1
|
225
|
+
signing_key:
|
226
|
+
specification_version: 4
|
227
|
+
summary: Marketplace Kit
|
228
|
+
test_files: []
|