akamai-edgeauth 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/akamai/edgeauth.rb +54 -49
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 972a9f038408d8bc267683e7199b6c85b3c61b61
|
4
|
+
data.tar.gz: a9894996173a88191e669ab6d49c44b33da5956a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 023fdd09d3000b585c61480ba5e3aac04eae4ce613f377f2a6e5371b83515267b7228e2456bad01803d5c1df9ece7eed93ba2978959a8c30f4e00485985ee975
|
7
|
+
data.tar.gz: 6e720ca2f55c1dff666fe0a5c462474d1757287718b0538cbf408fb38bfc02b43974f4a89ec3efe29b3ab8deaa9a879955663eae6c613a37ab9c538e65684a6d
|
data/lib/akamai/edgeauth.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2018 Akamai Technologies http://developer.akamai.com.
|
2
2
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -28,32 +28,34 @@ module Akamai
|
|
28
28
|
|
29
29
|
|
30
30
|
class EdgeAuth
|
31
|
-
attr_accessor :token_type, :token_name, :key, :algorithm, :salt,
|
32
|
-
:
|
33
|
-
:
|
31
|
+
attr_accessor :token_type, :token_name, :key, :algorithm, :salt,
|
32
|
+
:ip, :payload, :session_id, :start_time, :end_time,
|
33
|
+
:window_seconds, :field_delimiter, :acl_delimiter,
|
34
|
+
:escape_early, :verbose
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
algorithm: 'sha256', salt: nil, start_time: nil, end_time: nil,
|
42
|
-
window_seconds: nil, field_delimiter: '~', escape_early: false, verbose: false)
|
43
|
-
|
36
|
+
def initialize(token_type: nil, token_name: '__token__',
|
37
|
+
key: nil, algorithm: 'sha256', salt: nil,
|
38
|
+
ip: nil, payload: nil, session_id: nil,
|
39
|
+
start_time: nil, end_time: nil, window_seconds: nil,
|
40
|
+
field_delimiter: '~', acl_delimiter: '!',
|
41
|
+
escape_early: false, verbose: false)
|
44
42
|
@token_type = token_type
|
45
43
|
@token_name = token_name
|
46
|
-
@start_time = start_time
|
47
|
-
@end_time = end_time
|
48
|
-
@window_seconds = window_seconds
|
49
44
|
if !key || key.length <= 0
|
50
45
|
raise EdgeAuthError,
|
51
46
|
'You must provide a secret in order to generate a new token.'
|
52
47
|
end
|
53
48
|
@key = key
|
54
|
-
@algorithm = algorithm
|
55
49
|
@salt = salt
|
50
|
+
@algorithm = algorithm
|
51
|
+
@ip = ip
|
52
|
+
@payload = payload
|
53
|
+
@session_id = session_id
|
54
|
+
@start_time = start_time
|
55
|
+
@end_time = end_time
|
56
|
+
@window_seconds = window_seconds
|
56
57
|
@field_delimiter = field_delimiter
|
58
|
+
@acl_delimiter = acl_delimiter
|
57
59
|
@escape_early = escape_early
|
58
60
|
@verbose = verbose
|
59
61
|
end
|
@@ -66,18 +68,9 @@ module Akamai
|
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
72
|
-
if !start_time
|
73
|
-
start_time = @start_time
|
74
|
-
end
|
75
|
-
if !end_time
|
76
|
-
end_time = @end_time
|
77
|
-
end
|
78
|
-
if !window_seconds
|
79
|
-
window_seconds = @window_seconds
|
80
|
-
end
|
71
|
+
def _generateToken(path, isUrl)
|
72
|
+
start_time = @start_time
|
73
|
+
end_time = @end_time
|
81
74
|
|
82
75
|
if start_time.to_s.downcase == 'now'
|
83
76
|
start_time = Time.new.getgm.to_i
|
@@ -102,9 +95,9 @@ module Akamai
|
|
102
95
|
end
|
103
96
|
end
|
104
97
|
|
105
|
-
if window_seconds
|
98
|
+
if @window_seconds
|
106
99
|
begin
|
107
|
-
if window_seconds <= 0
|
100
|
+
if @window_seconds <= 0
|
108
101
|
raise EdgeAuthError, 'window_seconds must be ( > 0 )'
|
109
102
|
end
|
110
103
|
rescue
|
@@ -113,11 +106,11 @@ module Akamai
|
|
113
106
|
end
|
114
107
|
|
115
108
|
if !end_time
|
116
|
-
if window_seconds
|
109
|
+
if @window_seconds
|
117
110
|
if !start_time
|
118
|
-
end_time = Time.new.getgm.to_i + window_seconds
|
111
|
+
end_time = Time.new.getgm.to_i + @window_seconds
|
119
112
|
else
|
120
|
-
end_time = start_time + window_seconds
|
113
|
+
end_time = start_time + @window_seconds
|
121
114
|
end
|
122
115
|
else
|
123
116
|
raise EdgeAuthError, 'You must provide an expiration time or a duration window..'
|
@@ -128,27 +121,22 @@ module Akamai
|
|
128
121
|
raise EdgeAuthError, 'Token will have already expired.'
|
129
122
|
end
|
130
123
|
|
131
|
-
if (!acl && !url) || (acl && url)
|
132
|
-
raise EdgeAuthError, 'You must provide a URL or an ACL'
|
133
|
-
end
|
134
|
-
|
135
124
|
if @verbose
|
136
125
|
puts "Akamai Token Generation Parameters"
|
137
126
|
puts "Token Type : #{@token_type}"
|
138
127
|
puts "Token Name : #{@token_name}"
|
139
128
|
puts "Start Time : #{start_time}"
|
140
129
|
puts "End Time : #{end_time}"
|
141
|
-
puts "Window(seconds) : #{window_seconds}"
|
142
|
-
puts "IP : #{ip}"
|
143
|
-
puts "URL
|
144
|
-
puts "ACL : #{acl}"
|
130
|
+
puts "Window(seconds) : #{@window_seconds}"
|
131
|
+
puts "IP : #{@ip}"
|
132
|
+
puts "URL/ACL : #{path}"
|
145
133
|
puts "Key/Secret : #{@key}"
|
146
|
-
puts "Payload : #{payload}"
|
134
|
+
puts "Payload : #{@payload}"
|
147
135
|
puts "Algo : #{@algo}"
|
148
136
|
puts "Salt : #{@salt}"
|
149
|
-
puts "Session ID : #{session_id}"
|
137
|
+
puts "Session ID : #{@session_id}"
|
150
138
|
puts "Field Delimiter : #{@field_delimiter}"
|
151
|
-
puts "ACL Delimiter : #{
|
139
|
+
puts "ACL Delimiter : #{@acl_delimiter}"
|
152
140
|
puts "Escape Early : #{@escape_early}"
|
153
141
|
end
|
154
142
|
|
@@ -163,8 +151,8 @@ module Akamai
|
|
163
151
|
end
|
164
152
|
new_token.push('exp=%s' % end_time)
|
165
153
|
|
166
|
-
if
|
167
|
-
new_token.push('acl=%s' %
|
154
|
+
if !isUrl
|
155
|
+
new_token.push('acl=%s' % path)
|
168
156
|
end
|
169
157
|
if session_id
|
170
158
|
new_token.push('id=%s' % _escapeEarly(session_id))
|
@@ -175,8 +163,8 @@ module Akamai
|
|
175
163
|
|
176
164
|
hash_code = new_token.clone
|
177
165
|
|
178
|
-
if
|
179
|
-
hash_code.push('url=%s' % _escapeEarly(
|
166
|
+
if isUrl
|
167
|
+
hash_code.push('url=%s' % _escapeEarly(path))
|
180
168
|
end
|
181
169
|
|
182
170
|
if @salt
|
@@ -195,5 +183,22 @@ module Akamai
|
|
195
183
|
|
196
184
|
return new_token.join(@field_delimiter)
|
197
185
|
end
|
186
|
+
|
187
|
+
def generateACLToken(acl)
|
188
|
+
if !acl
|
189
|
+
raise EdgeAuthError, 'You must provide the ACL(s)'
|
190
|
+
elsif acl.is_a?(Array)
|
191
|
+
acl = acl.join(@acl_delimiter)
|
192
|
+
end
|
193
|
+
return _generateToken(acl, false)
|
194
|
+
end
|
195
|
+
|
196
|
+
def generateURLToken(url)
|
197
|
+
if !url
|
198
|
+
raise EdgeAuthError, 'You must provide a URL'
|
199
|
+
end
|
200
|
+
|
201
|
+
return _generateToken(url, true)
|
202
|
+
end
|
198
203
|
end
|
199
204
|
end
|
metadata
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: akamai-edgeauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Astin Choi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Akamai-EdgeAuth is Akamai Edge Authorization Token for Ruby 2.0+
|
14
|
-
email:
|
14
|
+
email: asciineo@gmail.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/akamai/edgeauth.rb
|
20
|
-
homepage: https://github.com/
|
20
|
+
homepage: https://github.com/akamai/EdgeAuth-Token-Ruby
|
21
21
|
licenses:
|
22
22
|
- Apache-2.0
|
23
23
|
metadata: {}
|