Skip to content

Commit

Permalink
Fixes #30857 - Merge puppet_proxy_puppet_api into mod
Browse files Browse the repository at this point in the history
In 7e7015a the legacy provider was
dropped. Since then, there is only one provider. The provider code was
kept since it didn't need any changes to configuration files. However,
having a module with just a single provider is complex. Both from a code
perspective and as an admin.

The implications are that the puppet.yaml and
puppet_proxy_puppet_api.yaml files are merged (after being split in
df0fc72). This means installer and
manual updates are needed to reflect this.
  • Loading branch information
ekohl committed Aug 31, 2022
1 parent 6b0b909 commit efe845c
Show file tree
Hide file tree
Showing 25 changed files with 131 additions and 361 deletions.
11 changes: 11 additions & 0 deletions config/settings.d/puppet.yml.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
---
# Can be true, false, or http/https to enable just one of the protocols
:enabled: false

# URL of the puppet master itself for API requests.
#:puppet_url: https://puppet.example.com:8140

# SSL certificates used to access the puppet API
#:puppet_ssl_ca: /etc/puppetlabs/puppet/ssl/certs/ca.pem
#:puppet_ssl_cert: /etc/puppetlabs/puppet/ssl/certs/puppet.example.com.pem
#:puppet_ssl_key: /etc/puppetlabs/puppet/ssl/private_keys/puppet.example.com.pem

# Smart Proxy api timeout when Puppet's environment classes api is used and classes cache is disabled
#:api_timeout: 30
11 changes: 0 additions & 11 deletions config/settings.d/puppet_proxy_puppet_api.yml.example

This file was deleted.

88 changes: 0 additions & 88 deletions extra/migrations/20160413000000_migrate_puppet_settings.rb

This file was deleted.

1 change: 0 additions & 1 deletion lib/smart_proxy_main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ module Proxy
require 'puppetca_hostname_whitelisting/puppetca_hostname_whitelisting'
require 'puppetca_token_whitelisting/puppetca_token_whitelisting'
require 'puppet_proxy/puppet'
require 'puppet_proxy_puppet_api/puppet_proxy_puppet_api'
require 'bmc/bmc'
require 'realm/realm'
require 'realm_freeipa/realm_freeipa'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
require 'puppet_proxy_common/api_request'

module Proxy::PuppetApi
class EnvironmentsApiv3 < ::Proxy::Puppet::ApiRequest
module Proxy::Puppet
class Apiv3 < ::Proxy::Puppet::ApiRequest
NOT_MODIFIED = Object.new

def find_environments
handle_response(send_request('puppet/v3/environments'), "Failed to query Puppet find environments v3 API")
end
end

class EnvironmentClassesApiv3 < ::Proxy::Puppet::ApiRequest
NOT_MODIFIED = Object.new

def list_classes(environment, etag, timeout)
response = send_request("puppet/v3/environment_classes?environment=#{environment}", timeout, "If-None-Match" => etag)
Expand Down
35 changes: 29 additions & 6 deletions modules/puppet_proxy/configuration_loader.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
module ::Proxy::Puppet
class ConfigurationLoader
def load_programmable_settings(settings)
settings[:use_provider] = [:puppet_proxy_puppet_api]
settings
end

def load_classes
require 'puppet_proxy_common/errors'
require 'puppet_proxy/errors'
require 'puppet_proxy/dependency_injection'
require 'puppet_proxy/puppet_api'
require 'puppet_proxy/environment'
require 'puppet_proxy/puppet_class'
require 'puppet_proxy_common/api_request'
require 'puppet_proxy/apiv3'
require 'puppet_proxy/v3_environments_retriever'
require 'puppet_proxy/v3_environment_classes_api_classes_retriever'
end

def load_dependency_injection_wirings(container_instance, settings)
container_instance.dependency :environment_retriever_impl,
(lambda do
api = Proxy::Puppet::Apiv3.new(
settings[:puppet_url],
settings[:puppet_ssl_ca],
settings[:puppet_ssl_cert],
settings[:puppet_ssl_key])
::Proxy::Puppet::V3EnvironmentsRetriever.new(api)
end)

container_instance.singleton_dependency :class_retriever_impl,
(lambda do
::Proxy::Puppet::V3EnvironmentClassesApiClassesRetriever.new(
settings[:puppet_url],
settings[:puppet_ssl_ca],
settings[:puppet_ssl_cert],
settings[:puppet_ssl_key],
settings[:api_timeout])
end)
end
end
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 6 additions & 2 deletions modules/puppet_proxy/puppet_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ class Plugin < Proxy::Plugin

plugin :puppet, ::Proxy::VERSION

uses_provider
load_programmable_settings ::Proxy::Puppet::ConfigurationLoader
load_classes ::Proxy::Puppet::ConfigurationLoader
load_dependency_injection_wirings ::Proxy::Puppet::ConfigurationLoader

default_settings :puppet_ssl_ca => '/etc/puppetlabs/puppet/ssl/certs/ca.pem', :api_timeout => 30
validate :puppet_url, :url => true
expose_setting :puppet_url
validate_readable :puppet_ssl_ca, :puppet_ssl_cert, :puppet_ssl_key
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'concurrent'

class Proxy::PuppetApi::V3EnvironmentClassesApiClassesRetriever
class Proxy::Puppet::V3EnvironmentClassesApiClassesRetriever
include ::Proxy::Log

DEFAULT_CLIENT_TIMEOUT = 15
Expand All @@ -18,7 +18,7 @@ def initialize(puppet_url, puppet_ssl_ca, puppet_ssl_cert, puppet_ssl_key, api_t
@puppet_url = puppet_url
@api_timeout = api_timeout
@m = Monitor.new
@puppet_api = api || Proxy::PuppetApi::EnvironmentClassesApiv3
@puppet_api = api || Proxy::Puppet::Apiv3
end

def classes_in_environment(environment)
Expand Down Expand Up @@ -84,7 +84,7 @@ def async_get_classes(environment)
raise e
end

if response == Proxy::PuppetApi::EnvironmentClassesApiv3::NOT_MODIFIED
if response == Proxy::Puppet::Apiv3::NOT_MODIFIED
@m.synchronize do
@futures_cache.delete(environment)
logger.debug { "Puppet cache counts: classes %d, etag %d, futures %d" % [@classes_cache.size, @etag_cache.size, @futures_cache.size] }
Expand Down
22 changes: 22 additions & 0 deletions modules/puppet_proxy/v3_environments_retriever.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Proxy::Puppet
class V3EnvironmentsRetriever
def initialize(api)
@api = api
end

def get(an_environment)
found = all.find { |e| e.name == an_environment }
raise Proxy::Puppet::EnvironmentNotFound.new("Could not find environment '#{an_environment}'") unless found
found
end

def all
response = @api.find_environments
raise Proxy::Puppet::DataError.new("No environments list in Puppet API response") unless response['environments']
environments = response['environments'].each_with_object({}) do |item, envs|
envs[item.first] = item.last['settings']['modulepath'] if item.last && item.last['settings'] && item.last['settings']['modulepath']
end
environments.map { |env, path| Proxy::Puppet::Environment.new(env, path) }
end
end
end
25 changes: 0 additions & 25 deletions modules/puppet_proxy_common/environments_retriever_base.rb

This file was deleted.

35 changes: 0 additions & 35 deletions modules/puppet_proxy_puppet_api/plugin_configuration.rb

This file was deleted.

2 changes: 0 additions & 2 deletions modules/puppet_proxy_puppet_api/puppet_proxy_puppet_api.rb

This file was deleted.

15 changes: 0 additions & 15 deletions modules/puppet_proxy_puppet_api/puppet_proxy_puppet_api_plugin.rb

This file was deleted.

8 changes: 0 additions & 8 deletions modules/puppet_proxy_puppet_api/v3_environments_retriever.rb

This file was deleted.

Loading

0 comments on commit efe845c

Please sign in to comment.