Skip to content

Commit f38f392

Browse files
authored
Merge pull request #6 from yue9944882/feat/simple-ssl-x509-support
Feat: Simple x509 support for ApiClient
2 parents 0dc7551 + cade329 commit f38f392

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

.openapi-generator-ignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
#docs/*.md
2222
# Then explicitly reverse the ignore rule for a single file:
2323
#!docs/README.md
24+
lib/Kubernetes/ApiClient.pm

cpanfile

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ requires 'Module::Runtime';
66
requires 'URI::Query';
77
requires 'Module::Find';
88
requires 'LWP::UserAgent';
9+
requires 'LWP::Protocol::https';
910
requires 'Class::Accessor';
1011

1112
on 'test' => sub {

examples/ssl_client.pl

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use strict;
2+
use warnings;
3+
4+
my $api_factory = Kubernetes::ApiFactory->new(
5+
'base_url' => 'https://127.0.0.1:6443',
6+
'ssl_opts' => {
7+
# Disabling server ca validation
8+
# SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
9+
# verify_hostname => 0,
10+
11+
SSL_use_cert => 1,
12+
SSL_ca_file => "/path/to/ca",
13+
SSL_cert_file => "/path/to/cert",
14+
SSL_key_file => "/path/to/key",
15+
},
16+
);
17+
18+
my $corev1_api = $api_factory->get_api('CoreV1');
19+
20+
my $namespaceList = $corev1_api->list_namespace();
21+
22+
printf "found %d namespaces:\n", scalar @{$namespaceList->items};
23+
printf "=====================\n", length @{$namespaceList->items};
24+
foreach my $namespace (@{$namespaceList->items}) {
25+
printf "%s\n", $namespace->metadata->name;
26+
}

lib/Kubernetes/ApiClient.pm

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ sub new {
5151
}
5252

5353
my (%args) = (
54-
'ua' => LWP::UserAgent->new,
54+
'ua' => LWP::UserAgent->new(
55+
ssl_opts => $config->{ssl_opts},
56+
),
5557
'config' => $config,
5658
);
57-
59+
5860
return bless \%args, $class;
5961
}
6062

lib/Kubernetes/Configuration.pm

+5-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ sub new {
110110
$p{access_token} //= '';
111111

112112
# base_url
113-
$p{base_url} //= 'http://localhost';
113+
$p{base_url} //= 'http://localhost';
114+
115+
$p{ssl_opts} //= {
116+
verify_hostname => 1,
117+
};
114118

115119
return bless \%p => $self;
116120
}

0 commit comments

Comments
 (0)