akamai-edgegrid 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/akamai/edgegrid.rb +37 -3
  2. metadata +18 -2
@@ -7,7 +7,7 @@
7
7
  #
8
8
  # == License
9
9
  #
10
- # Copyright 2014 Akamai Technologies, Inc. All rights reserved.
10
+ # Copyright 2014-2015 Akamai Technologies, Inc. All rights reserved.
11
11
  #
12
12
  # Licensed under the Apache License, Version 2.0 (the "License");
13
13
  # you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ require 'logger'
27
27
  require 'securerandom'
28
28
  require 'uri'
29
29
  require 'net/http'
30
+ require 'inifile'
30
31
 
31
32
  module Akamai #:nodoc:
32
33
  module Edgegrid #:nodoc:
@@ -58,7 +59,7 @@ module Akamai #:nodoc:
58
59
  # => "Hongkong, Hong Kong
59
60
  #
60
61
  class HTTP < Net::HTTP
61
-
62
+ attr_accessor :host, :section
62
63
  private
63
64
 
64
65
  def self.base64_hmac_sha256(data, key)
@@ -76,7 +77,20 @@ module Akamai #:nodoc:
76
77
  public
77
78
 
78
79
  # Creates a new Akamai::Edgegrid::HTTP object (takes same options as Net::HTTP)
79
- def initialize(address, port)
80
+ def initialize(address, port, filename='~/.edgerc', section='default')
81
+ if filename
82
+ edgerc_path = File.expand_path(filename)
83
+
84
+ if File.exist?(edgerc_path)
85
+ @section = section
86
+ file = IniFile.load(edgerc_path)
87
+ data = file[address]
88
+ address = data["host"] || ""
89
+ address.gsub!('/','')
90
+ @host = address
91
+ end
92
+ end
93
+
80
94
  super(address, port)
81
95
  if port == 80
82
96
  @use_ssl = false
@@ -181,6 +195,26 @@ module Akamai #:nodoc:
181
195
  end
182
196
  end
183
197
 
198
+ def setup_from_edgerc(opts)
199
+ edgerc_path = opts[:filename] || File.expand_path('~/.edgerc')
200
+
201
+ if File.exist?(edgerc_path) && @section
202
+ file = IniFile.load(edgerc_path)
203
+ data = file[@section]
204
+ @client_token = data["client_token"]
205
+ @client_secret = data["client_secret"]
206
+ @access_token = data["access_token"]
207
+ @max_body = data["max_body"] || 2048
208
+ @headers_to_sign = opts[:headers_to_sign] || []
209
+ end
210
+
211
+ if opts[:debug]
212
+ @log = Logger.new(STDERR)
213
+ else
214
+ @log = Logger.new('/dev/null')
215
+ end
216
+ end
217
+
184
218
  # Returns the computed Authorization header for the given request, timestamp and nonce
185
219
  def make_auth_header(request, timestamp, nonce)
186
220
  auth_header = "EG1-HMAC-SHA256 " + [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akamai-edgegrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-21 00:00:00.000000000 Z
12
+ date: 2015-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: simplecov
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.7.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: inifile
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.0'
30
46
  description: Implements the Akamai {OPEN} EdgeGrid Authentication specified by https://developer.akamai.com/introduction/Client_Auth.html
31
47
  email: jlandis@akamai.com
32
48
  executables: []