|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Copyright 2025 Perforce Software Inc. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +require_relative "base_with_port" |
| 18 | + |
| 19 | +module PEClient |
| 20 | + module Resource |
| 21 | + # Server-specific Puppet API endpoints. |
| 22 | + # |
| 23 | + # @see https://help.puppet.com/core/current/Content/PuppetCore/server/http_api/puppet-api/v3/environment_classes.htm |
| 24 | + # @see https://help.puppet.com/core/current/Content/PuppetCore/server/http_api/puppet-api/v3/environment_modules.htm |
| 25 | + # @see https://help.puppet.com/core/current/Content/PuppetCore/server/http_api/puppet-api/v3/static_file_content.htm |
| 26 | + class PuppetServerV3 < BaseWithPort |
| 27 | + # The base path for Puppet Server API v3 endpoints. |
| 28 | + BASE_PATH = "/puppet/v3" |
| 29 | + |
| 30 | + # Default Puppet Server API Port |
| 31 | + PORT = 8140 |
| 32 | + |
| 33 | + # The environment classes API serves as a replacement for the Puppet resource type API for classes, which was removed in Puppet. |
| 34 | + # |
| 35 | + # @param environment [String] The environment to query. |
| 36 | + # |
| 37 | + # @return [Hash] |
| 38 | + def environment_classes(environment:) |
| 39 | + @client.get "#{BASE_PATH}/environment_classes", params: {environment:} |
| 40 | + end |
| 41 | + |
| 42 | + # The environment modules API returns information about what modules are installed for the requested environment. |
| 43 | + # |
| 44 | + # @param environment [String] The environment to query. |
| 45 | + # |
| 46 | + # @return [Array<Hash>, Hash] |
| 47 | + def environment_modules(environment: nil) |
| 48 | + @client.get "#{BASE_PATH}/environment_modules", params: {environment:}.compact |
| 49 | + end |
| 50 | + |
| 51 | + # The static_file_content endpoint returns the standard output of a `code-content-command` script, which should output the contents of a specific version of a `file resource` that has a source attribute with a `puppet:///` URI value. |
| 52 | + # That source must be a file from the files or tasks directory of a module in a specific environment. |
| 53 | + # |
| 54 | + # @param file_path [String] The path corresponds to the requested file's path on the Server relative to the given environment's root directory, and must point to a file in the */*/files/**, */*/lib/**, */*/scripts/**, or */*/tasks/** glob. |
| 55 | + # |
| 56 | + # @return [String] |
| 57 | + def static_file_content(file_path:) |
| 58 | + @client.get File.join("#{BASE_PATH}/static_file_content", file_path) |
| 59 | + end |
| 60 | + end |
| 61 | + end |
| 62 | +end |
0 commit comments