avm-tools 0.114.1 → 0.114.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c54ac1c77f2c1db81cb6e2fa45e97ff5bd9ffad83054e33d8baeb94ff682dea
4
- data.tar.gz: 842806c80c5fa0fa93f1b6207f498831e833a94147ad9015e2717ebf9e3ec01b
3
+ metadata.gz: 7e2a7df849fd040b8e6fddad4e1c8507139926f0b587ceab796c1416fb9af873
4
+ data.tar.gz: 70eb055f94b37d37e05510563a654350137d0358283ad7d33a4d895110f1f2cc
5
5
  SHA512:
6
- metadata.gz: 7d026169d9ce0ef808fb38cad55a307eabdd023f7585dd42a6d61e6aa66ca1b7cb203a75aeaa25675e24c4267564dbc4d423dba6902be83d279b3234f6514459
7
- data.tar.gz: ebc64d8a3e11ab4eee57147b797b2f69fa7816be26d8621383822d1180f7f6ea8c4d9570d19ef21dbb844c25aa41ee3ef4cca0a48efcb30483114d092978810a
6
+ metadata.gz: 90be4e12df6cda16ffc88680a42a6d3dd118e96f97840cfb4a49b4418b76df1826485065ca069e3105d942136ed9273f03e9e15b340c4913abfeacae01ce1eba
7
+ data.tar.gz: 262a63d17a298911bef85e025b678779e8d7795e2376349128999fc50442275a0303bde419921e2799a3f8a9923366d3996c655ea032d909ca555f6b7d6892a5
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.114.1'
5
+ VERSION = '0.114.2'
6
6
  end
7
7
  end
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.add_dependency 'avm-eac_ubuntu_base0', '~> 0.2'
17
17
  s.add_dependency 'curb', '~> 0.9.10'
18
18
  s.add_dependency 'eac_fs', '~> 0.4'
19
+ s.add_dependency 'eac_rest', '~> 0.4'
19
20
  s.add_dependency 'eac_ruby_utils', '~> 0.68'
20
21
 
21
22
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.4'
@@ -10,11 +10,13 @@ module Avm
10
10
  class DataUnit < ::Avm::Data::Instance::Unit
11
11
  common_constructor :instance
12
12
 
13
+ EXPORT_PATH = '/backup/export'
13
14
  EXTENSION = '.tar'
15
+ IMPORT_PATH = '/backup/import.json'
14
16
 
15
17
  def do_dump(data_path)
16
18
  ::File.open(data_path, 'wb') do |file|
17
- file << URI.parse(export_url).read
19
+ file << export_request.response.body_data_or_raise
18
20
  end
19
21
  end
20
22
 
@@ -37,18 +39,12 @@ module Avm
37
39
  true
38
40
  end
39
41
 
40
- def export_url
41
- url('/backup/export')
42
+ def export_request
43
+ instance.rest_api.request(EXPORT_PATH)
42
44
  end
43
45
 
44
46
  def import_url
45
- url('/backup/import.json')
46
- end
47
-
48
- def url(path)
49
- uri = ::Addressable::URI.parse(instance.read_entry('web.url')) + path
50
- uri.query_values = { key: instance.read_entry('admin.api_key') }
51
- uri.to_s
47
+ instance.rest_api.build_service_url(IMPORT_PATH).to_s
52
48
  end
53
49
  end
54
50
  end
@@ -1,13 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'addressable/uri'
3
4
  require 'avm/eac_redmine_base0/data_unit'
4
5
  require 'avm/eac_redmine_base0/instances/docker_image'
6
+ require 'avm/eac_redmine_base0/rest_api'
5
7
  require 'avm/eac_webapp_base0/instance'
6
8
  require 'avm/eac_rails_base1/instance'
7
9
 
8
10
  module Avm
9
11
  module EacRedmineBase0
10
12
  class Instance < ::Avm::EacRailsBase1::Instance
13
+ enable_simple_cache
14
+
11
15
  FILES_UNITS = { files: 'files' }.freeze
12
16
 
13
17
  def docker_image_class
@@ -32,6 +36,22 @@ module Avm
32
36
  }
33
37
  )
34
38
  end
39
+
40
+ # @return [Addressable::URI]
41
+ def root_url
42
+ r = ::Addressable::URI.parse(read_entry(::Avm::Instances::EntryKeys::WEB_URL))
43
+ r.query_values = nil
44
+ r
45
+ end
46
+
47
+ private
48
+
49
+ # @return [Avm::EacRedmineBase0::RestApi]
50
+ def rest_api_uncached
51
+ url = root_url
52
+ url.query_values = { key: read_entry('api.key') }
53
+ ::Avm::EacRedmineBase0::RestApi.new(url)
54
+ end
35
55
  end
36
56
  end
37
57
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_rest/api'
5
+
6
+ module Avm
7
+ module EacRedmineBase0
8
+ class RestApi < ::EacRest::Api
9
+ end
10
+ end
11
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module EacRedmineBase0
5
- VERSION = '0.3.1'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+
5
+ require 'eac_rest/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'eac_rest'
9
+ s.version = EacRest::VERSION
10
+ s.authors = ['Eduardo H. Bogoni']
11
+ s.summary = 'A REST helper for Ruby.'
12
+
13
+ s.files = Dir['{lib}/**/*']
14
+
15
+ s.add_dependency 'eac_ruby_utils', '~> 0.70'
16
+
17
+ s.add_development_dependency 'eac_ruby_gem_support', '~> 0.3'
18
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_rest/request'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacRest
7
+ # Abstract methods
8
+ # * self.issue_get_url_suffix(provider_issue_id)
9
+ class Api
10
+ require_sub __FILE__, include_modules: true
11
+ common_constructor :root_url, :username, :password, default: [nil, nil]
12
+
13
+ def request(service_url_suffix, headers = {}, &body_data_proc)
14
+ r = ::EacRest::Request.new(build_service_url(service_url_suffix),
15
+ body_data_proc)
16
+ headers.each { |name, value| r = r.header(name, value) }
17
+ r = r.autenticate(username, password) if username.present?
18
+ r
19
+ end
20
+
21
+ def request_json(service_url_suffix, headers = {}, &body_data_proc)
22
+ request(service_url_suffix, headers.merge('Accept' => 'application/json')) do |body_data|
23
+ r = ::JSON.parse(body_data)
24
+ r = body_data_proc.call(r) if body_data_proc
25
+ r
26
+ end
27
+ end
28
+
29
+ # @return [Addressable::URI]
30
+ def build_service_url(suffix)
31
+ s = ::Addressable::URI.parse(suffix)
32
+ r = ::Addressable::URI.parse(root_url)
33
+ r.path += s.path
34
+ r.query_values = r.query_values(::Array).if_present([]) +
35
+ s.query_values(::Array).if_present([])
36
+ r
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRest
6
+ class Entity
7
+ enable_simple_cache
8
+ common_constructor :api, :data
9
+
10
+ class << self
11
+ def from_array_data(api, array_data, *args)
12
+ array_data.map { |item_data| new(api, item_data, *args) }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'curb'
4
+ require 'eac_rest/response'
5
+ require 'eac_ruby_utils/core_ext'
6
+ require 'ostruct'
7
+
8
+ module EacRest
9
+ class Request
10
+ COMMON_MODIFIERS = %w[auth body_data verb].freeze
11
+ HASH_MODIFIERS = %w[header].freeze
12
+ MODIFIERS = COMMON_MODIFIERS + HASH_MODIFIERS.map(&:pluralize)
13
+
14
+ enable_immutable
15
+ immutable_accessor(*COMMON_MODIFIERS, type: :common)
16
+ immutable_accessor(*HASH_MODIFIERS, type: :hash)
17
+
18
+ enable_listable
19
+ lists.add_symbol :verb, :get, :delete, :options, :post, :put
20
+
21
+ common_constructor :url, :body_data_proc, default: [nil]
22
+
23
+ def autenticate(username, password)
24
+ auth(::OpenStruct.new(username: username, password: password))
25
+ end
26
+
27
+ def immutable_constructor_args
28
+ [url, body_data_proc]
29
+ end
30
+
31
+ def response
32
+ ::EacRest::Response.new(build_curl, body_data_proc)
33
+ end
34
+
35
+ private
36
+
37
+ def build_curl
38
+ r = ::Curl::Easy.new(url)
39
+ MODIFIERS.each { |suffix| send("build_curl_#{suffix}", r) }
40
+ r
41
+ end
42
+
43
+ def build_curl_auth(curl)
44
+ auth.if_present do |a|
45
+ curl.http_auth_types = :basic
46
+ curl.username = a.username
47
+ curl.password = a.password
48
+ end
49
+ end
50
+
51
+ def build_curl_body_data(curl)
52
+ www_form_body_data_encoded.if_present { |v| curl.post_body = v }
53
+ end
54
+
55
+ def build_curl_headers(curl)
56
+ curl.headers.merge!(headers)
57
+ end
58
+
59
+ def build_curl_verb(curl)
60
+ curl.set(
61
+ :customrequest,
62
+ verb.if_present(VERB_GET) { |v| self.class.lists.verb.value_validate!(v) }.to_s.upcase
63
+ )
64
+ end
65
+
66
+ def www_form_body_data_encoded
67
+ body_data.if_present do |v|
68
+ v = v.map { |k, vv| [k, vv] } if v.is_a?(::Hash)
69
+ v = URI.encode_www_form(v) if v.is_a?(::Array)
70
+ v.to_s
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,72 @@
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 EacRest
8
+ class Response < ::StandardError
9
+ common_constructor :curl, :body_data_proc
10
+
11
+ def body_data
12
+ r = performed_curl.headers['Accept'].if_present(body_str) do |v|
13
+ method_name = "body_data_from_#{v.parameterize.underscore}"
14
+ respond_to?(method_name) ? send(method_name) : body_str
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
+ delegate :body_str, :headers, to: :performed_curl
27
+
28
+ def body_str_or_raise
29
+ raise_unless_200
30
+
31
+ body_str
32
+ end
33
+
34
+ def raise_unless_200
35
+ return nil if status == 200
36
+
37
+ raise self
38
+ end
39
+
40
+ def status
41
+ performed_curl.status.to_i
42
+ end
43
+
44
+ delegate :url, to: :curl
45
+
46
+ def to_s
47
+ "URL: #{url}\nStatus: #{status}\nBody:\n\n#{body_str}"
48
+ end
49
+
50
+ private
51
+
52
+ def body_data_from_application_json
53
+ ::JSON.parse(body_str)
54
+ end
55
+
56
+ def body_data_from_application_xml
57
+ Hash.from_xml(body_str)
58
+ end
59
+
60
+ def perform
61
+ @perform ||= begin
62
+ curl.perform || raise("CURL perform failed for #{url}")
63
+ true
64
+ end
65
+ end
66
+
67
+ def performed_curl
68
+ perform
69
+ curl
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRest
4
+ VERSION = '0.4.0'
5
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRest
6
+ require_sub __FILE__
7
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ ::EacRubyUtils::Rspec.default_setup.describe_rubocop
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/rspec/default_setup'
4
+ ::EacRubyUtils::Rspec.default_setup_create(::File.expand_path('..', __dir__))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.114.1
4
+ version: 0.114.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-25 00:00:00.000000000 Z
11
+ date: 2022-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.3'
75
+ version: '0.4'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.3'
82
+ version: '0.4'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: avm-eac_ruby_base1
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -510,6 +510,7 @@ files:
510
510
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/deploy.rb
511
511
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instance.rb
512
512
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/docker_image.rb
513
+ - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/rest_api.rb
513
514
  - sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb
514
515
  - sub/avm-eac_redmine_base0/spec/rubocop_spec.rb
515
516
  - sub/avm-eac_redmine_base0/spec/spec_helper.rb
@@ -1124,6 +1125,16 @@ files:
1124
1125
  - sub/eac_git/vendor/git-subrepo/test/setup
1125
1126
  - sub/eac_git/vendor/git-subrepo/test/status.t
1126
1127
  - sub/eac_git/vendor/git-subrepo/test/submodule.t
1128
+ - sub/eac_rest/Gemfile
1129
+ - sub/eac_rest/eac_rest.gemspec
1130
+ - sub/eac_rest/lib/eac_rest.rb
1131
+ - sub/eac_rest/lib/eac_rest/api.rb
1132
+ - sub/eac_rest/lib/eac_rest/entity.rb
1133
+ - sub/eac_rest/lib/eac_rest/request.rb
1134
+ - sub/eac_rest/lib/eac_rest/response.rb
1135
+ - sub/eac_rest/lib/eac_rest/version.rb
1136
+ - sub/eac_rest/spec/rubocop_spec.rb
1137
+ - sub/eac_rest/spec/spec_helper.rb
1127
1138
  - sub/eac_ruby_base0/Gemfile
1128
1139
  - sub/eac_ruby_base0/eac_ruby_base0.gemspec
1129
1140
  - sub/eac_ruby_base0/lib/eac_ruby_base0.rb