akamai_ccu 1.4.1 → 1.5.0
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 +4 -4
- data/README.md +16 -29
- data/lib/akamai_ccu/cli.rb +3 -12
- data/lib/akamai_ccu/secret.rb +13 -15
- data/lib/akamai_ccu/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42d7a18832075e64a3b665f937ee63f160621d31
|
4
|
+
data.tar.gz: de91792521bce4ff10dbb5870bbd47794f48dc4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f54ecccd6a50ccd8a44b1506a42ace24cebde3b6fe8e7e0db33f4e4612717067acae2bd9a26c1baeb52f95b62d325d585af92e529af994cab60f9e21cf17c1a6
|
7
|
+
data.tar.gz: d08aed26cf776579064aa76662ad1f765daeb0c8ad860786967500beba34a0725a8aa5a72f51ba1890746cc819e535f06a97f6eda88f0dc3f4c03f841f78ae1c
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
* [edgerc](#edgerc)
|
9
9
|
* [txt](#txt)
|
10
10
|
* [Usage](#usage)
|
11
|
-
* [
|
11
|
+
* [Library](#library)
|
12
12
|
* [Secret](#secret)
|
13
13
|
* [Edge network](#edge-network)
|
14
14
|
* [Invalidating](#invalidating)
|
@@ -92,7 +92,7 @@ client_token = akab-client-token-xxx-xxx
|
|
92
92
|
|
93
93
|
## Usage
|
94
94
|
|
95
|
-
###
|
95
|
+
### Library
|
96
96
|
You can require the gem to use it as a library inside your scripts:
|
97
97
|
|
98
98
|
#### Secret
|
@@ -100,11 +100,8 @@ Once you've got APIs credentials, you can instantiate the secret object aimed to
|
|
100
100
|
```ruby
|
101
101
|
require "akamai_ccu"
|
102
102
|
|
103
|
-
# by .edgerc
|
104
|
-
secret = AkamaiCCU::Secret.
|
105
|
-
|
106
|
-
# by txt file
|
107
|
-
secret = AkamaiCCU::Secret.by_txt("tokens.txt")
|
103
|
+
# by file, both .edgerc or .txt one
|
104
|
+
secret = AkamaiCCU::Secret.by_file("~/tokens.txt") # default to ~/.edgerc
|
108
105
|
|
109
106
|
# by using initializer
|
110
107
|
secret = AkamaiCCU::Secret.new(client_secret: "xxx=", host: "akaa-baseurl-xxx-xxx.luna.akamaiapis.net/", access_token: "akab-access-token-xxx-xxx", client_token: "akab-client-token-xxx-xxx", max_body: 131072)
|
@@ -154,9 +151,8 @@ You can use the CLI by:
|
|
154
151
|
Calling the help for the specific action:
|
155
152
|
```shell
|
156
153
|
ccu_invalidate -h
|
157
|
-
Usage: ccu_invalidate --edgerc
|
158
|
-
-
|
159
|
-
-t, --txt=TXT Load secret by TXT file
|
154
|
+
Usage: ccu_invalidate --secret=~/.edgerc --production --cp="12345, 98765"
|
155
|
+
-s, --secret=SECRET Load secret data by file
|
160
156
|
-c, --cp=CP Specify contents by provider (CP) codes
|
161
157
|
-u, --url=URL Specify contents by URLs
|
162
158
|
-b, --bulk=BULK Specify bulk contents in a file
|
@@ -168,7 +164,7 @@ Usage: ccu_invalidate --edgerc=./.edgerc --production --cp="12345, 98765"
|
|
168
164
|
#### ccu_invalidate
|
169
165
|
Do request for contents invalidation by:
|
170
166
|
```shell
|
171
|
-
ccu_invalidate --
|
167
|
+
ccu_invalidate --secret=~/.edgerc \
|
172
168
|
--url=https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/main.css,https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/main.js \
|
173
169
|
--production
|
174
170
|
```
|
@@ -176,7 +172,7 @@ ccu_invalidate --edgerc=~/.edgerc \
|
|
176
172
|
#### ccu_delete
|
177
173
|
Do request for contents deletion by:
|
178
174
|
```shell
|
179
|
-
ccu_delete --
|
175
|
+
ccu_delete --secret=~/tokens.txt \
|
180
176
|
--cp=12345,98765 \
|
181
177
|
--headers=Accept,Content-Length
|
182
178
|
```
|
@@ -194,41 +190,32 @@ https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/static/index.html
|
|
194
190
|
|
195
191
|
Specify the bulk option by using the file path:
|
196
192
|
```shell
|
197
|
-
ccu_invalidate --
|
193
|
+
ccu_invalidate --secret=~/.edgerc --bulk=urls.txt
|
198
194
|
```
|
199
195
|
|
200
196
|
#### Redirecting output
|
201
197
|
In case you're calling the CLI from another program (like your Jenkins script), just redirect the output to your log file:
|
202
198
|
```shell
|
203
|
-
ccu_invalidate --
|
199
|
+
ccu_invalidate --secret=~/.edgerc --cp=12345,98765 >> mylog.log
|
204
200
|
```
|
205
201
|
|
206
202
|
#### Overwriting options
|
207
|
-
The CLI allows different options
|
208
|
-
|
209
|
-
##### Secret
|
210
|
-
The `edgerc` option has always precedence over the `txt` one:
|
211
|
-
|
212
|
-
This command will load secret from ~/.edgerc:
|
213
|
-
```shell
|
214
|
-
ccu_invalidate --txt=~/tokens.txt \
|
215
|
-
--edgerc=~/.edgerc \
|
216
|
-
--cp=12345,98765
|
217
|
-
```
|
203
|
+
The CLI allows different options to specify the contents to be purged.
|
204
|
+
If multiple options for contents are provided, the program runs by specific precedence rules:
|
218
205
|
|
219
|
-
#####
|
206
|
+
##### Options precedence
|
220
207
|
The `bulk` option has always precedence over the `cp` one, that has precedence over `url`:
|
221
208
|
|
222
209
|
This command will invalidate by URLs:
|
223
210
|
```shell
|
224
|
-
ccu_invalidate --
|
211
|
+
ccu_invalidate --secret=~/tokens.txt \
|
225
212
|
--cp=12345,98765
|
226
213
|
--bulk=urls.txt
|
227
214
|
```
|
228
215
|
|
229
216
|
This command will delete by CP codes:
|
230
217
|
```shell
|
231
|
-
ccu_delete --
|
218
|
+
ccu_delete --secret=~/tokens.txt \
|
232
219
|
--cp=12345,98765
|
233
220
|
--url=https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/main.css,https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/main.js
|
234
221
|
```
|
@@ -246,7 +233,7 @@ AkamaiCCU::Wrapper.logger = Logger.new(STDOUT)
|
|
246
233
|
CLI uses a logger writing to `STDOUT` by default with an `INFO` level.
|
247
234
|
In case you want to control the log level, just pass an environment variable to the script:
|
248
235
|
```shell
|
249
|
-
LOG_LEVEL=DEBUG ccu_invalidate --
|
236
|
+
LOG_LEVEL=DEBUG ccu_invalidate --secret=~/.edgerc --cp=12345,98765
|
250
237
|
```
|
251
238
|
|
252
239
|
### Possible Issues
|
data/lib/akamai_ccu/cli.rb
CHANGED
@@ -26,16 +26,11 @@ module AkamaiCCU
|
|
26
26
|
return @logger.warn("specify contents to purge by bulk, CP codes or urls") if Array(@objects).empty?
|
27
27
|
return @logger.warn("specify path to the secret file either by edgerc or by txt") unless @secret
|
28
28
|
return @logger.warn("specified secret file does not exist") unless File.exist?(@secret)
|
29
|
-
@wrapper_klass.setup(secret, Client, @logger)
|
29
|
+
@wrapper_klass.setup(@secret_klass.by_file(@secret), Client, @logger)
|
30
30
|
wrapper = @wrapper_klass.new(endpoint: endpoint, headers: Array(@headers))
|
31
31
|
@logger.info wrapper.call(@objects).to_s
|
32
32
|
end
|
33
33
|
|
34
|
-
private def secret
|
35
|
-
return @secret_klass.by_txt(@secret) if File.extname(@secret) == ".txt"
|
36
|
-
@secret_klass.by_edgerc(@secret)
|
37
|
-
end
|
38
|
-
|
39
34
|
private def endpoint
|
40
35
|
@endpoint_klass.new(network, action, mode)
|
41
36
|
end
|
@@ -54,13 +49,9 @@ module AkamaiCCU
|
|
54
49
|
|
55
50
|
private def parser
|
56
51
|
OptionParser.new do |opts|
|
57
|
-
opts.banner = %Q{Usage: ccu_#{@action} --edgerc
|
58
|
-
|
59
|
-
opts.on("-eEDGERC", "--edgerc=EDGERC", "Load secret by .edgerc file") do |secret|
|
60
|
-
@secret = File.expand_path(secret)
|
61
|
-
end
|
52
|
+
opts.banner = %Q{Usage: ccu_#{@action} --secret=~/.edgerc --production --cp="12345, 98765"}
|
62
53
|
|
63
|
-
opts.on("-
|
54
|
+
opts.on("-sSECRET", "--secret=SECRET", "Load secret data by file") do |secret|
|
64
55
|
@secret = File.expand_path(secret)
|
65
56
|
end
|
66
57
|
|
data/lib/akamai_ccu/secret.rb
CHANGED
@@ -4,36 +4,34 @@ require "securerandom"
|
|
4
4
|
module AkamaiCCU
|
5
5
|
class Secret
|
6
6
|
DIGEST = "EG1-HMAC-SHA256"
|
7
|
-
|
7
|
+
ENTRY_REGEX = /(.+?)\s?=\s?(.+)/
|
8
|
+
BODY_SIZE = 131072
|
9
|
+
|
10
|
+
class FileContentError < ArgumentError; end
|
8
11
|
|
9
12
|
class << self
|
10
13
|
private def factory(opts, time)
|
11
|
-
new(client_secret: opts.fetch("client_secret"), host: opts.fetch("host"), access_token: opts.fetch("access_token"), client_token: opts.fetch("client_token"), max_body: opts.fetch("max-body",
|
14
|
+
new(client_secret: opts.fetch("client_secret"), host: opts.fetch("host"), access_token: opts.fetch("access_token"), client_token: opts.fetch("client_token"), max_body: opts.fetch("max-body", BODY_SIZE), time: time)
|
12
15
|
end
|
13
16
|
|
14
|
-
def
|
17
|
+
def by_file(name = "~/.edgerc", time = Time.now)
|
15
18
|
path = File.expand_path(name)
|
16
19
|
return unless File.exist?(path)
|
17
|
-
data = File.readlines(path).map(&:strip).
|
18
|
-
entry.
|
20
|
+
data = File.readlines(path).map(&:strip).reduce([]) do |acc, entry|
|
21
|
+
m = entry.match(ENTRY_REGEX)
|
22
|
+
acc << [m[1], m[2]] if m
|
23
|
+
acc
|
19
24
|
end
|
20
25
|
factory(Hash[data], time)
|
21
|
-
|
22
|
-
|
23
|
-
def by_edgerc(name = "~/.edgerc", time = Time.now)
|
24
|
-
path = File.expand_path(name)
|
25
|
-
return unless File.exist?(path)
|
26
|
-
data = File.readlines(path).map(&:strip)
|
27
|
-
data.shift
|
28
|
-
data.map! { |entry| entry.split(EQUALITY) }
|
29
|
-
factory(Hash[data], time)
|
26
|
+
rescue KeyError => e
|
27
|
+
raise FileContentError, "bad file content, #{e.message}", e.backtrace
|
30
28
|
end
|
31
29
|
end
|
32
30
|
|
33
31
|
attr_reader :host, :max_body, :nonce, :timestamp
|
34
32
|
|
35
33
|
def initialize(client_secret:, host:, access_token:, client_token:,
|
36
|
-
max_body:
|
34
|
+
max_body: BODY_SIZE, nonce: SecureRandom.uuid, time: Time.now)
|
37
35
|
@client_secret = client_secret
|
38
36
|
@host = URI(host)
|
39
37
|
@access_token = access_token
|
data/lib/akamai_ccu/version.rb
CHANGED