akamai_ccu 1.3.9 → 1.4.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: a24bee1480f3f5e009ab732d5a0af9b1994fea05
4
- data.tar.gz: a03462df7c7a34d56e9589ecc193b1a76c310f1a
3
+ metadata.gz: 90eb919f024235aa67dcf1b4f028e9041179986f
4
+ data.tar.gz: b4f679753d318e95e1bf2ee9633c8d29c95063a1
5
5
  SHA512:
6
- metadata.gz: bef943c60a6fe07f0cb5cb601f550a6f17b617392ba963afd32933f9a9efba331a9e469def5fb5318563ee015997b1f7139ec52ffea76548a41afebae8dbde0f
7
- data.tar.gz: 9b0d155906efba022fe14127b091a0679473976f8948a14e74c4cb37f25c33329effd2aaa5d929ee3ecad9739ee7cec211cc17b92cf6c847de901c3432d9ab19
6
+ metadata.gz: c2c87599dcbd0968571ecb7d303244a2f4b4f799520e3a352b4f20a2053bca5648c38bdbe3fca44db011a9d98a87b7e23d1d999acd59219ccf0800125881d359
7
+ data.tar.gz: 7d905b042e620911b32817bc6841350cff1a518015e2c028bc9e9a56ddcafc1ab5e89bd6046b7b7f94cddd051d747fb0c7b6a4fe74105c757505bd2935843117
data/README.md CHANGED
@@ -20,6 +20,9 @@
20
20
  * [Bulk operation](#bulk-operation)
21
21
  * [Redirecting output](#redirecting-output)
22
22
  * [Overwriting options](#overwriting-options)
23
+ * [Logging](#logging)
24
+ * [Library logger](#library-logger)
25
+ * [CLI logger](#cli-logger)
23
26
  * [Possible issues](#possible-issues)
24
27
  * [Invalid timestamp](#invalid-timestamp)
25
28
  * [No wildcard](#no-wildcard)
@@ -98,7 +101,7 @@ Once you've got APIs credentials, you can instantiate the secret object aimed to
98
101
  require "akamai_ccu"
99
102
 
100
103
  # by .edgerc
101
- secret = AkamaiCCU::Secret.by_edgerc(".edgerc")
104
+ secret = AkamaiCCU::Secret.by_edgerc(".edgerc") # default to ~/.edgerc
102
105
 
103
106
  # by txt file
104
107
  secret = AkamaiCCU::Secret.by_txt("tokens.txt")
@@ -197,7 +200,7 @@ ccu_invalidate --edgerc=~/.edgerc --bulk=urls.txt
197
200
  #### Redirecting output
198
201
  In case you're calling the CLI from another program (like your Jenkins script), just redirect the output to your log file:
199
202
  ```shell
200
- ccu_invalidate --edgerc=~/.edgerc --cp=12345,98765 > mylog.log
203
+ ccu_invalidate --edgerc=~/.edgerc --cp=12345,98765 >> mylog.log
201
204
  ```
202
205
 
203
206
  #### Overwriting options
@@ -230,6 +233,22 @@ ccu_delete --txt=~/tokens.txt \
230
233
  --url=https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/main.css,https://akaa-baseurl-xxx-xxx.luna.akamaiapis.net/main.js
231
234
  ```
232
235
 
236
+ ### Logging
237
+
238
+ #### Library logger
239
+ By default the `Wrapper` class accepts a logger pointing to `dev/null`.
240
+ In case you want to replace it with yours, just use the class attribute writer:
241
+ ```ruby
242
+ AkamaiCCU::Wrapper.logger = Logger.new(STDOUT)
243
+ ```
244
+
245
+ #### CLI logger
246
+ CLI uses a logger writing to `STDOUT` by default with an `INFO` level.
247
+ In case you want to control the log level, just pass an environment variable to the script:
248
+ ```shell
249
+ LOG_LEVEL=DEBUG ccu_invalidate --edgerc=~/.edgerc --cp=12345,98765
250
+ ```
251
+
233
252
  ### Possible Issues
234
253
 
235
254
  #### Invalid timestamp
@@ -5,6 +5,7 @@ require "akamai_ccu/wrapper"
5
5
  module AkamaiCCU
6
6
  class CLI
7
7
  SCHEME = "http"
8
+ LOG_LEVEL = Logger.const_get(ENV.fetch("LOG_LEVEL", "INFO"))
8
9
 
9
10
  attr_reader :network, :action
10
11
 
@@ -13,6 +14,7 @@ module AkamaiCCU
13
14
  @action = action
14
15
  @io = io
15
16
  @logger = Logger.new(io)
17
+ @logger.level = LOG_LEVEL
16
18
  @wrapper_klass = wrapper_klass
17
19
  @secret_klass = secret_klass
18
20
  @endpoint_klass = endpoint_klass
@@ -24,7 +26,7 @@ module AkamaiCCU
24
26
  return @logger.warn("specify contents to purge by bulk, CP codes or urls") if Array(@objects).empty?
25
27
  return @logger.warn("specify path to the secret file either by edgerc or by txt") unless @secret
26
28
  return @logger.warn("specified secret file does not exist") unless File.exist?(@secret)
27
- @wrapper_klass.setup(secret)
29
+ @wrapper_klass.setup(secret, Client, @logger)
28
30
  wrapper = @wrapper_klass.new(endpoint: endpoint, headers: Array(@headers))
29
31
  @logger.info wrapper.call(@objects).to_s
30
32
  end
@@ -20,7 +20,7 @@ module AkamaiCCU
20
20
  factory(Hash[data], time)
21
21
  end
22
22
 
23
- def by_edgerc(name, time = Time.now)
23
+ def by_edgerc(name = "~/.edgerc", time = Time.now)
24
24
  path = File.expand_path(name)
25
25
  return unless File.exist?(path)
26
26
  data = File.readlines(path).map(&:strip)
@@ -1,3 +1,3 @@
1
1
  module AkamaiCCU
2
- VERSION = "1.3.9"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -7,10 +7,12 @@ module AkamaiCCU
7
7
  class Wrapper
8
8
  class << self
9
9
  attr_reader :secret, :client
10
+ attr_accessor :logger
10
11
 
11
- def setup(secret, client_klass = Client)
12
+ def setup(secret, client_klass = Client, logger = Logger.new(nil))
12
13
  @secret ||= secret
13
14
  @client ||= client_klass.new(host: @secret.host)
15
+ @logger ||= logger
14
16
  end
15
17
 
16
18
  Endpoint::Network.constants.each do |network|
@@ -37,11 +39,13 @@ module AkamaiCCU
37
39
  end
38
40
 
39
41
  def call(objects)
40
- res = self.class.client.call(path: @endpoint.path) do |request|
42
+ response = self.class.client.call(path: @endpoint.path) do |request|
41
43
  request.body = { objects: objects }.to_json
42
44
  @signer_klass.new(request, self.class.secret.touch, @headers).call!
45
+ self.class.logger.debug { "request: uri=#{request.path}; body=#{request.body}; authorization=#{request["Authorization"]}" }
43
46
  end
44
- response_klass.factory(res.body)
47
+ self.class.logger.debug { "response: inspect=#{response.inspect}; body=#{response.body}" }
48
+ response_klass.factory(response.body)
45
49
  end
46
50
  end
47
51
  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.3.9
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - costajob