fastly-deploy 1.0.110 → 1.0.111

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: 443248833c9d3bb99994838f8439c3f6a87f89c7
4
- data.tar.gz: 710511dce4c39157a80f41c9db1eee8a8072f059
3
+ metadata.gz: 8334964829245084bc2a5bbab65c1f16cce82359
4
+ data.tar.gz: 1e389ac41af678b43986374f0a79efd8351e8799
5
5
  SHA512:
6
- metadata.gz: 6db21357b083c1014bfbf3f571b572380f0eaa360d99b50dfda1c67019106ef632623ddc113b91ec6a94a86b98b83fbb7f4013e9ca91e9c8a1fa86d5351a90d6
7
- data.tar.gz: 7ae52ab828aed5c4b6b1183d2408f8ba773c273a40cb0964d2c5c9f4b31c2d9a624d01b9f298bd0d8ce4c9a378001d4a82f79a4cb08920493280ce29e0a703cf
6
+ metadata.gz: 296ba01b4844b1f2b5c5f1ff022b8e2a525d2e461d06760e1f77e75223f9507838e97e58ce6e24c98c7182ab4247c944882d7f634c52511b91b78f78e52ccf64
7
+ data.tar.gz: 6894e3a66e59e24aa37406f21e6ad71bdcce897e1aed96080a4796436faa86c158b756a48b3758796f040409a44cbcca546f7cd43bd67ae6f6062bcaf0cb5a3f
data/bin/fastly-deploy CHANGED
@@ -7,21 +7,21 @@ require 'optparse'
7
7
  def deploy(argv)
8
8
  options = {}
9
9
  optparse = OptionParser.new do |opts|
10
- opts.banner = "Usage: fastly-deploy [options]"
11
- opts.on("-k", "--api-key API_KEY", "Fastly API Key") do |api_key|
10
+ opts.banner = 'Usage: fastly-deploy [options]'
11
+ opts.on('-k', '--api-key API_KEY', 'Fastly API Key') do |api_key|
12
12
  options[:api_key] = api_key
13
13
  end
14
- opts.on("-s", "--service-id SERVICE_ID", "Service ID") do |service_id|
14
+ opts.on('-s', '--service-id SERVICE_ID', 'Service ID') do |service_id|
15
15
  options[:service_id] = service_id
16
16
  end
17
- opts.on("-v", "--vcl-path FILE", "VCL Path") do |vcl_path|
17
+ opts.on('-v', '--vcl-path FILE', 'VCL Path') do |vcl_path|
18
18
  options[:vcl_path] = vcl_path
19
19
  end
20
- opts.on("-i", "--vcl-includes INCLUDES_DIR", "Includes Directory") do |includes_dir|
20
+ opts.on('-i', '--vcl-includes INCLUDES_DIR', 'Includes Directory') do |includes_dir|
21
21
  options[:includes_dir] = includes_dir
22
22
  end
23
23
  options[:purge_all] = false
24
- opts.on("-p", "--purge-all", "Purge All") do |purge_all|
24
+ opts.on('-p', '--purge-all', 'Purge All') do
25
25
  options[:purge_all] = true
26
26
  end
27
27
  opts.on('-h', '--help', 'Display this screen') do
@@ -31,9 +31,7 @@ def deploy(argv)
31
31
  end
32
32
  optparse.parse! argv
33
33
 
34
- if options[:api_key].nil? ||
35
- options[:service_id].nil? ||
36
- options[:vcl_path].nil? then
34
+ if options[:api_key].nil? || options[:service_id].nil? || options[:vcl_path].nil?
37
35
  puts optparse
38
36
  exit 1
39
37
  end
@@ -46,11 +44,10 @@ def deploy(argv)
46
44
  options[:vcl_path],
47
45
  options[:purge_all],
48
46
  includes
49
- return options[:api_key]
47
+
48
+ options[:api_key]
50
49
  end
51
50
 
52
- # This is only run when run as a script. The FILE bit stops it
51
+ # This is only run when run as a script. The FILE bit stops it
53
52
  # from being run during the tests
54
- if __FILE__ == $0
55
- deploy ARGV
56
- end
53
+ deploy ARGV if __FILE__ == $PROGRAM_NAME
@@ -1,7 +1,7 @@
1
1
  def get_includes(main_vcl_path, includes_dir)
2
2
  includes_found = []
3
3
  get_includes_for_vcl main_vcl_path, includes_dir, includes_found
4
- return includes_found
4
+ includes_found
5
5
  end
6
6
 
7
7
  def get_includes_for_vcl(vcl_path, includes_dir, includes_found)
@@ -17,7 +17,7 @@ end
17
17
  def get_includes_directly_in_vcl(vcl_path, includes_dir)
18
18
  # Using '$' for line ending is os dependent and fails w/windows line endings on linux
19
19
  include_pattern = /^include "(.*)";?[\r\n]+/
20
- return File.readlines(vcl_path).select { |line| include_pattern.match(line) }
21
- .map{ |line| include_pattern.match(line)[1] }
22
- .map{ |vcl_file_name| File.join(includes_dir, vcl_file_name + ".vcl")}
20
+ File.readlines(vcl_path).select { |line| include_pattern.match(line) }
21
+ .map { |line| include_pattern.match(line)[1] }
22
+ .map { |vcl_file_name| File.join(includes_dir, vcl_file_name + '.vcl') }
23
23
  end
data/lib/methods.rb CHANGED
@@ -3,79 +3,78 @@ require 'net/http'
3
3
  require 'colorize'
4
4
 
5
5
  def deploy_vcl(api_key, service_id, vcl_path, purge_all, include_files)
6
-
7
- login_opts = { :api_key => api_key }
6
+ login_opts = { api_key: api_key }
8
7
  fastly = Fastly.new(login_opts)
9
8
  service = fastly.get_service(service_id)
10
9
 
11
- active_version = service.versions.find{|ver| ver.active?}
10
+ active_version = service.versions.find(&:active?)
12
11
  puts "Active Version: #{active_version.number}"
13
- domain = fastly.list_domains(:service_id => service.id,
14
- :version => active_version.number).first
12
+ domain = fastly.list_domains(service_id: service.id,
13
+ version: active_version.number).first
15
14
  puts "Domain Name: #{domain.name}"
16
15
 
17
16
  new_version = active_version.clone
18
17
  puts "New Version: #{new_version.number}"
19
18
 
20
- fastly.list_vcls(:service_id => service.id,
21
- :version => new_version.number)
22
- .each { |vcl| vcl.delete! }
19
+ fastly.list_vcls(service_id: service.id,
20
+ version: new_version.number)
21
+ .each(&:delete!)
23
22
 
24
23
  can_verify_deployment = upload_main_vcl new_version, vcl_path, service_id
25
24
 
26
- if include_files != nil
27
- include_files.each do | include_file |
28
- upload_include_vcl new_version, include_file, service_id
25
+ unless include_files.nil?
26
+ include_files.each do |include_file|
27
+ upload_include_vcl new_version, include_file, service_id
29
28
  end
30
- end
29
+ end
30
+
31
+ puts 'Validating...'
31
32
 
32
- puts "Validating..."
33
-
34
33
  validate(new_version)
35
34
 
36
- puts "Activating..."
35
+ puts 'Activating...'
37
36
  new_version.activate!
38
37
 
39
- if can_verify_deployment then
40
- print "Waiting for changes to take effect."
38
+ if can_verify_deployment
39
+ print 'Waiting for changes to take effect.'
41
40
  attempts = 1
42
41
  deployed_vcl_version_number = 0
43
42
 
44
- while attempts < 150 && deployed_vcl_version_number != new_version.number.to_s do
43
+ while attempts < 150 && deployed_vcl_version_number != new_version.number.to_s
45
44
  sleep 2
46
45
  url = URI.parse("http://#{domain.name}.global.prod.fastly.net/vcl_version")
47
46
  req = Net::HTTP::Get.new(url.to_s)
48
- res = Net::HTTP.start(url.host, url.port) {|http|
47
+ res = Net::HTTP.start(url.host, url.port) do |http|
49
48
  http.request(req)
50
- }
49
+ end
51
50
  deployed_vcl_version_number = res.body
52
- print "."
51
+ print '.'
53
52
  attempts += 1
54
53
  end
55
- puts "done."
54
+ puts 'done.'
56
55
 
57
- if deployed_vcl_version_number != new_version.number.to_s then
56
+ if deployed_vcl_version_number != new_version.number.to_s
58
57
  STDERR.puts "Verify failed. /vcl_version returned [#{deployed_vcl_version_number}].".red
59
58
  exit 1
60
59
  end
61
60
  end
62
61
 
63
- if purge_all then
64
- puts "Purging all..."
62
+ if purge_all
63
+ puts 'Purging all...'
65
64
  service.purge_all
66
65
  end
67
- puts "Deployment complete.".green
66
+ puts 'Deployment complete.'.green
68
67
  end
69
68
 
70
69
  def upload_main_vcl(version, vcl_path, service_id)
71
- vcl_name = File.basename(vcl_path, ".vcl")
70
+ vcl_name = File.basename(vcl_path, '.vcl')
72
71
  can_verify_deployment = upload_vcl version, vcl_path, vcl_name, service_id
73
72
  version.vcl(vcl_name).set_main!
74
- return can_verify_deployment
73
+ can_verify_deployment
75
74
  end
76
75
 
77
76
  def upload_include_vcl(version, vcl_path, service_id)
78
- vcl_name = File.basename(vcl_path, ".vcl")
77
+ vcl_name = File.basename(vcl_path, '.vcl')
79
78
  upload_vcl version, vcl_path, vcl_name, service_id
80
79
  end
81
80
 
@@ -87,8 +86,8 @@ def upload_vcl(version, vcl_path, name, service_id)
87
86
  puts "Uploading #{name}"
88
87
  version.upload_vcl name, vcl_contents_with_deploy_injection
89
88
 
90
- return vcl_contents_with_deploy_injection != vcl_contents_with_service_id_injection
91
- end
89
+ vcl_contents_with_deploy_injection != vcl_contents_with_service_id_injection
90
+ end
92
91
 
93
92
  def inject_deploy_verify_code(vcl, version_num)
94
93
  deploy_recv_vcl = <<-END
@@ -111,19 +110,16 @@ def inject_deploy_verify_code(vcl, version_num)
111
110
  END
112
111
 
113
112
  vcl.gsub(/#7D_DEPLOY recv/, deploy_recv_vcl)
114
- .gsub(/#7D_DEPLOY error/, deploy_error_vcl)
113
+ .gsub(/#7D_DEPLOY error/, deploy_error_vcl)
115
114
  end
116
115
 
117
116
  def inject_service_id(vcl_contents, service_id)
118
- vcl_contents.gsub(/#7D_FASTLY_SERVICE_ID/, service_id)
119
- end
117
+ vcl_contents.gsub(/#7D_FASTLY_SERVICE_ID/, service_id)
118
+ end
120
119
 
121
120
  def validate(version)
122
121
  path = version.class.get_path(version.service_id, version.number)
123
122
  response = version.fetcher.client.get("#{path}/validate")
124
- status = response["status"]
125
- if status!= "ok"
126
- raise response["msg"]
127
- end
123
+ status = response['status']
124
+ raise response['msg'] if status != 'ok'
128
125
  end
129
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastly-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.110
4
+ version: 1.0.111
5
5
  platform: ruby
6
6
  authors:
7
7
  - 7digital
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.41'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.41'
69
83
  description: Automated deploys for Fastly vcl configs. Also supports splitting up
70
84
  configs via include statements.
71
85
  email: developers@7digital.com