Class: K8y::REST::Transport
- Inherits:
-
Object
- Object
- K8y::REST::Transport
- Defined in:
- lib/k8y/rest/transport.rb
Instance Attribute Summary collapse
-
#ca_data ⇒ Object
readonly
Returns the value of attribute ca_data.
-
#ca_file ⇒ Object
readonly
Returns the value of attribute ca_file.
-
#cert_data ⇒ Object
readonly
Returns the value of attribute cert_data.
-
#cert_file ⇒ Object
readonly
Returns the value of attribute cert_file.
-
#key_data ⇒ Object
readonly
Returns the value of attribute key_data.
-
#key_file ⇒ Object
readonly
Returns the value of attribute key_file.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(cert_file: nil, key_file: nil, ca_file: nil, cert_data: nil, key_data: nil, ca_data: nil) ⇒ Transport
constructor
A new instance of Transport.
- #reconcile! ⇒ Object
- #to_faraday_options ⇒ Object
Constructor Details
#initialize(cert_file: nil, key_file: nil, ca_file: nil, cert_data: nil, key_data: nil, ca_data: nil) ⇒ Transport
Returns a new instance of Transport.
22 23 24 25 26 27 28 29 30 |
# File 'lib/k8y/rest/transport.rb', line 22 def initialize(cert_file: nil, key_file: nil, ca_file: nil, cert_data: nil, key_data: nil, ca_data: nil) @cert_file = cert_file @key_file = key_file @ca_file = ca_file @cert_data = cert_data @key_data = key_data @ca_data = ca_data end |
Instance Attribute Details
#ca_data ⇒ Object
Returns the value of attribute ca_data.
6 7 8 |
# File 'lib/k8y/rest/transport.rb', line 6 def ca_data @ca_data end |
#ca_file ⇒ Object (readonly)
Returns the value of attribute ca_file.
6 7 8 |
# File 'lib/k8y/rest/transport.rb', line 6 def ca_file @ca_file end |
#cert_data ⇒ Object
Returns the value of attribute cert_data.
6 7 8 |
# File 'lib/k8y/rest/transport.rb', line 6 def cert_data @cert_data end |
#cert_file ⇒ Object (readonly)
Returns the value of attribute cert_file.
6 7 8 |
# File 'lib/k8y/rest/transport.rb', line 6 def cert_file @cert_file end |
#key_data ⇒ Object
Returns the value of attribute key_data.
6 7 8 |
# File 'lib/k8y/rest/transport.rb', line 6 def key_data @key_data end |
#key_file ⇒ Object (readonly)
Returns the value of attribute key_file.
6 7 8 |
# File 'lib/k8y/rest/transport.rb', line 6 def key_file @key_file end |
Class Method Details
.from_kubeconfig(kubeconfig, context: nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/k8y/rest/transport.rb', line 9 def from_kubeconfig(kubeconfig, context: nil) context = context ? context : kubeconfig.current_context cluster = kubeconfig.cluster_for_context(context) auth_info = kubeconfig.user_for_context(context).auth_info transport = new(cert_file: auth_info.client_certificate, key_file: auth_info.client_key, ca_file: cluster., cert_data: auth_info.client_certificate_data, key_data: auth_info.client_key_data, ca_data: cluster.) transport.reconcile! transport end |
Instance Method Details
#reconcile! ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/k8y/rest/transport.rb', line 32 def reconcile! return if reconciled? reconcile_cert_data! reconcile_key_data! reconcile_ca_data! @reconciled = true end |
#to_faraday_options ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/k8y/rest/transport.rb', line 41 def if ca_data cert_store = OpenSSL::X509::Store.new cert_store.add_cert(OpenSSL::X509::Certificate.new(ca_data)) end { client_cert: (OpenSSL::X509::Certificate.new(cert_data) if cert_data), client_key: (OpenSSL::PKey::RSA.new(key_data) if key_data), cert_store: cert_store, verify: OpenSSL::SSL::VERIFY_PEER, } end |