Skip to content

Instantly share code, notes, and snippets.

@danajp
danajp / monkey-patch-rest-client.rb
Created May 23, 2017 18:58
[net http blog] monkey patch rest client const
# Avoid "already initialized constant" warnings
ssl_option_list = RestClient::Request::SSLOptionList
ssl_option_list << 'extra_chain_cert'
RestClient::Request.send(:remove_const, 'SSLOptionList')
RestClient::Request.const_set('SSLOptionList', ssl_option_list)
@danajp
danajp / monkey-patch-rest-client-request.rb
Created May 23, 2017 19:00
[net http blog] monkey patch rest client request
module MonkeyPatches
module RestClientRequest
def net_http_object(hostname, port)
net = super(hostname, port)
extra_chain_cert = @ssl_opts[:extra_chain_cert]
net.extra_chain_cert = extra_chain_cert if extra_chain_cert
net
end
@danajp
danajp / monkey-patch-kubeclient-config.rb
Created May 23, 2017 19:01
[net http blog] monkey patch kubeclient config
module MonkeyPatches
module KubeclientConfigMixin
def context(context_name = nil)
old = super(context_name)
new_ssl_options = old.ssl_options.merge(
:extra_chain_cert => client_certificate_intermediate_chain(context_name)
)
Context.new(old.api_endpoint, old.api_version, new_ssl_options, old.auth_options)
@danajp
danajp / monkey-patch-kubeclient-client.rb
Last active May 24, 2017 17:28
[net http blog] monkey patch kubeclient client
module MonkeyPatches
module KubeclientClientMixin
def create_rest_client(path = nil)
path ||= @api_endpoint.path
options = {
:ssl_ca_file => @ssl_options[:ca_file],
:ssl_cert_store => @ssl_options[:cert_store],
:verify_ssl => @ssl_options[:verify_ssl],
:ssl_client_cert => @ssl_options[:client_cert],
:ssl_client_key => @ssl_options[:client_key],
@danajp
danajp / irb.txt
Created May 23, 2017 19:03
[net http blog] irb kubeclient working
irb(main):001:0> require "kubeclient"
=> true
irb(main):002:0> config = Kubeclient::Config.read("/home/dana/.kube/config")
=> #<Kubeclient::Config:0x00560ede0bc528 ...>
irb(main):003:0> client = Kubeclient::Client.new(
irb(main):004:1* config.context.api_endpoint,
irb(main):005:1* config.context.api_version,
irb(main):006:1* {
irb(main):007:2* :ssl_options => config.context.ssl_options,
irb(main):008:2* :auth_options => config.context.auth_options