akamai_ccu 1.4.1 → 1.5.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: 54fe3c8b980c14e50ef78c4789eab9e376609733
4
- data.tar.gz: c1603bc6a64a685d5ba73eed5c968b3d02888373
3
+ metadata.gz: 42d7a18832075e64a3b665f937ee63f160621d31
4
+ data.tar.gz: de91792521bce4ff10dbb5870bbd47794f48dc4f
5
5
  SHA512:
6
- metadata.gz: 0b04c3c310a4db4c85e17dd638b78be47774b05caec0b4aeb4a3778a6df054aa387a97555b460d97ac128ddc97cc746a89158b766179ccfe24c6f6b2b0f2b103
7
- data.tar.gz: e1517ac58e83c73cc563a7407da7e0e38824f58343ce370d2cf095a37638bbdec39fde099271de7c604cf2052a7a9affe2209d0c4cf2c08102138a7f44a96111
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
- * [As library](#as-library)
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
- ### As library
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.by_edgerc(".edgerc") # default to ~/.edgerc
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=./.edgerc --production --cp="12345, 98765"
158
- -e, --edgerc=EDGERC Load secret by .edgerc file
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 --edgerc=~/.edgerc \
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 --txt=~/tokens.txt \
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 --edgerc=~/.edgerc --bulk=urls.txt
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 --edgerc=~/.edgerc --cp=12345,98765 >> mylog.log
199
+ ccu_invalidate --secret=~/.edgerc --cp=12345,98765 >> mylog.log
204
200
  ```
205
201
 
206
202
  #### Overwriting options
207
- The CLI allows different options for the same scope on secret and contents specification. If multiple options for the same scope are provided, the program runs by assigning specific precedence rules:
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
- ##### Contents
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 --txt=~/tokens.txt \
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 --txt=~/tokens.txt \
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 --edgerc=~/.edgerc --cp=12345,98765
236
+ LOG_LEVEL=DEBUG ccu_invalidate --secret=~/.edgerc --cp=12345,98765
250
237
  ```
251
238
 
252
239
  ### Possible Issues
@@ -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=./.edgerc --production --cp="12345, 98765"}
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("-tTXT", "--txt=TXT", "Load secret by TXT file") do |secret|
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
 
@@ -4,36 +4,34 @@ require "securerandom"
4
4
  module AkamaiCCU
5
5
  class Secret
6
6
  DIGEST = "EG1-HMAC-SHA256"
7
- EQUALITY = " = "
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", 2048), time: time)
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 by_txt(name, time = Time.now)
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).reject(&:empty?).map do |entry|
18
- entry.split(EQUALITY)
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
- end
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: 2048, nonce: SecureRandom.uuid, time: Time.now)
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
@@ -1,3 +1,3 @@
1
1
  module AkamaiCCU
2
- VERSION = "1.4.1"
2
+ VERSION = "1.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akamai_ccu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - costajob