jhthorsen / jhthorsen/openapi-client

Mojo::UserAgent attribute in constructor ignored for the constructor

Open
#40 3 comments 0 reactions 1 assignee Claimed by @yoe View on GitHub
enhancement help wanted
Dominant language
Perl
Stars
12
Forks
18
PR merge metrics
No merged PRs in 30d

Description

I'm trying to connect to a Kubernetes API server. This requires me to do two things:

- Pass a token in a header
- Set the API server's CA certificate

This is even true when trying to access the OpenAPI definition (at $apiserver/openapi/v2).

In order to do that, I prepared a Mojo::UserAgent like so:

```perl
my $token;
{
local $/="";
open my $token_f, "
}
my $ua = Mojo::UserAgent->new;
$ua->on(prepare => sub($ua, $tx) {
$tx->req->headers->header("Authorization: Bearer $token");
});
$ua = $ua->ca("/run/secrets/kubernetes.io/serviceaccount/ca.crt");
my $client = OpenAPI::Client->new("https://" . $ENV{KUBERNETES_SERVICE_HOST} . ":" . $ENV{KUBERNETES_SERVICE_PORT} . "/openapi/v2", ua => $ua);
```

However, OpenAPI::Client does not seem to use the Mojo::UserAgent at this point:

```
root@perl:~# perl ./test
GET https://10.152.183.1:443/openapi/v2: SSL connect attempt failed error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
```

One can bypass that by setting MOJO_CA_FILE, but that misses the header:

```
root@perl:~# MOJO_CA_FILE=/run/secrets/kubernetes.io/serviceaccount/ca.crt perl ./test
GET https://10.152.183.1:443/openapi/v2: Forbidden at /usr/local/lib/perl5/site_perl/5.36.0/JSON/Validator/Store.pm line 190.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.