fastly 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +7 -3
- data/README.md +0 -2
- data/bin/fastly_upload_vcl +18 -18
- data/fastly.gemspec +11 -11
- data/lib/ext/curb_fu/response/base.rb +20 -0
- data/lib/fastly.rb +69 -83
- data/lib/fastly/base.rb +9 -9
- data/lib/fastly/belongs_to_service_and_version.rb +9 -14
- data/lib/fastly/cache_setting.rb +32 -34
- data/lib/fastly/client.rb +55 -120
- data/lib/fastly/client/curl.rb +57 -0
- data/lib/fastly/condition.rb +32 -32
- data/lib/fastly/customer.rb +1 -1
- data/lib/fastly/director.rb +4 -4
- data/lib/fastly/fetcher.rb +10 -12
- data/lib/fastly/gem_version.rb +2 -2
- data/lib/fastly/gzip.rb +26 -27
- data/lib/fastly/header.rb +67 -68
- data/lib/fastly/invoice.rb +17 -16
- data/lib/fastly/origin.rb +4 -5
- data/lib/fastly/request_setting.rb +68 -69
- data/lib/fastly/response_object.rb +46 -47
- data/lib/fastly/s3_logging.rb +48 -50
- data/lib/fastly/service.rb +20 -26
- data/lib/fastly/settings.rb +10 -11
- data/lib/fastly/syslog.rb +53 -57
- data/lib/fastly/user.rb +4 -6
- data/lib/fastly/util.rb +1 -0
- data/lib/fastly/version.rb +25 -30
- data/test/admin_test.rb +8 -8
- data/test/api_key_test.rb +20 -39
- data/test/common.rb +64 -66
- data/test/fastly/util_test.rb +1 -0
- data/test/full_login_test.rb +77 -82
- data/test/helper.rb +15 -24
- data/test/missing_api_key_test.rb +1 -1
- data/test/stats_test.rb +42 -50
- metadata +17 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f311beb83bf3886557b6da399d17d49682ec4ffb
|
4
|
+
data.tar.gz: f47f3014d3b66738f9938e3b84e5ab4d46b9a8d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be5c1f769e551f2bbf7a16bab3508a14191c42cee4f9e7a95075c4be14f9e76aee9d1294e14b4d0bfa13f4bad7de9cb2f130bb6670a6e37ebee7217649dc0f4f
|
7
|
+
data.tar.gz: 9b8c4b14104b4d3148e2c9679a92db0a8e5f59fd2e0e4fbf21ddebb908f37ddd2fe8e4746974333074a665046cb8cda70eca279b5789cee1fb37d89b4959d008
|
data/HISTORY.md
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
# HEAD
|
2
2
|
|
3
|
-
|
4
|
-
*
|
3
|
+
## 2014-12-15 v1.1.5
|
4
|
+
* major refactor and reorganization of code (merged branch https://github.com/fastly/fastly-ruby/pull/31)
|
5
|
+
* bump curb dep to 0.8.6 for ruby 2.1 support (see https://github.com/fastly/fastly-ruby/issues/43)
|
5
6
|
|
6
|
-
|
7
|
+
2014-09-29 v1.1.4
|
8
|
+
* Require API Key for purge by key requests
|
9
|
+
|
10
|
+
2014-07-25 v1.1.3
|
7
11
|
* Add test:unit rake task
|
8
12
|
* Add Rubocop and some rubocop cleanup
|
9
13
|
* Clarify gem name in documentation
|
data/README.md
CHANGED
@@ -75,9 +75,7 @@ new_version.activate!
|
|
75
75
|
The test suite requires the following `ENV` variables to be set:
|
76
76
|
|
77
77
|
* `FASTLY_TEST_USER` - Your user email
|
78
|
-
* `FASTLY_TEST_NAME` - Your name on your account (ie "John Smith")
|
79
78
|
* `FASTLY_TEST_PASSWORD` - Your account password
|
80
|
-
* `FASTLY_TEST_CUSTOMER` - Your customer or company name (ie. "Fastly" or "Acme, Inc.")
|
81
79
|
* `FASTLY_TEST_API_KEY` - Your API key (found at https://app.fastly.com/#account)
|
82
80
|
|
83
81
|
While the test suite is safe to be run on all accounts and isn't harmful to your
|
data/bin/fastly_upload_vcl
CHANGED
@@ -8,25 +8,25 @@
|
|
8
8
|
# License:: Distributes under the same terms as Ruby
|
9
9
|
#
|
10
10
|
# = USAGE
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# fastly_upload_vcl <options> <service id or name> <path to vcl file>
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# = CONFIGURATION
|
15
|
-
#
|
15
|
+
#
|
16
16
|
# You can either have a config file in either ~/.fastly or /etc/fastly with
|
17
|
-
#
|
17
|
+
#
|
18
18
|
# api_key = <key>
|
19
|
-
#
|
19
|
+
#
|
20
20
|
# or a config file with
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# user = <login>
|
23
23
|
# password = <password>
|
24
|
-
#
|
24
|
+
#
|
25
25
|
# Alternatively you can pass in any of those options on the command line
|
26
|
-
#
|
26
|
+
#
|
27
27
|
# fastly_upload_vcl --api_key <key> <service id or name> <path to vcl file>
|
28
28
|
# fastly_upload_vcl --user <login> --password <password> <service id or name> <path to vcl file>
|
29
|
-
#
|
29
|
+
#
|
30
30
|
|
31
31
|
require 'rubygems'
|
32
32
|
require 'fastly'
|
@@ -34,26 +34,26 @@ require 'fastly'
|
|
34
34
|
# :nodoc:
|
35
35
|
def die(message)
|
36
36
|
warn message
|
37
|
-
exit
|
37
|
+
exit(-1)
|
38
38
|
end
|
39
39
|
|
40
|
-
params = Fastly.get_options("#{ENV['HOME']}/.fastly",
|
40
|
+
params = Fastly.get_options("#{ENV['HOME']}/.fastly", '/etc/fastly')
|
41
41
|
|
42
|
-
service_id = ARGV.shift || die(
|
43
|
-
vcl_file = ARGV.shift || die(
|
42
|
+
service_id = ARGV.shift || die('You must pass in a service id')
|
43
|
+
vcl_file = ARGV.shift || die('You must pass in a vcl file')
|
44
44
|
|
45
|
-
die("Couldn't find any of the config files - #{configs.join(',')}") unless params.keys.size>0
|
45
|
+
die("Couldn't find any of the config files - #{configs.join(',')}") unless params.keys.size > 0
|
46
46
|
die("Couldn't find vcl file #{vcl_file}") unless File.file?(vcl_file)
|
47
47
|
|
48
|
-
fastly = Fastly.new(params)
|
48
|
+
fastly = Fastly.new(params)
|
49
49
|
|
50
50
|
service = fastly.get_service(service_id) || die("Couldn't find service #{service_id}")
|
51
51
|
version = service.version
|
52
52
|
die "Can't upload a vcl file to the last (#{version.number}) version of #{service.name} (#{service.id}) because it's locked" if version.locked?
|
53
53
|
puts "Uploading #{vcl_file} to version #{version.number}"
|
54
54
|
begin
|
55
|
-
name = File.basename(vcl_file,
|
56
|
-
content = File.new(vcl_file,
|
55
|
+
name = File.basename(vcl_file, '.vcl')
|
56
|
+
content = File.new(vcl_file, 'r').read
|
57
57
|
vcl = version.vcl(name)
|
58
58
|
if vcl
|
59
59
|
vcl.content = content
|
@@ -65,4 +65,4 @@ begin
|
|
65
65
|
rescue => e
|
66
66
|
die("Couldn't upload vcl: #{e}")
|
67
67
|
end
|
68
|
-
puts
|
68
|
+
puts 'Done! You should now go and activate it at https://app.fastly.com/#configure'
|
data/fastly.gemspec
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
3
3
|
require 'fastly/gem_version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
6
|
+
s.name = 'fastly'
|
7
7
|
s.version = Fastly::VERSION
|
8
|
-
s.authors = [
|
9
|
-
s.email = [
|
10
|
-
s.homepage =
|
11
|
-
s.summary = %q
|
12
|
-
s.description = %q
|
8
|
+
s.authors = ['Fastly']
|
9
|
+
s.email = ['simon@fastly.com', 'zeke@templ.in', 'tyler@fastly.com']
|
10
|
+
s.homepage = 'http://github.com/fastly/fastly-ruby'
|
11
|
+
s.summary = %q(Client library for the Fastly acceleration system)
|
12
|
+
s.description = %q(Client library for the Fastly acceleration system)
|
13
13
|
s.license = 'MIT'
|
14
14
|
|
15
15
|
s.files = `git ls-files`.split("\n")
|
16
16
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
17
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
-
s.require_paths = [
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
18
|
+
s.require_paths = ['lib']
|
19
19
|
|
20
|
-
s.add_dependency 'curb', '
|
21
|
-
s.add_dependency 'curb-fu', '
|
20
|
+
s.add_dependency 'curb', '~> 0.8.6'
|
21
|
+
s.add_dependency 'curb-fu', '~> 0.6.2'
|
22
22
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'curb-fu'
|
2
|
+
|
3
|
+
module CurbFu
|
4
|
+
module Response
|
5
|
+
# :nodoc: all
|
6
|
+
class Base
|
7
|
+
def get_fields(key)
|
8
|
+
if (match = @headers.find { |k, _| k.downcase == key.downcase })
|
9
|
+
[match.last].flatten
|
10
|
+
else
|
11
|
+
[]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](key)
|
16
|
+
get_fields(key).last
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/fastly.rb
CHANGED
@@ -3,36 +3,38 @@
|
|
3
3
|
# License:: Distributes under the same terms as Ruby
|
4
4
|
|
5
5
|
# A client library for interacting with the Fastly web acceleration service
|
6
|
+
require 'fastly/gem_version'
|
7
|
+
require 'fastly/util'
|
8
|
+
require 'ext/curb_fu/response/base'
|
9
|
+
require 'fastly/fetcher'
|
10
|
+
require 'fastly/client'
|
11
|
+
|
12
|
+
require 'fastly/base'
|
13
|
+
require 'fastly/belongs_to_service_and_version'
|
14
|
+
require 'fastly/backend'
|
15
|
+
require 'fastly/cache_setting'
|
16
|
+
require 'fastly/condition'
|
17
|
+
require 'fastly/customer'
|
18
|
+
require 'fastly/director'
|
19
|
+
require 'fastly/domain'
|
20
|
+
require 'fastly/header'
|
21
|
+
require 'fastly/healthcheck'
|
22
|
+
require 'fastly/gzip'
|
23
|
+
require 'fastly/invoice'
|
24
|
+
require 'fastly/match'
|
25
|
+
require 'fastly/origin'
|
26
|
+
require 'fastly/request_setting'
|
27
|
+
require 'fastly/response_object'
|
28
|
+
require 'fastly/service'
|
29
|
+
require 'fastly/settings'
|
30
|
+
require 'fastly/syslog'
|
31
|
+
require 'fastly/s3_logging'
|
32
|
+
require 'fastly/user'
|
33
|
+
require 'fastly/vcl'
|
34
|
+
require 'fastly/version'
|
35
|
+
|
36
|
+
# Top-level Fastly class
|
6
37
|
class Fastly
|
7
|
-
require 'fastly/gem_version'
|
8
|
-
require 'fastly/util'
|
9
|
-
require 'fastly/fetcher'
|
10
|
-
require 'fastly/client'
|
11
|
-
|
12
|
-
require 'fastly/base'
|
13
|
-
require 'fastly/belongs_to_service_and_version'
|
14
|
-
require 'fastly/backend'
|
15
|
-
require 'fastly/cache_setting'
|
16
|
-
require 'fastly/condition'
|
17
|
-
require 'fastly/customer'
|
18
|
-
require 'fastly/director'
|
19
|
-
require 'fastly/domain'
|
20
|
-
require 'fastly/header'
|
21
|
-
require 'fastly/healthcheck'
|
22
|
-
require 'fastly/gzip'
|
23
|
-
require 'fastly/invoice'
|
24
|
-
require 'fastly/match'
|
25
|
-
require 'fastly/origin'
|
26
|
-
require 'fastly/request_setting'
|
27
|
-
require 'fastly/response_object'
|
28
|
-
require 'fastly/service'
|
29
|
-
require 'fastly/settings'
|
30
|
-
require 'fastly/syslog'
|
31
|
-
require 'fastly/s3_logging'
|
32
|
-
require 'fastly/user'
|
33
|
-
require 'fastly/vcl'
|
34
|
-
require 'fastly/version'
|
35
|
-
|
36
38
|
include Fastly::Fetcher
|
37
39
|
|
38
40
|
# Create a new Fastly client. Options are
|
@@ -45,7 +47,7 @@ class Fastly
|
|
45
47
|
#
|
46
48
|
# Some methods require full username and password rather than just auth token.
|
47
49
|
def initialize(opts)
|
48
|
-
|
50
|
+
client(opts)
|
49
51
|
self
|
50
52
|
end
|
51
53
|
|
@@ -62,26 +64,17 @@ class Fastly
|
|
62
64
|
|
63
65
|
# Return a Customer object representing the customer of the current logged in user.
|
64
66
|
def current_customer
|
65
|
-
|
67
|
+
fail AuthRequired unless authed?
|
66
68
|
@current_customer ||= get(Customer)
|
67
69
|
end
|
68
70
|
|
69
71
|
# Return a User object representing the current logged in user.
|
70
72
|
# NOTE: requires you to be fully authed - will not work with only an API key
|
71
73
|
def current_user
|
72
|
-
|
74
|
+
fail FullAuthRequired unless fully_authed?
|
73
75
|
@current_user ||= get(User)
|
74
76
|
end
|
75
77
|
|
76
|
-
# Set the current customer to act as.
|
77
|
-
# NOTE: this will only work if you're an admin
|
78
|
-
def set_customer(id)
|
79
|
-
raise Fastly::FullAuthRequired "You must be fully authed to set the customer" unless self.fully_authed?;
|
80
|
-
raise Fastly::AdminRequired "You must be an admin to set the customer" unless self.current_user.can_do?(:admin);
|
81
|
-
@current_customer = nil
|
82
|
-
client.set_customer(id);
|
83
|
-
end
|
84
|
-
|
85
78
|
# Return a hash representing all commands available.
|
86
79
|
#
|
87
80
|
# Useful for information.
|
@@ -91,8 +84,7 @@ class Fastly
|
|
91
84
|
|
92
85
|
# Purge the specified path from your cache.
|
93
86
|
def purge(path)
|
94
|
-
|
95
|
-
#res = client.post("/purge/", :path => path)
|
87
|
+
client.post("/purge/#{path}")
|
96
88
|
end
|
97
89
|
|
98
90
|
# Fetches historical stats for each of your fastly services and groups the results by service id.
|
@@ -112,13 +104,13 @@ class Fastly
|
|
112
104
|
#
|
113
105
|
# See http://docs.fastly.com/docs/stats for details.
|
114
106
|
def stats(opts)
|
115
|
-
|
107
|
+
if opts[:aggregate] && (opts[:field] || opts[:service])
|
108
|
+
fail Error, "You can't specify a field or a service for an aggregate request"
|
109
|
+
end
|
116
110
|
|
117
|
-
url =
|
111
|
+
url = '/stats'
|
118
112
|
|
119
|
-
if opts.delete(:aggregate)
|
120
|
-
url += "/aggregate"
|
121
|
-
end
|
113
|
+
url += '/aggregate' if opts.delete(:aggregate)
|
122
114
|
|
123
115
|
if service = opts.delete(:service)
|
124
116
|
url += "/service/#{service}"
|
@@ -128,12 +120,12 @@ class Fastly
|
|
128
120
|
url += "/field/#{field}"
|
129
121
|
end
|
130
122
|
|
131
|
-
client.get_stats(url, opts)
|
123
|
+
client.get_stats(url, opts)
|
132
124
|
end
|
133
125
|
|
134
126
|
# Returns usage information aggregated across all Fastly services and grouped by region.
|
135
127
|
#
|
136
|
-
# If the :by_service flag is passed then
|
128
|
+
# If the :by_service flag is passed then returns usage information aggregated by service and grouped by service & region.
|
137
129
|
#
|
138
130
|
# Other options available are:
|
139
131
|
#
|
@@ -144,43 +136,43 @@ class Fastly
|
|
144
136
|
#
|
145
137
|
# See http://docs.fastly.com/docs/stats for details.
|
146
138
|
def usage(opts)
|
147
|
-
url =
|
148
|
-
url +=
|
139
|
+
url = '/stats/usage'
|
140
|
+
url += '_by_service' if opts.delete(:by_service)
|
149
141
|
client.get_stats(url, opts)
|
150
142
|
end
|
151
143
|
|
152
144
|
# Fetches the list of codes for regions that are covered by the Fastly CDN service.
|
153
145
|
def regions
|
154
|
-
client.get_stats(
|
146
|
+
client.get_stats('/stats/regions')
|
155
147
|
end
|
156
148
|
|
157
149
|
[User, Customer, Backend, CacheSetting, Condition, Director, Domain, Header, Healthcheck, Gzip, Match, Origin, RequestSetting, ResponseObject, Service, S3Logging, Syslog, VCL, Version].each do |klass|
|
158
150
|
type = Util.class_to_path(klass)
|
151
|
+
|
159
152
|
# unless the class doesn't have a list path or it already exists
|
160
153
|
unless klass.list_path.nil? || klass.respond_to?("list_#{type}s".to_sym)
|
161
|
-
|
162
|
-
|
163
|
-
|
154
|
+
send :define_method, "list_#{type}s".to_sym do |*args|
|
155
|
+
list(klass, *args)
|
156
|
+
end
|
164
157
|
end
|
165
158
|
|
166
|
-
|
159
|
+
send :define_method, "get_#{type}".to_sym do |*args|
|
167
160
|
get(klass, *args)
|
168
161
|
end
|
169
162
|
|
170
|
-
|
163
|
+
send :define_method, "create_#{type}".to_sym do |obj|
|
171
164
|
create(klass, obj)
|
172
165
|
end
|
173
166
|
|
174
|
-
|
167
|
+
send :define_method, "update_#{type}".to_sym do |obj|
|
175
168
|
update(klass, obj)
|
176
169
|
end
|
177
170
|
|
178
|
-
|
171
|
+
send :define_method, "delete_#{type}".to_sym do |obj|
|
179
172
|
delete(klass, obj)
|
180
173
|
end
|
181
174
|
end
|
182
175
|
|
183
|
-
|
184
176
|
# :method: create_version(opts)
|
185
177
|
# opts must contain a service_id param
|
186
178
|
|
@@ -433,7 +425,6 @@ class Fastly
|
|
433
425
|
# You can also call
|
434
426
|
# version.save!
|
435
427
|
|
436
|
-
|
437
428
|
##
|
438
429
|
# :method: delete_user(user)
|
439
430
|
# You can also call
|
@@ -449,25 +440,21 @@ class Fastly
|
|
449
440
|
# You can also call
|
450
441
|
# service.delete!
|
451
442
|
|
452
|
-
|
453
443
|
##
|
454
444
|
# :method: delete_version(version)
|
455
445
|
# You can also call
|
456
446
|
# version.delete!
|
457
447
|
|
458
|
-
|
459
448
|
##
|
460
449
|
# :method:delete_backend(backend)
|
461
450
|
# You can also call
|
462
451
|
# backend.delete!
|
463
452
|
|
464
|
-
|
465
453
|
##
|
466
454
|
# :method: delete_director(backend)
|
467
455
|
# You can also call
|
468
456
|
# backend.delete!
|
469
457
|
|
470
|
-
|
471
458
|
##
|
472
459
|
# :method: delete_domain(domain
|
473
460
|
# You can also call
|
@@ -483,7 +470,6 @@ class Fastly
|
|
483
470
|
# You can also call
|
484
471
|
# match.delete!(match)
|
485
472
|
|
486
|
-
|
487
473
|
##
|
488
474
|
# :method: delete_origin(origin)
|
489
475
|
# You can also call
|
@@ -499,7 +485,6 @@ class Fastly
|
|
499
485
|
# You can also call
|
500
486
|
# syslog.delete!
|
501
487
|
|
502
|
-
|
503
488
|
##
|
504
489
|
# :method: delete_vcl(vcl)
|
505
490
|
# You can also call
|
@@ -616,8 +601,6 @@ class Fastly
|
|
616
601
|
#
|
617
602
|
# Get a list of all versions
|
618
603
|
|
619
|
-
|
620
|
-
|
621
604
|
##
|
622
605
|
# Attempts to load various config options in the form
|
623
606
|
#
|
@@ -631,18 +614,19 @@ class Fastly
|
|
631
614
|
options = {}
|
632
615
|
return options unless File.exist?(file)
|
633
616
|
|
634
|
-
File.open(file,
|
635
|
-
while
|
617
|
+
File.open(file, 'r') do |infile|
|
618
|
+
while line = infile.gets
|
636
619
|
line.chomp!
|
637
|
-
next if
|
638
|
-
next if
|
639
|
-
next unless line =~
|
620
|
+
next if line =~ /^#/
|
621
|
+
next if line =~ /^\s*$/
|
622
|
+
next unless line =~ /=/
|
640
623
|
line.strip!
|
641
624
|
key, val = line.split(/\s*=\s*/, 2)
|
642
|
-
options[key.to_sym] = val
|
625
|
+
options[key.to_sym] = val
|
643
626
|
end
|
644
627
|
end
|
645
|
-
|
628
|
+
|
629
|
+
options
|
646
630
|
end
|
647
631
|
|
648
632
|
##
|
@@ -656,18 +640,20 @@ class Fastly
|
|
656
640
|
#
|
657
641
|
def self.get_options(*files)
|
658
642
|
options = {}
|
643
|
+
|
659
644
|
files.each do |file|
|
660
645
|
next unless File.exist?(file)
|
661
646
|
options = load_config(file)
|
662
647
|
break
|
663
648
|
end
|
664
649
|
|
665
|
-
while
|
666
|
-
options[$1.to_sym] = $2
|
667
|
-
ARGV.shift
|
650
|
+
while ARGV.size > 0 && ARGV[0] =~ /^-+(\w+)\=(\w+)$/
|
651
|
+
options[$1.to_sym] = $2
|
652
|
+
ARGV.shift
|
668
653
|
end
|
669
|
-
|
670
|
-
options
|
654
|
+
|
655
|
+
fail "Couldn't find options from command line arguments or #{files.join(', ')}" unless options.size > 0
|
656
|
+
|
657
|
+
options
|
671
658
|
end
|
672
659
|
end
|
673
|
-
|