avmtrf1-tools 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/bin/oracle +7 -0
- data/exe/avmtrf1 +8 -0
- data/init.rb +10 -0
- data/lib/avmtrf1/ini/profile.rb +46 -0
- data/lib/avmtrf1/ini.rb +45 -0
- data/lib/avmtrf1/patches/inifile.rb +13 -0
- data/lib/avmtrf1/patches.rb +1 -0
- data/lib/avmtrf1/red/client/authorization.xml.erb +4 -0
- data/lib/avmtrf1/red/client.rb +38 -0
- data/lib/avmtrf1/red/helper.rb +50 -0
- data/lib/avmtrf1/red/profile/put_file.xml.erb +19 -0
- data/lib/avmtrf1/red/profile.rb +73 -0
- data/lib/avmtrf1/red/server.rb +33 -0
- data/lib/avmtrf1/red.rb +5 -0
- data/lib/avmtrf1/tools/runner/red.rb +87 -0
- data/lib/avmtrf1/tools/runner.rb +21 -0
- data/lib/avmtrf1/tools/version.rb +7 -0
- data/lib/avmtrf1/tools.rb +4 -0
- data/lib/avmtrf1.rb +6 -0
- data/lib/oracle/commands/base.rb +15 -0
- data/lib/oracle/commands/source_get.rb +50 -0
- data/lib/oracle/connection/base.rb +48 -0
- data/lib/oracle/connection/string_builder.rb +43 -0
- data/lib/oracle/runner.rb +49 -0
- metadata +166 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5cb1ffb9dde8a2732c1ad3f49a7213250ed76e462a95f904a18804c7b7a5b4a4
|
4
|
+
data.tar.gz: ca10e34e58da0794d751f42d2ebc8e6ec5a2773c5b2b956f0998f1b6d2dbef38
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 55b49d07b25d00446eb6618218a9a62eb97da7382a9c7b539d118fbac3f888ef529f16421ad28e42bd7017854e8b664bf22a498e1cd8fbd60975661f91b7fe75
|
7
|
+
data.tar.gz: 688fb0d1d371ffe8fbeaa60a2339d11fec845ae6b6fe5755bf4c9397c078c740720e74e40a769866082412378cc40e8108959ad3aaa1e9cee821c2d1dc4c9e58
|
data/Gemfile
ADDED
data/bin/oracle
ADDED
data/exe/avmtrf1
ADDED
data/init.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
ENV['BUNDLE_GEMFILE'] = ::File.join(__dir__, 'Gemfile')
|
4
|
+
ENV['NLS_LANG'] = 'BRAZILIAN PORTUGUESE_BRAZIL.WE8ISO8859P1'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'bundler/setup'
|
7
|
+
require 'eac_ruby_utils'
|
8
|
+
require 'active_support/core_ext/object'
|
9
|
+
|
10
|
+
$LOAD_PATH.unshift ::File.join(__dir__, 'lib')
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/simple_cache'
|
4
|
+
|
5
|
+
module Avmtrf1
|
6
|
+
class Ini
|
7
|
+
class Profile
|
8
|
+
include ::EacRubyUtils::SimpleCache
|
9
|
+
|
10
|
+
attr_reader :ini, :name, :parent_name, :self_data
|
11
|
+
|
12
|
+
# @param profiles [Avmtrf1::Ini::Profiles
|
13
|
+
def initialize(ini, name, parent_name, self_data)
|
14
|
+
@ini = ini
|
15
|
+
@name = name
|
16
|
+
@parent_name = parent_name
|
17
|
+
@self_data = self_data
|
18
|
+
end
|
19
|
+
|
20
|
+
def [](key)
|
21
|
+
data[key]
|
22
|
+
end
|
23
|
+
|
24
|
+
def fetch(key)
|
25
|
+
data.fetch(key)
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_h(prefix = '')
|
29
|
+
data.select { |k, _v| k.start_with?(prefix) }
|
30
|
+
.map { |e| [e[0].gsub(/\A#{Regexp.quote(prefix)}/, ''), e[1]] }.to_h
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def data_uncached
|
36
|
+
r = self_data
|
37
|
+
r = parent.data.merge(r) if parent
|
38
|
+
r
|
39
|
+
end
|
40
|
+
|
41
|
+
def parent
|
42
|
+
parent_name ? ini.profiles[parent_name] : nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/avmtrf1/ini.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/simple_cache'
|
4
|
+
require 'pp'
|
5
|
+
require 'avmtrf1/ini/profile'
|
6
|
+
require 'avmtrf1/patches/inifile'
|
7
|
+
|
8
|
+
module Avmtrf1
|
9
|
+
# Leitor de arquivos .ini com suporte a herança de seções/perfis.
|
10
|
+
class Ini
|
11
|
+
include ::EacRubyUtils::SimpleCache
|
12
|
+
|
13
|
+
class << self
|
14
|
+
SECTION_NAME_PATTERN = /\A([^\:]+)(?:\:([^\:]+))?\z/.freeze
|
15
|
+
|
16
|
+
# @return Um [Array] em que o primeiro elemento é o perfil e o segundo é seu super-perfil.
|
17
|
+
def parse_section_name(section_name)
|
18
|
+
m = SECTION_NAME_PATTERN.match(section_name)
|
19
|
+
return [m[1], m[2]] if m
|
20
|
+
|
21
|
+
raise "Section name pattern \"#{SECTION_NAME_PATTERN}\" not match \"#{section_name}\""
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :inifile
|
26
|
+
|
27
|
+
# @param ini Um [IniFile] ou um caminho de arquivo .ini.
|
28
|
+
def initialize(inifile)
|
29
|
+
@inifile = ::IniFile.load(inifile.to_s) unless inifile.is_a?(::IniFile)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def profiles_uncached
|
35
|
+
r = {}
|
36
|
+
inifile.each_section do |section|
|
37
|
+
profile_name, profile_parent_name = self.class.parse_section_name(section)
|
38
|
+
r[profile_name] = ::Avmtrf1::Ini::Profile.new(
|
39
|
+
self, profile_name, profile_parent_name, inifile[section]
|
40
|
+
)
|
41
|
+
end
|
42
|
+
r.sort.to_h.freeze
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avmtrf1/red/server'
|
4
|
+
require 'avmtrf1/red/helper'
|
5
|
+
require 'pp'
|
6
|
+
require 'tempfile'
|
7
|
+
|
8
|
+
module Avmtrf1
|
9
|
+
module Red
|
10
|
+
class Client
|
11
|
+
include ::Avmtrf1::Red::Helper
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def by_ini_profile(ini_profile)
|
15
|
+
::Avmtrf1::Red::Client.new(
|
16
|
+
::Avmtrf1::Red::Server.by_ini_profile(ini_profile),
|
17
|
+
ini_profile.to_h('parametros.')
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :server, :login, :ip, :sistema, :nome_maquina
|
23
|
+
|
24
|
+
def initialize(server, parametros)
|
25
|
+
@server = server
|
26
|
+
@login = parametros.fetch('login')
|
27
|
+
@ip = parametros.fetch('ip')
|
28
|
+
@sistema = parametros.fetch('sistema')
|
29
|
+
@nome_maquina = parametros.fetch('nomeMaquina')
|
30
|
+
end
|
31
|
+
|
32
|
+
def authorization_url
|
33
|
+
xml = post_xml('/REDCentral/autorizacaoinclusao', xml_content('authorization'))
|
34
|
+
xml.at_xpath('/root/retornoSolicitacaoInclusao/@url')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'active_support/core_ext/string'
|
5
|
+
require 'eac_ruby_utils/console/speaker'
|
6
|
+
require 'erb'
|
7
|
+
require 'httpclient'
|
8
|
+
require 'nokogiri'
|
9
|
+
|
10
|
+
module Avmtrf1
|
11
|
+
module Red
|
12
|
+
module Helper
|
13
|
+
extend ::ActiveSupport::Concern
|
14
|
+
|
15
|
+
included do
|
16
|
+
include ::EacRubyUtils::Console::Speaker
|
17
|
+
end
|
18
|
+
|
19
|
+
def http_client
|
20
|
+
@http_client ||= ::HTTPClient.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def check_request_result(url, result)
|
24
|
+
return if result.status == 200
|
25
|
+
|
26
|
+
raise "#{url} returned #{result.status}\n#{result.body}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def post(url, *post_args)
|
30
|
+
infom "Requesting \"#{url}\""
|
31
|
+
res = http_client.post(url, *post_args)
|
32
|
+
check_request_result(url, res)
|
33
|
+
res.body
|
34
|
+
end
|
35
|
+
|
36
|
+
def post_xml(url_suffix, xml_body)
|
37
|
+
url = server.resource_url(url_suffix)
|
38
|
+
::Nokogiri::XML(post(url, xml_body))
|
39
|
+
end
|
40
|
+
|
41
|
+
def xml_content(name)
|
42
|
+
::ERB.new(::File.read(xml_path(name))).result(binding)
|
43
|
+
end
|
44
|
+
|
45
|
+
def xml_path(name)
|
46
|
+
::File.join(__dir__, self.class.name.demodulize.underscore, "#{name}.xml.erb")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<root>
|
2
|
+
<MetadadosInclusao
|
3
|
+
dataHoraProducaoConteudo="<%= Time.now.strftime('%d/%m/%Y %H:%I:%S') %>"
|
4
|
+
numeroPasta="<%= metadados.fetch('numeroPasta') %>"
|
5
|
+
descricaoTituloDocumento="<%= metadados.fetch('descricaoTituloDocumento') %>"
|
6
|
+
numeroTipoSigilo="<%= metadados.fetch('numeroSigiloPublico') %>"
|
7
|
+
nomeSistemaIntrodutor="<%= client.sistema %>"
|
8
|
+
ipMaquinaResponsavelIntervencao = "<%= client.ip %>"
|
9
|
+
secaoOrigemDocumento ="<%= metadados.fetch('secaoOrigemDocumento') %>"
|
10
|
+
prioridadeReplicacao="<%= metadados.fetch('prioridadeReplicacaoNormal') %>"
|
11
|
+
espacoDocumento="<%= metadados.fetch('espacoDocumento') %>"
|
12
|
+
indicadorAnotacao="<%= metadados.fetch('indicadorAnotacaoMinutaTemporario') %>"
|
13
|
+
nomeMaquinaResponsavelIntervensao="<%= metadados.fetch('nomeMaquinaResponsavelIntervensao') %>"
|
14
|
+
>
|
15
|
+
|
16
|
+
<SecaoDestino idSecao = "<%= metadados.fetch('secaoDestinoIdSecao') %>"/>
|
17
|
+
|
18
|
+
</MetadadosInclusao>
|
19
|
+
</root>
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avmtrf1/red/client'
|
4
|
+
require 'avmtrf1/red/helper'
|
5
|
+
require 'eac_ruby_utils/simple_cache'
|
6
|
+
|
7
|
+
module Avmtrf1
|
8
|
+
module Red
|
9
|
+
class Profile
|
10
|
+
include ::Avmtrf1::Red::Helper
|
11
|
+
include ::EacRubyUtils::SimpleCache
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def by_ini_profile(ini_profile)
|
15
|
+
new(
|
16
|
+
::Avmtrf1::Red::Client.by_ini_profile(ini_profile),
|
17
|
+
ini_profile.to_h('metadados.')
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :client, :metadados
|
23
|
+
|
24
|
+
# @param client [Avmtrf1::Red::Client]
|
25
|
+
# @param metadados [Hash]
|
26
|
+
def initialize(client, metadados)
|
27
|
+
@client = client
|
28
|
+
@metadados = metadados.dup.freeze
|
29
|
+
end
|
30
|
+
|
31
|
+
def put_file(file_path)
|
32
|
+
auth_url = client.authorization_url
|
33
|
+
infov 'Authorization URL', auth_url
|
34
|
+
put_file_request(auth_url, file_path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def server
|
38
|
+
client.server
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def put_file_request(auth_url, file_path)
|
44
|
+
post(auth_url, put_file_args(file_path))
|
45
|
+
end
|
46
|
+
|
47
|
+
def put_file_args(file_path)
|
48
|
+
{
|
49
|
+
body: put_file_body(file_path),
|
50
|
+
header: {
|
51
|
+
'Content-Type' => 'multipart/form-data'
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def metadados_file_path_uncached
|
57
|
+
file = Tempfile.new(['red_metadados', '.xml'])
|
58
|
+
::File.write(file.path, xml_content('put_file'))
|
59
|
+
file.path
|
60
|
+
end
|
61
|
+
|
62
|
+
def put_file_body(file_path)
|
63
|
+
infov 'Metadados', ::File.read(metadados_file_path)
|
64
|
+
{
|
65
|
+
'ip' => client.ip,
|
66
|
+
'login' => client.login,
|
67
|
+
'metadado' => ::File.open(metadados_file_path, 'r'),
|
68
|
+
'conteudo' => ::File.open(file_path, 'r')
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avmtrf1/red/client'
|
4
|
+
|
5
|
+
module Avmtrf1
|
6
|
+
module Red
|
7
|
+
class Server
|
8
|
+
class << self
|
9
|
+
def by_ini_profile(ini_profile)
|
10
|
+
new(ini_profile.fetch('red.server'))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :host
|
15
|
+
|
16
|
+
def initialize(host)
|
17
|
+
@host = host
|
18
|
+
end
|
19
|
+
|
20
|
+
def client(login, ip, sistema, nome_maquina)
|
21
|
+
::Avmtrf1::Red::Client.new(self, login, ip, sistema, nome_maquina)
|
22
|
+
end
|
23
|
+
|
24
|
+
def root_url
|
25
|
+
"http://#{host}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def resource_url(url_suffix)
|
29
|
+
"#{root_url}#{url_suffix}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/avmtrf1/red.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
4
|
+
require 'eac_ruby_utils/console/speaker'
|
5
|
+
require 'eac_ruby_utils/simple_cache'
|
6
|
+
require 'avmtrf1/ini'
|
7
|
+
require 'avmtrf1/red/profile'
|
8
|
+
|
9
|
+
module Avmtrf1
|
10
|
+
module Tools
|
11
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
12
|
+
class Red < ::EacRubyUtils::Console::DocoptRunner
|
13
|
+
include ::EacRubyUtils::Console::Speaker
|
14
|
+
include ::EacRubyUtils::SimpleCache
|
15
|
+
|
16
|
+
DOC = <<~DOCOPT
|
17
|
+
Utilidades para RED.
|
18
|
+
|
19
|
+
Usage:
|
20
|
+
__PROGRAM__ [options] [-i <red-ini-path>] file put <file>
|
21
|
+
__PROGRAM__ -h | --help
|
22
|
+
|
23
|
+
Options:
|
24
|
+
-h --help Mostra esta ajuda.
|
25
|
+
-i --red-ini=<red-ini-path> Arquivo red.ini com parâmetros de conexão e upload.
|
26
|
+
-p --red-profile=<red-profile> Perfil/seção do red.ini [default: development].
|
27
|
+
DOCOPT
|
28
|
+
|
29
|
+
def run
|
30
|
+
start_banner
|
31
|
+
if options.fetch('file') && options.fetch('put')
|
32
|
+
file_put
|
33
|
+
else
|
34
|
+
fatal_error('Subcomando não mapeado (Isto é um defeito do software)')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def start_banner
|
39
|
+
infov 'red.ini', options.fetch('--red-ini')
|
40
|
+
infov 'Perfil de red.ini', red_profile_name
|
41
|
+
infov 'Arquivo para upload', options.fetch('<file>')
|
42
|
+
end
|
43
|
+
|
44
|
+
def file_put
|
45
|
+
result = red_profile.put_file(file)
|
46
|
+
require 'pp'
|
47
|
+
puts '>' * 20
|
48
|
+
puts result
|
49
|
+
puts '<' * 20
|
50
|
+
end
|
51
|
+
|
52
|
+
def red_profile_name
|
53
|
+
options.fetch('--red-profile')
|
54
|
+
end
|
55
|
+
|
56
|
+
def red_profile_uncached
|
57
|
+
::Avmtrf1::Red::Profile.by_ini_profile(red_ini_profile)
|
58
|
+
end
|
59
|
+
|
60
|
+
def file
|
61
|
+
required_file('<file>')
|
62
|
+
end
|
63
|
+
|
64
|
+
def red_ini_path_uncached
|
65
|
+
required_file('--red-ini')
|
66
|
+
end
|
67
|
+
|
68
|
+
def red_ini_uncached
|
69
|
+
::Avmtrf1::Ini.new(red_ini_path)
|
70
|
+
end
|
71
|
+
|
72
|
+
def red_ini_profile
|
73
|
+
return red_ini.profiles[red_profile_name] if red_ini.profiles.key?(red_profile_name)
|
74
|
+
|
75
|
+
fatal_error "Perfil/seção \"#{red_profile_name}\" não encontrada em \"#{red_ini_path}\""
|
76
|
+
end
|
77
|
+
|
78
|
+
def required_file(option_key)
|
79
|
+
path = options.fetch(option_key)
|
80
|
+
return path if path
|
81
|
+
|
82
|
+
fatal_error("Arquivo \"#{path}\" não existe (Informado na opção #{option_key})")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
4
|
+
require 'avmtrf1/tools/runner/red'
|
5
|
+
|
6
|
+
module Avmtrf1
|
7
|
+
module Tools
|
8
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
9
|
+
DOC = <<~DOCOPT
|
10
|
+
Utilidades para AVM-TRF1 (http://redmine.trf1.gov.br/projects/avm-trf1).
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
__PROGRAM__ [options] __SUBCOMMANDS__
|
14
|
+
__PROGRAM__ -h | --help
|
15
|
+
|
16
|
+
Options:
|
17
|
+
-h --help Show this screen.
|
18
|
+
DOCOPT
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/avmtrf1.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oracle/commands/base'
|
4
|
+
|
5
|
+
module Oracle
|
6
|
+
module Commands
|
7
|
+
class SourceGet < ::Oracle::Commands::Base
|
8
|
+
include ::EacRubyUtils::Console::Speaker
|
9
|
+
|
10
|
+
TABLE = 'all_source'
|
11
|
+
|
12
|
+
def initialize(connection, options)
|
13
|
+
super(connection)
|
14
|
+
@name = options[:name]
|
15
|
+
@type = options[:type]
|
16
|
+
validate
|
17
|
+
run
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :name, :type
|
23
|
+
|
24
|
+
def validate
|
25
|
+
raise '"name" is blank' if name.blank?
|
26
|
+
end
|
27
|
+
|
28
|
+
def run
|
29
|
+
infov('Name', name)
|
30
|
+
infov('Type', type)
|
31
|
+
infov('Found', found_count)
|
32
|
+
infov('Enconding', OCI8.encoding)
|
33
|
+
connection.query(sql(false)) do |row|
|
34
|
+
out(row['TEXT'].encode('UTF-8').to_s)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def found_count
|
39
|
+
connection.unique_value(sql(true)).to_i
|
40
|
+
end
|
41
|
+
|
42
|
+
def sql(count)
|
43
|
+
projection = count ? 'count(*)' : '*'
|
44
|
+
selection = "lower(name) = lower('#{name}')"
|
45
|
+
selection += " and lower(type) = lower('#{type}')" if type.present?
|
46
|
+
"select #{projection} from #{TABLE} where #{selection} order by line"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oci8'
|
4
|
+
|
5
|
+
module Oracle
|
6
|
+
module Connection
|
7
|
+
class Base
|
8
|
+
DEFAULT_PORT = 1521
|
9
|
+
|
10
|
+
def initialize(connection_string)
|
11
|
+
@connection = OCI8.new(connection_string)
|
12
|
+
end
|
13
|
+
|
14
|
+
def unique_value(sql)
|
15
|
+
connection.exec(sql) do |row|
|
16
|
+
return row.first
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def query(sql, &block)
|
21
|
+
if block
|
22
|
+
query_with_block(sql, block)
|
23
|
+
else
|
24
|
+
query_without_block(sql)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :connection
|
31
|
+
|
32
|
+
def query_without_block(sql)
|
33
|
+
connection.exec(sql)
|
34
|
+
end
|
35
|
+
|
36
|
+
def query_with_block(sql, block)
|
37
|
+
cursor = query_without_block(sql)
|
38
|
+
begin
|
39
|
+
while (row = cursor.fetch_hash)
|
40
|
+
block.call(row)
|
41
|
+
end
|
42
|
+
ensure
|
43
|
+
cursor.close
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Oracle
|
4
|
+
module Connection
|
5
|
+
class StringBuilder
|
6
|
+
DEFAULT_PORT = 1521
|
7
|
+
|
8
|
+
FIELDS = %w[user password host port service_name].freeze
|
9
|
+
|
10
|
+
attr_accessor(*FIELDS)
|
11
|
+
attr_accessor :string
|
12
|
+
|
13
|
+
def initialize(options = nil)
|
14
|
+
if options.is_a?(String)
|
15
|
+
self.string = options
|
16
|
+
elsif options.is_a?(Hash)
|
17
|
+
options.each do |k, v|
|
18
|
+
send("#{k}=", v)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def port
|
24
|
+
@port || DEFAULT_PORT
|
25
|
+
end
|
26
|
+
|
27
|
+
def build
|
28
|
+
if string
|
29
|
+
string
|
30
|
+
else
|
31
|
+
validate_fields
|
32
|
+
"#{user}/#{password}@//#{host}:#{port}/#{service_name}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def validate_fields
|
39
|
+
FIELDS.each { |f| raise "\"#{f}\" is blank" if send(f).blank? }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oracle/connection/base.rb'
|
4
|
+
require 'oracle/connection/string_builder.rb'
|
5
|
+
require 'oracle/commands/source_get.rb'
|
6
|
+
|
7
|
+
module Oracle
|
8
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
9
|
+
include ::EacRubyUtils::Console::Speaker
|
10
|
+
|
11
|
+
DOC = <<~DOCOPT
|
12
|
+
Usage:
|
13
|
+
__PROGRAM__ [options] source:get <name> <type>
|
14
|
+
__PROGRAM__ -h | --help
|
15
|
+
|
16
|
+
Options:
|
17
|
+
-h --help Show this screen
|
18
|
+
-H --host=<host> Host Oracle (Ex.: 172.16.3.3)
|
19
|
+
-p --port=<port> Porta Oracle (Ex.: 1521) (Padrão: 1521).
|
20
|
+
-s --service-name=<service> Serviço Oracle (Ex.: trf1.trf1.gov.br)
|
21
|
+
-u --user=<user> Usuário Oracle
|
22
|
+
-w --password=<password> Senha Oracle
|
23
|
+
DOCOPT
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def run
|
28
|
+
run_source_get if options['source:get']
|
29
|
+
end
|
30
|
+
|
31
|
+
def run_source_get
|
32
|
+
Oracle::Commands::SourceGet.new(connection, name: options['<name>'], type: options['<type>'])
|
33
|
+
end
|
34
|
+
|
35
|
+
def connection
|
36
|
+
@connection ||= ::Oracle::Connection::Base.new(connection_string)
|
37
|
+
end
|
38
|
+
|
39
|
+
def connection_string
|
40
|
+
::Oracle::Connection::StringBuilder.new(
|
41
|
+
host: options['--host'],
|
42
|
+
port: options['--port'],
|
43
|
+
user: options['--user'],
|
44
|
+
password: options['--password'],
|
45
|
+
service_name: options['--service-name']
|
46
|
+
).build
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: avmtrf1-tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eduardo H. Bogoni
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: eac_ruby_utils
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: inifile
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.73.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.73.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.34.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.34.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: ruby-oci8
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
executables:
|
114
|
+
- avmtrf1
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- Gemfile
|
119
|
+
- bin/oracle
|
120
|
+
- exe/avmtrf1
|
121
|
+
- init.rb
|
122
|
+
- lib/avmtrf1.rb
|
123
|
+
- lib/avmtrf1/ini.rb
|
124
|
+
- lib/avmtrf1/ini/profile.rb
|
125
|
+
- lib/avmtrf1/patches.rb
|
126
|
+
- lib/avmtrf1/patches/inifile.rb
|
127
|
+
- lib/avmtrf1/red.rb
|
128
|
+
- lib/avmtrf1/red/client.rb
|
129
|
+
- lib/avmtrf1/red/client/authorization.xml.erb
|
130
|
+
- lib/avmtrf1/red/helper.rb
|
131
|
+
- lib/avmtrf1/red/profile.rb
|
132
|
+
- lib/avmtrf1/red/profile/put_file.xml.erb
|
133
|
+
- lib/avmtrf1/red/server.rb
|
134
|
+
- lib/avmtrf1/tools.rb
|
135
|
+
- lib/avmtrf1/tools/runner.rb
|
136
|
+
- lib/avmtrf1/tools/runner/red.rb
|
137
|
+
- lib/avmtrf1/tools/version.rb
|
138
|
+
- lib/oracle/commands/base.rb
|
139
|
+
- lib/oracle/commands/source_get.rb
|
140
|
+
- lib/oracle/connection/base.rb
|
141
|
+
- lib/oracle/connection/string_builder.rb
|
142
|
+
- lib/oracle/runner.rb
|
143
|
+
homepage: http://redmine.trf1.gov.br/projects/avm-trf1
|
144
|
+
licenses: []
|
145
|
+
metadata: {}
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 2.7.7
|
163
|
+
signing_key:
|
164
|
+
specification_version: 4
|
165
|
+
summary: Ferramentas para AVM-TRF1.
|
166
|
+
test_files: []
|