Class: Cassette::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cassette/client.rb,
lib/cassette/client/cache.rb

Defined Under Namespace

Classes: Cache

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client


10
11
12
13
14
15
# File 'lib/cassette/client.rb', line 10

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


5
6
7
8
# File 'lib/cassette/client.rb', line 5

def self.method_missing(name, *args)
  @default_client ||= new
  @default_client.send(name, *args)
end

Instance Method Details

#health_checkObject


17
18
19
# File 'lib/cassette/client.rb', line 17

def health_check
  st_for('monitoring')
end

#st(tgt_param, service, force = false) ⇒ Object


31
32
33
34
35
36
37
38
39
40
# File 'lib/cassette/client.rb', line 31

def st(tgt_param, service, force = false)
  logger.info "Requesting ST for #{service}"
  cache.fetch_st(service, force: force) do
    tgt = tgt_param.respond_to?(:call) ? tgt_param[] : tgt_param
    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


42
43
44
# File 'lib/cassette/client.rb', line 42

def st_for(service_name)
  st_with_retry(config.username, config.password, service_name)
end

#tgt(usr, pwd, force = false) ⇒ Object


21
22
23
24
25
26
27
28
29
# File 'lib/cassette/client.rb', line 21

def tgt(usr, pwd, force = false)
  logger.info 'Requesting TGT'
  cache.fetch_tgt(force: force) do
    response = http.post(tickets_path, username: usr, password: pwd)
    tgt = Regexp.last_match(1) if response.headers['Location'] =~ /tickets\/(.*)/
    logger.info "TGT is #{tgt}"
    tgt
  end
end