Class: Puppet::HTTP::Service Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/http/service.rb

Overview

This class is abstract.

Subclass and implement methods for the service's REST APIs.

Represents an abstract Puppet web service.

Direct Known Subclasses

Ca, Compiler, FileServer, Puppetserver, Report

Defined Under Namespace

Classes: Ca, Compiler, FileServer, Puppetserver, Report

Constant Summary collapse

SERVICE_NAMES =

Returns available services.

Returns:

  • (Array<Symbol>)

    available services

[:ca, :fileserver, :puppet, :puppetserver, :report].freeze
EXCLUDED_FORMATS =

Returns format types that are unsupported.

Returns:

  • (Array<Symbol>)

    format types that are unsupported

[:yaml, :b64_zlib_yaml, :dot].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, session, url) ⇒ Service

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new service. Services should be created by calling Puppet::HTTP::Session#route_to.

Parameters:



87
88
89
90
91
# File 'lib/puppet/http/service.rb', line 87

def initialize(client, session, url)
  @client = client
  @session = session
  @url = url
end

Instance Attribute Details

#urlURI (readonly)

Returns the url associated with this service.

Returns:

  • (URI)

    the url associated with this service



9
10
11
# File 'lib/puppet/http/service.rb', line 9

def url
  @url
end

Class Method Details

.create_service(client, session, name, server = nil, port = nil) ⇒ Puppet::HTTP::Service

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new web service, which contains the URL used to connect to the service. The four services implemented are :ca, :fileserver, :puppet, and :report.

The :ca and :report services handle certs and reports, respectively. The :fileserver service handles puppet file metadata and content requests. And the default service, :puppet, handles nodes, facts, and catalogs.

Parameters:

  • client (Puppet::HTTP::Client)

    the owner of the session

  • session (Puppet::HTTP::Session)

    the owner of the service

  • name (Symbol)

    the type of service to create

  • server (<Type>) (defaults to: nil)

    optional, the server to connect to

  • port (<Type>) (defaults to: nil)

    optional, the port to connect to

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/puppet/http/service.rb', line 34

def self.create_service(client, session, name, server = nil, port = nil)
  # this is the entry point for creating all services, check and issue warning here.
  unless Puppet.settings.set_by_config? :server
    if Puppet.features.root?
      Puppet.deprecation_warning('OpenVox will not default to `server=puppet` as of version 9.0. Please update your configuration appropriately.')
    else
      Puppet.deprecation_warning('OpenVox no longer defaults to `server=puppet` when running as a non-privileged user. (Did you mean to run as root?)')

      case name
      when :ca
        raise ArgumentError, 'Neither `server` nor `ca_server` is specified.' unless Puppet.settings.set_by_config? :ca_server
      when :report
        raise ArgumentError, 'Neither `server` nor `report_server` is specified.' unless Puppet.settings.set_by_config? :report_server
      when :fileserver, :puppet, :puppetserver
        raise ArgumentError, 'Required setting `server` is not specified.'
      end
    end
  end

  case name
  when :ca
    Puppet::HTTP::Service::Ca.new(client, session, server, port)
  when :fileserver
    Puppet::HTTP::Service::FileServer.new(client, session, server, port)
  when :puppet
    ::Puppet::HTTP::Service::Compiler.new(client, session, server, port)
  when :puppetserver
    ::Puppet::HTTP::Service::Puppetserver.new(client, session, server, port)
  when :report
    Puppet::HTTP::Service::Report.new(client, session, server, port)
  else
    raise ArgumentError, "Unknown service #{name}"
  end
end

.valid_name?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if the service named is included in the list of available services.

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)


76
77
78
# File 'lib/puppet/http/service.rb', line 76

def self.valid_name?(name)
  SERVICE_NAMES.include?(name)
end

Instance Method Details

#connect(ssl_context: nil) ⇒ void

This method returns an undefined value.

Open a connection using the given ssl context.

Parameters:



112
113
114
# File 'lib/puppet/http/service.rb', line 112

def connect(ssl_context: nil)
  @client.connect(@url, options: { ssl_context: ssl_context })
end

#with_base_url(path) ⇒ URI

Return the url with the given path encoded and appended

Parameters:

  • path (String)

    the string to append to the base url

Returns:

  • (URI)

    the URI object containing the encoded path



100
101
102
103
104
# File 'lib/puppet/http/service.rb', line 100

def with_base_url(path)
  u = @url.dup
  u.path += Puppet::Util.uri_encode(path)
  u
end