Packages
k8s
0.2.0
2.8.0
2.7.0
2.6.2
2.6.1
2.6.0
2.5.0
2.4.2
2.4.1
2.4.0
2.3.0
2.2.0
2.1.1
2.1.0
2.0.3
2.0.2
2.0.1
2.0.0
2.0.0-rc.6
2.0.0-rc.5
2.0.0-rc.4
2.0.0-rc.3
2.0.0-rc.2
2.0.0-rc.1
2.0.0-rc.0
1.2.1
1.2.0
1.1.10
1.1.9
1.1.8
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.0
1.0.0-rc1
0.5.2
0.5.1
0.5.0
0.5.0-rc.2
0.5.0-rc.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.13
0.2.12
0.2.11
0.2.10
0.2.9
0.2.8
0.2.7
retired
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.3
Kubernetes API Client for Elixir
Current section
Files
Jump to
Current section
Files
lib/k8s/conf/auth/certificate.ex
defmodule K8s.Conf.Auth.Certificate do
@moduledoc """
Certificate based cluster authentication.
"""
@behaviour K8s.Conf.Auth
alias K8s.Conf
alias K8s.Conf.PKI
@type t :: %__MODULE__{certificate: binary, key: binary}
defstruct [:certificate, :key]
@impl true
@spec create(map(), String.t()) :: K8s.Conf.Auth.Certificate.t() | nil
def create(%{"client-certificate" => cert_file, "client-key" => key_file}, base_path) do
cert_path = Conf.resolve_file_path(cert_file, base_path)
key_path = Conf.resolve_file_path(key_file, base_path)
%K8s.Conf.Auth.Certificate{
certificate: PKI.cert_from_pem(cert_path),
key: PKI.private_key_from_pem(key_path)
}
end
def create(
%{
"client-certificate-data" => cert_data,
"client-key-data" => key_data
},
_
) do
%K8s.Conf.Auth.Certificate{
certificate: PKI.cert_from_base64(cert_data),
key: PKI.private_key_from_base64(key_data)
}
end
def create(_, _), do: nil
defimpl Inspect, for: __MODULE__ do
import Inspect.Algebra
def inspect(_auth, _opts) do
concat(["#Certficate<...>"])
end
end
defimpl K8s.Conf.RequestOptions, for: __MODULE__ do
@doc "Generates HTTP Authorization options for certificate authentication"
@spec generate(K8s.Conf.Auth.Certificate.t()) :: K8s.Conf.RequestOptions.t()
def generate(%K8s.Conf.Auth.Certificate{certificate: certificate, key: key}) do
%K8s.Conf.RequestOptions{
headers: [],
ssl_options: [cert: certificate, key: key]
}
end
end
end