Class: Cassette::Client

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

Defined Under Namespace

Classes: Cache

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of 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)
  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, service, force = false) ⇒ Object



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

def st(tgt, service, force = false)
  logger.info "Requesting ST for #{service}"
  cache.fetch_st(service, force: force) do
    response = http.post("#{tickets_uri}/#{tgt}", service: service)
    response.body.tap do |st|
      logger.info "ST is #{st}"
    end
  end
end

#st_for(service_name) ⇒ Object



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

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_uri, username: usr, password: pwd)
    tgt = $1 if response.headers["Location"] =~ /tickets\/(.*)/
    logger.info "TGT is #{tgt}"
    tgt
  end
end