smart_proxy_pulp 1.5.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -21
- data/lib/smart_proxy_pulp.rb +1 -3
- data/lib/smart_proxy_pulp_plugin/pulpcore_api.rb +19 -0
- data/lib/smart_proxy_pulp_plugin/{pulp3_client.rb → pulpcore_client.rb} +8 -5
- data/lib/smart_proxy_pulp_plugin/pulpcore_http_config.ru +5 -0
- data/lib/smart_proxy_pulp_plugin/pulpcore_plugin.rb +28 -0
- data/lib/smart_proxy_pulp_plugin/validators.rb +15 -0
- data/lib/smart_proxy_pulp_plugin/version.rb +1 -1
- data/settings.d/pulpcore.yml.example +8 -0
- metadata +20 -30
- data/lib/smart_proxy_pulp_plugin/disk_usage.rb +0 -120
- data/lib/smart_proxy_pulp_plugin/pulp3_api.rb +0 -38
- data/lib/smart_proxy_pulp_plugin/pulp3_http_config.ru +0 -5
- data/lib/smart_proxy_pulp_plugin/pulp3_plugin.rb +0 -25
- data/lib/smart_proxy_pulp_plugin/pulp_api.rb +0 -41
- data/lib/smart_proxy_pulp_plugin/pulp_client.rb +0 -36
- data/lib/smart_proxy_pulp_plugin/pulp_http_config.ru +0 -5
- data/lib/smart_proxy_pulp_plugin/pulp_node_http_config.ru +0 -5
- data/lib/smart_proxy_pulp_plugin/pulp_node_plugin.rb +0 -14
- data/lib/smart_proxy_pulp_plugin/pulp_plugin.rb +0 -15
- data/lib/smart_proxy_pulp_plugin/settings.rb +0 -12
- data/lib/smart_proxy_pulp_plugin/validators/pulp_url_validator.rb +0 -12
- data/settings.d/pulp.yml.example +0 -8
- data/settings.d/pulp3.yml.example +0 -7
- data/settings.d/pulpnode.yml.example +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 530d39840a6bb5adb12546ec4c3e4fa50616e616ebadef98243076d9bd6d6692
|
4
|
+
data.tar.gz: ba3525a72ef1b4367519147166d71b03cc076b2ac7f101a7b0d31886f2a8529e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb0ae49fe75c6a216182e430d9eff93bb509482fd84b48b36a39591ad2a2440824f964b09f4976ce34c14607fe782c9d9ecd805f19e17630d6d3ac248eac7361
|
7
|
+
data.tar.gz: 1bc3741848e30b49bf2cfed07bdd81c68b37a59db888e2ace7a203a20ddbf890a79b055c5982fd088bb121fd4d33325c1771341c6cd91eab9976d0135b58d7c6
|
data/Gemfile
CHANGED
@@ -5,24 +5,5 @@ group :development do
|
|
5
5
|
gem 'smart_proxy', :git => 'https://github.com/theforeman/smart-proxy', :branch => 'develop'
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
if RUBY_VERSION < '2.1'
|
11
|
-
gem 'public_suffix', '< 3'
|
12
|
-
else
|
13
|
-
gem 'public_suffix'
|
14
|
-
end
|
15
|
-
if RUBY_VERSION < '2.2'
|
16
|
-
gem 'rack-test', '< 0.8'
|
17
|
-
else
|
18
|
-
gem 'rack-test'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
if RUBY_VERSION < '2.2'
|
23
|
-
gem 'sinatra', '< 2'
|
24
|
-
gem 'rack', '>= 1.1', '< 2.0.0'
|
25
|
-
else
|
26
|
-
gem 'sinatra'
|
27
|
-
gem 'rack', '>= 1.1'
|
28
|
-
end
|
8
|
+
gem 'sinatra'
|
9
|
+
gem 'rack', '>= 1.1'
|
data/lib/smart_proxy_pulp.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'smart_proxy_pulp_plugin/pulpcore_client'
|
3
|
+
|
4
|
+
module PulpProxy
|
5
|
+
class PulpcoreApi < Sinatra::Base
|
6
|
+
helpers ::Proxy::Helpers
|
7
|
+
|
8
|
+
get '/status' do
|
9
|
+
content_type :json
|
10
|
+
begin
|
11
|
+
result = PulpcoreClient.get("/pulp/api/v3/status/")
|
12
|
+
return result.body if result.is_a?(Net::HTTPSuccess)
|
13
|
+
log_halt result.code, "Pulp server at #{PulpcoreClient.pulp_url} returned an error: '#{result.message}'"
|
14
|
+
rescue SocketError, Errno::ECONNREFUSED => e
|
15
|
+
log_halt 503, "Communication error with '#{URI.parse(PulpcoreClient.pulp_url).host}': #{e.message}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,20 +1,19 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'net/https'
|
3
3
|
require 'uri'
|
4
|
-
require 'smart_proxy_pulp_plugin/settings'
|
5
4
|
require 'proxy/log'
|
6
5
|
|
7
6
|
module PulpProxy
|
8
|
-
class
|
7
|
+
class PulpcoreClient
|
9
8
|
def self.get(path)
|
10
|
-
uri = URI.parse(
|
9
|
+
uri = URI.parse(pulp_url)
|
11
10
|
req = Net::HTTP::Get.new(URI.join(uri.to_s.chomp('/') + '/', path))
|
12
11
|
req.add_field('Accept', 'application/json')
|
13
12
|
self.http.request(req)
|
14
13
|
end
|
15
14
|
|
16
15
|
def self.capabilities
|
17
|
-
body = JSON.parse(get("api/v3/status/").body)
|
16
|
+
body = JSON.parse(get("/pulp/api/v3/status/").body)
|
18
17
|
body['versions'].map{|item| item['component'] }
|
19
18
|
rescue => e
|
20
19
|
logger.error("Could not fetch capabilities: #{e.message}")
|
@@ -26,10 +25,14 @@ module PulpProxy
|
|
26
25
|
end
|
27
26
|
|
28
27
|
def self.http
|
29
|
-
uri = URI.parse(
|
28
|
+
uri = URI.parse(pulp_url)
|
30
29
|
http = Net::HTTP.new(uri.host, uri.port)
|
31
30
|
http.use_ssl = uri.scheme == 'https'
|
32
31
|
http
|
33
32
|
end
|
33
|
+
|
34
|
+
def self.pulp_url
|
35
|
+
::PulpProxy::PulpcorePlugin.settings.pulp_url.to_s
|
36
|
+
end
|
34
37
|
end
|
35
38
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'smart_proxy_pulp_plugin/validators'
|
2
|
+
|
3
|
+
module PulpProxy
|
4
|
+
class PulpcorePlugin < ::Proxy::Plugin
|
5
|
+
plugin "pulpcore", ::PulpProxy::VERSION
|
6
|
+
default_settings :pulp_url => 'https://localhost',
|
7
|
+
:content_app_url => 'https://localhost:24816/',
|
8
|
+
:mirror => false,
|
9
|
+
:client_authentication => ['password', 'client_certificate']
|
10
|
+
|
11
|
+
AUTH_TYPES = ['password', 'client_certificate', 'client_certificate_admin_only'].freeze
|
12
|
+
|
13
|
+
load_validators include: ::PulpProxy::Validators::Include
|
14
|
+
validate :pulp_url, :url => true
|
15
|
+
validate :content_app_url, :url => true
|
16
|
+
validate :client_authentication, :include => AUTH_TYPES
|
17
|
+
|
18
|
+
expose_setting :pulp_url
|
19
|
+
expose_setting :mirror
|
20
|
+
expose_setting :content_app_url
|
21
|
+
expose_setting :username
|
22
|
+
expose_setting :password
|
23
|
+
expose_setting :client_authentication
|
24
|
+
|
25
|
+
capability -> { PulpcoreClient.capabilities }
|
26
|
+
rackup_path File.expand_path('pulpcore_http_config.ru', __dir__)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PulpProxy
|
2
|
+
module Validators
|
3
|
+
class Include < ::Proxy::PluginValidators::Base
|
4
|
+
def validate!(settings)
|
5
|
+
setting_value = settings[@setting_name]
|
6
|
+
|
7
|
+
unless (setting_value - @params).empty?
|
8
|
+
raise ::Proxy::Error::ConfigurationError, "Parameter '#{@setting_name}' is expected to be one or more of #{@params}"
|
9
|
+
else
|
10
|
+
true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_proxy_pulp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitri Dolguikh
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mocha
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rack-test
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '13'
|
76
76
|
type: :development
|
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: '
|
82
|
+
version: '13'
|
83
83
|
description: " Basic Pulp support for Foreman Smart-Proxy\n"
|
84
84
|
email:
|
85
85
|
- dmitri@redhat.com
|
@@ -91,44 +91,34 @@ files:
|
|
91
91
|
- LICENSE
|
92
92
|
- bundler.d/pulp.rb
|
93
93
|
- lib/smart_proxy_pulp.rb
|
94
|
-
- lib/smart_proxy_pulp_plugin/
|
95
|
-
- lib/smart_proxy_pulp_plugin/
|
96
|
-
- lib/smart_proxy_pulp_plugin/
|
97
|
-
- lib/smart_proxy_pulp_plugin/
|
98
|
-
- lib/smart_proxy_pulp_plugin/
|
99
|
-
- lib/smart_proxy_pulp_plugin/pulp_api.rb
|
100
|
-
- lib/smart_proxy_pulp_plugin/pulp_client.rb
|
101
|
-
- lib/smart_proxy_pulp_plugin/pulp_http_config.ru
|
102
|
-
- lib/smart_proxy_pulp_plugin/pulp_node_http_config.ru
|
103
|
-
- lib/smart_proxy_pulp_plugin/pulp_node_plugin.rb
|
104
|
-
- lib/smart_proxy_pulp_plugin/pulp_plugin.rb
|
105
|
-
- lib/smart_proxy_pulp_plugin/settings.rb
|
106
|
-
- lib/smart_proxy_pulp_plugin/validators/pulp_url_validator.rb
|
94
|
+
- lib/smart_proxy_pulp_plugin/pulpcore_api.rb
|
95
|
+
- lib/smart_proxy_pulp_plugin/pulpcore_client.rb
|
96
|
+
- lib/smart_proxy_pulp_plugin/pulpcore_http_config.ru
|
97
|
+
- lib/smart_proxy_pulp_plugin/pulpcore_plugin.rb
|
98
|
+
- lib/smart_proxy_pulp_plugin/validators.rb
|
107
99
|
- lib/smart_proxy_pulp_plugin/version.rb
|
108
|
-
- settings.d/
|
109
|
-
- settings.d/pulp3.yml.example
|
110
|
-
- settings.d/pulpnode.yml.example
|
100
|
+
- settings.d/pulpcore.yml.example
|
111
101
|
homepage: https://github.com/theforeman/smart-proxy-pulp-plugin
|
112
102
|
licenses:
|
113
103
|
- GPL-3.0
|
114
104
|
metadata: {}
|
115
|
-
post_install_message:
|
105
|
+
post_install_message:
|
116
106
|
rdoc_options: []
|
117
107
|
require_paths:
|
118
108
|
- lib
|
119
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
110
|
requirements:
|
121
|
-
- - "
|
111
|
+
- - "~>"
|
122
112
|
- !ruby/object:Gem::Version
|
123
|
-
version: '
|
113
|
+
version: '2.5'
|
124
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
115
|
requirements:
|
126
116
|
- - ">="
|
127
117
|
- !ruby/object:Gem::Version
|
128
118
|
version: '0'
|
129
119
|
requirements: []
|
130
|
-
rubygems_version: 3.
|
131
|
-
signing_key:
|
120
|
+
rubygems_version: 3.1.6
|
121
|
+
signing_key:
|
132
122
|
specification_version: 4
|
133
123
|
summary: Basic Pulp support for Foreman Smart-Proxy
|
134
124
|
test_files: []
|
@@ -1,120 +0,0 @@
|
|
1
|
-
module PulpProxy
|
2
|
-
class DiskUsage
|
3
|
-
include ::Proxy::Util
|
4
|
-
include ::Proxy::Log
|
5
|
-
SIZE = { :byte => 1, :kilobyte => 1_024, :megabyte => 1_048_576, :gigabyte => 1_073_741_824, :terabyte => 1_099_511_627_776 }
|
6
|
-
|
7
|
-
attr_reader :path, :stat, :size
|
8
|
-
|
9
|
-
def initialize(opts ={})
|
10
|
-
raise(::Proxy::Error::ConfigurationError, 'Unable to continue - must provide a path.') if opts[:path].nil?
|
11
|
-
@paths_hash = validate_path(path_hash(opts[:path]))
|
12
|
-
@path = @paths_hash.values
|
13
|
-
@size_format = opts[:size] || :kilobyte
|
14
|
-
@size = SIZE[@size_format]
|
15
|
-
@stat = {}
|
16
|
-
find_df
|
17
|
-
get_stat
|
18
|
-
end
|
19
|
-
|
20
|
-
def to_json
|
21
|
-
stat.to_json
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
attr_reader :command_path
|
27
|
-
|
28
|
-
def find_df
|
29
|
-
@command_path = which('df') || raise(::Proxy::Error::ConfigurationError, 'df command was not found unable to retrieve usage information.')
|
30
|
-
end
|
31
|
-
|
32
|
-
def command
|
33
|
-
[command_path, "-P", "-B", "#{size}", *path]
|
34
|
-
end
|
35
|
-
|
36
|
-
# Inspired and copied from Facter
|
37
|
-
# @ https://github.com/puppetlabs/facter/blob/2.x/lib/facter/core/execution/base.rb
|
38
|
-
# @TODO: Refactor http://projects.theforeman.org/issues/15235 when removing support for 1.8.7
|
39
|
-
def with_env(values)
|
40
|
-
old = {}
|
41
|
-
values.each do |var, value|
|
42
|
-
# save the old value if it exists
|
43
|
-
if old_val = ENV[var]
|
44
|
-
old[var] = old_val
|
45
|
-
end
|
46
|
-
# set the new (temporary) value for the environment variable
|
47
|
-
ENV[var] = value
|
48
|
-
end
|
49
|
-
# execute the caller's block, capture the return value
|
50
|
-
rv = yield
|
51
|
-
# use an ensure block to make absolutely sure we restore the variables
|
52
|
-
ensure
|
53
|
-
# restore the old values
|
54
|
-
values.each do |var, value|
|
55
|
-
if old.include?(var)
|
56
|
-
ENV[var] = old[var]
|
57
|
-
else
|
58
|
-
# if there was no old value, delete the key from the current environment variables hash
|
59
|
-
ENV.delete(var)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
# return the captured return value
|
63
|
-
rv
|
64
|
-
end
|
65
|
-
|
66
|
-
def get_stat
|
67
|
-
with_env 'LC_ALL' => 'C' do
|
68
|
-
raw = Open3::popen3(*command) do |stdin, stdout, stderr, thread|
|
69
|
-
unless stderr.read.empty?
|
70
|
-
error_line = stderr.read
|
71
|
-
logger.error "[#{command_path}] #{error_line}"
|
72
|
-
raise(::Proxy::Error::ConfigurationError, "#{command_path} raised an error: #{error_line}")
|
73
|
-
end
|
74
|
-
stdout.read.split("\n")
|
75
|
-
end
|
76
|
-
|
77
|
-
logger.debug "[#{command_path}] #{raw.to_s}"
|
78
|
-
|
79
|
-
titles = normalize_titles(raw)
|
80
|
-
raw.each_with_index do |line, index|
|
81
|
-
mount_path = path[index]
|
82
|
-
values = normalize_values(line.split)
|
83
|
-
@stat[hash_key_for(mount_path)] = Hash[titles.zip(values)].merge({:path => mount_path, :size => @size_format})
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def path_hash(path)
|
89
|
-
path.is_a?(Hash) ? path : Hash[path, path]
|
90
|
-
end
|
91
|
-
|
92
|
-
def hash_key_for(path)
|
93
|
-
@paths_hash.select { |k,v| v == path}.first[0]
|
94
|
-
end
|
95
|
-
|
96
|
-
|
97
|
-
def normalize_titles(raw)
|
98
|
-
replacers = {"mounted on" => :mounted, "capacity" => :percent, "1024-blocks" => :"1k-blocks" }
|
99
|
-
raw.shift.downcase.gsub(/(capacity|mounted on|1024-blocks)/) { |m| replacers.fetch(m,m)}.split.map(&:to_sym)
|
100
|
-
end
|
101
|
-
|
102
|
-
def normalize_values(values)
|
103
|
-
values.each_with_index do |value, index|
|
104
|
-
is_int = Integer(value) rescue false
|
105
|
-
values[index] = is_int if is_int
|
106
|
-
end
|
107
|
-
values
|
108
|
-
end
|
109
|
-
|
110
|
-
def validate_path(path_hash)
|
111
|
-
path_hash.each do |key, value|
|
112
|
-
unless File.readable?(value)
|
113
|
-
logger.warn "File at #{value} defined in #{key} parameter doesn't exist or is unreadable"
|
114
|
-
path_hash.delete(key)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
path_hash
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'sinatra'
|
2
|
-
require 'smart_proxy_pulp_plugin/pulp3_client'
|
3
|
-
require 'smart_proxy_pulp_plugin/disk_usage'
|
4
|
-
|
5
|
-
module PulpProxy
|
6
|
-
class Pulp3Api < Sinatra::Base
|
7
|
-
helpers ::Proxy::Helpers
|
8
|
-
|
9
|
-
get '/status' do
|
10
|
-
content_type :json
|
11
|
-
begin
|
12
|
-
result = Pulp3Client.get("api/v3/status/")
|
13
|
-
return result.body if result.is_a?(Net::HTTPSuccess)
|
14
|
-
log_halt result.code, "Pulp server at #{::PulpProxy::Settings.settings.pulp_url} returned an error: '#{result.message}'"
|
15
|
-
rescue SocketError, Errno::ECONNREFUSED => e
|
16
|
-
log_halt 503, "Communication error with '#{URI.parse(::PulpProxy::Settings.settings.pulp_url.to_s).host}': #{e.message}"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
get '/status/disk_usage' do
|
21
|
-
content_type :json
|
22
|
-
if params[:size]
|
23
|
-
size = params[:size] ? params[:size].to_sym : nil
|
24
|
-
log_halt 400, "size parameter must be of: #{DiskUsage::SIZE.keys.join(',')}" unless DiskUsage::SIZE.include?(size)
|
25
|
-
else
|
26
|
-
size = :byte
|
27
|
-
end
|
28
|
-
|
29
|
-
monitor_dirs = Hash[::PulpProxy::Pulp3Plugin.settings.marshal_dump.select { |key, _| key == :pulp_dir || key == :pulp_content_dir }]
|
30
|
-
begin
|
31
|
-
pulp_disk = DiskUsage.new({:path => monitor_dirs, :size => size.to_sym})
|
32
|
-
pulp_disk.to_json
|
33
|
-
rescue ::Proxy::Error::ConfigurationError
|
34
|
-
log_halt 500, 'Could not find df command to evaluate disk space'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'smart_proxy_pulp_plugin/validators/pulp_url_validator'
|
2
|
-
|
3
|
-
module PulpProxy
|
4
|
-
class Pulp3Plugin < ::Proxy::Plugin
|
5
|
-
plugin "pulp3", ::PulpProxy::VERSION
|
6
|
-
default_settings :pulp_url => 'https://localhost/pulp/',
|
7
|
-
:content_app_url => 'https://localhost:24816/',
|
8
|
-
:pulp_dir => '/var/lib/pulp',
|
9
|
-
:pulp_content_dir => '/var/lib/pulp/content',
|
10
|
-
:mirror => false
|
11
|
-
|
12
|
-
load_validators :url => ::PulpProxy::Validators::PulpUrlValidator
|
13
|
-
validate :pulp_url, :url => true
|
14
|
-
validate :content_app_url, :url => true
|
15
|
-
|
16
|
-
expose_setting :pulp_url
|
17
|
-
expose_setting :mirror
|
18
|
-
expose_setting :content_app_url
|
19
|
-
capability( lambda do ||
|
20
|
-
Pulp3Client.capabilities
|
21
|
-
end)
|
22
|
-
http_rackup_path File.expand_path("pulp3_http_config.ru", File.expand_path("../", __FILE__))
|
23
|
-
https_rackup_path File.expand_path("pulp3_http_config.ru", File.expand_path("../", __FILE__))
|
24
|
-
end
|
25
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'sinatra'
|
2
|
-
require 'smart_proxy_pulp_plugin/pulp_client'
|
3
|
-
require 'smart_proxy_pulp_plugin/disk_usage'
|
4
|
-
require 'smart_proxy_pulp_plugin/settings'
|
5
|
-
|
6
|
-
module PulpProxy
|
7
|
-
class Api < Sinatra::Base
|
8
|
-
helpers ::Proxy::Helpers
|
9
|
-
authorize_with_trusted_hosts
|
10
|
-
authorize_with_ssl_client
|
11
|
-
|
12
|
-
get "/status" do
|
13
|
-
content_type :json
|
14
|
-
begin
|
15
|
-
result = PulpClient.get("api/v2/status/")
|
16
|
-
return result.body if result.is_a?(Net::HTTPSuccess)
|
17
|
-
log_halt result.code, "Pulp server at #{::PulpProxy::Settings.settings.pulp_url} returned an error: '#{result.message}'"
|
18
|
-
rescue Errno::ECONNREFUSED => e
|
19
|
-
log_halt 503, "Pulp server at #{::PulpProxy::Settings.settings.pulp_url} is not responding"
|
20
|
-
rescue SocketError => e
|
21
|
-
log_halt 503, "Pulp server '#{URI.parse(::PulpProxy::Settings.settings.pulp_url.to_s).host}' is unknown"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
get '/status/disk_usage' do
|
26
|
-
size = (params[:size] && DiskUsage::SIZE.keys.include?(params[:size].to_sym)) ? params[:size].to_sym : :kilobyte
|
27
|
-
monitor_dirs = Hash[::PulpProxy::Settings.settings.marshal_dump.select { |key, _| key == :pulp_dir || key == :pulp_content_dir || key == :mongodb_dir }]
|
28
|
-
begin
|
29
|
-
pulp_disk = DiskUsage.new({:path => monitor_dirs, :size => size})
|
30
|
-
pulp_disk.to_json
|
31
|
-
rescue ::Proxy::Error::ConfigurationError
|
32
|
-
log_halt 500, 'Could not find df command to evaluate disk space'
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
get '/status/puppet' do
|
37
|
-
content_type :json
|
38
|
-
{:puppet_content_dir => ::PulpProxy::Settings.settings.puppet_content_dir}.to_json
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'net/https'
|
3
|
-
require 'uri'
|
4
|
-
require 'smart_proxy_pulp_plugin/settings'
|
5
|
-
|
6
|
-
module PulpProxy
|
7
|
-
class PulpClient
|
8
|
-
def self.get(path)
|
9
|
-
uri = URI.parse(::PulpProxy::Settings.settings.pulp_url.to_s)
|
10
|
-
req = Net::HTTP::Get.new(URI.join(uri.to_s.chomp('/') + '/', path))
|
11
|
-
req.add_field('Accept', 'application/json')
|
12
|
-
req.content_type = 'application/json'
|
13
|
-
response = self.http.request(req)
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.http
|
17
|
-
uri = URI.parse(::PulpProxy::Settings.settings.pulp_url.to_s)
|
18
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
19
|
-
http.use_ssl = uri.scheme == 'https'
|
20
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
21
|
-
|
22
|
-
if http.use_ssl?
|
23
|
-
if Proxy::SETTINGS.ssl_ca_file && !Proxy::SETTINGS.ssl_ca_file.to_s.empty?
|
24
|
-
http.ca_file = Proxy::SETTINGS.ssl_ca_file
|
25
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
26
|
-
end
|
27
|
-
|
28
|
-
if Proxy::SETTINGS.ssl_certificate && !Proxy::SETTINGS.ssl_certificate.to_s.empty? && Proxy::SETTINGS.ssl_private_key && !Proxy::SETTINGS.ssl_private_key.to_s.empty?
|
29
|
-
http.cert = OpenSSL::X509::Certificate.new(File.read(Proxy::SETTINGS.ssl_certificate))
|
30
|
-
http.key = OpenSSL::PKey::RSA.new(File.read(Proxy::SETTINGS.ssl_private_key), nil)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
http
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module PulpNodeProxy
|
2
|
-
class Plugin < ::Proxy::Plugin
|
3
|
-
plugin "pulpnode", ::PulpProxy::VERSION
|
4
|
-
default_settings :pulp_url => 'https://localhost/pulp',
|
5
|
-
:pulp_dir => '/var/lib/pulp',
|
6
|
-
:pulp_content_dir => '/var/lib/pulp/content',
|
7
|
-
:puppet_content_dir => '/etc/puppet/environments',
|
8
|
-
:mongodb_dir => '/var/lib/mongodb'
|
9
|
-
|
10
|
-
expose_setting :pulp_url
|
11
|
-
http_rackup_path File.expand_path("pulp_node_http_config.ru", File.expand_path("../", __FILE__))
|
12
|
-
https_rackup_path File.expand_path("pulp_node_http_config.ru", File.expand_path("../", __FILE__))
|
13
|
-
end
|
14
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module PulpProxy
|
2
|
-
class Plugin < ::Proxy::Plugin
|
3
|
-
plugin "pulp", ::PulpProxy::VERSION
|
4
|
-
default_settings :pulp_url => 'https://localhost/pulp',
|
5
|
-
:pulp_dir => '/var/lib/pulp',
|
6
|
-
:pulp_content_dir => '/var/lib/pulp/content',
|
7
|
-
:puppet_content_dir => '/etc/puppet/environments',
|
8
|
-
:mongodb_dir => '/var/lib/mongodb'
|
9
|
-
|
10
|
-
expose_setting :pulp_url
|
11
|
-
|
12
|
-
http_rackup_path File.expand_path("pulp_http_config.ru", File.expand_path("../", __FILE__))
|
13
|
-
https_rackup_path File.expand_path("pulp_http_config.ru", File.expand_path("../", __FILE__))
|
14
|
-
end
|
15
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'sinatra'
|
2
|
-
require 'smart_proxy_pulp_plugin/pulp_node_plugin'
|
3
|
-
require 'smart_proxy_pulp_plugin/pulp_plugin'
|
4
|
-
|
5
|
-
module PulpProxy
|
6
|
-
class Settings
|
7
|
-
def self.settings
|
8
|
-
# work around until pulp node settings are no longer needed by foreman proxy, as pulp nodes have been removed
|
9
|
-
::PulpProxy::Plugin.settings.pulp_url ? ::PulpProxy::Plugin.settings : ::PulpNodeProxy::Plugin.settings
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module PulpProxy
|
2
|
-
module Validators
|
3
|
-
class PulpUrlValidator < ::Proxy::PluginValidators::Base
|
4
|
-
def validate!(settings)
|
5
|
-
raise ::Proxy::Error::ConfigurationError, "Setting 'pulp_url' is expected to contain a url for pulp server" if settings[:pulp_url].to_s.empty?
|
6
|
-
URI.parse(settings[:pulp_url])
|
7
|
-
rescue URI::InvalidURIError
|
8
|
-
raise ::Proxy::Error::ConfigurationError.new("Setting 'pulp_url' contains an invalid url for pulp server")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
data/settings.d/pulp.yml.example
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
---
|
2
|
-
:enabled: true
|
3
|
-
#:pulp_url: https://localhost/pulp
|
4
|
-
# Path to pulp, pulp content and mongodb directories
|
5
|
-
#:pulp_dir: /var/lib/pulp
|
6
|
-
#:pulp_content_dir: /var/lib/pulp/content
|
7
|
-
#:puppet_content_dir: /etc/pupppet/environments
|
8
|
-
#:mongodb_dir: /var/lib/mongodb
|
@@ -1,8 +0,0 @@
|
|
1
|
-
---
|
2
|
-
:enabled: true
|
3
|
-
#:pulp_url: https://localhost/pulp
|
4
|
-
# Path to pulp, pulp content and mongodb directories
|
5
|
-
#:pulp_dir: /var/lib/pulp
|
6
|
-
#:pulp_content_dir: /var/lib/pulp/content
|
7
|
-
#:puppet_content_dir: /etc/puppet/environments
|
8
|
-
#:mongodb_dir: /var/lib/mongodb
|