akamai-authtoken 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/akamai/authtoken.rb +49 -11
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1d6b93d6b4ddac65963b2a51b60ad4c003f79a7
4
- data.tar.gz: b0c1e74bd7c1b55ceb4f50ea31735a391b9125db
3
+ metadata.gz: c2f1acf762f72f6892eb2fd69819c4b19eca5e56
4
+ data.tar.gz: ca26f0256e2ff5cfd4ed4da6b403b36dc1c81328
5
5
  SHA512:
6
- metadata.gz: 934edf4bc3495870db8fab8aa8b27d7b69daff39fb62da7d40fe9834385986e924d4dae34313d8e03e29486d7acf392d2396d06ec16163b0bba7abd933bbb3e9
7
- data.tar.gz: 7a66faa06156f420af5e8c31acdb3740b0a66266c738782dfded6337e923b88be119d242492b38c0ec5a5dc510c0e1061ab25139f2d5893613e6473d0130876c
6
+ metadata.gz: c1ba618224e2d14f2620c86992c47f8737d0a054360dfa03d6d640b9b60d9a05ab9d00958ddd6f7cc09452d0aa08b786119d8a36fc7a911e6c4c287e5d58fb38
7
+ data.tar.gz: 5fd23496d859d0ae0813d6e98e60936d9613ba6484aebbcb3b83bca432ccdaeacd5a63420107c95e1befb23899a506b6dee9306060dd3475dade942d5ae61bef
@@ -1,3 +1,18 @@
1
+ # Copyright 2017 Akamai Technologies http://developer.akamai.com.
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
1
16
  require 'cgi'
2
17
  require 'openssl'
3
18
  require 'optparse'
@@ -5,6 +20,7 @@ require 'optparse'
5
20
 
6
21
  ENV['TZ'] = 'GMT'
7
22
 
23
+
8
24
  module Akamai
9
25
  class AuthTokenError < Exception
10
26
  """Base-class for all exceptions raised by AuthToken Class"""
@@ -16,10 +32,14 @@ module Akamai
16
32
  :start_time, :end_time, :window_secondse, :field_delimiter,
17
33
  :acl_delimiter, :escape_early, :verbose
18
34
 
35
+ @@acl_delimiter = '!'
36
+ def self.ACL_DELIMITER
37
+ @@acl_delimiter
38
+ end
39
+
19
40
  def initialize(token_type: nil, token_name: '__token__', key: nil,
20
41
  algorithm: 'sha256', salt: nil, start_time: nil, end_time: nil,
21
- window_seconds: nil, field_delimiter: '~', acl_delimiter: '!',
22
- escape_early: false, verbose: false)
42
+ window_seconds: nil, field_delimiter: '~', escape_early: false, verbose: false)
23
43
 
24
44
  @token_type = token_type
25
45
  @token_name = token_name
@@ -34,7 +54,6 @@ module Akamai
34
54
  @algorithm = algorithm
35
55
  @salt = salt
36
56
  @field_delimiter = field_delimiter
37
- @acl_delimiter = acl_delimiter
38
57
  @escape_early = escape_early
39
58
  @verbose = verbose
40
59
  end
@@ -62,16 +81,35 @@ module Akamai
62
81
 
63
82
  if start_time.to_s.downcase == 'now'
64
83
  start_time = Time.new.getgm.to_i
65
- elsif start_time && !(start_time.is_a? Integer)
66
- raise AuthTokenError, 'start_time must be numeric or now'
84
+ elsif start_time
85
+ begin
86
+ if start_time <= 0
87
+ raise AuthTokenError, 'start_time must be ( > 0 )'
88
+ end
89
+ rescue
90
+ raise AuthTokenError, 'start_time must be numeric or now'
91
+ end
92
+
67
93
  end
68
94
 
69
- if end_time && !(end_time.is_a? Integer)
70
- raise AuthTokenError, 'end_time must be numeric or now'
95
+ if end_time
96
+ begin
97
+ if end_time <= 0
98
+ raise AuthTokenError, 'end_time must be ( > 0 )'
99
+ end
100
+ rescue
101
+ raise AuthTokenError, 'end_time must be numeric'
102
+ end
71
103
  end
72
104
 
73
- if window_seconds && !(window_seconds.is_a? Integer)
74
- raise AuthTokenError, 'window_seconds must be numeric or now'
105
+ if window_seconds
106
+ begin
107
+ if window_seconds <= 0
108
+ raise AuthTokenError, 'window_seconds must be ( > 0 )'
109
+ end
110
+ rescue
111
+ raise AuthTokenError, 'window_seconds must be numeric'
112
+ end
75
113
  end
76
114
 
77
115
  if !end_time
@@ -86,7 +124,7 @@ module Akamai
86
124
  end
87
125
  end
88
126
 
89
- if start_time && end_time < start_time
127
+ if start_time && end_time <= start_time
90
128
  raise AuthTokenError, 'Token will have already expired.'
91
129
  end
92
130
 
@@ -110,7 +148,7 @@ module Akamai
110
148
  puts "Salt : #{@salt}"
111
149
  puts "Session ID : #{session_id}"
112
150
  puts "Field Delimiter : #{@field_delimiter}"
113
- puts "ACL Delimiter : #{@acl_delimiter}"
151
+ puts "ACL Delimiter : #{@@acl_delimiter}"
114
152
  puts "Escape Early : #{@escape_early}"
115
153
  end
116
154
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akamai-authtoken
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Astin Choi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-09 00:00:00.000000000 Z
11
+ date: 2017-03-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Akamai-AuthToken is Akamai Authorization Token for Ruby 2.0+
14
14
  email: achoi@akamai.com