Skip to content

Commit 28d9fbd

Browse files
authored
Feature: add PuppetServerV3 (#7)
1 parent a52ad6c commit 28d9fbd

File tree

7 files changed

+397
-0
lines changed

7 files changed

+397
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Supported endpoints:
1919
- Activity v1 and v2
2020
- Metrics v1 and v2
2121
- Puppet Admin v1
22+
- Puppet Server v3
2223

2324
## Installation
2425
Install the gem and add to the application's Gemfile by executing:

lib/pe_client/client.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ def puppet_admin_v1
190190
@puppet_admin_v1 ||= Resource::PuppetAdminV1.new(self)
191191
end
192192

193+
# @return [Resource::PuppetServerV3]
194+
def puppet_server_v3
195+
require_relative "resources/puppet_server.v3"
196+
@puppet_server_v3 ||= Resource::PuppetServerV3.new(self)
197+
end
198+
193199
private
194200

195201
# Handle HTTP response
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

sig/pe_client/client.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ module PEClient
3737
def metrics_v2: -> Resource::MetricsV2
3838
@puppet_admin_v1: Resource::PuppetAdminV1
3939
def puppet_admin_v1: -> Resource::PuppetAdminV1
40+
@puppet_server_v3: Resource::PuppetServerV3
41+
def puppet_server_v3: -> Resource::PuppetServerV3
4042

4143
# Private methods
4244
def handle_response: (Faraday::Response) -> (Hash[String, untyped] | Array[untyped] | String)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module PEClient
2+
module Resource
3+
class PuppetServerV3 < BaseWithPort
4+
BASE_PATH: String
5+
PORT: Integer
6+
7+
def environment_classes: (environment: String) -> Hash[String, untyped]
8+
def environment_modules: (?environment: nil) -> Array[Hash[String, untyped]]
9+
| (environment: String) -> Hash[String, untyped]
10+
def static_file_content: (file_path: String) -> String
11+
end
12+
end
13+
end

spec/pe_client/client_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,5 +423,18 @@
423423
expect(resource1).to equal(resource2)
424424
end
425425
end
426+
427+
describe "#puppet_server_v3" do
428+
it "returns a PuppetServerV3 resource" do
429+
resource = client.puppet_server_v3
430+
expect(resource).to be_a(PEClient::Resource::PuppetServerV3)
431+
end
432+
433+
it "memorizes the resource" do
434+
resource1 = client.puppet_server_v3
435+
resource2 = client.puppet_server_v3
436+
expect(resource1).to equal(resource2)
437+
end
438+
end
426439
end
427440
end

0 commit comments

Comments
 (0)