Skip to content

Instantly share code, notes, and snippets.

@ekohl ekohl/fp-curl
Created May 17, 2019

What would you like to do?
A script that wraps curl with the right connection details
#!/usr/bin/env ruby
# This script wraps curl with the right connection details so you don't need to
# care about it.
# The first argument is the path on the host, including the first slash:
# ./fp-curl /features
# ./fp-curl /v2/features | jq .
# ./fp-curl /puppet/ca/ -X DELETE
require 'openssl'
require 'uri'
require 'yaml'
raise Exception, "Usage: #{$0} /path [other]" unless ARGV.any?
SETTINGS_FILE = '/etc/foreman-proxy/settings.yml'
settings = YAML.load(
raise Exception, 'Unable to read settings' unless settings
certificate =[:ssl_certificate]))
cn = certificate.subject.to_a.find { |name, data, type| name == 'CN' }
raise Exception, 'No CN found in certificate' unless cn
uri ={:host => cn[1], :port => settings[:https_port], :path => ARGV.shift})
command = [
'--cacert', settings[:ssl_ca_file],
'--key', settings[:ssl_private_key],
'--cert', settings[:ssl_certificate],
] + ARGV
exit $?.exitstatus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.