Class: Cassette::Client
- Inherits:
-
Object
- Object
- Cassette::Client
- Defined in:
- lib/cassette/client.rb,
lib/cassette/client/cache.rb
Defined Under Namespace
Classes: Cache
Class Method Summary collapse
Instance Method Summary collapse
- #health_check ⇒ Object
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #st(tgt_param, service, force = false) ⇒ Object
- #st_for(service_name) ⇒ Object
- #tgt(usr, pwd, force = false) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 |
# File 'lib/cassette/client.rb', line 8 def initialize(opts = {}) self.config = opts.fetch(:config, Cassette.config) self.logger = opts.fetch(:logger, Cassette.logger) self.http = opts.fetch(:http_client, Cassette::Http::Request.new(config)) self.cache = opts.fetch(:cache, Cassette::Client::Cache.new(logger)) end |
Class Method Details
.method_missing(name, *args) ⇒ Object
3 4 5 6 |
# File 'lib/cassette/client.rb', line 3 def self.method_missing(name, *args) @default_client ||= new @default_client.send(name, *args) end |
Instance Method Details
#health_check ⇒ Object
15 16 17 |
# File 'lib/cassette/client.rb', line 15 def health_check st_for('monitoring') end |
#st(tgt_param, service, force = false) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cassette/client.rb', line 33 def st(tgt_param, service, force = false) logger.info "Requesting ST for #{service}" tgt = tgt_param.respond_to?(:call) ? tgt_param[] : tgt_param cache.fetch_st(tgt, service, force: force) do response = http.post("#{tickets_path}/#{tgt}", service: service) response.body.tap do |st| logger.info "ST is #{st}" end end end |
#st_for(service_name) ⇒ Object
45 46 47 |
# File 'lib/cassette/client.rb', line 45 def st_for(service_name) st_with_retry(config.username, config.password, service_name) end |
#tgt(usr, pwd, force = false) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cassette/client.rb', line 19 def tgt(usr, pwd, force = false) logger.info 'Requesting TGT' cached = true tgt = cache.fetch_tgt(force: force) do cached = false request_new_tgt(usr, pwd) end logger.info("TGT cache hit, value: '#{tgt}'") if cached tgt end |