avmtrf1-tools 0.27.0 → 0.31.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -0
  3. data/lib/avmtrf1/esosti/entities/issue.rb +5 -31
  4. data/lib/avmtrf1/esosti/instance.rb +4 -0
  5. data/lib/avmtrf1/esosti/instance/changed.rb +33 -0
  6. data/lib/avmtrf1/esosti/raw_data_sanitizer.rb +47 -0
  7. data/lib/avmtrf1/inventario_sistemas.rb +40 -0
  8. data/lib/avmtrf1/inventario_sistemas/parser.rb +42 -0
  9. data/lib/avmtrf1/inventario_sistemas/parser/body.rb +27 -0
  10. data/lib/avmtrf1/inventario_sistemas/parser/body_row.rb +12 -0
  11. data/lib/avmtrf1/inventario_sistemas/parser/header.rb +38 -0
  12. data/lib/avmtrf1/inventario_sistemas/parser/header_column.rb +27 -0
  13. data/lib/avmtrf1/inventario_sistemas/site_build.rb +71 -0
  14. data/lib/avmtrf1/inventario_sistemas/site_build/html_page_base.rb +41 -0
  15. data/lib/avmtrf1/inventario_sistemas/site_build/html_page_base/elements.rb +54 -0
  16. data/lib/avmtrf1/inventario_sistemas/site_build/html_page_base/layout.rb +55 -0
  17. data/lib/avmtrf1/inventario_sistemas/site_build/html_page_base/stylesheet.css +57 -0
  18. data/lib/avmtrf1/inventario_sistemas/site_build/index.rb +20 -0
  19. data/lib/avmtrf1/inventario_sistemas/site_build/sistema.rb +62 -0
  20. data/lib/avmtrf1/inventario_sistemas/site_build/sistemas_index.rb +31 -0
  21. data/lib/avmtrf1/oracle/connection/base.rb +1 -0
  22. data/lib/avmtrf1/oracle/oci8.rb +8 -4
  23. data/lib/avmtrf1/patches/eac_launcher/git/base.rb +0 -15
  24. data/lib/avmtrf1/redmine/instance.rb +2 -1
  25. data/lib/avmtrf1/rest_provider/instance.rb +13 -53
  26. data/lib/avmtrf1/rest_provider/instance/issues.rb +30 -0
  27. data/lib/avmtrf1/rest_provider/request.rb +44 -0
  28. data/lib/avmtrf1/rest_provider/response.rb +77 -0
  29. data/lib/avmtrf1/ruby.rb +9 -0
  30. data/lib/avmtrf1/ruby/gems.rb +11 -0
  31. data/lib/avmtrf1/ruby/gems/dependency.rb +20 -0
  32. data/lib/avmtrf1/ruby/gems/not_found_error.rb +17 -0
  33. data/lib/avmtrf1/tools/runner.rb +12 -0
  34. data/lib/avmtrf1/tools/runner/esosti.rb +2 -21
  35. data/lib/avmtrf1/tools/runner/esosti/changed.rb +52 -0
  36. data/lib/avmtrf1/tools/runner/esosti/fetch.rb +52 -0
  37. data/lib/avmtrf1/tools/runner/esosti/request.rb +88 -0
  38. data/lib/avmtrf1/tools/runner/inventario_sistemas.rb +73 -0
  39. data/lib/avmtrf1/tools/version.rb +1 -1
  40. metadata +64 -40
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avmtrf1/rest_provider/response'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'ostruct'
6
+
7
+ module Avmtrf1
8
+ module RestProvider
9
+ class Request
10
+ common_constructor :url, :body_data_proc, default: [nil]
11
+
12
+ def autenticate(username, password)
13
+ self.auth = ::OpenStruct.new(username: username, password: password)
14
+ end
15
+
16
+ def header(name, value)
17
+ headers[name.to_s] = value
18
+ end
19
+
20
+ def response
21
+ ::Avmtrf1::RestProvider::Response.new(build_curl, body_data_proc)
22
+ end
23
+
24
+ private
25
+
26
+ attr_accessor :auth
27
+
28
+ def build_curl
29
+ r = ::Curl::Easy.new(url)
30
+ auth.if_present do |a|
31
+ r.http_auth_types = :basic
32
+ r.username = a.username
33
+ r.password = a.password
34
+ end
35
+ r.headers.merge!(headers)
36
+ r
37
+ end
38
+
39
+ def headers
40
+ @headers ||= {}
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/hash/conversions'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'json'
6
+
7
+ module Avmtrf1
8
+ module RestProvider
9
+ class Response < ::StandardError
10
+ common_constructor :curl, :body_data_proc
11
+
12
+ def body_data
13
+ r = performed_curl.headers['Accept'].if_present(body_str) do |v|
14
+ send("body_data_from_#{v.parameterize.underscore}")
15
+ end
16
+ r = body_data_proc.call(r) if body_data_proc.present?
17
+ r
18
+ end
19
+
20
+ def body_data_or_raise
21
+ raise_unless_200
22
+
23
+ body_data
24
+ end
25
+
26
+ def body_str
27
+ performed_curl.body_str
28
+ end
29
+
30
+ def body_str_or_raise
31
+ raise_unless_200
32
+
33
+ body_str
34
+ end
35
+
36
+ def raise_unless_200
37
+ return nil if status == 200
38
+
39
+ raise self
40
+ end
41
+
42
+ def status
43
+ performed_curl.status.to_i
44
+ end
45
+
46
+ def url
47
+ curl.url
48
+ end
49
+
50
+ def to_s
51
+ "URL: #{url}\nStatus: #{status}\nBody:\n\n#{body_str}"
52
+ end
53
+
54
+ private
55
+
56
+ def body_data_from_application_json
57
+ ::JSON.parse(body_str)
58
+ end
59
+
60
+ def body_data_from_application_xml
61
+ Hash.from_xml(body_str)
62
+ end
63
+
64
+ def perform
65
+ @perform ||= begin
66
+ curl.perform || raise("CURL perform failed for #{url}")
67
+ true
68
+ end
69
+ end
70
+
71
+ def performed_curl
72
+ perform
73
+ curl
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avmtrf1
6
+ module Ruby
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avmtrf1
6
+ module Ruby
7
+ module Gems
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avmtrf1/ruby/gems/not_found_error'
5
+
6
+ module Avmtrf1
7
+ module Ruby
8
+ module Gems
9
+ class Dependency
10
+ common_constructor :gem_name, :lib_name
11
+
12
+ def require_lib
13
+ require lib_name
14
+ rescue LoadError
15
+ raise ::Avmtrf1::Ruby::Gems::NotFoundError, self
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avmtrf1
4
+ module Ruby
5
+ module Gems
6
+ class NotFoundError < ::StandardError
7
+ attr_reader :dependency
8
+
9
+ def initialize(dependency)
10
+ @dependency = dependency
11
+ super("Gem \"#{dependency.gem_name}\" not found" \
12
+ " (Library required: \"#{dependency.lib_name}\")")
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -4,6 +4,7 @@ require 'aranha/selenium/driver_factory/base'
4
4
  require 'eac_ruby_utils/console/docopt_runner'
5
5
  require 'eac_ruby_utils/require_sub'
6
6
  require 'avmtrf1/tools/version'
7
+ require 'avmtrf1/ruby/gems/not_found_error'
7
8
  require 'eac_ruby_utils/console/speaker'
8
9
 
9
10
  module Avmtrf1
@@ -33,6 +34,17 @@ module Avmtrf1
33
34
  else
34
35
  run_with_subcommand
35
36
  end
37
+ rescue ::Avmtrf1::Ruby::Gems::NotFoundError => e
38
+ on_gem_not_found(e.dependency)
39
+ end
40
+
41
+ private
42
+
43
+ def on_gem_not_found(dependency)
44
+ fatal_error "A gem \"#{dependency.gem_name}\" foi requerida " \
45
+ "(Por \"require '#{dependency.lib_name}'\") e não encontrada. Para instalá-la:\n\n" \
46
+ " gem install #{dependency.gem_name}\n\n" \
47
+ 'Nota: procedimentos adicionais podem ser necessários.'
36
48
  end
37
49
  end
38
50
  end
@@ -10,6 +10,7 @@ module Avmtrf1
10
10
  module Tools
11
11
  class Runner < ::EacRubyUtils::Console::DocoptRunner
12
12
  class Esosti < ::EacRubyUtils::Console::DocoptRunner
13
+ require_sub __FILE__
13
14
  enable_console_speaker
14
15
  enable_simple_cache
15
16
 
@@ -17,23 +18,14 @@ module Avmtrf1
17
18
  Utilidades para e-Sosti (Control Desk).
18
19
 
19
20
  Usage:
20
- __PROGRAM__ [options] fetch <solicitacao_id>
21
+ __PROGRAM__ [options] __SUBCOMMANDS__
21
22
  __PROGRAM__ -h | --help
22
23
 
23
24
  Options:
24
25
  -h --help Mostra esta ajuda.
25
- -u --user Usuário no e-Sosti.
26
26
  -U --url=<url> Utiliza o Control Desk em <url>.
27
27
  DOCOPT
28
28
 
29
- def run
30
- if options.fetch('fetch')
31
- fetch
32
- else
33
- fatal_error('Subcomando não mapeado (Isto é um defeito do software)')
34
- end
35
- end
36
-
37
29
  private
38
30
 
39
31
  def esosti_instance_uncached
@@ -41,17 +33,6 @@ module Avmtrf1
41
33
  ::Avmtrf1.trf1_esosti(url)
42
34
  end
43
35
  end
44
-
45
- def fetch
46
- infom "Recuperando informações de #{solicitacao_id}..."
47
- issue = esosti_instance.issue(solicitacao_id)
48
- fatal_error("Issue não encontrado: #{solicitacao_id}") unless issue
49
- out issue.data.to_yaml
50
- end
51
-
52
- def solicitacao_id
53
- options.fetch('<solicitacao_id>')
54
- end
55
36
  end
56
37
  end
57
38
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/console/docopt_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'avmtrf1/default_esosti'
6
+ require 'avmtrf1/ini'
7
+ require 'avmtrf1/red/profile'
8
+
9
+ module Avmtrf1
10
+ module Tools
11
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
12
+ class Esosti < ::EacRubyUtils::Console::DocoptRunner
13
+ class Changed < ::EacRubyUtils::Console::DocoptRunner
14
+ enable_console_speaker
15
+ enable_simple_cache
16
+
17
+ DOC = <<~DOCOPT
18
+ Recupera o conteúdo de uma solicitação e-Sosti (Control Desk).
19
+
20
+ Usage:
21
+ __PROGRAM__ [options] <time>
22
+ __PROGRAM__ -h | --help
23
+
24
+ Options:
25
+ -h --help Mostra esta ajuda.
26
+ DOCOPT
27
+
28
+ def run
29
+ infov 'Time', time
30
+ infov 'URL', request.url
31
+ out data.to_yaml
32
+ end
33
+
34
+ private
35
+
36
+ def data_uncached
37
+ infom 'Recuperando informações...'
38
+ request.response.body_data_or_raise
39
+ end
40
+
41
+ def request_uncached
42
+ context(:esosti_instance).changed_request(time)
43
+ end
44
+
45
+ def time
46
+ ::Time.parse(options.fetch('<time>'))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/console/docopt_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'avmtrf1/default_esosti'
6
+ require 'avmtrf1/ini'
7
+ require 'avmtrf1/red/profile'
8
+
9
+ module Avmtrf1
10
+ module Tools
11
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
12
+ class Esosti < ::EacRubyUtils::Console::DocoptRunner
13
+ class Fetch < ::EacRubyUtils::Console::DocoptRunner
14
+ enable_console_speaker
15
+ enable_simple_cache
16
+
17
+ DOC = <<~DOCOPT
18
+ Recupera o conteúdo de uma solicitação e-Sosti (Control Desk).
19
+
20
+ Usage:
21
+ __PROGRAM__ [options] <solicitacao_id>
22
+ __PROGRAM__ -h | --help
23
+
24
+ Options:
25
+ -h --help Mostra esta ajuda.
26
+ DOCOPT
27
+
28
+ def run
29
+ infov 'URL', request.url
30
+ fatal_error("Issue não encontrado: #{solicitacao_id}") unless issue
31
+ out issue.data.to_yaml
32
+ end
33
+
34
+ private
35
+
36
+ def request_uncached
37
+ context(:esosti_instance).issue_request(solicitacao_id)
38
+ end
39
+
40
+ def issue_uncached
41
+ infom "Recuperando informações de #{solicitacao_id}..."
42
+ request.response.body_data_or_raise
43
+ end
44
+
45
+ def solicitacao_id
46
+ options.fetch('<solicitacao_id>')
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/console/docopt_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'avmtrf1/default_esosti'
6
+ require 'avmtrf1/ini'
7
+ require 'avmtrf1/red/profile'
8
+
9
+ module Avmtrf1
10
+ module Tools
11
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
12
+ class Esosti < ::EacRubyUtils::Console::DocoptRunner
13
+ class Request < ::EacRubyUtils::Console::DocoptRunner
14
+ enable_console_speaker
15
+ enable_simple_cache
16
+
17
+ DOC = <<~DOCOPT
18
+ Requisições genéricas para e-Sosti (Control Desk).
19
+
20
+ Usage:
21
+ __PROGRAM__ [options] <url-suffix>
22
+ __PROGRAM__ -h | --help
23
+
24
+ Options:
25
+ -h --help Mostra esta ajuda.
26
+ -d --default Opções --json e --yaml.
27
+ -j --json Solicita resposta em JSON.
28
+ -x --xml Solicita resposta em XML.
29
+ -y --yaml Imprime saída em YAML.
30
+ DOCOPT
31
+
32
+ def run
33
+ start_banner
34
+ output_data
35
+ end
36
+
37
+ private
38
+
39
+ def json?
40
+ options.fetch('--json') || options.fetch('--default')
41
+ end
42
+
43
+ def start_banner
44
+ infov 'URL', request.url
45
+ infom 'Recuperando informações...'
46
+ infov 'Response status', response.status
47
+ end
48
+
49
+ def output_data
50
+ if yaml?
51
+ out ::YAML.dump(response.body_data)
52
+ else
53
+ out response.body_str
54
+ end
55
+ end
56
+
57
+ def request_uncached
58
+ context(:esosti_instance).request(url_suffix, request_headers)
59
+ end
60
+
61
+ def request_headers
62
+ r = {}
63
+ %w[json xml].each do |format|
64
+ r['Accept'] = "application/#{format}" if send("#{format}?")
65
+ end
66
+ r
67
+ end
68
+
69
+ def response_uncached
70
+ request.response
71
+ end
72
+
73
+ def url_suffix
74
+ options.fetch('<url-suffix>')
75
+ end
76
+
77
+ def xml?
78
+ options.fetch('--xml')
79
+ end
80
+
81
+ def yaml?
82
+ options.fetch('--yaml') || options.fetch('--default')
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end