akamai_cloudlet_manager 0.0.1 → 0.0.2

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: 3097dba680e9840c7433cb9891fffae7c4ec3df4
4
- data.tar.gz: 992429969fd5c9de85e9e2ddc6e2d468a4f3d68f
3
+ metadata.gz: f33e1ce2cf65b398f20153bacd85f6f7d2df49af
4
+ data.tar.gz: e4e4d7d402bdedb30527ff8ba0082c84e230cecd
5
5
  SHA512:
6
- metadata.gz: d7da5aea3185c4a29ed76642fa56263e0e304e9d352754d93987789ff39bdda4c2615f6c19739499c0dc5bf033209f1c7e8266e55a71490c87e1b17a6c86455b
7
- data.tar.gz: 03c52fda46f04ba25d38c0a4e6d508488f1489a647d5749d63ba66204c649782dac273f68f936b0e991422d14ac3d7f679ec6a0a277676f43c970e7cb49b912e
6
+ metadata.gz: 012ae566e4d7e58c6fc2eb6d10e1488a9d26322e3a548f5525d1ac5d1872bf8ee28b7c18fe5c29d1a9ddcb76329083987d126d378348eccb0cbd054c3675d308
7
+ data.tar.gz: f1f26d134b1c7d01eeba2df7e1e51233c960f22ae2f907cd5590927c2698d8c9b547c1c3d6cdc266b6ecc735e9b29cb4cfc460e874babbbdb04f0b6a245377ec
data/bin/acm CHANGED
@@ -39,8 +39,7 @@ class AkamaiCloudletManagerCli < Thor
39
39
  puts "No policy versions available"
40
40
  end
41
41
  rescue => err
42
- puts "cloning failed!"
43
- puts "Exception: #{err}"
42
+ puts "Exception: #{err.formatted_exception("Policy cloning failed!")}"
44
43
  err
45
44
  end
46
45
  end
@@ -48,7 +47,7 @@ class AkamaiCloudletManagerCli < Thor
48
47
  desc "update_policy_version", "Updates the policy version"
49
48
  long_desc <<-LONGDESC
50
49
  Updates the policy version. Policy version can be updated only in draft mode, not when it is activated.
51
- With --policy, policy on which version to be updated
50
+ With --policy_id, policy on which version to be updated
52
51
  With --draft_version, version which needs to be updated, this must be inactive version
53
52
  With --file_path, file_path from which rules can be constructed and updated to policy version
54
53
  With --rule_name, rule name so that it is visible in akamai control panel
@@ -66,7 +65,7 @@ class AkamaiCloudletManagerCli < Thor
66
65
  method_option :rule_type, required: false
67
66
  method_option :cookie_rules, required: false
68
67
  def update_policy_version
69
- puts "updates the policy version"
68
+ puts "updating the policy version"
70
69
  policy_version = AkamaiCloudletManager::PolicyVersion.new({
71
70
  policy_id: options[:policy_id],
72
71
  version_id: options[:draft_version]
@@ -79,6 +78,40 @@ class AkamaiCloudletManagerCli < Thor
79
78
  end
80
79
  end
81
80
 
81
+ desc "append_rules_to_policy_version", "Appends new rules to existing policy version"
82
+ long_desc <<-LONGDESC
83
+ Append new rules to existing policy version. Policy version can be updated only in draft mode, not when it is activated.
84
+ With --policy_id, policy on which version to be updated
85
+ With --draft_version, version which needs to be updated, this must be inactive version
86
+ With --file_path, file_path from which rules can be constructed and updated to policy version
87
+ With --rule_name, rule name so that it is visible in akamai control panel
88
+ With --origin_id, origin's id, this can be found from "get_policy_versions" command
89
+ With --rule_type, rule type, e.g. "albMatchRule"
90
+ With --cookie_rules, from which cookie rules can be constructed and updated to policy version, e.g. "abc=xyz"
91
+
92
+ LONGDESC
93
+
94
+ method_option :policy_id, required: true
95
+ method_option :draft_version, required: true
96
+ method_option :file_path, required: true
97
+ method_option :rule_name, required: true
98
+ method_option :origin_id, required: true
99
+ method_option :rule_type, required: false
100
+ method_option :cookie_rules, required: false
101
+ def append_rules_to_policy_version
102
+ puts "Appending rules to draft policy version with existing rules"
103
+ policy_version = AkamaiCloudletManager::PolicyVersion.new({
104
+ policy_id: options[:policy_id],
105
+ version_id: options[:draft_version]
106
+ })
107
+ begin
108
+ puts policy_version.append(options)
109
+ rescue => err
110
+ puts "Exception: #{err.formatted_exception("Policy version update failed!")}"
111
+ err
112
+ end
113
+ end
114
+
82
115
  desc "activate_policy_version", "Activate the policy version on a given network(staging/production)"
83
116
  long_desc <<-LONGDESC
84
117
  Activates the policy version
@@ -91,7 +124,7 @@ class AkamaiCloudletManagerCli < Thor
91
124
  method_option :version, required: true
92
125
  method_option :network, required: true, enum: ['staging','production']
93
126
  def activate_policy_version
94
- puts "activates the policy version"
127
+ puts "activating the policy version"
95
128
  policy_version = AkamaiCloudletManager::PolicyVersion.new({
96
129
  policy_id: options[:policy_id],
97
130
  version_id: options[:version]
@@ -102,8 +135,7 @@ class AkamaiCloudletManagerCli < Thor
102
135
  puts options[:version]
103
136
  puts policy_version.activate(options[:network])
104
137
  rescue => err
105
- puts "activation failed!"
106
- puts "Exception: #{err}"
138
+ puts "Exception: #{err.formatted_exception("Policy activation failed!")}"
107
139
  err
108
140
  end
109
141
  end
@@ -11,7 +11,6 @@ module AkamaiCloudletManager
11
11
  def info
12
12
  request = Net::HTTP::Get.new URI.join(@base_uri.to_s, "cloudlets/api/v2/cloudlet-info/#{@cloudlet_id}").to_s
13
13
  response = @http_host.request(request)
14
- # puts response.body
15
14
  response.body
16
15
  end
17
16
 
@@ -19,7 +18,6 @@ module AkamaiCloudletManager
19
18
  def list
20
19
  request = Net::HTTP::Get.new URI.join(@base_uri.to_s, "cloudlets/api/v2/cloudlet-info?#{@group_id}").to_s
21
20
  response = @http_host.request(request)
22
- # puts response.body
23
21
  response.body
24
22
  end
25
23
  end
@@ -5,7 +5,6 @@ module AkamaiCloudletManager
5
5
  def list(type)
6
6
  request = Net::HTTP::Get.new URI.join(@base_uri.to_s, "cloudlets/api/v2/origins?type=#{type}").to_s
7
7
  response = @http_host.request(request)
8
- # puts response.body
9
8
  response.body
10
9
  end
11
10
  end
@@ -12,7 +12,6 @@ module AkamaiCloudletManager
12
12
  "/cloudlets/api/v2/policies/#{@policy_id}/properties"
13
13
  ).to_s
14
14
  response = @http_host.request(request)
15
- # puts response.body
16
15
  response.body
17
16
  end
18
17
  end
@@ -7,11 +7,9 @@ module AkamaiCloudletManager
7
7
  end
8
8
 
9
9
  # Get Policy version's rules
10
- # request = Net::HTTP::Get.new URI.join(@base_uri.to_s, "cloudlets/api/v2/policies/38548/versions/1?omitRules=false&matchRuleFormat=1.0"').to_s
11
- def rules
10
+ def existing_rules
12
11
  request = Net::HTTP::Get.new URI.join(@base_uri.to_s, "cloudlets/api/v2/policies/#{@policy_id}/versions/#{@version_id}?omitRules=false&matchRuleFormat=1.0").to_s
13
12
  response = @http_host.request(request)
14
- # puts response.body
15
13
  response.body
16
14
  end
17
15
 
@@ -23,7 +21,6 @@ module AkamaiCloudletManager
23
21
  "cloudlets/api/v2/policies/#{@policy_id}/versions?includeRules=false&matchRuleFormat=1.0"
24
22
  ).to_s
25
23
  response = @http_host.request(request)
26
- # puts response.body
27
24
  response.body
28
25
  end
29
26
 
@@ -37,7 +34,6 @@ module AkamaiCloudletManager
37
34
  { 'Content-Type' => 'application/json'}
38
35
  )
39
36
  response = @http_host.request(request)
40
- # puts response.body
41
37
  response.body
42
38
  end
43
39
 
@@ -54,17 +50,26 @@ module AkamaiCloudletManager
54
50
  "network": network
55
51
  }.to_json
56
52
  response = @http_host.request(request)
57
- # puts response.body
58
53
  response.body
59
54
  end
60
55
 
56
+ def append(options={})
57
+ # Removing location is mandatory from matchRules, otherwise we see this error:
58
+ # matchRules : object instance has properties which are not allowed by the schema: [\"location\"]\n"
59
+ rules = JSON.parse(existing_rules)
60
+ rules = rules["matchRules"].map{|rule| rule.delete('location'); rule; }
61
+
62
+ update(options, rules)
63
+ end
64
+
61
65
  # Update policy version, all rules
62
- def update(options = {})
66
+ def update(options = {}, existing_rules = [])
67
+
63
68
  request = Net::HTTP::Put.new(
64
69
  URI.join(@base_uri.to_s, "cloudlets/api/v2/policies/#{@policy_id}/versions/#{@version_id}?omitRules=false&matchRuleFormat=1.0").to_s,
65
70
  { 'Content-Type' => 'application/json'}
66
71
  )
67
- rules = generate_path_rules(options) + generate_cookie_rules(options)
72
+ rules = generate_path_rules(options) + generate_cookie_rules(options) + existing_rules
68
73
 
69
74
  if rules.empty?
70
75
  puts "No rules to apply, please check syntax"
@@ -80,9 +85,9 @@ module AkamaiCloudletManager
80
85
 
81
86
  # All the path rules from one file will be added under same match, space separated
82
87
  def generate_path_rules(options={})
83
- return [] if options[:file_path].empty?
88
+ return [] if options[:file_path].nil? || options[:file_path].empty?
84
89
 
85
- options = options.merge(match_operator: 'equals', match_type: 'path')
90
+ options = options.merge(match_operator: 'contains', match_type: 'path')
86
91
  counter = 0
87
92
  match_value = []
88
93
 
@@ -99,19 +104,19 @@ module AkamaiCloudletManager
99
104
 
100
105
  match_rules(match_value, options)
101
106
  rescue => err
102
- puts "Exception: #{err}"
107
+ puts "Exception: #{err.formatted_exception("Path rules generation failed!")}"
103
108
  err
104
109
  end
105
110
 
106
111
  # All the path rules from one file will be added under same match, space separated
107
112
  def generate_cookie_rules(options = {})
108
- return [] if options[:cookie_rules].empty?
113
+ return [] if options[:cookie_rules].nil? || options[:cookie_rules].empty?
109
114
 
110
115
  options = options.merge(match_operator: 'contains', match_type: 'cookie')
111
116
 
112
117
  match_rules(options[:cookie_rules], options)
113
118
  rescue => err
114
- puts "Exception: #{err}"
119
+ puts "Exception: #{err.formatted_exception("Cookie rules generation failed!")}"
115
120
  err
116
121
  end
117
122
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akamai_cloudlet_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gourav Tiwari
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-11-03 00:00:00.000000000 Z
12
+ date: 2017-11-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: akamai-edgegrid
@@ -125,7 +125,7 @@ files:
125
125
  - lib/akamai_cloudlet_manager/policy_version.rb
126
126
  homepage: https://github.com/gouravtiwari/akamai-cloudlet-manager
127
127
  licenses:
128
- - Apache License
128
+ - Apache-2.0
129
129
  metadata: {}
130
130
  post_install_message:
131
131
  rdoc_options: []