puppetserver-ca 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 020665126fef9a8fe7bc63652247bf13cf909ab37e2a3336d43724bc63b26d32
4
- data.tar.gz: c8d62416aaa1c4ded40daee19907798a13ed6fa3ea123436701adf88b9b497cd
3
+ metadata.gz: 78b8703a01de06ec5c4a6202f8341662452f4d33d37c1390b558556ce817253d
4
+ data.tar.gz: eea0c603eee53c14a82de6b80f263014ca76261eb39fa2b679031ad6ecc69b1f
5
5
  SHA512:
6
- metadata.gz: 89f506f4124c95b8b7029043ce46f216b837d3863875077476bfb835cbaf83399734d02dc7bd64ec39234d4d68735e98997ea81a724146ccef7b540e02d59849
7
- data.tar.gz: 33b9fa7893650441e456e39edda8d5d4532bcd52fe42f0832769eafad982655d2eb26357b51080a90d1da313b4a69d02f01119ae9dc1e4af645641664e9f8699
6
+ metadata.gz: 64ff93865e33b2dccd3f4308580278315d007b450611acdbb36631aabc9794d82b5f8973aa5872384f05146abe62dfa3290b5e3774f8816bafa4b70db7bf3fbc
7
+ data.tar.gz: 734dc57fa4e9f8ce390a966502ea8104cb7640aec4564759ca39c377fdaeb06ed8992fbab88dfa3ef5a2c24921e6400223e4bee2c902d0f4f92f676537f779c5
data/.travis.yml CHANGED
@@ -8,6 +8,8 @@ rvm:
8
8
  - 2.5
9
9
  - 2.6
10
10
  - 2.7
11
+ - 3.1
12
+ - 3.2
11
13
  before_install:
12
14
  gem install bundler -v 1.16.1 && (gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true)
13
15
  script:
@@ -10,17 +10,12 @@ module Puppetserver
10
10
  # Utilities for doing HTTPS against the CA that wraps Net::HTTP constructs
11
11
  class HttpClient
12
12
 
13
- DEFAULT_HEADERS = {
14
- 'User-Agent' => 'PuppetserverCaCli',
15
- 'Content-Type' => 'application/json',
16
- 'Accept' => 'application/json'
17
- }
18
-
19
13
  attr_reader :store
20
14
 
21
15
  # Not all connections require a client cert to be present.
22
16
  # For example, when querying the status endpoint.
23
17
  def initialize(logger, settings, with_client_cert: true)
18
+ @default_headers = make_headers(ENV['HOME'])
24
19
  @logger = logger
25
20
  @store = make_store(settings[:localcacert],
26
21
  settings[:certificate_revocation],
@@ -52,7 +47,7 @@ module Puppetserver
52
47
  # The Connection object should have HTTP verbs defined on it that take
53
48
  # a body (and optional overrides). Returns whatever the block given returned.
54
49
  def with_connection(url, &block)
55
- request = ->(conn) { block.call(Connection.new(conn, url, @logger)) }
50
+ request = ->(conn) { block.call(Connection.new(conn, url, @logger, @default_headers)) }
56
51
 
57
52
  begin
58
53
  Net::HTTP.start(url.host, url.port,
@@ -68,7 +63,22 @@ module Puppetserver
68
63
 
69
64
  private
70
65
 
71
- def load_with_errors(path, setting, &block)
66
+ def make_headers(home)
67
+ headers = {
68
+ 'User-Agent' => 'PuppetserverCaCli',
69
+ 'Content-Type' => 'application/json',
70
+ 'Accept' => 'application/json'
71
+ }
72
+
73
+ token_path = "#{home}/.puppetlabs/token"
74
+ if File.exist?(token_path)
75
+ headers['X-Authentication'] = File.read(token_path)
76
+ end
77
+
78
+ headers
79
+ end
80
+
81
+ def load_with_errors(path, setting, &block)
72
82
  begin
73
83
  content = File.read(path)
74
84
  block.call(content)
@@ -81,21 +91,23 @@ module Puppetserver
81
91
  "Could not parse '#{setting}' at '#{path}'.\n" +
82
92
  " OpenSSL returned: #{e.message}")
83
93
  end
84
- end
94
+ end
85
95
 
86
96
  # Helper class that wraps a Net::HTTP connection, a HttpClient::URL
87
97
  # and defines methods named after HTTP verbs that are called on the
88
98
  # saved connection, returning a Result.
89
99
  class Connection
90
- def initialize(net_http_connection, url_struct, logger)
100
+
101
+ def initialize(net_http_connection, url_struct, logger, default_headers)
91
102
  @conn = net_http_connection
92
103
  @url = url_struct
93
104
  @logger = logger
105
+ @default_headers = default_headers
94
106
  end
95
107
 
96
- def get(url_overide = nil, headers = {})
108
+ def get(url_overide = nil, header_overrides = {})
97
109
  url = url_overide || @url
98
- headers = DEFAULT_HEADERS.merge(headers)
110
+ headers = @default_headers.merge(header_overrides)
99
111
 
100
112
  @logger.debug("Making a GET request at #{url.full_url}")
101
113
 
@@ -105,9 +117,9 @@ module Puppetserver
105
117
 
106
118
  end
107
119
 
108
- def put(body, url_override = nil, headers = {})
120
+ def put(body, url_override = nil, header_overrides = {})
109
121
  url = url_override || @url
110
- headers = DEFAULT_HEADERS.merge(headers)
122
+ headers = @default_headers.merge(header_overrides)
111
123
 
112
124
  @logger.debug("Making a PUT request at #{url.full_url}")
113
125
 
@@ -118,9 +130,9 @@ module Puppetserver
118
130
  Result.new(result.code, result.body)
119
131
  end
120
132
 
121
- def delete(url_override = nil, headers = {})
133
+ def delete(url_override = nil, header_overrides = {})
122
134
  url = url_override || @url
123
- headers = DEFAULT_HEADERS.merge(headers)
135
+ headers = @default_headers.merge(header_overrides)
124
136
 
125
137
  @logger.debug("Making a DELETE request at #{url.full_url}")
126
138
 
@@ -1,5 +1,5 @@
1
1
  module Puppetserver
2
2
  module Ca
3
- VERSION = "2.5.0"
3
+ VERSION = "2.6.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetserver-ca
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-14 00:00:00.000000000 Z
11
+ date: 2023-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: facter
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.0.9
146
+ rubygems_version: 3.4.12
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: A simple CLI tool for interacting with Puppet Server's Certificate Authority