akamai_api 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -0
  3. data/.yardopts +4 -0
  4. data/Gemfile +16 -0
  5. data/README.md +53 -52
  6. data/Thorfile +7 -1
  7. data/akamai_api.gemspec +1 -7
  8. data/bin/akamai_api +2 -1
  9. data/cassettes/akamai_api_ccu_arl_invalidate/invalid_credentials.yml +1 -1
  10. data/cassettes/akamai_api_ccu_arl_invalidate/invalid_item.yml +1 -1
  11. data/cassettes/akamai_api_ccu_arl_invalidate/multiple_items.yml +1 -1
  12. data/cassettes/akamai_api_ccu_arl_invalidate/single_item.yml +1 -1
  13. data/cassettes/akamai_api_ccu_arl_remove/invalid_credentials.yml +1 -1
  14. data/cassettes/akamai_api_ccu_arl_remove/invalid_item.yml +2 -2
  15. data/cassettes/akamai_api_ccu_arl_remove/multiple_items.yml +1 -1
  16. data/cassettes/akamai_api_ccu_arl_remove/single_item.yml +1 -1
  17. data/cassettes/akamai_api_ccu_cpcode_invalidate/invalid_credentials.yml +1 -1
  18. data/cassettes/akamai_api_ccu_cpcode_invalidate/invalid_item.yml +1 -1
  19. data/cassettes/akamai_api_ccu_cpcode_invalidate/multiple_items.yml +1 -1
  20. data/cassettes/akamai_api_ccu_cpcode_invalidate/single_item.yml +1 -1
  21. data/cassettes/akamai_api_ccu_cpcode_remove/invalid_credentials.yml +1 -1
  22. data/cassettes/akamai_api_ccu_cpcode_remove/invalid_item.yml +1 -1
  23. data/cassettes/akamai_api_ccu_cpcode_remove/multiple_items.yml +1 -1
  24. data/cassettes/akamai_api_ccu_cpcode_remove/single_item.yml +1 -1
  25. data/cassettes/akamai_api_eccu_all_ids/invalid_credentials.yml +68 -0
  26. data/cassettes/akamai_api_eccu_all_ids/successful.yml +72 -0
  27. data/cassettes/akamai_api_eccu_destroy/invalid_credentials.yml +69 -0
  28. data/cassettes/akamai_api_eccu_destroy/not_found_request.yml +55 -0
  29. data/cassettes/akamai_api_eccu_destroy/successful.yml +57 -0
  30. data/cassettes/akamai_api_eccu_find/invalid_credentials.yml +69 -0
  31. data/cassettes/akamai_api_eccu_find/not_found_request.yml +55 -0
  32. data/cassettes/akamai_api_eccu_find/successful.yml +70 -0
  33. data/cassettes/akamai_api_eccu_find/successful_without_content.yml +70 -0
  34. data/cassettes/akamai_api_eccu_publish/invalid_credentials.yml +5 -5
  35. data/cassettes/akamai_api_eccu_publish/invalid_domain.yml +7 -7
  36. data/cassettes/akamai_api_eccu_publish/successful.yml +8 -8
  37. data/cassettes/akamai_api_eccu_update_email/invalid_credentials.yml +69 -0
  38. data/cassettes/akamai_api_eccu_update_email/not_found_request.yml +55 -0
  39. data/cassettes/akamai_api_eccu_update_email/successful.yml +57 -0
  40. data/cassettes/akamai_api_eccu_update_notes/invalid_credentials.yml +70 -0
  41. data/cassettes/akamai_api_eccu_update_notes/not_found_request.yml +56 -0
  42. data/cassettes/akamai_api_eccu_update_notes/successful.yml +58 -0
  43. data/features/ccu_arl_invalidate.feature +5 -9
  44. data/features/ccu_arl_remove.feature +5 -9
  45. data/features/ccu_cpcode_invalidate.feature +2 -6
  46. data/features/ccu_cpcode_remove.feature +2 -6
  47. data/features/ccu_purge_status.feature +2 -2
  48. data/features/eccu_publish.feature +6 -42
  49. data/features/step_definitions/file_named_with_content_steps.rb +3 -0
  50. data/features/support/env.rb +12 -3
  51. data/lib/akamai_api/ccu/base_response.rb +27 -0
  52. data/lib/akamai_api/ccu/error.rb +38 -0
  53. data/lib/akamai_api/ccu/purge/request.rb +58 -11
  54. data/lib/akamai_api/ccu/purge/response.rb +15 -9
  55. data/lib/akamai_api/ccu/purge.rb +14 -3
  56. data/lib/akamai_api/ccu/purge_status/not_found.rb +18 -0
  57. data/lib/akamai_api/ccu/purge_status/request.rb +41 -7
  58. data/lib/akamai_api/ccu/purge_status/response.rb +49 -3
  59. data/lib/akamai_api/ccu/purge_status.rb +17 -9
  60. data/lib/akamai_api/ccu/status/request.rb +20 -7
  61. data/lib/akamai_api/ccu/status/response.rb +8 -2
  62. data/lib/akamai_api/ccu/status.rb +13 -2
  63. data/lib/akamai_api/ccu/unrecognized_option.rb +6 -0
  64. data/lib/akamai_api/ccu.rb +132 -23
  65. data/lib/akamai_api/cli/app.rb +15 -13
  66. data/lib/akamai_api/cli/ccu/arl.rb +10 -4
  67. data/lib/akamai_api/cli/ccu/base.rb +11 -3
  68. data/lib/akamai_api/cli/ccu/cp_code.rb +10 -4
  69. data/lib/akamai_api/cli/ccu/purge_renderer.rb +1 -1
  70. data/lib/akamai_api/cli/ccu/status_renderer.rb +46 -26
  71. data/lib/akamai_api/cli/ccu.rb +2 -4
  72. data/lib/akamai_api/cli/command.rb +60 -25
  73. data/lib/akamai_api/cli/eccu/base.rb +59 -0
  74. data/lib/akamai_api/cli/eccu/entry_renderer.rb +5 -3
  75. data/lib/akamai_api/cli/eccu.rb +2 -56
  76. data/lib/akamai_api/cli.rb +2 -6
  77. data/lib/akamai_api/eccu/base_edit_request.rb +51 -0
  78. data/lib/akamai_api/eccu/base_request.rb +32 -0
  79. data/lib/akamai_api/eccu/destroy_request.rb +30 -0
  80. data/lib/akamai_api/eccu/find_request.rb +45 -0
  81. data/lib/akamai_api/eccu/find_response.rb +110 -0
  82. data/lib/akamai_api/eccu/invalid_domain.rb +7 -0
  83. data/lib/akamai_api/eccu/list_request.rb +21 -0
  84. data/lib/akamai_api/eccu/not_found.rb +6 -0
  85. data/lib/akamai_api/eccu/publish_request.rb +75 -0
  86. data/lib/akamai_api/eccu/soap_body.rb +99 -0
  87. data/lib/akamai_api/eccu/update_attribute_request.rb +62 -0
  88. data/lib/akamai_api/eccu.rb +19 -0
  89. data/lib/akamai_api/eccu_request.rb +39 -117
  90. data/lib/akamai_api/error.rb +5 -0
  91. data/lib/akamai_api/unauthorized.rb +6 -0
  92. data/lib/akamai_api/version.rb +1 -1
  93. data/lib/akamai_api.rb +18 -4
  94. data/spec/features/ccu/purge_request_spec.rb +10 -12
  95. data/spec/features/ccu/purge_status_request_spec.rb +5 -5
  96. data/spec/features/ccu/status_request_spec.rb +3 -3
  97. data/spec/features/eccu/destroy_spec.rb +28 -0
  98. data/spec/features/eccu/find_request_spec.rb +34 -0
  99. data/spec/features/eccu/list_request_spec.rb +22 -0
  100. data/spec/features/eccu/publish_request_spec.rb +29 -0
  101. data/spec/features/eccu/update_email_spec.rb +28 -0
  102. data/spec/features/eccu/update_notes_spec.rb +28 -0
  103. data/spec/lib/akamai_api/ccu/{response_spec.rb → base_response_spec.rb} +2 -2
  104. data/spec/lib/akamai_api/ccu/purge/request_spec.rb +26 -20
  105. data/spec/lib/akamai_api/ccu/purge/response_spec.rb +16 -26
  106. data/spec/lib/akamai_api/ccu/purge_status/not_found_response_spec.rb +34 -34
  107. data/spec/lib/akamai_api/ccu/purge_status/request_spec.rb +24 -12
  108. data/spec/lib/akamai_api/ccu/purge_status/{successful_response_spec.rb → response_spec.rb} +8 -8
  109. data/spec/lib/akamai_api/ccu/status/request_spec.rb +6 -6
  110. data/spec/lib/akamai_api/ccu/status/response_spec.rb +2 -2
  111. data/spec/lib/akamai_api/ccu_spec.rb +7 -7
  112. data/spec/lib/akamai_api/cli/ccu/status_renderer_spec.rb +5 -17
  113. data/spec/lib/akamai_api/eccu/destroy_request_spec.rb +75 -0
  114. data/spec/lib/akamai_api/eccu/find_request_spec.rb +74 -0
  115. data/spec/lib/akamai_api/eccu/find_response_spec.rb +159 -0
  116. data/spec/lib/akamai_api/eccu/list_request_spec.rb +43 -0
  117. data/spec/lib/akamai_api/eccu/publish_request_spec.rb +133 -0
  118. data/spec/lib/akamai_api/eccu/soap_body_spec.rb +46 -0
  119. data/spec/lib/akamai_api/eccu/update_attribute_request_spec.rb +86 -0
  120. data/spec/lib/akamai_api/eccu_request_spec.rb +149 -158
  121. data/spec/spec_helper.rb +11 -3
  122. metadata +90 -104
  123. data/lib/akamai_api/ccu/purge_status/not_found_response.rb +0 -9
  124. data/lib/akamai_api/ccu/purge_status/successful_response.rb +0 -25
  125. data/lib/akamai_api/ccu/response.rb +0 -18
  126. data/lib/akamai_api/soap_body.rb +0 -40
  127. data/spec/lib/akamai_api/soap_body_spec.rb +0 -48
  128. data/spec/support/savon_backports.rb +0 -10
@@ -1,47 +1,156 @@
1
1
  require 'httparty'
2
- require 'active_support/core_ext'
3
- require 'akamai_api/ccu/response'
2
+
3
+ require 'active_support'
4
+ require 'active_support/core_ext/object/blank'
5
+
4
6
  require 'akamai_api/ccu/purge'
5
7
  require 'akamai_api/ccu/status'
6
8
  require 'akamai_api/ccu/purge_status'
7
9
 
8
10
  module AkamaiApi
9
- module Ccu
11
+ # This module contains the behavior needed to operate with the
12
+ # Akamai Content Control Utility (CCU) interface.
13
+ #
14
+ # Using the Akamai CCU interface you can:
15
+ # - submit a request to clean one or more resources (CPCodes or ARLs)
16
+ # - check the status of a particular request submitted through the Akamai CCU interface
17
+ # - check the status of the Akamai CCU queue
18
+ #
19
+ # For all operations you can directly use the helpers directly defined in this module.
20
+ #
21
+ # For more informations about the Akamai CCU interface, you can read the
22
+ # {https://api.CCU.akamai.com/CCU/v2/docs/index.html Developers Guide provided by Akamai}
23
+ module CCU
10
24
  extend self
11
25
 
12
- class UnrecognizedOption < StandardError; end
13
-
26
+ # @!method invalidate(type, items, opts={})
27
+ # Invalidates one or more resources
28
+ # @param [String,Symbol] type resource type to clean. Allowed values are:
29
+ # - :cpcode
30
+ # - :arl
31
+ # Check {AkamaiApi::CCU::Purge::Request#type} for more details
32
+ # @param [String,Array] items resource(s) to invalidate
33
+ # @param [Hash] opts additional options
34
+ # @option opts [String,Symbol] :domain domain type where to act. Allowed values are:
35
+ # - :production
36
+ # - :staging
37
+ # Check {AkamaiApi::CCU::Purge::Request#domain} for more details
38
+ # @return [AkamaiApi::CCU::Purge::Response] an object representing the received response
39
+ # @raise [AkamaiApi::CCU::Error] when there is an error in the request
40
+ # @raise [AkamaiApi::Unauthorized] when login credentials are invalid
41
+ # @!method remove(type, items, opts={})
42
+ # Remove one or more resources
43
+ # @param [String,Symbol] type resource type to clean. Allowed values are:
44
+ # - :cpcode
45
+ # - :arl
46
+ # Check {AkamaiApi::CCU::Purge::Request#type} for more details
47
+ # @param [String,Array] items resource(s) to remove
48
+ # @param [Hash] opts additional options
49
+ # @option opts [String,Symbol] :domain domain type where to act. Allowed values are:
50
+ # - :production
51
+ # - :staging
52
+ # Check {AkamaiApi::CCU::Purge::Request#domain} for more details
53
+ # @return [AkamaiApi::CCU::Purge::Response] an object representing the received response
54
+ # @raise [AkamaiApi::CCU::Error] when there is an error in the request
55
+ # @raise [AkamaiApi::Unauthorized] when login credentials are invalid
56
+ # @!method invalidate_arl(items, opts={})
57
+ # Invalidates one or more ARLs
58
+ # @param [String,Array] items ARL(s) to invalidate
59
+ # @param [Hash] opts additional options
60
+ # @option opts [String,Symbol] :domain domain type where to act. Allowed values are:
61
+ # - :production
62
+ # - :staging
63
+ # Check {AkamaiApi::CCU::Purge::Request#domain} for more details
64
+ # @return [AkamaiApi::CCU::Purge::Response] an object representing the received response
65
+ # @raise [AkamaiApi::CCU::Error] when there is an error in the request
66
+ # @raise [AkamaiApi::Unauthorized] when login credentials are invalid
67
+ # @!method invalidate_cpcode(items, opts={})
68
+ # Invalidates one or more CPCodes
69
+ # @param [String,Array] items CPCode(s) to invalidate
70
+ # @param [Hash] opts additional options
71
+ # @option opts [String,Symbol] :domain domain type where to act. Allowed values are:
72
+ # - :production
73
+ # - :staging
74
+ # Check {AkamaiApi::CCU::Purge::Request#domain} for more details
75
+ # @return [AkamaiApi::CCU::Purge::Response] an object representing the received response
76
+ # @raise [AkamaiApi::CCU::Error] when there is an error in the request
77
+ # @raise [AkamaiApi::Unauthorized] when login credentials are invalid
78
+ # @!method remove_arl(items, opts={})
79
+ # Invalidates one or more ARLs
80
+ # @param [String,Array] items ARL(s) to remove
81
+ # @param [Hash] opts additional options
82
+ # @option opts [String,Symbol] :domain domain type where to act. Allowed values are:
83
+ # - :production
84
+ # - :staging
85
+ # Check {AkamaiApi::CCU::Purge::Request#domain} for more details
86
+ # @return [AkamaiApi::CCU::Purge::Response] an object representing the received response
87
+ # @raise [AkamaiApi::CCU::Error] when there is an error in the request
88
+ # @raise [AkamaiApi::Unauthorized] when login credentials are invalid
89
+ # @!method remove_cpcode(items, opts={})
90
+ # Invalidates one or more CPCodes
91
+ # @param [String,Array] items CPCode(s) to remove
92
+ # @param [Hash] opts additional options
93
+ # @option opts [String,Symbol] :domain domain type where to act. Allowed values are:
94
+ # - :production
95
+ # - :staging
96
+ # Check {AkamaiApi::CCU::Purge::Request#domain} for more details
97
+ # @return [AkamaiApi::CCU::Purge::Response] an object representing the received response
98
+ # @raise [AkamaiApi::CCU::Error] when there is an error in the request
99
+ # @raise [AkamaiApi::Unauthorized] when login credentials are invalid
14
100
  [:invalidate, :remove].each do |action|
15
- send :define_method, action do |*params|
16
- raise ArgumentError, "wrong number of arguments (#{params.length} for 2..3)" if params.length < 2
17
- type, items, opts = params
18
- purge action, type, items, (opts || {})
101
+ define_method action do |type, items, opts={}|
102
+ purge action, type, items, opts
19
103
  end
20
104
  [:arl, :cpcode].each do |type|
21
- method_name = "#{action}_#{type}".to_sym
22
- send :define_method, method_name do |*params|
23
- raise ArgumentError, "wrong number of arguments (#{params.length} for 1..2)" if params.length < 1
24
- items, opts = params
25
- purge action, type, items, (opts || {})
105
+ define_method "#{action}_#{type}" do |items, opts={}|
106
+ purge action, type, items, opts
26
107
  end
27
108
  end
28
109
  end
29
110
 
30
- def purge action, type, items, args = {}
31
- request = Purge::Request.new action, type, domain: args[:domain]
111
+ # Purges one or more resources
112
+ # @param [String,Symbol] action type of clean action. Allowed values are:
113
+ # - :invalidate
114
+ # - :remove
115
+ # Check {AkamaiApi::CCU::Purge::Request#action} for more details
116
+ # @param [String,Symbol] type type of resource to clean. Allowed values are:
117
+ # - :cpcode
118
+ # - :arl
119
+ # Check {AkamaiApi::CCU::Purge::Request#type} for more details
120
+ # @param [String, Array] items resource(s) to clean
121
+ # @param [Hash] opts additional options
122
+ # @option opts [String] :domain domain type where to act. Allowed values are:
123
+ # - :production
124
+ # - :staging
125
+ # Check {AkamaiApi::CCU::Purge::Request#domain} for more details
126
+ # @return [AkamaiApi::CCU::Purge::Response] an object representing the received response
127
+ # @raise [AkamaiApi::CCU::Error] when there is an error in the request
128
+ # @raise [AkamaiApi::Unauthorized] when login credentials are invalid
129
+ def purge action, type, items, opts = {}
130
+ request = Purge::Request.new action, type, domain: opts[:domain]
32
131
  request.execute items
33
132
  end
34
133
 
35
- def status progress_uri = nil
36
- if progress_uri.present?
37
- PurgeStatus::Request.new.execute progress_uri
134
+ # @overload status
135
+ # Checks the status of the Akamai CCU queue
136
+ # @return [AkamaiApi::CCU::Status::Response] a response object describing the status of the Akamai CCU queue
137
+ # @raise [AkamaiApi::CCU::Error] when there is an error in the request
138
+ # @raise [AkamaiApi::Unauthorized] when login credentials are invalid
139
+ # @overload status(progress_uri)
140
+ # Checks the status of an Akamai CCU purge request
141
+ # @param [String] purge_id_or_progress_uri request id
142
+ # (both purge_id and progress_uri are accepted)
143
+ # @return [AkamaiApi::CCU::PurgeStatus::Response] an object detailing the response
144
+ # @raise [AkamaiApi::CCU::PurgeStatus::NotFound] when not request has been found
145
+ # @raise [AkamaiApi::CCU::Error] when there is an error in the request
146
+ # @raise [AkamaiApi::Unauthorized] when login credentials are invalid
147
+ # Checks the status of the Akamai CCU queue or the status of a purge request
148
+ def status purge_id_or_progress_uri = nil
149
+ if purge_id_or_progress_uri
150
+ PurgeStatus::Request.new.execute purge_id_or_progress_uri
38
151
  else
39
152
  Status::Request.new.execute
40
153
  end
41
154
  end
42
-
43
- def self.auth
44
- { username: AkamaiApi.config[:auth].first, password: AkamaiApi.config[:auth].last }
45
- end
46
155
  end
47
156
  end
@@ -1,18 +1,20 @@
1
- module AkamaiApi
2
- module Cli
3
- class App < Thor
4
- desc 'ccu', 'CCU Interface'
5
- subcommand 'ccu', AkamaiApi::Cli::Ccu::Base
1
+ require "thor"
2
+ require "akamai_api/cli/ccu"
3
+ require "akamai_api/cli/eccu"
6
4
 
7
- desc 'eccu', 'ECCU Interface'
8
- subcommand 'eccu', AkamaiApi::Cli::Eccu
5
+ module AkamaiApi::CLI
6
+ class App < Thor
7
+ desc 'ccu', 'CCU Interface'
8
+ subcommand 'ccu', AkamaiApi::CLI::CCU::Base
9
9
 
10
- def help *args
11
- puts
12
- puts "AkamaiApi is a command line utility to interact with Akamai CCU (Content Control Utility) and ECCU (Enhanced Content Control Utility) services."
13
- puts
14
- super
15
- end
10
+ desc 'eccu', 'ECCU Interface'
11
+ subcommand 'eccu', AkamaiApi::CLI::ECCU::Base
12
+
13
+ def help *args
14
+ puts
15
+ puts "AkamaiApi is a command line utility to interact with Akamai CCU (Content Control Utility) and ECCU (Enhanced Content Control Utility) services."
16
+ puts
17
+ super
16
18
  end
17
19
  end
18
20
  end
@@ -1,5 +1,9 @@
1
- module AkamaiApi::Cli::Ccu
2
- class Arl < AkamaiApi::Cli::Command
1
+ require "akamai_api/ccu"
2
+ require "akamai_api/cli/command"
3
+ require "akamai_api/cli/ccu/purge_renderer"
4
+
5
+ module AkamaiApi::CLI::CCU
6
+ class Arl < AkamaiApi::CLI::Command
3
7
  namespace 'ccu arl'
4
8
 
5
9
  desc 'remove http://john.com/a.txt http://www.smith.com/b.txt ...', 'Purge ARL(s) removing them from the cache'
@@ -26,8 +30,10 @@ module AkamaiApi::Cli::Ccu
26
30
  def purge_action type, arls
27
31
  raise 'You should provide at least one valid URL' if arls.blank?
28
32
  load_config
29
- res = AkamaiApi::Ccu.purge type, :arl, arls, :domain => options[:domain]
30
- puts ::AkamaiApi::Cli::Ccu::PurgeRenderer.new(res).render
33
+ res = AkamaiApi::CCU.purge type, :arl, arls, :domain => options[:domain]
34
+ puts PurgeRenderer.new(res).render
35
+ rescue AkamaiApi::CCU::Error
36
+ puts StatusRenderer.new($!).render_error
31
37
  rescue AkamaiApi::Unauthorized
32
38
  puts 'Your login credentials are invalid.'
33
39
  end
@@ -1,5 +1,11 @@
1
- module AkamaiApi::Cli::Ccu
2
- class Base < AkamaiApi::Cli::Command
1
+ require "akamai_api/ccu"
2
+ require "akamai_api/cli/command"
3
+ require "akamai_api/cli/ccu/cp_code"
4
+ require "akamai_api/cli/ccu/arl"
5
+ require "akamai_api/cli/ccu/status_renderer"
6
+
7
+ module AkamaiApi::CLI::CCU
8
+ class Base < AkamaiApi::CLI::Command
3
9
  desc 'cpcode', 'CP Code CCU actions'
4
10
  subcommand 'cpcode', CpCode
5
11
 
@@ -9,8 +15,10 @@ module AkamaiApi::Cli::Ccu
9
15
  desc 'status [progress_uri]', 'Show the CCU queue status if no progress_uri is given, or show a CCU Purge request status if a progress uri is given'
10
16
  def status progress_uri = nil
11
17
  load_config
12
- response = AkamaiApi::Ccu.status progress_uri
18
+ response = AkamaiApi::CCU.status progress_uri
13
19
  puts StatusRenderer.new(response).render
20
+ rescue AkamaiApi::CCU::Error => e
21
+ puts StatusRenderer.new(e).render_error
14
22
  rescue AkamaiApi::Unauthorized
15
23
  puts 'Your login credentials are invalid.'
16
24
  end
@@ -1,5 +1,9 @@
1
- module AkamaiApi::Cli::Ccu
2
- class CpCode < AkamaiApi::Cli::Command
1
+ require "akamai_api/ccu"
2
+ require "akamai_api/cli/command"
3
+ require "akamai_api/cli/ccu/purge_renderer"
4
+
5
+ module AkamaiApi::CLI::CCU
6
+ class CpCode < AkamaiApi::CLI::Command
3
7
  namespace 'ccu cpcode'
4
8
 
5
9
  desc 'remove CPCODE1 CPCODE2 ...', 'Purge CP Code(s) removing them from the cache'
@@ -29,8 +33,10 @@ module AkamaiApi::Cli::Ccu
29
33
  return
30
34
  end
31
35
  load_config
32
- res = AkamaiApi::Ccu.purge type, :cpcode, cpcodes, :domain => options[:domain]
33
- puts ::AkamaiApi::Cli::Ccu::PurgeRenderer.new(res).render
36
+ res = AkamaiApi::CCU.purge type, :cpcode, cpcodes, :domain => options[:domain]
37
+ puts PurgeRenderer.new(res).render
38
+ rescue AkamaiApi::CCU::Error
39
+ puts StatusRenderer.new($!).render_error
34
40
  rescue AkamaiApi::Unauthorized
35
41
  puts "Your login credentials are invalid."
36
42
  end
@@ -1,4 +1,4 @@
1
- module AkamaiApi::Cli::Ccu
1
+ module AkamaiApi::CLI::CCU
2
2
  class PurgeRenderer
3
3
  attr_reader :response
4
4
 
@@ -1,4 +1,7 @@
1
- module AkamaiApi::Cli::Ccu
1
+ require "akamai_api/ccu/status/response"
2
+ require "akamai_api/ccu/purge_status/response"
3
+
4
+ module AkamaiApi::CLI::CCU
2
5
  class StatusRenderer
3
6
  attr_reader :response
4
7
 
@@ -6,8 +9,16 @@ module AkamaiApi::Cli::Ccu
6
9
  @response = response
7
10
  end
8
11
 
12
+ def render_error
13
+ if response.is_a? AkamaiApi::CCU::PurgeStatus::NotFound
14
+ render_not_found
15
+ else
16
+ render_generic_error
17
+ end
18
+ end
19
+
9
20
  def render
10
- res = response.is_a?(AkamaiApi::Ccu::Status::Response) ? render_status : render_purge_status
21
+ res = response.is_a?(AkamaiApi::CCU::Status::Response) ? queue_status : purge_status
11
22
  [
12
23
  '----------',
13
24
  res,
@@ -15,41 +26,26 @@ module AkamaiApi::Cli::Ccu
15
26
  ].join "\n"
16
27
  end
17
28
 
18
- def render_status
29
+ def queue_status
19
30
  [
20
31
  "Akamai CCU Queue Status",
21
32
  "\t* Result: #{response.code} - #{response.message}",
22
33
  "\t* Support ID: #{response.support_id}",
23
34
  "\t* Queue Length: #{response.queue_length}"
24
- ].join "\n"
25
- end
26
-
27
- def render_purge_status
28
- if response.is_a? AkamaiApi::Ccu::PurgeStatus::SuccessfulResponse
29
- render_successful_purge_status
30
- else
31
- render_not_found_purge_status
32
- end
35
+ ]
33
36
  end
34
37
 
35
- def render_successful_purge_status
38
+ def purge_status
36
39
  output = [
37
- successful_purge_status_description,
40
+ purge_description,
38
41
  "\t* Result: #{response.code} - #{response.status}",
39
42
  "\t* Purge ID: #{response.purge_id} | Support ID: #{response.support_id}",
40
43
  "\t* Submitted by: #{response.submitted_by} on #{response.submitted_at}"
41
44
  ]
42
- if response.completed_at
43
- output << "\t* Completed on: #{response.completed_at}"
44
- else
45
- output << "\t* Estimated time: #{response.estimated_time} secs."
46
- output << "\t* Queue length: #{response.queue_length}"
47
- output << "\t* Time to wait before next check: #{response.time_to_wait} secs."
48
- end
49
- output.join "\n"
45
+ output.concat response.completed_at ? successful_completed_purge : successful_pending_purge
50
46
  end
51
47
 
52
- def successful_purge_status_description
48
+ def purge_description
53
49
  if response.completed_at
54
50
  "Purge request has been successfully completed:"
55
51
  else
@@ -57,13 +53,37 @@ module AkamaiApi::Cli::Ccu
57
53
  end
58
54
  end
59
55
 
60
- def render_not_found_purge_status
56
+ def render_not_found
61
57
  [
58
+ "----------",
62
59
  "No purge request found using #{response.progress_uri}:",
63
60
  "\t* Result: #{response.code} - #{response.message}",
64
- "\t* Purge ID: #{response.purge_id} | Support ID: #{response.support_id}",
65
- "\t* Time to wait before next check: #{response.time_to_wait} secs."
61
+ "\t* Support ID: #{response.support_id}",
62
+ "\t* Time to wait before next check: #{response.time_to_wait} secs.",
63
+ "----------"
64
+ ].join "\n"
65
+ end
66
+
67
+ def render_generic_error
68
+ [
69
+ "----------",
70
+ "Error #{response.code}: '#{response.message}' (#{response.detail})",
71
+ " Described by: #{response.described_by}",
72
+ " Support ID: #{response.support_id}",
73
+ "----------"
66
74
  ].join "\n"
67
75
  end
76
+
77
+ def successful_completed_purge
78
+ ["\t* Completed on: #{response.completed_at}"]
79
+ end
80
+
81
+ def successful_pending_purge
82
+ [
83
+ "\t* Estimated time was: #{response.original_estimated_time} secs.",
84
+ "\t* Queue length was: #{response.original_queue_length}",
85
+ "\t* Time to wait before next check: #{response.time_to_wait} secs.",
86
+ ]
87
+ end
68
88
  end
69
89
  end
@@ -1,6 +1,4 @@
1
- %w(cp_code arl status_renderer purge_renderer base).each do |file|
2
- require File.expand_path "../ccu/#{file}", __FILE__
3
- end
1
+ require "akamai_api/cli/ccu/base"
4
2
 
5
- module AkamaiApi::Cli::Ccu
3
+ module AkamaiApi::CLI::CCU
6
4
  end
@@ -1,30 +1,65 @@
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 = {}
12
- config_file = File.expand_path '~/.akamai_api.yml'
13
- if File::exists?( config_file )
14
- config = YAML::load_file(config_file).symbolize_keys
15
- end
16
- if ENV['AKAMAI_USERNAME'] && ENV['AKAMAI_PASSWORD']
17
- config.merge! :auth => [ENV['AKAMAI_USERNAME'], ENV['AKAMAI_PASSWORD']]
18
- end
19
- if options[:username] && options[:password]
20
- config.merge! :auth => [options[:username], options[:password]]
21
- end
22
- if config[:auth].nil? || config[:auth].compact.blank?
23
- raise "#{config_file} does not exist OR doesn't contain auth info OR you didn't export environment variables OR you didn't specify username and password on the command line"
24
- end
25
- AkamaiApi.config.merge! config
1
+ require "thor"
2
+ require "active_support"
3
+ require "active_support/core_ext/hash"
4
+
5
+ module AkamaiApi::CLI
6
+ class Command < Thor
7
+ class_option :username, :type => :string, :aliases => '-u',
8
+ :desc => 'Username used to authenticate on Akamai Control Panel'
9
+ class_option :password, :type => :string, :aliases => '-p',
10
+ :desc => 'Password used to authenticate on Akamai Control Panel'
11
+
12
+ no_tasks do
13
+ def load_config
14
+ load_config_from_file
15
+ load_config_from_env
16
+ load_config_from_options
17
+ if AkamaiApi.auth_empty?
18
+ render_auth_info
19
+ exit 1
20
+ end
21
+ end
22
+
23
+ def config_file
24
+ File.expand_path '~/.akamai_api.yml'
25
+ end
26
+
27
+ def load_config_from_file
28
+ if File.exists?(config_file)
29
+ AkamaiApi.config.merge! YAML::load_file(config_file).symbolize_keys
30
+ end
31
+ end
32
+
33
+ def load_config_from_options
34
+ AkamaiApi.config[:auth].tap do |auth|
35
+ auth[0] = options.fetch 'username', auth[0]
36
+ auth[1] = options.fetch 'password', auth[1]
26
37
  end
27
38
  end
39
+
40
+ def load_config_from_env
41
+ AkamaiApi.config[:auth].tap do |auth|
42
+ auth[0] = ENV.fetch 'AKAMAI_USERNAME', auth[0]
43
+ auth[1] = ENV.fetch 'AKAMAI_PASSWORD', auth[1]
44
+ end
45
+ end
46
+
47
+ def render_auth_info
48
+ puts <<-OUTPUT
49
+ No authentication config found. You can specify auth credentials with one of the following methods:"
50
+
51
+ * Creating a file in your home directory named `.akamai_api.yml` with the following content:"
52
+ auth:"
53
+ - my_username"
54
+ - my_password"
55
+
56
+ * Using the environment variables AKAMAI_USERNAME and AKAMAI_PASSWORD. E.g:"
57
+ AKAMAI_USERNAME=my_username AKAMAI_PASSWORD=my_password akamai_api ECCU last_request"
58
+
59
+ * Passing username and password options from command line. E.g.:"
60
+ akamai_api ECCU last_request -u my_username -p my_password"
61
+ OUTPUT
62
+ end
28
63
  end
29
64
  end
30
65
  end
@@ -0,0 +1,59 @@
1
+ require "akamai_api/cli/command"
2
+ require "akamai_api/cli/eccu/entry_renderer"
3
+
4
+ module AkamaiApi::CLI::ECCU
5
+ class Base < AkamaiApi::CLI::Command
6
+ desc 'requests', 'Print the list of the last requests made to ECCU'
7
+ method_option :content, :type => :boolean, :aliases => '-c',
8
+ :desc => 'Print request content too'
9
+ def requests
10
+ load_config
11
+ requests = AkamaiApi::ECCURequest.all :verbose => options[:content]
12
+ puts EntryRenderer.render requests
13
+ rescue ::AkamaiApi::Unauthorized
14
+ puts "Your login credentials are invalid."
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 EntryRenderer.new(request).render
24
+ rescue ::AkamaiApi::Unauthorized
25
+ puts "Your login credentials are invalid."
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 => '-P',
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 #{AkamaiApi::VERSION}"
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
+ :emails => options[:emails]
47
+ }
48
+ id = AkamaiApi::ECCURequest.publish_file property, source, args
49
+ puts "Request correctly published:"
50
+ puts EntryRenderer.new(AkamaiApi::ECCURequest.find(id, :verbose => true)).render
51
+ rescue ::AkamaiApi::Unauthorized
52
+ puts "Your login credentials are invalid."
53
+ rescue ::AkamaiApi::ECCU::InvalidDomain
54
+ puts "You are not authorized to specify this digital property."
55
+ rescue Savon::SOAPFault
56
+ puts $!.message
57
+ end
58
+ end
59
+ end
@@ -1,6 +1,8 @@
1
- class AkamaiApi::Cli::Eccu
2
- class EntryRenderer
1
+ require "active_support"
2
+ require "active_support/core_ext/object/blank"
3
3
 
4
+ module AkamaiApi::CLI::ECCU
5
+ class EntryRenderer
4
6
  def self.render entries
5
7
  output = ["----------"]
6
8
  entries.each do |e|
@@ -28,7 +30,7 @@ class AkamaiApi::Cli::Eccu
28
30
  output = [
29
31
  "* Code : #{entry.code}",
30
32
  entry_status,
31
- " #{entry.status[:update_date]}",
33
+ " #{entry.status[:updated_at]}",
32
34
  entry_property
33
35
  ]
34
36
  output << "* Notes : #{entry.notes}" if entry.notes.present?
@@ -1,58 +1,4 @@
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
- puts EntryRenderer.render requests
11
- rescue ::AkamaiApi::Unauthorized
12
- puts "Your login credentials are invalid."
13
- end
1
+ require "akamai_api/cli/eccu/base"
14
2
 
15
- desc 'last_request', 'Print the last request made to ECCU'
16
- method_option :content, :type => :boolean, :aliases => '-c',
17
- :desc => 'Print request content too'
18
- def last_request
19
- load_config
20
- request = AkamaiApi::EccuRequest.last verbose: options[:content]
21
- puts EntryRenderer.new(request).render
22
- rescue ::AkamaiApi::Unauthorized
23
- puts "Your login credentials are invalid."
24
- end
25
-
26
- desc 'publish_xml path/to/request.xml john.com', 'Publish a request made in XML for the specified Digital Property (usually the Host Header)'
27
- long_desc 'Publish a request made in XML (ECCU Request Format) and apply it to the specified Digital Property (usually the Host Header)'
28
- method_option :property_type, :type => :string, :aliases => '-pt',
29
- :default => 'hostheader', :banner => 'type',
30
- :desc => 'Type of enlisted properties'
31
- method_option :no_exact_match, :type => :boolean,
32
- :desc => 'Do not do an exact match on property names'
33
- method_option :emails, :type => :array, :aliases => '-e',
34
- :banner => "foo@foo.com bar@bar.com",
35
- :desc => 'Email(s) to use to send notification on status change'
36
- method_option :notes, :type => :string, :aliases => '-n',
37
- :default => 'ECCU Request using AkamaiApi gem'
38
- def publish_xml(source, property)
39
- load_config
40
- args = {
41
- :notes => options[:notes],
42
- :property_exact_match => !options[:no_exact_match],
43
- :property_type => options[:property_type],
44
- :emails => options[:emails]
45
- }
46
- id = AkamaiApi::EccuRequest.publish_file property, source, args
47
- puts "Request correctly published:"
48
- puts EntryRenderer.new(AkamaiApi::EccuRequest.find(id, :verbose => true)).render
49
- rescue ::AkamaiApi::Unauthorized
50
- puts "Your login credentials are invalid."
51
- rescue Savon::SOAPFault
52
- puts $!.message
53
- end
54
- end
55
- end
3
+ module AkamaiApi::CLI::ECCU
56
4
  end
57
-
58
- require File.expand_path '../eccu/entry_renderer', __FILE__