akamai_ccu 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59bb2a82f3a775533b7efd02a019444caddefb90
4
- data.tar.gz: 9f1bd419f021dae8f3112d8a088aaeac6554a395
3
+ metadata.gz: 20f56b91f406cdd333d1c23d885c7370658fc906
4
+ data.tar.gz: 3887d4f39e9a4b3e7a14e47f2df6ac1aea47aff5
5
5
  SHA512:
6
- metadata.gz: 9b44d3a5cdbba02da05b2f942d0e66b14066428af90e82089af540656455cad09932ea8c1714c79ab90cee34296936696166459f0dab5d136f2d9bd62a7eb325
7
- data.tar.gz: e59750ba6ab033ed37c1b7521de7d44b8d1ffd6383830799a676c40e3183c1f10b95f6330122f47c0192472ab508019c8b243ce18cd0f100f839b9f84e471b45
6
+ metadata.gz: 9590ad88f2e5426399d9049d5f60852ec7212b163e99da0c177ff3a9cb9b4ac3450a33004adb4571a6d9ae701da10f4ed8aa549d2163162669a7b02e97ee8aa3
7
+ data.tar.gz: '0403824dafb5fecb2f3d3cb8dfbf07c2b8b1f15399b99bf3591475f5f99b64c3e933e5938a1639548f223550203eaa041f185d6314928782804a2f5dd4a57d21'
data/README.md CHANGED
@@ -17,6 +17,8 @@
17
17
  * [Help](#help)
18
18
  * [ccu_invalidate](#ccu_invalidate)
19
19
  * [ccu_delete](#ccu_delete)
20
+ * [Bulk operation](#bulk-operation)
21
+ * [Redirecting output](#redirecting-output)
20
22
  * [Overwriting options](#overwriting-options)
21
23
  * [Possible issues](#possible-issues)
22
24
 
@@ -163,7 +165,7 @@ Usage: invalidate --edgerc=./.edgerc --production --cp="12345, 98765"
163
165
  You can request for contents invalidation by calling:
164
166
  ```shell
165
167
  ccu_invalidate --edgerc=~/.edgerc \
166
- --url="https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/*.css,https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/*.js" \
168
+ --url=https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/*.css,https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/*.js \
167
169
  --production
168
170
  ```
169
171
 
@@ -175,6 +177,31 @@ ccu_delete --txt=~/tokens.txt \
175
177
  --headers=Accept,Content-Length
176
178
  ```
177
179
 
180
+ #### Bulk operation
181
+ In case you have multiple contents to work with, it could be impractical to write several entries on the CLI.
182
+ Just specify them on a separate file and use the bulk option:
183
+
184
+ `urls.txt` file with each url/CP code specified on one line:
185
+ ```txt
186
+ https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/*.css
187
+ https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/*.js
188
+ https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/static/*.html
189
+ ```
190
+
191
+ Specify the bulk option by using the file path:
192
+ ```shell
193
+ ccu_invalidate --edgerc=~/.edgerc --bulk=urls.txt
194
+ ```
195
+
196
+ ##### Do not mix content types
197
+ You cannot specify both CP codes and URLs on the same bulk file, mind being consistent!
198
+
199
+ #### Redirecting output
200
+ In case you're calling the CLI from another program (like your Jenkins script), just redirect the output to your log file:
201
+ ```shell
202
+ ccu_invalidate --edgerc=~/.edgerc --cp=12345,98765 > mylog.log
203
+ ```
204
+
178
205
  #### Overwriting options
179
206
  The CLI does allow only one option to specify the secret file and the content objects.
180
207
  If multiple options for the same scope are provided, the program runs by giving precedence to:
@@ -189,12 +216,20 @@ ccu_invalidate --txt=~/tokens.txt \
189
216
  ```
190
217
 
191
218
  ##### Content objects
192
- The `cp` option has always precedence over the `url` one:
219
+ The `bulk` option has always precedence over the `cp` one, that has precedence over the `url`:
220
+
221
+ This command will invalidate by urls:
193
222
  ```shell
194
- # will invalidate by CP code
195
223
  ccu_invalidate --txt=~/tokens.txt \
196
- --url="https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/*.css,https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/*.js" \
197
224
  --cp=12345,98765
225
+ --bulk=urls.txt
226
+ ```
227
+
228
+ This command will delete by CP codes:
229
+ ```shell
230
+ ccu_delete --txt=~/tokens.txt \
231
+ --cp=12345,98765
232
+ --url=https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/*.css,https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/*.js
198
233
  ```
199
234
 
200
235
  ### Possible Issues
@@ -1,3 +1,4 @@
1
+ require "logger"
1
2
  require "optparse"
2
3
  require "akamai_ccu/wrapper"
3
4
 
@@ -9,6 +10,7 @@ module AkamaiCCU
9
10
  @args = args
10
11
  @action = action
11
12
  @io = io
13
+ @logger = Logger.new(io)
12
14
  @wrapper_klass = wrapper_klass
13
15
  @secret_klass = secret_klass
14
16
  @endpoint_klass = endpoint_klass
@@ -17,10 +19,11 @@ module AkamaiCCU
17
19
 
18
20
  def call
19
21
  parser.parse!(@args)
20
- return @io.puts(%q{Specify contents to purge either by cp codes or by urls}) unless @objects
21
- return @io.puts(%q{Specify path to the secret file either by edgerc or by txt}) unless @secret
22
+ return @logger.warn("specify contents to purge either by cp codes or by urls") unless @objects
23
+ return @logger.warn("specify path to the secret file either by edgerc or by txt") unless @secret
24
+ return @logger.warn("specified secret file does not exist") unless File.exist?(@secret)
22
25
  wrapper = @wrapper_klass.new(secret: secret, endpoint: endpoint, headers: Array(@headers))
23
- @io.puts wrapper.call(@objects)
26
+ @logger.info wrapper.call(@objects).to_s
24
27
  end
25
28
 
26
29
  private def secret
@@ -37,16 +40,24 @@ module AkamaiCCU
37
40
  Endpoint::Mode::URL
38
41
  end
39
42
 
43
+ private def bulk_objects(file)
44
+ return unless File.exist?(file)
45
+ File.readlines(file).map(&:strip).reject(&:empty?).map do |entry|
46
+ entry = entry.to_i unless entry.start_with?("http")
47
+ entry
48
+ end
49
+ end
50
+
40
51
  private def parser
41
52
  OptionParser.new do |opts|
42
53
  opts.banner = %Q{Usage: #{@action} --edgerc=./.edgerc --production --cp="12345, 98765"}
43
54
 
44
55
  opts.on("-eEDGERC", "--edgerc=EDGERC", "Load secret by .edgerc file") do |secret|
45
- @secret = secret
56
+ @secret = File.expand_path(secret)
46
57
  end
47
58
 
48
59
  opts.on("-tTXT", "--txt=TXT", "Load secret by TXT file") do |secret|
49
- @secret = secret
60
+ @secret = File.expand_path(secret)
50
61
  end
51
62
 
52
63
  opts.on("-cCP", "--cp=CP", "Specify contents by provider (CP) codes") do |objects|
@@ -57,6 +68,10 @@ module AkamaiCCU
57
68
  @objects = objects.split(",").map(&:strip)
58
69
  end
59
70
 
71
+ opts.on("-bBULK", "--bulk=BULK", "Specify bulk contents in a file") do |bulk|
72
+ @objects = bulk_objects(bulk)
73
+ end
74
+
60
75
  opts.on("--headers=HEADERS", "Specify HTTP headers to sign") do |headers|
61
76
  @headers = headers.split(",").map(&:strip)
62
77
  end
@@ -1,3 +1,3 @@
1
1
  module AkamaiCCU
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akamai_ccu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - costajob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-21 00:00:00.000000000 Z
11
+ date: 2017-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler