akamai_api 0.0.1
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.
- data/.gitignore +19 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +189 -0
- data/Thorfile +30 -0
- data/akamai_api.gemspec +27 -0
- data/bin/akamai_api +22 -0
- data/lib/akamai_api/ccu.rb +71 -0
- data/lib/akamai_api/ccu_response.rb +51 -0
- data/lib/akamai_api/cli/ccu.rb +11 -0
- data/lib/akamai_api/cli/ccu_arl.rb +40 -0
- data/lib/akamai_api/cli/ccu_cp_code.rb +48 -0
- data/lib/akamai_api/cli/command.rb +24 -0
- data/lib/akamai_api/cli/eccu.rb +55 -0
- data/lib/akamai_api/cli/template.rb +36 -0
- data/lib/akamai_api/cli.rb +3 -0
- data/lib/akamai_api/cp_code.rb +26 -0
- data/lib/akamai_api/eccu_request.rb +137 -0
- data/lib/akamai_api/soap_body.rb +52 -0
- data/lib/akamai_api/version.rb +3 -0
- data/lib/akamai_api.rb +9 -0
- data/spec/fixtures/delete/success.xml +8 -0
- data/spec/fixtures/eccu_request.xml +10 -0
- data/spec/fixtures/get_cp_codes/sample.xml +21 -0
- data/spec/fixtures/get_ids/success.xml +11 -0
- data/spec/fixtures/get_info/success.xml +25 -0
- data/spec/fixtures/set_notes/success.xml +8 -0
- data/spec/fixtures/set_status_change_email/success.xml +8 -0
- data/spec/fixtures/upload/fault.xml +13 -0
- data/spec/fixtures/upload/success.xml +8 -0
- data/spec/fixtures/wsdl:purge_request/success.xml +15 -0
- data/spec/lib/akamai_api/ccu_spec.rb +115 -0
- data/spec/lib/akamai_api/cp_code_spec.rb +25 -0
- data/spec/lib/akamai_api/eccu_request_spec.rb +216 -0
- data/spec/lib/akamai_api/soap_body_spec.rb +51 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/support/savon_tester.rb +18 -0
- data/wsdls/ccuapi.wsdl +82 -0
- metadata +197 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Nicola Racco
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
# AkamaiApi
|
2
|
+
|
3
|
+
AkamaiApi is a ruby library and command line utility to interact with Akamai CCU (Content Control Utility) and ECCU (Enhanced Content Control Utility) services.
|
4
|
+
|
5
|
+
# Using the CLI
|
6
|
+
|
7
|
+
After gem installation you will have a CLI utility to execute operations on Akamai. Each method requires authentication. You can provide auth info using one of the following methods:
|
8
|
+
|
9
|
+
- Passing --username (-u) and --password (-p) arguments at each invocation
|
10
|
+
- Creating a config file in your HOME directory named .akamai_api.yml with the following format:
|
11
|
+
|
12
|
+
```yaml
|
13
|
+
auth:
|
14
|
+
- user
|
15
|
+
- pass
|
16
|
+
```
|
17
|
+
|
18
|
+
## Tasks
|
19
|
+
|
20
|
+
When using the CLI you can work with both CCU and ECCU.
|
21
|
+
|
22
|
+
```
|
23
|
+
akamai_api ccu # CCU Interface
|
24
|
+
akamai_api eccu # ECCU Interface
|
25
|
+
akamai_api help [TASK] # Describe available tasks or one specific task
|
26
|
+
```
|
27
|
+
Use *akamai_api help* to view the help of the CLI.
|
28
|
+
|
29
|
+
## CCU
|
30
|
+
|
31
|
+
In the CCU interface you can work with CP Codes and ARLs.
|
32
|
+
|
33
|
+
```
|
34
|
+
akamai_api ccu cpcode # CP Code CCU actions
|
35
|
+
akamai_api ccu help [COMMAND] # Describe subcommands or one specific subcommand
|
36
|
+
akamai_api ccu arl # ARL CCU actions
|
37
|
+
```
|
38
|
+
|
39
|
+
### CP Code
|
40
|
+
|
41
|
+
```
|
42
|
+
akamai_api ccu cpcode help [COMMAND] # Describe subcommands or one specific subcommand
|
43
|
+
akamai_api ccu cpcode invalidate CPCODE1 CPCODE2 ... # Purge CP Code(s) marking their cache as expired
|
44
|
+
akamai_api ccu cpcode list # Print the list of CP Codes
|
45
|
+
akamai_api ccu cpcode remove CPCODE1 CPCODE2 ... # Purge CP Code(s) removing them from the cache
|
46
|
+
```
|
47
|
+
|
48
|
+
When removing or invalidating a CP Code you can provide the following optional arguments:
|
49
|
+
|
50
|
+
- *--domain*: Specify if you want to work with *production* or *staging*. This is a completely optional argument and usually you don't need to set it.
|
51
|
+
- *--emails*: Specify the list of email used by Akamai to send notifications about the purge request.
|
52
|
+
|
53
|
+
### ARL
|
54
|
+
|
55
|
+
```
|
56
|
+
akamai_api ccu arl help [COMMAND] # Describe subcommands or one specific subcommand
|
57
|
+
akamai_api ccu arl invalidate http://john.com/a.txt http://www.smith.com/b.txt ... # Purge ARL(s) marking their cache as expired
|
58
|
+
akamai_api ccu arl remove http://john.com/a.txt http://www.smith.com/b.txt ... # Purge ARL(s) removing them from the cache
|
59
|
+
```
|
60
|
+
|
61
|
+
When removing or invalidating an ARL you can provide the following optional arguments:
|
62
|
+
|
63
|
+
- *--domain*: Specify if you want to work with *production* or *staging*. This is a completely optional argument and usually you don't need to set it.
|
64
|
+
- *--emails*: Specify the list of email used by Akamai to send notifications about the purge request.
|
65
|
+
|
66
|
+
## ECCU
|
67
|
+
|
68
|
+
In the ECCU interface you can see the requestes already published and publish your own requests.
|
69
|
+
|
70
|
+
```
|
71
|
+
akamai_api eccu help [COMMAND] # Describe subcommands or one specific subcommand
|
72
|
+
akamai_api eccu last_request # Print the last request made to ECCU
|
73
|
+
akamai_api eccu publish_xml path/to/request.xml john.com # Publish a request made in XML for the specified Digital Property (usually the Host Header)
|
74
|
+
akamai_api eccu requests # Print the list of the last requests made to ECCU
|
75
|
+
```
|
76
|
+
|
77
|
+
### Viewing Requests
|
78
|
+
|
79
|
+
You can see the requests published on ECCU using *akamai_api eccu requests*
|
80
|
+
For each request you will see all its details (code, status, etc.) except the file content.
|
81
|
+
To view the file content add the --content (-c) option.
|
82
|
+
|
83
|
+
To see only the last request you can use *akamai_api eccu last_request*.
|
84
|
+
|
85
|
+
### Publishing Requests in XML
|
86
|
+
|
87
|
+
To publish requests made in XML (ECCU Request Format) you can use *akamai_api eccu publish_xml*.
|
88
|
+
|
89
|
+
```
|
90
|
+
Usage:
|
91
|
+
akamai_api publish_xml path/to/request.xml john.com
|
92
|
+
|
93
|
+
Options:
|
94
|
+
-pt, [--property-type=type] # Type of enlisted properties
|
95
|
+
# Default: hostheader
|
96
|
+
[--no-exact-match] # Do not do an exact match on property names
|
97
|
+
-e, [--emails=foo@foo.com bar@bar.com] # Email(s) to use to send notification on status change
|
98
|
+
-n, [--notes=NOTES]
|
99
|
+
# Default: ECCU Request using AkamaiApi gem
|
100
|
+
```
|
101
|
+
|
102
|
+
The command takes two arguments:
|
103
|
+
- the file containing the request;
|
104
|
+
- the Digital Property to which you want to apply the request (usually it's the host);
|
105
|
+
|
106
|
+
# As a Library
|
107
|
+
|
108
|
+
Remember to init the AkamaiApi gem with your login credentials. You can set your credentials with the following statement:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
AkamaiApi.config.merge! :auth => ['user', 'pass']
|
112
|
+
```
|
113
|
+
|
114
|
+
- CpCode: model representing a CP Code. Use the ::all method to retrieve the list of available CpCode.
|
115
|
+
- Ccu : CCU interface. Use the ::purge method to purge a list of resources.
|
116
|
+
- EccuRequest: model representing an ECCU request.
|
117
|
+
|
118
|
+
## Ccu
|
119
|
+
|
120
|
+
### ::purge
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
def purge action, type, items, args = {}
|
124
|
+
...
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
128
|
+
- action: symbol or string. It should be *remove* or *invalidate*. See the CLI documentation for more details
|
129
|
+
- type: symbol or string. It should be *arl* or *cpcode*. Use arl to purge a list of urls, and cpcodes to purge a list of cp codes
|
130
|
+
- items: the list of the resources to clean
|
131
|
+
- args: additional options (email, domain)
|
132
|
+
|
133
|
+
e.g.
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
AkamaiApi::Ccu.purge :remove, :arl, ['http://www.foo.com/a.txt'], :email => ['foo@foo.com']
|
137
|
+
```
|
138
|
+
|
139
|
+
### Helpers
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
ccu = AkamaiApi::Ccu
|
143
|
+
|
144
|
+
ccu.invalidate_cpcodes cpcodes # => wrapper to call .purge :invalidate, :cpcode
|
145
|
+
ccu.invalidate_arl arls # => wrapper to call .purge :invalidate, :arl
|
146
|
+
ccu.invalidate :arl, arls # => wrapper to call .purge :invalidate
|
147
|
+
|
148
|
+
ccu.remove_cpcodes cpcodes # => wrapper to call .purge :remove, :cpcode
|
149
|
+
ccu.remove_arl arls # => wrapper to call .purge :remove, :arl
|
150
|
+
ccu.remove :arl # => wrapper to call .purge :remove
|
151
|
+
```
|
152
|
+
|
153
|
+
## EccuRequest
|
154
|
+
|
155
|
+
An EccuRequest is an object representing an ECCU Request. To see all the published requests use the ::all method.
|
156
|
+
To retrieve only the last request, you can use the ::last method.
|
157
|
+
The following code should be self explaining about both class methods and instance methods:
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
all_requests_ids = EccuRequest.all_ids # => Returns all available requests ids
|
161
|
+
first_request = EccuRequest.find all_requests_ids.first # => Return the EccuRequest model with the specified code
|
162
|
+
|
163
|
+
all_requests = EccuRequest.all # => Returns all available requests
|
164
|
+
last_request = EccuRequest.last # => Return the last available request
|
165
|
+
|
166
|
+
last_request.update_notes! 'My new note' # => Invoke the ECCU service to change the notes field
|
167
|
+
last_request.update_email! 'foo@foo.com' # => Invoke the ECCU service to change the email to be notified on status change
|
168
|
+
last_request.destroy # => Invoke the ECCU service to delete the request
|
169
|
+
```
|
170
|
+
|
171
|
+
Use the ::publish method to publish an ECCU Request:
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
AkamaiApi::EccuRequest.publish 'example.com', my_content, args
|
175
|
+
AkamaiApi::EccuRequest.publish_file 'example.com', 'path/to/file.xml', args
|
176
|
+
```
|
177
|
+
|
178
|
+
You can specify the following optional arguments in args: file_name, notes, version, emails, property_type, property_exact_match
|
179
|
+
|
180
|
+
# Specs
|
181
|
+
|
182
|
+
Before running the specs create a file auth.rb in ./spec with the following
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
# Fill the following with your akamai login before running your spec
|
186
|
+
AkamaiApi.config.merge!({
|
187
|
+
:auth => ['user', 'pass']
|
188
|
+
})
|
189
|
+
```
|
data/Thorfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
require 'bundler'
|
5
|
+
require 'thor/rake_compat'
|
6
|
+
|
7
|
+
class Default < Thor
|
8
|
+
include Thor::RakeCompat
|
9
|
+
Bundler::GemHelper.install_tasks
|
10
|
+
|
11
|
+
desc "build", "Build akamai_api-#{AkamaiApi::VERSION}.gem into the pkg directory"
|
12
|
+
def build
|
13
|
+
Rake::Task["build"].execute
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "install", "Build and install akamai_api-#{AkamaiApi::VERSION}.gem into system gems"
|
17
|
+
def install
|
18
|
+
Rake::Task["install"].execute
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "release", "Create tag v#{AkamaiApi::VERSION} and build and push akamai_api-#{AkamaiApi::VERSION}.gem to Rubygems"
|
22
|
+
def release
|
23
|
+
Rake::Task["release"].execute
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "spec", "Run RSpec code examples"
|
27
|
+
def spec
|
28
|
+
exec "rspec --color --format=documentation spec"
|
29
|
+
end
|
30
|
+
end
|
data/akamai_api.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'akamai_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "akamai_api"
|
8
|
+
gem.version = AkamaiApi::VERSION
|
9
|
+
gem.authors = ["Nicola Racco"]
|
10
|
+
gem.email = ["nicola@nicolaracco.com"]
|
11
|
+
gem.description = %q{Ruby toolkit to work with Akamai Content Control Utility API}
|
12
|
+
gem.summary = %q{Ruby toolkit to work with Akamai Content Control Utility API}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'active_support', '>= 2'
|
21
|
+
gem.add_dependency 'thor', '~> 0.14.0'
|
22
|
+
gem.add_dependency 'savon', '~> 1.2.0'
|
23
|
+
gem.add_dependency 'builder', '~> 3.1.3'
|
24
|
+
|
25
|
+
gem.add_development_dependency 'rspec', '~> 2.11'
|
26
|
+
gem.add_development_dependency 'savon_spec', '~> 1.3'
|
27
|
+
end
|
data/bin/akamai_api
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'thor'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
require 'akamai_api'
|
5
|
+
require 'akamai_api/cli'
|
6
|
+
|
7
|
+
class AkamaiApiCommand < Thor
|
8
|
+
desc 'ccu', 'CCU Interface'
|
9
|
+
subcommand 'ccu', AkamaiApi::Cli::Ccu
|
10
|
+
|
11
|
+
desc 'eccu', 'ECCU Interface'
|
12
|
+
subcommand 'eccu', AkamaiApi::Cli::Eccu
|
13
|
+
|
14
|
+
def help *args
|
15
|
+
puts
|
16
|
+
puts "AkamaiApi is a command line utility to interact with Akamai CCU (Content Control Utility) and ECCU (Enhanced Content Control Utility) services."
|
17
|
+
puts
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
AkamaiApiCommand.start
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
|
3
|
+
module AkamaiApi
|
4
|
+
class Ccu
|
5
|
+
extend Savon::Model
|
6
|
+
|
7
|
+
document File.expand_path('../../../wsdls/ccuapi.wsdl', __FILE__)
|
8
|
+
|
9
|
+
class << self
|
10
|
+
[:invalidate, :remove].each do |action|
|
11
|
+
send :define_method, action do |type, items, args = {}|
|
12
|
+
purge action, type, items, args
|
13
|
+
end
|
14
|
+
[:arl, :cpcode].each do |type|
|
15
|
+
method_name = "#{action}_#{type}".to_sym
|
16
|
+
send :define_method, method_name do |items, args = {}|
|
17
|
+
purge action, type, items, args
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def purge action, type, items, args = {}
|
23
|
+
validate_action action
|
24
|
+
validate_type type
|
25
|
+
options = ["action=#{action}", "type=#{type}"]
|
26
|
+
add_domain args[:domain], options
|
27
|
+
add_email args[:email], options
|
28
|
+
response = client.request 'wsdl:purgeRequest' do
|
29
|
+
SoapBody.new(soap) do
|
30
|
+
string :name, AkamaiApi.config[:auth].first
|
31
|
+
string :pwd, AkamaiApi.config[:auth].last
|
32
|
+
string :network, ''
|
33
|
+
array :opt, options
|
34
|
+
array :uri, items
|
35
|
+
end
|
36
|
+
end
|
37
|
+
CcuResponse.new response, items
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def validate_action action
|
43
|
+
unless %w[invalidate remove].include? action.to_s
|
44
|
+
raise "Unknown type '#{action}' (only 'remove' and 'invalidate' are allowed)"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def validate_type type
|
49
|
+
unless %w[cpcode arl].include? type.to_s
|
50
|
+
raise "Unknown type '#{type}' (only 'cpcode' and 'arl' are allowed)"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_domain domain, options
|
55
|
+
if domain.present?
|
56
|
+
unless %w[production staging].include? domain.to_s
|
57
|
+
raise "Unknown domain type '#{domain}' (only :production and :staging are allowed)"
|
58
|
+
end
|
59
|
+
options << "domain=#{domain}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_email email, options
|
64
|
+
if email.present?
|
65
|
+
emails = Array.wrap(email).join ','
|
66
|
+
options << "email-notification=#{emails}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'active_support/core_ext/module/delegation'
|
3
|
+
|
4
|
+
module AkamaiApi
|
5
|
+
class CcuResponse
|
6
|
+
attr_reader :raw_body, :requested_items
|
7
|
+
|
8
|
+
def initialize(response, requested_items)
|
9
|
+
@raw_body = response.body
|
10
|
+
@requested_items = requested_items
|
11
|
+
end
|
12
|
+
|
13
|
+
delegate :result_code, :result_msg, :session_id, :est_time, :uri_index, :to => :body
|
14
|
+
alias message result_msg
|
15
|
+
|
16
|
+
def body
|
17
|
+
@body ||= OpenStruct.new(raw_body[:purge_request_response][:return])
|
18
|
+
end
|
19
|
+
|
20
|
+
def code
|
21
|
+
result_code.to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
def estimated_time
|
25
|
+
est_time.to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
def uri
|
29
|
+
int_index = uri_index.to_i
|
30
|
+
int_index >= 0 && requested_items[int_index] || nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def status
|
34
|
+
case code
|
35
|
+
when (100..199) then 'Successful Request'
|
36
|
+
when (200..299) then 'Warning. The removal request has been accepted'
|
37
|
+
when 301 then 'Invalid username or password'
|
38
|
+
when 302 then 'Bad syntax for an option'
|
39
|
+
when 303 then 'Invalid value for an option'
|
40
|
+
when 304 then 'Option already provided'
|
41
|
+
when 320 then 'URI provided'
|
42
|
+
when 321 then 'Format of ARL/URL is invalid'
|
43
|
+
when 322 then 'You are not authorized to purge this ARL/URL'
|
44
|
+
when 323 then 'ARL/URL illegal'
|
45
|
+
when 332 then 'Maximum number of ARL/URLs in outstanding purge requests exceeded'
|
46
|
+
when (300..399) then 'Bad or invalid request'
|
47
|
+
when (400..499) then 'Contact Akamai Customer Care'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module AkamaiApi
|
2
|
+
module Cli
|
3
|
+
class CcuArl < Command
|
4
|
+
namespace 'ccu arl'
|
5
|
+
|
6
|
+
desc 'remove http://john.com/a.txt http://www.smith.com/b.txt ...', 'Purge ARL(s) removing them from the cache'
|
7
|
+
method_option :domain, :type => :string, :aliases => '-d',
|
8
|
+
:banner => 'production|staging',
|
9
|
+
:desc => 'Optional argument used to specify the environment. Usually you will not need this option'
|
10
|
+
method_option :emails, :type => :array, :aliases => '-e',
|
11
|
+
:banner => "foo@foo.com bar@bar.com",
|
12
|
+
:desc => 'Email(s) used to send notification when the purge has been completed'
|
13
|
+
def remove(*arls)
|
14
|
+
purge_action :remove, arls
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'invalidate http://john.com/a.txt http://www.smith.com/b.txt ...', 'Purge ARL(s) marking their cache as expired'
|
18
|
+
method_option :domain, :type => :string, :aliases => '-d',
|
19
|
+
:banner => 'production|staging',
|
20
|
+
:desc => 'Optional argument used to specify the environment. Usually you will not need this option'
|
21
|
+
method_option :emails, :type => :array, :aliases => '-e',
|
22
|
+
:banner => "foo@foo.com bar@bar.com",
|
23
|
+
:desc => 'Email(s) used to send notification when the purge has been completed'
|
24
|
+
def invalidate(*arls)
|
25
|
+
purge_action :invalidate, arls
|
26
|
+
end
|
27
|
+
|
28
|
+
no_tasks do
|
29
|
+
def purge_action type, arls
|
30
|
+
raise 'You should provide at least one valid URL' if arls.blank?
|
31
|
+
load_config
|
32
|
+
res = AkamaiApi::Ccu.purge type, :arl, arls, :domain => options[:domain], :email => options[:emails]
|
33
|
+
puts '------------'
|
34
|
+
puts AkamaiApi::Cli::Template.ccu_response res
|
35
|
+
puts '------------'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module AkamaiApi
|
2
|
+
module Cli
|
3
|
+
class CcuCpCode < Command
|
4
|
+
namespace 'ccu cpcode'
|
5
|
+
|
6
|
+
desc 'list', 'Print the list of CP Codes'
|
7
|
+
def list
|
8
|
+
load_config
|
9
|
+
AkamaiApi::CpCode.all.each do |cp_code|
|
10
|
+
puts AkamaiApi::Cli::Template.cp_code(cp_code)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'remove CPCODE1 CPCODE2 ...', 'Purge CP Code(s) removing them from the cache'
|
15
|
+
method_option :domain, :type => :string, :aliases => '-d',
|
16
|
+
:banner => 'production|staging',
|
17
|
+
:desc => 'Optional argument used to specify the environment. Usually you will not need this option'
|
18
|
+
method_option :emails, :type => :array, :aliases => '-e',
|
19
|
+
:banner => "foo@foo.com bar@bar.com",
|
20
|
+
:desc => 'Email(s) used to send notification when the purge has been completed'
|
21
|
+
def remove(*cpcodes)
|
22
|
+
purge_action :remove, cpcodes
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'invalidate CPCODE1 CPCODE2 ...', 'Purge CP Code(s) marking their cache as expired'
|
26
|
+
method_option :domain, :type => :string, :aliases => '-d',
|
27
|
+
:banner => 'production|staging',
|
28
|
+
:desc => 'Optional argument used to specify the environment. Usually you will not need this option'
|
29
|
+
method_option :emails, :type => :array, :aliases => '-e',
|
30
|
+
:banner => "foo@foo.com bar@bar.com",
|
31
|
+
:desc => 'Email(s) used to send notification when the purge has been completed'
|
32
|
+
def invalidate(*cpcodes)
|
33
|
+
purge_action :invalidate, cpcodes
|
34
|
+
end
|
35
|
+
|
36
|
+
no_tasks do
|
37
|
+
def purge_action type, cpcodes
|
38
|
+
raise 'You should provide at least one valid CP Code' if cpcodes.blank?
|
39
|
+
load_config
|
40
|
+
res = AkamaiApi::Ccu.purge type, :cpcode, cpcodes, :domain => options[:domain], :email => options[:emails]
|
41
|
+
puts '------------'
|
42
|
+
puts AkamaiApi::Cli::Template.ccu_response res
|
43
|
+
puts '------------'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AkamaiApi
|
2
|
+
module Cli
|
3
|
+
class Command < Thor
|
4
|
+
class_option :username, :type => :string, :aliases => '-u',
|
5
|
+
:desc => 'Username used to authenticate on Akamai Control Panel'
|
6
|
+
class_option :password, :type => :string, :aliases => '-p',
|
7
|
+
:desc => 'Password used to authenticate on Akamai Control Panel'
|
8
|
+
|
9
|
+
no_tasks do
|
10
|
+
def load_config
|
11
|
+
config_file = File.expand_path '~/.akamai_api.yml'
|
12
|
+
config = YAML::load_file(config_file).symbolize_keys
|
13
|
+
if options[:username] && options[:password]
|
14
|
+
config.merge! :auth => [options[:username], options[:password]]
|
15
|
+
end
|
16
|
+
if config[:auth].nil? || config[:auth].compact.blank?
|
17
|
+
raise "#{config_file} does not exist or doesn't contain auth info and you didn't specify username and password options"
|
18
|
+
end
|
19
|
+
AkamaiApi.config.merge! config
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module AkamaiApi
|
2
|
+
module Cli
|
3
|
+
class Eccu < Command
|
4
|
+
desc 'requests', 'Print the list of the last requests made to ECCU'
|
5
|
+
method_option :content, :type => :boolean, :aliases => '-c',
|
6
|
+
:desc => 'Print request content too'
|
7
|
+
def requests
|
8
|
+
load_config
|
9
|
+
requests = AkamaiApi::EccuRequest.all :verbose => options[:content]
|
10
|
+
requests.each do |request|
|
11
|
+
puts '------------'
|
12
|
+
puts AkamaiApi::Cli::Template.eccu_request request
|
13
|
+
end
|
14
|
+
puts '------------'
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'last_request', 'Print the last request made to ECCU'
|
18
|
+
method_option :content, :type => :boolean, :aliases => '-c',
|
19
|
+
:desc => 'Print request content too'
|
20
|
+
def last_request
|
21
|
+
load_config
|
22
|
+
request = AkamaiApi::EccuRequest.last :verbose => options[:content]
|
23
|
+
puts '------------'
|
24
|
+
puts AkamaiApi::Cli::Template.eccu_request request
|
25
|
+
puts '------------'
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'publish_xml path/to/request.xml john.com', 'Publish a request made in XML for the specified Digital Property (usually the Host Header)'
|
29
|
+
long_desc 'Publish a request made in XML (ECCU Request Format) and apply it to the specified Digital Property (usually the Host Header)'
|
30
|
+
method_option :property_type, :type => :string, :aliases => '-pt',
|
31
|
+
:default => 'hostheader', :banner => 'type',
|
32
|
+
:desc => 'Type of enlisted properties'
|
33
|
+
method_option :no_exact_match, :type => :boolean,
|
34
|
+
:desc => 'Do not do an exact match on property names'
|
35
|
+
method_option :emails, :type => :array, :aliases => '-e',
|
36
|
+
:banner => "foo@foo.com bar@bar.com",
|
37
|
+
:desc => 'Email(s) to use to send notification on status change'
|
38
|
+
method_option :notes, :type => :string, :aliases => '-n',
|
39
|
+
:default => 'ECCU Request using AkamaiApi gem'
|
40
|
+
def publish_xml(source, property)
|
41
|
+
load_config
|
42
|
+
args = {
|
43
|
+
:notes => options[:notes],
|
44
|
+
:property_exact_match => !options[:no_exact_match],
|
45
|
+
:property_type => options[:property_type],
|
46
|
+
}
|
47
|
+
id = AkamaiApi::EccuRequest.publish_file property, source, args
|
48
|
+
puts 'Request correctly published. Details:'
|
49
|
+
puts '------------'
|
50
|
+
puts AkamaiApi::Cli::Template.eccu_request AkamaiApi::EccuRequest.find id, :verbose => true
|
51
|
+
puts '------------'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module AkamaiApi
|
2
|
+
module Cli
|
3
|
+
module Template
|
4
|
+
def self.eccu_request request
|
5
|
+
res = ["* Code : #{request.code}",
|
6
|
+
"* Status : #{request.status[:code]}"]
|
7
|
+
res.last << " - #{request.status[:extended]}" if request.status[:extended].present?
|
8
|
+
res << " #{request.status[:update_date]}"
|
9
|
+
res << "* Property: #{request.property[:name]} (#{request.property[:type]})"
|
10
|
+
res << " with exact match" if request.property[:exact_match]
|
11
|
+
res << "* Notes : #{request.notes}" if request.notes.present?
|
12
|
+
res << "* Email : #{request.email}" if request.email
|
13
|
+
res << "* Uploaded by #{request.uploaded_by} on #{request.upload_date}"
|
14
|
+
if request.file[:content].present?
|
15
|
+
res << "* Content:"
|
16
|
+
res << request.file[:content]
|
17
|
+
end
|
18
|
+
res.join "\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.cp_code cpcode
|
22
|
+
"#{cpcode.code}\t#{cpcode.description}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.ccu_response response
|
26
|
+
res = ['#### Response Details ####',
|
27
|
+
"* Request ID: #{response.session_id}",
|
28
|
+
"* Code: #{response.code} (#{response.status})",
|
29
|
+
"* Message: #{response.message}"]
|
30
|
+
res << "* Estimate Time: #{response.estimated_time} secs.;" if response.estimated_time > 0
|
31
|
+
res << "* Error caused by: #{response.uri};" if response.uri
|
32
|
+
res.join "\n"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|