smart_proxy_acd 0.3.0 → 0.4.0

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: 881bee215ecdb92ddd19b7b60397274f9e5eb72911660a289d235b5ab09aa8bc
4
- data.tar.gz: 25abeb5af5ca858c7a18fbce66b4727a8bfe7d8b120089a7ecfd370792a75931
3
+ metadata.gz: 183250a25f2479402b6eb73acd841ec985da00ebe17cb4b836df7b1e3d37ae48
4
+ data.tar.gz: d9b0c52df1fad8c9a998930252617eb971a8319a3f53fdd0e910b17bcef8b439
5
5
  SHA512:
6
- metadata.gz: 05a4fa40b1df875b7526b584b2ac5a2a544abd3d2248aa04dc31bc8b4592f094163929e6790d3abd826f5d7c9d0401a2add3476b5dc813aae027e5cd0354ffa1
7
- data.tar.gz: ae1ad0260d9c7c95c3ae78be4bcc05e68a679ff6c3d453311598dcf2c51c4428c8e03056b2293ae4fcc85480566da7e48a5576e8473783f5816668b388d05f0c
6
+ metadata.gz: 88664606e79721dc883ee637bf749f54d6bfd3481ba42366abb4c0725a727fad4ec94d1029b25f0142b889b6bcdbde07f6e1142f419a939e8b3d4ae9ccddc5fa
7
+ data.tar.gz: 23cc133598f5d3888e0298bf5b2c3786d6a429ff6ba3625d673efdc0f61f338e64d749811c8dcbab8ff0cce544d7ec5672c813dbb38492cf2293f16d59c30f33
data/README.md CHANGED
@@ -14,7 +14,6 @@ This plug-in adds support for [Application Centric Deployment](https://github.co
14
14
 
15
15
  We expect your proxy to also have
16
16
  [smart_proxy_dynflow](https://github.com/theforeman/smart_proxy_dynflow)
17
- and [foreman-tasks-core](https://github.com/theforeman/foreman-tasks) as
18
17
  a gem requirement.
19
18
 
20
19
  ### Get the code
@@ -13,6 +13,8 @@ module Proxy
13
13
  require 'smart_proxy_acd/acd_task_launcher'
14
14
  end
15
15
 
16
+ default_settings :timeout => 60
17
+
16
18
  load_dependency_injection_wirings do |_container_instance, _settings|
17
19
  Proxy::Dynflow::TaskLauncherRegistry.register('acd', AcdTaskLauncher)
18
20
  end
@@ -5,6 +5,17 @@ module Proxy
5
5
  extend ::Proxy::Log
6
6
 
7
7
  class << self
8
+ def plugin_settings
9
+ # rubocop:disable ClassVars
10
+ @@settings ||= OpenStruct.new(read_settings)
11
+ # rubocop:enable ClassVars
12
+ end
13
+
14
+ def read_settings
15
+ ::Proxy::Acd::Plugin.default_settings.merge(
16
+ YAML.load_file(File.join(::Proxy::SETTINGS.settings_directory, ::Proxy::Acd::Plugin.settings_file))
17
+ )
18
+ end
8
19
  end
9
20
  end
10
21
  end
@@ -1,8 +1,10 @@
1
+ require 'smart_proxy_dynflow/runner/base'
1
2
  require 'smart_proxy_dynflow/runner/command_runner'
2
3
  require 'tempfile'
3
4
  require 'rest-client'
4
5
  require 'tmpdir'
5
6
  require 'socket'
7
+ require 'proxy/request'
6
8
 
7
9
  # rubocop:disable ClassLength
8
10
 
@@ -12,42 +14,6 @@ module Proxy
12
14
  class AcdRunner < Proxy::Dynflow::Runner::CommandRunner
13
15
  DEFAULT_REFRESH_INTERVAL = 1
14
16
 
15
- class << self
16
- def parse_dynflow_settings(path)
17
- return @dynflow_settings if defined? @dynflow_settings
18
- if File.exist?(path)
19
- @dynflow_settings = {}
20
- YAML.load_file(path).each do |key, value|
21
- @dynflow_settings[key.to_s] = value
22
- end
23
- end
24
- @dynflow_settings
25
- end
26
-
27
- def parse_ssl_options
28
- return @ssl_options if defined? @ssl_options
29
-
30
- @ssl_options = {}
31
- return @ssl_options unless URI.parse(@dynflow_settings['foreman_url']).scheme == 'https'
32
-
33
- @ssl_options[:verify_ssl] = OpenSSL::SSL::VERIFY_PEER
34
-
35
- private_key_file = @dynflow_settings['foreman_ssl_key'] || @dynflow_settings['ssl_private_key']
36
- if private_key_file
37
- private_key = File.read(private_key_file)
38
- @ssl_options[:ssl_client_key] = OpenSSL::PKey::RSA.new(private_key)
39
- end
40
- certificate_file = @dynflow_settings['foreman_ssl_cert'] || @dynflow_settings['ssl_certificate']
41
- if certificate_file
42
- certificate = File.read(certificate_file)
43
- @ssl_options[:ssl_client_cert] = OpenSSL::X509::Certificate.new(certificate)
44
- end
45
- ca_file = @dynflow_settings['foreman_ssl_ca'] || @dynflow_settings['ssl_ca_file']
46
- @ssl_options[:ssl_ca_file] = ca_file if ca_file
47
- @ssl_options
48
- end
49
- end
50
-
51
17
  def initialize(options, suspended_action:)
52
18
  super(options, :suspended_action => suspended_action)
53
19
  @options = options
@@ -55,19 +21,21 @@ module Proxy
55
21
 
56
22
  def get_playbook(playbook_id)
57
23
  logger.debug("Get playbook with id #{playbook_id}")
58
- response = playbook_resource(playbook_id).get
24
+ response = playbook_resource(playbook_id)
59
25
  if response.code.to_s != '200'
60
26
  raise "Failed performing callback to Foreman server: #{response.code} #{response.body}"
61
27
  end
62
28
  tmp_file = Tempfile.new.path
63
- File.write(tmp_file, response)
29
+ File.write(tmp_file, response.body)
64
30
  @playbook_tmp_base64_file = tmp_file
65
31
  end
66
32
 
67
33
  def playbook_resource(playbook_id)
68
- dynflow_settings = self.class.parse_dynflow_settings('/etc/foreman-proxy/settings.yml')
69
- playbook_url = dynflow_settings['foreman_url'] + "/acd/api/v2/ansible_playbooks/#{playbook_id}/grab"
70
- @resource ||= RestClient::Resource.new(playbook_url, self.class.parse_ssl_options)
34
+ playbook_download_path = "/acd/api/v2/ansible_playbooks/#{playbook_id}/grab"
35
+ foreman_request = Proxy::HttpRequest::ForemanRequest.new
36
+ req = foreman_request.request_factory.create_get(playbook_download_path)
37
+ foreman_request.http.read_timeout = Proxy::Acd::Plugin.settings.timeout
38
+ foreman_request.send_request(req)
71
39
  end
72
40
 
73
41
  def store_playbook
@@ -133,6 +101,12 @@ module Proxy
133
101
  complete_inventory = YAML.safe_load(@acd_job['inventory'])
134
102
  my_inventory = complete_inventory[proxy_hostname]
135
103
 
104
+ my_inventory['all']['children'].each_value do |group|
105
+ group['hosts'].each_value do |host_vars|
106
+ host_vars['ansible_ssh_private_key_file'] ||= Proxy::RemoteExecution::Ssh::Plugin.settings[:ssh_identity_key_file]
107
+ end
108
+ end
109
+
136
110
  tmp_inventory_file = Tempfile.new('acd_inventory')
137
111
  tmp_inventory_file << my_inventory.to_yaml
138
112
  tmp_inventory_file << "\n"
@@ -1,3 +1,5 @@
1
+ require 'smart_proxy_dynflow/task_launcher'
2
+
1
3
  module Proxy
2
4
  module Acd
3
5
  # Implements the TaskLauncher::Batch for Acd
@@ -1,5 +1,5 @@
1
1
  module Proxy
2
2
  module Acd
3
- VERSION = '0.3.0'.freeze
3
+ VERSION = '0.4.0'.freeze
4
4
  end
5
5
  end
@@ -1,2 +1,4 @@
1
1
  ---
2
2
  :enabled: true
3
+ # The time we wait till the request to download the ansible playbook should be answered by the Foreman, in seconds.
4
+ :timeout: 60
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_acd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Bucher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-16 00:00:00.000000000 Z
11
+ date: 2022-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop