Class: TrainPlugins::F5::Connection
- Inherits:
-
Train::Plugins::Transport::BaseConnection
- Object
- Train::Plugins::Transport::BaseConnection
- TrainPlugins::F5::Connection
- Defined in:
- lib/train-f5/connection.rb
Overview
F5 Connection
Instance Method Summary collapse
- #delete(uri) ⇒ Object
-
#get(uri) ⇒ Object
Do GET,PUT,POST, DELETE with the cached Faraday client.
-
#initialize(options) ⇒ Connection
constructor
Initialise Faraday as the HTTP handler with basic auth and automatic JSON conversion.
-
#platform ⇒ Object
Allow Train to query the platform we are connected to.
- #post(uri, data = nil) ⇒ Object
- #process_response(resp) ⇒ Object
- #put(uri, data = nil) ⇒ Object
Constructor Details
#initialize(options) ⇒ Connection
Initialise Faraday as the HTTP handler with basic auth and automatic JSON conversion.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/train-f5/connection.rb', line 15 def initialize() super() @baseurl = "https://#{[:host]}:#{[:port]}" @httpclient = Faraday.new( url: @baseurl, ssl: { verify: ![:insecure] }, headers: { "Content-Type" => "application/json", "Accept" => "application/json" } ) do |conn| if Faraday::VERSION.split(".")[0] == "1" conn.request :basic_auth, [:user], [:password] else conn.request :authorization, :basic, [:user], [:password] end conn.request :json end end |
Instance Method Details
#delete(uri) ⇒ Object
53 54 55 |
# File 'lib/train-f5/connection.rb', line 53 def delete(uri) process_response(@httpclient.delete(uri)) end |
#get(uri) ⇒ Object
Do GET,PUT,POST, DELETE with the cached Faraday client
41 42 43 |
# File 'lib/train-f5/connection.rb', line 41 def get(uri) process_response(@httpclient.get(uri)) end |
#platform ⇒ Object
Allow Train to query the platform we are connected to
32 33 34 35 36 37 38 |
# File 'lib/train-f5/connection.rb', line 32 def platform body = get("/mgmt/tm/sys/version") f5_release = body["entries"].values[0]["nestedStats"]["entries"]["Version"]["description"] # f5_family = body['entries'].values[0]['nestedStats']['entries']['Product']['description'] Train::Platforms.name("f5").in_family("api") force_platform!("f5", release: f5_release) end |
#post(uri, data = nil) ⇒ Object
49 50 51 |
# File 'lib/train-f5/connection.rb', line 49 def post(uri, data = nil) process_response(@httpclient.post(uri, data)) end |
#process_response(resp) ⇒ Object
57 58 59 |
# File 'lib/train-f5/connection.rb', line 57 def process_response(resp) JSON.parse(resp.body) end |
#put(uri, data = nil) ⇒ Object
45 46 47 |
# File 'lib/train-f5/connection.rb', line 45 def put(uri, data = nil) process_response(@httpclient.put(uri, data)) end |