cassette 1.0.2 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/README.md +125 -106
- data/lib/cassette/authentication/authorities.rb +5 -5
- data/lib/cassette/authentication/cache.rb +5 -6
- data/lib/cassette/authentication/filter.rb +9 -9
- data/lib/cassette/authentication/user.rb +4 -4
- data/lib/cassette/authentication.rb +9 -9
- data/lib/cassette/cache.rb +2 -4
- data/lib/cassette/client/cache.rb +12 -12
- data/lib/cassette/client.rb +11 -16
- data/lib/cassette/errors/not_a_customer.rb +1 -2
- data/lib/cassette/errors/not_an_employee.rb +1 -2
- data/lib/cassette/errors.rb +8 -8
- data/lib/cassette/rubycas/helper.rb +21 -25
- data/lib/cassette/rubycas/not_single_sign_out_constraint.rb +1 -2
- data/lib/cassette/rubycas/single_sign_out_constraint.rb +6 -7
- data/lib/cassette/rubycas.rb +3 -4
- data/lib/cassette/version.rb +6 -10
- data/lib/cassette.rb +21 -21
- data/spec/cas_spec.rb +21 -21
- data/spec/cassette/authentication/authorities_spec.rb +82 -0
- data/spec/{cas → cassette}/authentication/cache_spec.rb +0 -0
- data/spec/{cas → cassette}/authentication/filter_spec.rb +52 -53
- data/spec/cassette/authentication/user_spec.rb +70 -0
- data/spec/cassette/authentication_spec.rb +84 -0
- data/spec/{cas → cassette}/cache_spec.rb +7 -8
- data/spec/{cas → cassette}/client/cache_spec.rb +0 -0
- data/spec/{cas → cassette}/errors_spec.rb +6 -6
- data/spec/config.yml +4 -4
- data/spec/integration/cas/client_spec.rb +32 -31
- data/spec/spec_helper.rb +7 -7
- metadata +57 -57
- data/spec/cas/authentication/authorities_spec.rb +0 -82
- data/spec/cas/authentication/user_spec.rb +0 -70
- data/spec/cas/authentication_spec.rb +0 -84
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NDE0YzllMWRjN2E0M2RlNGJiN2JjY2MzYTdkZGRmNGMwOTYyZDljNQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 544f24bd7aba263a362e116e0b478bc0096ca5ef
|
4
|
+
data.tar.gz: c07059b72cc076c904880bcbb2e22a6eb8347952
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
OTQyNDdhN2I4MjE0ODE0ZTZjZmUyNjQ1NzgzMDM1NjJiOGUzYTQ3MDZmZDBm
|
11
|
-
Y2QyZDRjMWQ3MTZkNjBkMGIxMzExMmZjOThlNzk5OGU1OGI4Mzk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
M2QxMzhjOTJlNzUwNDk1NDE0ZWM1YjBjNDY0MTI2MmVhYTY3NTkzMjcwYjM4
|
14
|
-
YTYwZmM0NTQ5NzcxYzc3NGIwYWMyZjRhYjY1NTQwMzhlMmU1Nzg0N2JmNGJk
|
15
|
-
MjU4MjZlNDBjZTBmNWVmODI1MDIwZmQzZmU0MGU3YmE2YTRiZWQ=
|
6
|
+
metadata.gz: 7af98b5bc6c3070704b139b0cab9cbc8da25d646955036adc2335ea225ea241708ef7aa998440d233d0b4bd58ba4c5e5df9c2a5c788e17d9c55f700577feef31
|
7
|
+
data.tar.gz: fe36aae7cdbb1ddaf2ed77504181eb53885ab7aed58467cee87ca474932ea0541e0c7b96feb7839e4884d81f58140d6e5a84635f5267b0a4e71b0d12caf1ff93
|
data/README.md
CHANGED
@@ -1,106 +1,125 @@
|
|
1
|
-
# Cassette::Client
|
2
|
-
|
3
|
-
Library to generate and validate STs and TGTs
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
1
|
+
# Cassette::Client
|
2
|
+
|
3
|
+
Library to generate and validate STs and TGTs
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'cassette'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```shell
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Require this library and create an intializer to set its configuration:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Cassette.config = config
|
25
|
+
```
|
26
|
+
|
27
|
+
where config is an object that responds to the methods #base for the base CAS uri, #username and #password
|
28
|
+
if you are authenticating on other systems and #service and #base\_authority if you are using the authentication filter
|
29
|
+
to authenticate your app
|
30
|
+
|
31
|
+
|
32
|
+
You may also set the caching backend using the .backend= module method:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
Cassette::Cache.backend = ActiveSupport::Cache::MemcacheStorage.new
|
36
|
+
```
|
37
|
+
|
38
|
+
By default, Cassette::Cache will check if you have Rails.cache defined or instantiate a new ActiveSupport::Cache::MemoryStore
|
39
|
+
|
40
|
+
|
41
|
+
To authenticate your Rails app, add to your ApplicationController (or any authenticated controller):
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class ApplicationController < ActionController::Base
|
45
|
+
include Cassette::Authentication::Filter
|
46
|
+
|
47
|
+
# ...
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
You should also rescue from Cassette::Errors::Forbidden with more friendly errors
|
52
|
+
|
53
|
+
If you wish to have actions that skip the authentication filter, add to your controller:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
class SomeController < ApplicationController
|
57
|
+
skip_authentication # [*options]
|
58
|
+
|
59
|
+
# skip_authentication only: "index"
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
Where options are the same options you can pass to Rails' __skip_before_filter__ method
|
64
|
+
|
65
|
+
## RubyCAS client helpers
|
66
|
+
|
67
|
+
|
68
|
+
If you are authenticating users with RubyCAS and want role checking, in your rubycas initializer:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
require "cas/rubycas"
|
72
|
+
```
|
73
|
+
|
74
|
+
And in your ApplicationController (or any authenticated controller):
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
class SomeController < ApplicationController
|
78
|
+
include Cassette::Rubycas::Helper
|
79
|
+
|
80
|
+
# - Allow only employees:
|
81
|
+
#
|
82
|
+
# before_filter :employee_only_filter
|
83
|
+
#
|
84
|
+
# rescue_from Cassette::Errors::NotAnEmployee do
|
85
|
+
# redirect_to '/403.html'
|
86
|
+
# end
|
87
|
+
|
88
|
+
# - Allow only customers:
|
89
|
+
#
|
90
|
+
# before_filter :customer_only_filter
|
91
|
+
#
|
92
|
+
# rescue_from Cassette::Errors::NotACustomer do
|
93
|
+
# redirect_to '/403.html'
|
94
|
+
# end
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
## Instantiating Cassette::Client and Cassette::Authentication
|
99
|
+
|
100
|
+
You can create your own instances of __Cassette::Client__ (st/tgt generator) and __Cassette::Authentication__ (st validator).
|
101
|
+
|
102
|
+
The constructor accepts a hash with keys (as symbols) for the values of cache, logger, http_client and configuration.
|
103
|
+
|
104
|
+
All values default to the same values used when accessing the class methods directly.
|
105
|
+
|
106
|
+
Please check the constructors or integration specs for details.
|
107
|
+
|
108
|
+
## About caching and tests
|
109
|
+
|
110
|
+
It is a good idea to always clear the cache between tests, specially if you're
|
111
|
+
using VCR. You can do it by using the invoking the `#clear` method of the cache
|
112
|
+
backend in use. The following excerpt will clear the cache of the default client
|
113
|
+
`Cassette::Client` instance:
|
114
|
+
|
115
|
+
```
|
116
|
+
Cassette::Client.cache.backend.clear
|
117
|
+
```
|
118
|
+
|
119
|
+
## Contributing
|
120
|
+
|
121
|
+
1. Fork it
|
122
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
123
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
124
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
125
|
+
5. Create new Pull Request
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'cassette/authentication'
|
4
4
|
|
5
5
|
class Cassette::Authentication::Authorities
|
6
6
|
def self.parse(authorities, base_authority = nil)
|
@@ -12,20 +12,20 @@ class Cassette::Authentication::Authorities
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def has_raw_role?(role)
|
15
|
-
return true if ENV[
|
15
|
+
return true if ENV['NOAUTH']
|
16
16
|
@authorities.include?(role)
|
17
17
|
end
|
18
18
|
|
19
19
|
def has_role?(role)
|
20
|
-
return true if ENV[
|
21
|
-
has_raw_role?("#{base}_#{role.to_s.upcase.gsub(
|
20
|
+
return true if ENV['NOAUTH']
|
21
|
+
has_raw_role?("#{base}_#{role.to_s.upcase.gsub('_', '-')}")
|
22
22
|
end
|
23
23
|
|
24
24
|
def initialize(authorities, base_authority = nil)
|
25
25
|
@base_authority = base_authority || Cassette.config.base_authority
|
26
26
|
|
27
27
|
if authorities.is_a?(String)
|
28
|
-
@authorities = authorities.gsub(/^\[(.*)\]$/,
|
28
|
+
@authorities = authorities.gsub(/^\[(.*)\]$/, '\\1').split(',').map(&:strip)
|
29
29
|
else
|
30
30
|
@authorities = Array(authorities).map(&:strip)
|
31
31
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'cassette/authentication'
|
4
|
+
require 'cassette/cache'
|
5
5
|
|
6
6
|
class Cassette::Authentication::Cache
|
7
7
|
include Cassette::Cache
|
@@ -11,7 +11,7 @@ class Cassette::Authentication::Cache
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def fetch_authentication(ticket, options = {}, &block)
|
14
|
-
options = {expires_in: 5 * 60, max_uses: 5000, force: false}.merge(options)
|
14
|
+
options = { expires_in: 5 * 60, max_uses: 5000, force: false }.merge(options)
|
15
15
|
fetch("Cassette::Authentication.validate_ticket(#{ticket})", options) do
|
16
16
|
logger.info("Authentication for #{ticket} is not cached")
|
17
17
|
block.call
|
@@ -19,12 +19,11 @@ class Cassette::Authentication::Cache
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def clear_authentication_cache!
|
22
|
-
backend.delete_matched(
|
23
|
-
backend.delete_matched("#{uses_key(
|
22
|
+
backend.delete_matched('Cassette::Authentication.validate_ticket*')
|
23
|
+
backend.delete_matched("#{uses_key('Cassette::Authentication.validate_ticket')}*")
|
24
24
|
end
|
25
25
|
|
26
26
|
protected
|
27
27
|
|
28
28
|
attr_accessor :logger
|
29
29
|
end
|
30
|
-
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'cassette/authentication/user'
|
5
5
|
|
6
6
|
module Cassette::Authentication::Filter
|
7
7
|
extend ActiveSupport::Concern
|
@@ -18,10 +18,10 @@ module Cassette::Authentication::Filter
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def validate_authentication_ticket(service = Cassette.config.service)
|
21
|
-
ticket = request.headers[
|
21
|
+
ticket = request.headers['Service-Ticket'] || params[:ticket]
|
22
22
|
|
23
|
-
if ENV[
|
24
|
-
Cassette.logger.debug
|
23
|
+
if ENV['NOAUTH']
|
24
|
+
Cassette.logger.debug 'NOAUTH set and no Service Ticket, skipping authentication'
|
25
25
|
self.current_user = Cassette::Authentication::User.new
|
26
26
|
return
|
27
27
|
end
|
@@ -30,12 +30,12 @@ module Cassette::Authentication::Filter
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def validate_role!(role)
|
33
|
-
return if ENV[
|
34
|
-
|
33
|
+
return if ENV['NOAUTH']
|
34
|
+
fail Cassette::Errors::Forbidden unless current_user.has_role?(role)
|
35
35
|
end
|
36
36
|
|
37
37
|
def validate_raw_role!(role)
|
38
|
-
return if ENV[
|
39
|
-
|
38
|
+
return if ENV['NOAUTH']
|
39
|
+
fail Cassette::Errors::Forbidden unless current_user.has_raw_role?(role)
|
40
40
|
end
|
41
41
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require 'cassette/authentication'
|
4
|
+
require 'cassette/authentication/authorities'
|
5
|
+
require 'delegate'
|
6
6
|
|
7
7
|
class Cassette::Authentication::User
|
8
8
|
attr_accessor :login, :name, :authorities, :email, :ticket
|
@@ -16,7 +16,7 @@ class Cassette::Authentication::User
|
|
16
16
|
@email = attrs[:email]
|
17
17
|
@ticket = attrs[:ticket]
|
18
18
|
@authorities = Cassette::Authentication::Authorities
|
19
|
-
|
19
|
+
.parse(attrs.fetch(:authorities, '[]'), config && config.base_authority)
|
20
20
|
end
|
21
21
|
|
22
22
|
%w(customer employee).each do |type|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'active_support/xml_mini'
|
4
4
|
ActiveSupport::XmlMini.backend = 'LibXML'
|
5
5
|
|
6
6
|
module Cassette
|
@@ -19,12 +19,12 @@ module Cassette
|
|
19
19
|
|
20
20
|
def validate_ticket(ticket, service = config.service)
|
21
21
|
logger.debug "Cassette::Authentication validating ticket: #{ticket}"
|
22
|
-
|
22
|
+
fail Cassette::Errors::AuthorizationRequired if ticket.nil? || ticket.blank?
|
23
23
|
|
24
24
|
user = ticket_user(ticket, service)
|
25
25
|
logger.info "Cassette::Authentication user: #{user.inspect}"
|
26
26
|
|
27
|
-
|
27
|
+
fail Cassette::Errors::Forbidden unless user
|
28
28
|
|
29
29
|
user
|
30
30
|
end
|
@@ -39,15 +39,15 @@ module Cassette
|
|
39
39
|
|
40
40
|
user = nil
|
41
41
|
|
42
|
-
ActiveSupport::XmlMini.with_backend(
|
42
|
+
ActiveSupport::XmlMini.with_backend('LibXML') do
|
43
43
|
result = ActiveSupport::XmlMini.parse(response)
|
44
44
|
|
45
|
-
login = result.try(:[],
|
45
|
+
login = result.try(:[], 'serviceResponse').try(:[], 'authenticationSuccess').try(:[], 'user').try(:[], '__content__')
|
46
46
|
|
47
47
|
if login
|
48
|
-
attributes = result[
|
49
|
-
name = attributes.try(:[],
|
50
|
-
authorities = attributes.try(:[],
|
48
|
+
attributes = result['serviceResponse']['authenticationSuccess']['attributes']
|
49
|
+
name = attributes.try(:[], 'cn').try(:[], '__content__')
|
50
|
+
authorities = attributes.try(:[], 'authorities').try(:[], '__content__')
|
51
51
|
|
52
52
|
user = Cassette::Authentication::User.new(login: login, name: name, authorities: authorities, ticket: ticket, config: config)
|
53
53
|
end
|
@@ -66,7 +66,7 @@ module Cassette
|
|
66
66
|
attr_accessor :cache, :logger, :http, :config
|
67
67
|
|
68
68
|
def validate_uri
|
69
|
-
"#{config.base.gsub(/\/?$/,
|
69
|
+
"#{config.base.gsub(/\/?$/, '')}/serviceValidate"
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
data/lib/cassette/cache.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'active_support/cache'
|
4
4
|
|
5
5
|
module Cassette
|
6
6
|
module Cache
|
@@ -14,9 +14,7 @@ module Cassette
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
@backend = backend
|
19
|
-
end
|
17
|
+
attr_writer :backend
|
20
18
|
|
21
19
|
def uses_key(key)
|
22
20
|
"uses:#{key}"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'cassette/client'
|
4
|
+
require 'cassette/cache'
|
5
5
|
|
6
6
|
class Cassette::Client::Cache
|
7
7
|
include Cassette::Cache
|
@@ -10,17 +10,17 @@ class Cassette::Client::Cache
|
|
10
10
|
self.logger = logger
|
11
11
|
end
|
12
12
|
|
13
|
-
def fetch_tgt(options = {}, &
|
14
|
-
options = {expires_in: 4 * 3600, max_uses: 5000, force: false}.merge(options)
|
15
|
-
fetch(
|
13
|
+
def fetch_tgt(options = {}, &_block)
|
14
|
+
options = { expires_in: 4 * 3600, max_uses: 5000, force: false }.merge(options)
|
15
|
+
fetch('Cassette::Client.tgt', options) do
|
16
16
|
self.clear_st_cache!
|
17
|
-
logger.info
|
17
|
+
logger.info 'TGT is not cached'
|
18
18
|
yield
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def fetch_st(service, options = {}, &
|
23
|
-
options = {max_uses: 2000, expires_in: 252, force: false}.merge(options)
|
22
|
+
def fetch_st(service, options = {}, &_block)
|
23
|
+
options = { max_uses: 2000, expires_in: 252, force: false }.merge(options)
|
24
24
|
fetch("Cassette::Client.st(#{service})", options) do
|
25
25
|
logger.info "ST for #{service} is not cached"
|
26
26
|
yield
|
@@ -28,13 +28,13 @@ class Cassette::Client::Cache
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def clear_tgt_cache!
|
31
|
-
backend.delete(
|
32
|
-
backend.delete("#{uses_key(
|
31
|
+
backend.delete('Cassette::Client.tgt')
|
32
|
+
backend.delete("#{uses_key('Cassette::Client.tgt')}")
|
33
33
|
end
|
34
34
|
|
35
35
|
def clear_st_cache!
|
36
|
-
backend.delete_matched(
|
37
|
-
backend.delete_matched("#{uses_key(
|
36
|
+
backend.delete_matched('Cassette::Client.st*')
|
37
|
+
backend.delete_matched("#{uses_key('Cassette::Client.st')}*")
|
38
38
|
end
|
39
39
|
|
40
40
|
protected
|
data/lib/cassette/client.rb
CHANGED
@@ -15,14 +15,14 @@ module Cassette
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def health_check
|
18
|
-
st_for(
|
18
|
+
st_for('monitoring')
|
19
19
|
end
|
20
20
|
|
21
21
|
def tgt(usr, pwd, force = false)
|
22
|
-
logger.info
|
22
|
+
logger.info 'Requesting TGT'
|
23
23
|
cache.fetch_tgt(force: force) do
|
24
24
|
response = http.post(tickets_uri, username: usr, password: pwd)
|
25
|
-
tgt =
|
25
|
+
tgt = Regexp.last_match(1) if response.headers['Location'] =~ /tickets\/(.*)/
|
26
26
|
logger.info "TGT is #{tgt}"
|
27
27
|
tgt
|
28
28
|
end
|
@@ -46,23 +46,18 @@ module Cassette
|
|
46
46
|
|
47
47
|
attr_accessor :cache, :logger, :http, :config
|
48
48
|
|
49
|
-
def st_with_retry(user, pass, service)
|
49
|
+
def st_with_retry(user, pass, service, retrying = true)
|
50
|
+
st(tgt(user, pass, retrying), service)
|
51
|
+
rescue Cassette::Errors::NotFound => e
|
52
|
+
raise e unless retrying
|
53
|
+
|
54
|
+
logger.info 'Got 404 response, regenerating TGT'
|
50
55
|
retrying = false
|
51
|
-
|
52
|
-
st(tgt(user, pass, retrying), service)
|
53
|
-
rescue Cassette::Errors::NotFound => e
|
54
|
-
unless retrying
|
55
|
-
logger.info "Got 404 response, regenerating TGT"
|
56
|
-
retrying = true
|
57
|
-
retry
|
58
|
-
end
|
59
|
-
raise e
|
60
|
-
end
|
56
|
+
retry
|
61
57
|
end
|
62
58
|
|
63
59
|
def tickets_uri
|
64
|
-
"#{config.base.gsub(/\/?$/,
|
60
|
+
"#{config.base.gsub(/\/?$/, '')}/v1/tickets"
|
65
61
|
end
|
66
62
|
end
|
67
63
|
end
|
68
|
-
|
data/lib/cassette/errors.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'active_support/inflector'
|
4
4
|
|
5
5
|
module Cassette
|
6
6
|
module Errors
|
@@ -10,16 +10,16 @@ module Cassette
|
|
10
10
|
403 => :forbidden,
|
11
11
|
500 => :internal_server_error,
|
12
12
|
404 => :not_found,
|
13
|
-
412 => :precondition_failed
|
13
|
+
412 => :precondition_failed
|
14
14
|
}
|
15
15
|
|
16
16
|
def self.raise_by_code(code)
|
17
17
|
name = TYPES[code.to_i]
|
18
18
|
|
19
19
|
if name
|
20
|
-
|
20
|
+
fail error_class(name)
|
21
21
|
else
|
22
|
-
|
22
|
+
fail error_class(:internal_server_error)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -29,16 +29,16 @@ module Cassette
|
|
29
29
|
|
30
30
|
class Base < StandardError
|
31
31
|
def code
|
32
|
-
self.class.const_get(
|
32
|
+
self.class.const_get('CODE')
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
TYPES.each do |status, name|
|
37
37
|
const_set(name.to_s.camelize, Class.new(Errors::Base))
|
38
|
-
error_class(name).const_set(
|
38
|
+
error_class(name).const_set('CODE', status)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
require
|
44
|
-
require
|
43
|
+
require 'cassette/errors/not_an_employee'
|
44
|
+
require 'cassette/errors/not_a_customer'
|