evostream-event 1.0.0.pre.58 → 1.0.0.pre.59
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/evostream +19 -0
- data/lib/evostream/{event → action}/action.rb +0 -0
- data/lib/evostream/cli/code_error.rb +42 -0
- data/lib/evostream/cli/config.rb +60 -0
- data/lib/evostream/cli/help +11 -3
- data/lib/evostream/cli/option.rb +59 -6
- data/lib/evostream/cli/runner.rb +63 -19
- data/lib/evostream/cli/search.rb +30 -0
- data/lib/evostream/event.rb +1 -1
- data/lib/evostream/event/event/events/out_stream_created.rb +1 -1
- data/lib/evostream/event/response/response.rb +2 -0
- data/spec/evostream/commands/create_spec.rb +1 -1
- data/spec/evostream/events/request_out_stream_created_spec.rb +2 -2
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11e21c32b959d3c3a5036afe6c3c03bb3dc6070d
|
4
|
+
data.tar.gz: ff51bfc42cf538c060f07fa1d7e45d6b6daffd4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94b45eda4743b32592200a7b863c7d6f80947e080592175e9c1a49c352dc1364f992ec6656a5aeb3b39add4d019032fac7e9889925ec2399fb995a3cfc99fea4
|
7
|
+
data.tar.gz: 4c586c822c22a4b4b38c4ff762228b27171ff0dff2b4d1b8316c0b1c0a363d223763d496140766628b6a8eb4856cc2617669330ef7e924a8fd4fa3c92cca352a
|
data/bin/evostream
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift("#{__dir__}/../lib/evostream/cli")
|
4
|
+
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'active_support/inflector'
|
7
|
+
require 'json'
|
8
|
+
require 'runner'
|
9
|
+
require 'benchmark'
|
10
|
+
|
11
|
+
cli = Evostream::Runner.new
|
12
|
+
result = 0
|
13
|
+
|
14
|
+
time = Benchmark.realtime do
|
15
|
+
result = cli.run
|
16
|
+
end
|
17
|
+
|
18
|
+
puts "Finished in #{time} seconds" if Evostream::Service.environment.eql?(:development)
|
19
|
+
exit result
|
File without changes
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Evostream
|
4
|
+
module CodeError
|
5
|
+
# Program finished correctly
|
6
|
+
class Finished < RuntimeError; end
|
7
|
+
|
8
|
+
# Error 1xx
|
9
|
+
module Syntax
|
10
|
+
# Syntax to command is invalid
|
11
|
+
class CommandInvalid < RuntimeError
|
12
|
+
def initialize
|
13
|
+
puts 'Command is invalid !!'.red
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Syntax to option is invalid
|
18
|
+
class OptionInvalid < RuntimeError
|
19
|
+
def initialize
|
20
|
+
puts 'No command executed !! No command precise.'.red
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Error 2xx
|
26
|
+
module Evostream
|
27
|
+
# Connection to Evostream failed
|
28
|
+
class ConnectionFailed < RuntimeError
|
29
|
+
def initialize
|
30
|
+
puts 'Connection to Evostream REFUSED !!'.red
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Response to evostream is empty
|
35
|
+
class NoResult < RuntimeError
|
36
|
+
def initialize
|
37
|
+
puts 'No result for this command.'.yellow
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
module Evostream
|
6
|
+
module CLI
|
7
|
+
# Configuration file for CLI
|
8
|
+
class Config
|
9
|
+
def initialize
|
10
|
+
@options = @uri = nil
|
11
|
+
load_file_configuration
|
12
|
+
Evostream::Service.environment = :production
|
13
|
+
apply_uri
|
14
|
+
end
|
15
|
+
|
16
|
+
def change_host(host)
|
17
|
+
@uri.host = host
|
18
|
+
apply_uri
|
19
|
+
end
|
20
|
+
|
21
|
+
def change_port(port)
|
22
|
+
@uri.port = port
|
23
|
+
apply_uri
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_custom_file(file)
|
27
|
+
load_yml(file)
|
28
|
+
save_uri
|
29
|
+
apply_uri
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def apply_uri
|
35
|
+
Evostream::Service.uri_in = @uri
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_yml(file)
|
39
|
+
@options = YAML.safe_load(ERB.new(File.read(file)).result)
|
40
|
+
end
|
41
|
+
|
42
|
+
def load_file_configuration
|
43
|
+
load_yml(File.join(ENV['HOME'], '.evostream-configuration.yml'))
|
44
|
+
save_uri
|
45
|
+
end
|
46
|
+
|
47
|
+
def save_uri
|
48
|
+
@uri = URI.parse("http://#{options_host}:#{options_port}")
|
49
|
+
end
|
50
|
+
|
51
|
+
def options_host
|
52
|
+
@options['evostream']['host']
|
53
|
+
end
|
54
|
+
|
55
|
+
def options_port
|
56
|
+
@options['evostream']['port']
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/evostream/cli/help
CHANGED
@@ -1,14 +1,22 @@
|
|
1
1
|
Usage :
|
2
|
-
evostream [options] [command]
|
2
|
+
evostream [options] [command] [data]
|
3
3
|
|
4
4
|
Example :
|
5
5
|
### List to configuration in evostream
|
6
6
|
% evostream listConfig
|
7
7
|
|
8
|
+
Options :
|
8
9
|
-h, --help Display this help.
|
9
10
|
|
10
11
|
-c, --commands Display list command managed by this software.
|
11
12
|
|
12
|
-
|
13
|
+
--server Evostream URL.
|
14
|
+
default : localhost
|
13
15
|
|
14
|
-
|
16
|
+
--port Evostream PORT.
|
17
|
+
default : 7777
|
18
|
+
|
19
|
+
-s, --search Search a node in result to request.
|
20
|
+
|
21
|
+
--config Use customize file configuration
|
22
|
+
default : ~/.evostream-configuration.yml
|
data/lib/evostream/cli/option.rb
CHANGED
@@ -1,26 +1,49 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# :reek:InstanceVariableAssumption
|
4
|
+
# :reek:TooManyConstants
|
5
|
+
# :reek:TooManyStatements
|
6
|
+
|
3
7
|
module Evostream
|
4
8
|
module CLI
|
9
|
+
# Class for parsing option used in CLI software
|
5
10
|
class Options
|
6
|
-
CASE_HELP = ['-h', '--help']
|
7
|
-
CASE_CMD = ['-c', '--commands']
|
8
|
-
|
9
|
-
|
11
|
+
CASE_HELP = ['-h', '--help'].freeze
|
12
|
+
CASE_CMD = ['-c', '--commands'].freeze
|
13
|
+
CASE_HOST = ['--server'].freeze
|
14
|
+
CASE_PORT = ['--port'].freeze
|
15
|
+
CASE_SEARCH = ['-s', '--search'].freeze
|
16
|
+
CASE_CONFIG = ['--config'].freeze
|
17
|
+
|
18
|
+
attr_reader :search
|
10
19
|
|
11
|
-
def initialize
|
20
|
+
def initialize(configuration)
|
21
|
+
@search = nil
|
12
22
|
@file = File.read(File.join(__dir__, 'help'))
|
23
|
+
@config = configuration
|
13
24
|
end
|
14
25
|
|
15
26
|
# Parse options and execute action if necessary
|
27
|
+
# rubocop:disable Style/EmptyCaseCondition
|
28
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
29
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
30
|
+
# rubocop:disable Metrics/AbcSize
|
16
31
|
def parse(argv)
|
17
32
|
@command_line_args = argv
|
18
33
|
case
|
19
34
|
when include(CASE_HELP) then display_help
|
20
35
|
when include(CASE_CMD) then display_command
|
36
|
+
when include(CASE_HOST) then use_host
|
37
|
+
when include(CASE_PORT) then use_port
|
38
|
+
when include(CASE_SEARCH) then search_in_response
|
39
|
+
when include(CASE_CONFIG) then use_config_file
|
21
40
|
when @command_line_args.empty? then display_no_command
|
22
41
|
end
|
23
42
|
end
|
43
|
+
# rubocop:enable Style/EmptyCaseCondition
|
44
|
+
# rubocop:enable Metrics/AbcSize
|
45
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
46
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
24
47
|
|
25
48
|
private
|
26
49
|
|
@@ -30,6 +53,7 @@ module Evostream
|
|
30
53
|
|
31
54
|
def display_help
|
32
55
|
puts @file
|
56
|
+
raise CodeError::Finished
|
33
57
|
end
|
34
58
|
|
35
59
|
def display_command
|
@@ -37,11 +61,40 @@ module Evostream
|
|
37
61
|
Evostream::Commands::Command.descendants.each do |cmd|
|
38
62
|
puts " - #{cmd.to_s.split('::').last}"
|
39
63
|
end
|
64
|
+
raise CodeError::Finished
|
65
|
+
end
|
66
|
+
|
67
|
+
def use_host
|
68
|
+
@config.change_host(parameter('--server'))
|
69
|
+
end
|
70
|
+
|
71
|
+
def use_port
|
72
|
+
@config.change_port(parameter('--port'))
|
73
|
+
end
|
74
|
+
|
75
|
+
def search_in_response
|
76
|
+
CASE_SEARCH.each do |search|
|
77
|
+
@search = parameter(search) if args_has_present?(search)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def use_config_file
|
82
|
+
file = File.join(parameter('--config'))
|
83
|
+
@config.load_custom_file(file)
|
40
84
|
end
|
41
85
|
|
42
86
|
def display_no_command
|
43
|
-
puts 'No command executed !!'.red
|
44
87
|
display_help
|
88
|
+
raise CodeError::Syntax::OptionInvalid
|
89
|
+
end
|
90
|
+
|
91
|
+
def parameter(search_case)
|
92
|
+
param = @command_line_args.find_index(search_case)
|
93
|
+
@command_line_args[param + 1]
|
94
|
+
end
|
95
|
+
|
96
|
+
def args_has_present?(ind)
|
97
|
+
@command_line_args.find_index(ind)
|
45
98
|
end
|
46
99
|
end
|
47
100
|
end
|
data/lib/evostream/cli/runner.rb
CHANGED
@@ -2,13 +2,22 @@
|
|
2
2
|
|
3
3
|
require 'colorize'
|
4
4
|
require 'option'
|
5
|
+
require 'config'
|
6
|
+
require 'search'
|
7
|
+
require 'timeout'
|
8
|
+
require 'socket'
|
9
|
+
require 'code_error'
|
10
|
+
require 'yaml'
|
11
|
+
require 'yaml/dbm'
|
5
12
|
|
6
13
|
$LOAD_PATH.unshift("#{__dir__}/../")
|
7
14
|
require 'event'
|
8
15
|
|
16
|
+
# :reek:TooManyStatements
|
17
|
+
|
9
18
|
module Evostream
|
19
|
+
# Execute CLI with this gem
|
10
20
|
class Runner
|
11
|
-
|
12
21
|
attr_reader :options
|
13
22
|
|
14
23
|
def initialize
|
@@ -19,38 +28,73 @@ module Evostream
|
|
19
28
|
##################################
|
20
29
|
INFO
|
21
30
|
puts txt.red
|
22
|
-
@
|
23
|
-
|
31
|
+
@config = CLI::Config.new
|
32
|
+
@options = CLI::Options.new(@config)
|
24
33
|
end
|
25
34
|
|
35
|
+
# rubocop:disable Metrics/MethodLength
|
26
36
|
def run(args = ARGV)
|
27
|
-
@options = CLI::Options.new
|
28
37
|
@options.parse(args)
|
29
38
|
|
39
|
+
access_evostream?
|
30
40
|
execute_runner(args.last) if args.count >= 1
|
31
|
-
|
41
|
+
rescue CodeError::Evostream::ConnectionFailed
|
42
|
+
return 201
|
43
|
+
rescue CodeError::Evostream::NoResult
|
44
|
+
return 200
|
45
|
+
rescue CodeError::Syntax::CommandInvalid
|
46
|
+
return 101
|
47
|
+
rescue CodeError::Syntax::OptionInvalid
|
48
|
+
return 100
|
49
|
+
rescue CodeError::Finished
|
32
50
|
return 0
|
33
51
|
end
|
52
|
+
# rubocop:enable Metrics/MethodLength
|
34
53
|
|
35
54
|
private
|
36
55
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
Evostream::
|
43
|
-
|
44
|
-
|
56
|
+
def access_evostream?
|
57
|
+
Timeout.timeout(1) do
|
58
|
+
test_server_started
|
59
|
+
end
|
60
|
+
rescue Timeout::Error
|
61
|
+
raise CodeError::Evostream::ConnectionFailed
|
62
|
+
end
|
63
|
+
|
64
|
+
# :reek:FeatureEnvy
|
65
|
+
def test_server_started
|
66
|
+
uri = URI.parse(Evostream::Service.uri_in.to_s)
|
67
|
+
socket = TCPSocket.new(uri.host, uri.port)
|
68
|
+
socket.close
|
69
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
70
|
+
raise CodeError::Evostream::ConnectionFailed
|
45
71
|
end
|
46
72
|
|
47
73
|
def execute_runner(cmd)
|
48
|
-
|
49
|
-
|
50
|
-
act
|
51
|
-
|
52
|
-
|
53
|
-
|
74
|
+
test_command(cmd) do
|
75
|
+
act = Evostream::Action.new
|
76
|
+
interpret_response(act.execute_action(cmd)[:data])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def interpret_response(result)
|
81
|
+
if @options.search.nil?
|
82
|
+
puts result.to_yaml
|
83
|
+
else
|
84
|
+
CLI::Search.new(@options.search).search_node(result)
|
85
|
+
end
|
86
|
+
raise CodeError::Finished
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_command(cmd)
|
90
|
+
raise CodeError::Syntax::CommandInvalid \
|
91
|
+
if cmd.start_with?('-', '--') || cmd_exist?(cmd)
|
92
|
+
yield
|
93
|
+
end
|
94
|
+
|
95
|
+
def cmd_exist?(cmd)
|
96
|
+
Evostream::Commands::Command.descendants.none? do |command|
|
97
|
+
command.to_s.split('::').last.casecmp(cmd).zero?
|
54
98
|
end
|
55
99
|
end
|
56
100
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Evostream
|
4
|
+
module CLI
|
5
|
+
# Search data in evostream result
|
6
|
+
class Search
|
7
|
+
def initialize(yaml_search)
|
8
|
+
YAML.load(yaml_search).each do |key, value|
|
9
|
+
@search = [key.to_sym, value]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def search_node(result)
|
14
|
+
YAML.load(result.to_yaml).each do |_key, value|
|
15
|
+
inspect_array(value) if value.is_a?(Array) && !value.empty?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def inspect_array(evostream_response)
|
22
|
+
evostream_response.each do |value|
|
23
|
+
value.each do |hash_value|
|
24
|
+
puts value.to_yaml if hash_value == @search
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/evostream/event.rb
CHANGED
@@ -5,7 +5,7 @@ require 'evostream/event/info'
|
|
5
5
|
require 'evostream/event/service'
|
6
6
|
require 'evostream/event/commands'
|
7
7
|
require 'evostream/event/event'
|
8
|
-
require 'evostream/
|
8
|
+
require 'evostream/action/action'
|
9
9
|
require 'evostream/event/response/response'
|
10
10
|
require 'net/http'
|
11
11
|
require 'evostream/event/response/mock'
|
@@ -54,7 +54,7 @@ describe Evostream::Events::OutStreamCreated do
|
|
54
54
|
overwriteDestination: true,
|
55
55
|
playlistLength: 5,
|
56
56
|
playlistName: "#{Faker::Lorem.word}.#{Faker::Lorem.word}",
|
57
|
-
playlistType: %w
|
57
|
+
playlistType: %w[rolling appending].sample,
|
58
58
|
staleRetentionCount: 5,
|
59
59
|
startOffset: 0,
|
60
60
|
targetFolder: Faker::File.file_name(Faker::Lorem.word,
|
@@ -151,7 +151,7 @@ describe Evostream::Events::OutStreamCreated do
|
|
151
151
|
operationType: 6,
|
152
152
|
overwriteDestination: true,
|
153
153
|
playlistLength: 5,
|
154
|
-
playlistType: %w
|
154
|
+
playlistType: %w[rolling appending].sample,
|
155
155
|
staleRetentionCount: 5,
|
156
156
|
targetFolder: Faker::File.file_name(Faker::Lorem.word,
|
157
157
|
Faker::GameOfThrones.city,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evostream-event
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.
|
4
|
+
version: 1.0.0.pre.59
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- VAILLANT Jeremy
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -282,7 +282,8 @@ description: |2
|
|
282
282
|
Manipulate event evostream and send actions to evostream server.
|
283
283
|
email:
|
284
284
|
- jeremy@dazzl.tv
|
285
|
-
executables:
|
285
|
+
executables:
|
286
|
+
- evostream
|
286
287
|
extensions: []
|
287
288
|
extra_rdoc_files: []
|
288
289
|
files:
|
@@ -290,11 +291,15 @@ files:
|
|
290
291
|
- LICENSE
|
291
292
|
- README.md
|
292
293
|
- Rakefile
|
294
|
+
- bin/evostream
|
295
|
+
- lib/evostream/action/action.rb
|
296
|
+
- lib/evostream/cli/code_error.rb
|
297
|
+
- lib/evostream/cli/config.rb
|
293
298
|
- lib/evostream/cli/help
|
294
299
|
- lib/evostream/cli/option.rb
|
295
300
|
- lib/evostream/cli/runner.rb
|
301
|
+
- lib/evostream/cli/search.rb
|
296
302
|
- lib/evostream/event.rb
|
297
|
-
- lib/evostream/event/action.rb
|
298
303
|
- lib/evostream/event/commands.rb
|
299
304
|
- lib/evostream/event/commands/create.rb
|
300
305
|
- lib/evostream/event/commands/create/dash.rb
|