Skip to content

Commit 68b0dfe

Browse files
authored
Expose mtls certificate config params in python and php configuration templates (#22229)
* Expose mtls config params in python template * Expose certFile and keyFile configuration items to support mtls in php generated client * Regenerate of examples
1 parent 31e462d commit 68b0dfe

File tree

18 files changed

+277
-14
lines changed

18 files changed

+277
-14
lines changed

modules/openapi-generator/src/main/resources/php/Configuration.mustache

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ class Configuration
115115
*/
116116
protected $tempFolderPath;
117117
118+
/**
119+
* Path to a certificate file, for mTLS
120+
*
121+
* @var string
122+
*/
123+
protected $certFile;
124+
125+
/**
126+
* Path to a key file, for mTLS
127+
*
128+
* @var string
129+
*/
130+
protected $keyFile;
131+
118132
/**
119133
* Constructor
120134
*/
@@ -388,6 +402,49 @@ class Configuration
388402
return $this->tempFolderPath;
389403
}
390404

405+
/**
406+
* Sets the certificate file path, for mTLS
407+
*
408+
* @return $this
409+
*/
410+
public function setCertFile($certFile)
411+
{
412+
$this->certFile = $certFile;
413+
return $this;
414+
}
415+
416+
/**
417+
* Gets the certificate file path, for mTLS
418+
*
419+
* @return string Certificate file path
420+
*/
421+
public function getCertFile()
422+
{
423+
return $this->certFile;
424+
}
425+
426+
/**
427+
* Sets the certificate key path, for mTLS
428+
*
429+
* @return $this
430+
*/
431+
public function setKeyFile($keyFile)
432+
{
433+
$this->keyFile = $keyFile;
434+
return $this;
435+
}
436+
437+
/**
438+
* Gets the certificate key path, for mTLS
439+
*
440+
* @return string Certificate key path
441+
*/
442+
public function getKeyFile()
443+
{
444+
return $this->keyFile;
445+
}
446+
447+
391448
/**
392449
* Gets the default configuration instance
393450
*

modules/openapi-generator/src/main/resources/php/api.mustache

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,14 @@ use {{invokerPackage}}\ObjectSerializer;
832832
}
833833
}
834834

835+
if ($this->config->getCertFile()) {
836+
$options[RequestOptions::CERT] = $this->config->getCertFile();
837+
}
838+
839+
if ($this->config->getKeyFile()) {
840+
$options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
841+
}
842+
835843
return $options;
836844
}
837845

modules/openapi-generator/src/main/resources/python/configuration.mustache

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ class Configuration:
186186
:param retries: Number of retries for API requests.
187187
:param ca_cert_data: verify the peer using concatenated CA certificate data
188188
in PEM (str) or DER (bytes) format.
189+
:param cert_file: the path to a client certificate file, for mTLS.
190+
:param key_file: the path to a client key file, for mTLS.
189191

190192
{{#hasAuthMethods}}
191193
:Example:
@@ -293,6 +295,8 @@ conf = {{{packageName}}}.Configuration(
293295
ssl_ca_cert: Optional[str]=None,
294296
retries: Optional[int] = None,
295297
ca_cert_data: Optional[Union[str, bytes]] = None,
298+
cert_file: Optional[str]=None,
299+
key_file: Optional[str]=None,
296300
*,
297301
debug: Optional[bool] = None,
298302
) -> None:
@@ -381,10 +385,10 @@ conf = {{{packageName}}}.Configuration(
381385
"""Set this to verify the peer using PEM (str) or DER (bytes)
382386
certificate data.
383387
"""
384-
self.cert_file = None
388+
self.cert_file = cert_file
385389
"""client certificate file
386390
"""
387-
self.key_file = None
391+
self.key_file = key_file
388392
"""client key file
389393
"""
390394
self.assert_hostname = None

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/configuration.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ class Configuration:
165165
:param retries: Number of retries for API requests.
166166
:param ca_cert_data: verify the peer using concatenated CA certificate data
167167
in PEM (str) or DER (bytes) format.
168+
:param cert_file: the path to a client certificate file, for mTLS.
169+
:param key_file: the path to a client key file, for mTLS.
168170
169171
:Example:
170172
@@ -203,6 +205,8 @@ def __init__(
203205
ssl_ca_cert: Optional[str]=None,
204206
retries: Optional[int] = None,
205207
ca_cert_data: Optional[Union[str, bytes]] = None,
208+
cert_file: Optional[str]=None,
209+
key_file: Optional[str]=None,
206210
*,
207211
debug: Optional[bool] = None,
208212
) -> None:
@@ -284,10 +288,10 @@ def __init__(
284288
"""Set this to verify the peer using PEM (str) or DER (bytes)
285289
certificate data.
286290
"""
287-
self.cert_file = None
291+
self.cert_file = cert_file
288292
"""client certificate file
289293
"""
290-
self.key_file = None
294+
self.key_file = key_file
291295
"""client key file
292296
"""
293297
self.assert_hostname = None

samples/client/echo_api/python/openapi_client/configuration.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ class Configuration:
165165
:param retries: Number of retries for API requests.
166166
:param ca_cert_data: verify the peer using concatenated CA certificate data
167167
in PEM (str) or DER (bytes) format.
168+
:param cert_file: the path to a client certificate file, for mTLS.
169+
:param key_file: the path to a client key file, for mTLS.
168170
169171
:Example:
170172
@@ -203,6 +205,8 @@ def __init__(
203205
ssl_ca_cert: Optional[str]=None,
204206
retries: Optional[int] = None,
205207
ca_cert_data: Optional[Union[str, bytes]] = None,
208+
cert_file: Optional[str]=None,
209+
key_file: Optional[str]=None,
206210
*,
207211
debug: Optional[bool] = None,
208212
) -> None:
@@ -284,10 +288,10 @@ def __init__(
284288
"""Set this to verify the peer using PEM (str) or DER (bytes)
285289
certificate data.
286290
"""
287-
self.cert_file = None
291+
self.cert_file = cert_file
288292
"""client certificate file
289293
"""
290-
self.key_file = None
294+
self.key_file = key_file
291295
"""client key file
292296
"""
293297
self.assert_hostname = None

samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ protected function createHttpClientOption()
408408
}
409409
}
410410

411+
if ($this->config->getCertFile()) {
412+
$options[RequestOptions::CERT] = $this->config->getCertFile();
413+
}
414+
415+
if ($this->config->getKeyFile()) {
416+
$options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
417+
}
418+
411419
return $options;
412420
}
413421

samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,14 @@ protected function createHttpClientOption()
381381
}
382382
}
383383

384+
if ($this->config->getCertFile()) {
385+
$options[RequestOptions::CERT] = $this->config->getCertFile();
386+
}
387+
388+
if ($this->config->getKeyFile()) {
389+
$options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
390+
}
391+
384392
return $options;
385393
}
386394

samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7578,6 +7578,14 @@ protected function createHttpClientOption()
75787578
}
75797579
}
75807580

7581+
if ($this->config->getCertFile()) {
7582+
$options[RequestOptions::CERT] = $this->config->getCertFile();
7583+
}
7584+
7585+
if ($this->config->getKeyFile()) {
7586+
$options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
7587+
}
7588+
75817589
return $options;
75827590
}
75837591

samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,14 @@ protected function createHttpClientOption()
413413
}
414414
}
415415

416+
if ($this->config->getCertFile()) {
417+
$options[RequestOptions::CERT] = $this->config->getCertFile();
418+
}
419+
420+
if ($this->config->getKeyFile()) {
421+
$options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
422+
}
423+
416424
return $options;
417425
}
418426

samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3450,6 +3450,14 @@ protected function createHttpClientOption()
34503450
}
34513451
}
34523452

3453+
if ($this->config->getCertFile()) {
3454+
$options[RequestOptions::CERT] = $this->config->getCertFile();
3455+
}
3456+
3457+
if ($this->config->getKeyFile()) {
3458+
$options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
3459+
}
3460+
34533461
return $options;
34543462
}
34553463

0 commit comments

Comments
 (0)