avmtrf1-tools 0.32.1 → 0.33.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 +4 -4
- data/lib/avmtrf1/openvpn/config/builder.rb +59 -0
- data/lib/avmtrf1/openvpn/config/parser.rb +20 -0
- data/lib/avmtrf1/openvpn/config/parser/builder.rb +62 -0
- data/lib/avmtrf1/openvpn/config/parser/line.rb +47 -0
- data/lib/avmtrf1/openvpn/config/parser/simple.rb +27 -0
- data/lib/avmtrf1/openvpn/config/parser/tag.rb +39 -0
- data/lib/avmtrf1/tools/runner/openvpn.rb +57 -4
- data/lib/avmtrf1/tools/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28aaea569505102ad3211b02ec77cf0c2b290acc629b3530190acf0603f289d1
|
4
|
+
data.tar.gz: 755924e206af72290f5958622a20a545cf925882b4ebc6a8c1e5fc7821bbe6ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 767c2478bcc066672821f52114c903f4bf6e30f44b6a1a746c045cce80c33b8589f1fc36051b33009fc02318ff6971b15cc039cc9aad7b725ea93a291a5aa563
|
7
|
+
data.tar.gz: 382e3a8930764a843005e9c24a2f8e9f1cb3deb89886433ed34bcfa40996aaf2a57324c8e61a146cb1834810dff2deeb4fc13fddbb53eb8fbc75610fab557f43
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avmtrf1/openvpn/config/parser'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'eac_ruby_utils/fs/temp'
|
6
|
+
|
7
|
+
module Avmtrf1
|
8
|
+
module Openvpn
|
9
|
+
module Config
|
10
|
+
class Builder
|
11
|
+
common_constructor :source_data do
|
12
|
+
unless source_data.is_a?(::Hash)
|
13
|
+
self.source_data = ::Avmtrf1::Openvpn::Config::Parser.new(source_data.to_s).data
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def data
|
18
|
+
[simple, tags].reject(&:blank?).join("\n")
|
19
|
+
end
|
20
|
+
|
21
|
+
def on_data_file
|
22
|
+
::EacRubyUtils::Fs::Temp.on_file do |file|
|
23
|
+
file.write(data)
|
24
|
+
yield(file)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def simple
|
29
|
+
source_data.fetch(:simple)
|
30
|
+
.map { |s| ::Shellwords.join([s.fetch(:attribute)] + s.fetch(:args)) }
|
31
|
+
.map { |s| "#{s}\n" }.join
|
32
|
+
end
|
33
|
+
|
34
|
+
def simple_add_or_update(name, args)
|
35
|
+
new_data = { attribute: name, args: args }
|
36
|
+
s = simple_find(name)
|
37
|
+
if s
|
38
|
+
s.merge!(new_data)
|
39
|
+
else
|
40
|
+
source_data.fetch(:simple) << new_data
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def tags
|
45
|
+
source_data.fetch(:tags).map { |t| tag_to_data(t) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def tag_to_data(tag)
|
49
|
+
["<#{tag.fetch(:name)}>", tag.fetch(:content), "</#{tag.fetch(:name)}>"]
|
50
|
+
.map { |v| "#{v}\n" }.join
|
51
|
+
end
|
52
|
+
|
53
|
+
def simple_find(name)
|
54
|
+
source_data.fetch(:simple).find { |s| s.fetch(:attribute) == name }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aranha/parsers/base'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module Avmtrf1
|
7
|
+
module Openvpn
|
8
|
+
module Config
|
9
|
+
class Parser < ::Aranha::Parsers::Base
|
10
|
+
require_sub __FILE__
|
11
|
+
|
12
|
+
def data
|
13
|
+
builder = ::Avmtrf1::Openvpn::Config::Parser::Builder.new
|
14
|
+
content.each_line { |line| builder.add_line(line) }
|
15
|
+
{ simple: builder.simple.map(&:data), tags: builder.tags.map(&:data) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avmtrf1/openvpn/config/parser/line'
|
4
|
+
require 'avmtrf1/openvpn/config/parser/simple'
|
5
|
+
require 'avmtrf1/openvpn/config/parser/tag'
|
6
|
+
|
7
|
+
module Avmtrf1
|
8
|
+
module Openvpn
|
9
|
+
module Config
|
10
|
+
class Parser < ::Aranha::Parsers::Base
|
11
|
+
class Builder
|
12
|
+
attr_reader :simple, :tags
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@simple = []
|
16
|
+
@tags = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_line(line_text)
|
20
|
+
line = ::Avmtrf1::Openvpn::Config::Parser::Line.new(line_text)
|
21
|
+
if on_tag?
|
22
|
+
add_line_on_tag(line)
|
23
|
+
else
|
24
|
+
add_line_not_on_tag(line)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_line_on_tag(line)
|
29
|
+
if line.close_tag?
|
30
|
+
if line.tag_name != current_tag.name
|
31
|
+
raise("Closing tag \"#{line.tag_name}\" does not match current tag " \
|
32
|
+
"\"#{current_tag}\"")
|
33
|
+
end
|
34
|
+
|
35
|
+
current_tag.close
|
36
|
+
else
|
37
|
+
current_tag.add_line(line.text)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_line_not_on_tag(line)
|
42
|
+
return if line.blank_text?
|
43
|
+
|
44
|
+
if line.open_tag?
|
45
|
+
tags << ::Avmtrf1::Openvpn::Config::Parser::Tag.new(line.tag_name)
|
46
|
+
else
|
47
|
+
simple << ::Avmtrf1::Openvpn::Config::Parser::Simple.new(line.simple_parts)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def current_tag
|
52
|
+
tags.last
|
53
|
+
end
|
54
|
+
|
55
|
+
def on_tag?
|
56
|
+
tags.last.if_present(false, &:open?)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module Avmtrf1
|
6
|
+
module Openvpn
|
7
|
+
module Config
|
8
|
+
class Parser < ::Aranha::Parsers::Base
|
9
|
+
class Line
|
10
|
+
OPEN_TAG_PATTERN = /\A<(.+)>\z/.freeze
|
11
|
+
CLOSE_TAG_PATTERN = %r{\A</(.+)>\z}.freeze
|
12
|
+
SIMPLE_PATTERN = /\A(\S+)(?:\s+(\S.*))\z/.freeze
|
13
|
+
|
14
|
+
common_constructor :text do
|
15
|
+
self.text = text.rstrip
|
16
|
+
end
|
17
|
+
|
18
|
+
def simple_parts
|
19
|
+
::Shellwords.split(text)
|
20
|
+
end
|
21
|
+
|
22
|
+
def blank_text?
|
23
|
+
text.blank?
|
24
|
+
end
|
25
|
+
|
26
|
+
def open_tag?
|
27
|
+
OPEN_TAG_PATTERN.match?(text)
|
28
|
+
end
|
29
|
+
|
30
|
+
def close_tag?
|
31
|
+
CLOSE_TAG_PATTERN.match?(text)
|
32
|
+
end
|
33
|
+
|
34
|
+
def tag_name
|
35
|
+
if close_tag?
|
36
|
+
CLOSE_TAG_PATTERN.if_match(text) { |m| m[1] }
|
37
|
+
elsif open_tag?
|
38
|
+
OPEN_TAG_PATTERN.if_match(text) { |m| m[1] }
|
39
|
+
else
|
40
|
+
raise "Unmapped branch in #{__method__}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module Avmtrf1
|
6
|
+
module Openvpn
|
7
|
+
module Config
|
8
|
+
class Parser < ::Aranha::Parsers::Base
|
9
|
+
class Simple
|
10
|
+
common_constructor :parts
|
11
|
+
|
12
|
+
def data
|
13
|
+
{ attribute: attribute, args: args }
|
14
|
+
end
|
15
|
+
|
16
|
+
def attribute
|
17
|
+
parts.first
|
18
|
+
end
|
19
|
+
|
20
|
+
def args
|
21
|
+
parts[1..-1]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module Avmtrf1
|
6
|
+
module Openvpn
|
7
|
+
module Config
|
8
|
+
class Parser < ::Aranha::Parsers::Base
|
9
|
+
class Tag
|
10
|
+
common_constructor :name do
|
11
|
+
@open = true
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_line(text)
|
15
|
+
lines << text
|
16
|
+
end
|
17
|
+
|
18
|
+
def data
|
19
|
+
{ name: name, content: lines.join("\n") }
|
20
|
+
end
|
21
|
+
|
22
|
+
def open?
|
23
|
+
@open
|
24
|
+
end
|
25
|
+
|
26
|
+
def close
|
27
|
+
@open = false
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def lines
|
33
|
+
@lines ||= []
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'avmtrf1/ad_user'
|
3
4
|
require 'avmtrf1/executables'
|
5
|
+
require 'avmtrf1/openvpn/config/builder'
|
4
6
|
require 'eac_cli/core_ext'
|
5
7
|
|
6
8
|
module Avmtrf1
|
@@ -10,17 +12,25 @@ module Avmtrf1
|
|
10
12
|
runner_with :help do
|
11
13
|
desc 'Conecta-se utilizando OpenVPN com configurações dinâmicas.'
|
12
14
|
bool_opt '-S', '--no-sudo', 'Não executa com "sudo".'
|
15
|
+
bool_opt '-A', '--no-ad-auth', 'Não utiliza autenticação do Active Directory.'
|
13
16
|
pos_arg :ovpn_path
|
14
17
|
end
|
15
18
|
|
16
19
|
def run
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
on_temp_files do
|
21
|
+
start_banner
|
22
|
+
infov 'Resultado', command.system
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
private
|
23
27
|
|
28
|
+
attr_accessor :credentials_path, :ovpn_config_path
|
29
|
+
|
30
|
+
def ad_auth?
|
31
|
+
!parsed.no_ad_auth?
|
32
|
+
end
|
33
|
+
|
24
34
|
def command_uncached
|
25
35
|
if parsed.no_sudo?
|
26
36
|
::Avmtrf1::Executables.env.command(*openvpn_args)
|
@@ -29,8 +39,51 @@ module Avmtrf1
|
|
29
39
|
end
|
30
40
|
end
|
31
41
|
|
42
|
+
def config_builder_uncached
|
43
|
+
r = ::Avmtrf1::Openvpn::Config::Builder.new(parsed.ovpn_path)
|
44
|
+
r.simple_add_or_update('auth-user-pass', [credentials_path.to_path]) if ad_auth?
|
45
|
+
r
|
46
|
+
end
|
47
|
+
|
32
48
|
def openvpn_args
|
33
|
-
['openvpn', '--config',
|
49
|
+
['openvpn', '--config', ovpn_config_path]
|
50
|
+
end
|
51
|
+
|
52
|
+
def start_banner
|
53
|
+
infov 'Arquivo de configuração', parsed.ovpn_path
|
54
|
+
infov 'Linha de comando', ::Shellwords.join(command.args)
|
55
|
+
end
|
56
|
+
|
57
|
+
def on_temp_files
|
58
|
+
on_credentials_file do
|
59
|
+
on_config_file { yield }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def on_credentials_file(&block)
|
64
|
+
if ad_auth?
|
65
|
+
on_temp_file(:credentials_path, -> { credentials_content }, &block)
|
66
|
+
else
|
67
|
+
block.call
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def on_config_file(&block)
|
72
|
+
on_temp_file(:ovpn_config_path, -> { config_builder.data }, &block)
|
73
|
+
end
|
74
|
+
|
75
|
+
def on_temp_file(attr, content_proc)
|
76
|
+
::EacRubyUtils::Fs::Temp.on_file do |file|
|
77
|
+
file.write(content_proc.call)
|
78
|
+
send("#{attr}=", file)
|
79
|
+
yield
|
80
|
+
send("#{attr}=", nil)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def credentials_content
|
85
|
+
[::Avmtrf1.ad_user.username, ::Avmtrf1.ad_user.password]
|
86
|
+
.map { |v| "#{v}\n" }.join
|
34
87
|
end
|
35
88
|
end
|
36
89
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avmtrf1-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.33.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo H. Bogoni
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aranha-parsers
|
@@ -305,6 +305,12 @@ files:
|
|
305
305
|
- lib/avmtrf1/jira/entities.rb
|
306
306
|
- lib/avmtrf1/jira/entities/issue.rb
|
307
307
|
- lib/avmtrf1/jira/instance.rb
|
308
|
+
- lib/avmtrf1/openvpn/config/builder.rb
|
309
|
+
- lib/avmtrf1/openvpn/config/parser.rb
|
310
|
+
- lib/avmtrf1/openvpn/config/parser/builder.rb
|
311
|
+
- lib/avmtrf1/openvpn/config/parser/line.rb
|
312
|
+
- lib/avmtrf1/openvpn/config/parser/simple.rb
|
313
|
+
- lib/avmtrf1/openvpn/config/parser/tag.rb
|
308
314
|
- lib/avmtrf1/oracle.rb
|
309
315
|
- lib/avmtrf1/oracle/connection.rb
|
310
316
|
- lib/avmtrf1/oracle/connection/base.rb
|