fastly 1.1.4 → 1.1.5
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.
- 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
data/lib/fastly/condition.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
class Fastly
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
# An endpoint to stream syslogs to
|
3
|
+
class Condition < BelongsToServiceAndVersion
|
4
|
+
attr_accessor :service_id, :name, :priority, :statement, :type
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
##
|
7
|
+
# :attr: service_id
|
8
|
+
#
|
9
|
+
# The id of the service this belongs to.
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
##
|
12
|
+
# :attr: version
|
13
|
+
#
|
14
|
+
# The number of the version this belongs to.
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
##
|
17
|
+
# :attr: name
|
18
|
+
#
|
19
|
+
# The name of the condition
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
##
|
22
|
+
# :attr: statement
|
23
|
+
#
|
24
|
+
# The statement of the condition, should be a varnish if statement line
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
##
|
27
|
+
# :attr: priority
|
28
|
+
#
|
29
|
+
# What order to run them in, higher priority gets executed after lower priority
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
##
|
32
|
+
# :attr: type
|
33
|
+
#
|
34
|
+
# request, cache or response
|
35
|
+
#
|
36
|
+
# request has req. object only
|
37
|
+
# cache has req. and beresp.
|
38
|
+
# response has req. and resp.
|
39
|
+
end
|
40
40
|
end
|
data/lib/fastly/customer.rb
CHANGED
data/lib/fastly/director.rb
CHANGED
@@ -48,16 +48,16 @@ class Fastly
|
|
48
48
|
#
|
49
49
|
# Return true on success and false on failure
|
50
50
|
def add_backend(backend)
|
51
|
-
hash = fetcher.client.post(
|
52
|
-
|
51
|
+
hash = fetcher.client.post("#{Director.put_path(self)}/backend/#{backend.name}")
|
52
|
+
!hash.nil?
|
53
53
|
end
|
54
54
|
|
55
55
|
# Delete a Backend object from a Director
|
56
56
|
#
|
57
57
|
# Return true on success and false on failure
|
58
58
|
def delete_backend(backend)
|
59
|
-
hash = fetcher.client.delete(
|
60
|
-
|
59
|
+
hash = fetcher.client.delete("#{Director.put_path(self)}/backend/#{backend.name}")
|
60
|
+
!hash.nil?
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
data/lib/fastly/fetcher.rb
CHANGED
@@ -2,7 +2,7 @@ class Fastly
|
|
2
2
|
# :nodoc:
|
3
3
|
class AuthRequired < RuntimeError; end
|
4
4
|
# :nodoc:
|
5
|
-
class FullAuthRequired <
|
5
|
+
class FullAuthRequired < AuthRequired; end
|
6
6
|
# :nodoc:
|
7
7
|
class Error < RuntimeError; end
|
8
8
|
# :nodoc:
|
@@ -10,14 +10,14 @@ class Fastly
|
|
10
10
|
# :nodoc:
|
11
11
|
class AdminRequired < AuthRequired; end
|
12
12
|
|
13
|
+
# Encapsulates HTTP client interactions
|
13
14
|
module Fetcher # :nodoc: all
|
14
|
-
|
15
15
|
# Get the current Fastly::Client
|
16
|
-
def client(opts={})
|
17
|
-
@client ||=
|
16
|
+
def client(opts = {})
|
17
|
+
@client ||= Client.new(opts)
|
18
18
|
end
|
19
19
|
|
20
|
-
def list(klass, opts={})
|
20
|
+
def list(klass, opts = {})
|
21
21
|
list = client.get(klass.list_path(opts))
|
22
22
|
return [] if list.nil?
|
23
23
|
list.map { |hash| klass.new(hash, self) }
|
@@ -29,23 +29,21 @@ class Fastly
|
|
29
29
|
else
|
30
30
|
hash = client.get(klass.get_path(*args))
|
31
31
|
end
|
32
|
-
|
33
|
-
return klass.new(hash, self)
|
32
|
+
hash.nil? ? nil : klass.new(hash, self)
|
34
33
|
end
|
35
34
|
|
36
35
|
def create(klass, opts)
|
37
|
-
hash = client.post(klass.post_path(opts),opts)
|
38
|
-
|
36
|
+
hash = client.post(klass.post_path(opts), opts)
|
37
|
+
klass.new(hash, self)
|
39
38
|
end
|
40
39
|
|
41
40
|
def update(klass, obj)
|
42
41
|
hash = client.put(klass.put_path(obj), obj.as_hash)
|
43
|
-
|
42
|
+
klass.new(hash, self)
|
44
43
|
end
|
45
44
|
|
46
45
|
def delete(klass, obj)
|
47
|
-
|
46
|
+
client.delete(klass.delete_path(obj))
|
48
47
|
end
|
49
|
-
|
50
48
|
end
|
51
49
|
end
|
data/lib/fastly/gem_version.rb
CHANGED
data/lib/fastly/gzip.rb
CHANGED
@@ -3,37 +3,36 @@ class Fastly
|
|
3
3
|
class Gzip < BelongsToServiceAndVersion
|
4
4
|
attr_accessor :service_id, :name, :extensions, :content_types, :cache_condition
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
##
|
7
|
+
# :attr: service_id
|
8
|
+
#
|
9
|
+
# The id of the service this belongs to.
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
##
|
12
|
+
# :attr: version
|
13
|
+
#
|
14
|
+
# The number of the version this belongs to.
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
##
|
17
|
+
# :attr: name
|
18
|
+
#
|
19
|
+
# The name of the condition
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
##
|
22
|
+
# :attr: extensions
|
23
|
+
#
|
24
|
+
# File extensions to be gzipped. Seems to want them in a list like
|
25
|
+
# "js css html"
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
##
|
34
|
-
# :attr" cache_condition
|
35
|
-
#
|
36
|
-
# Cache condition to be used to determine when to apply this gzip setting
|
27
|
+
##
|
28
|
+
# :attr: content_types
|
29
|
+
#
|
30
|
+
# Content types to be gzipped. Seems to want them in a list like
|
31
|
+
# "text/html application/x-javascript"
|
37
32
|
|
33
|
+
##
|
34
|
+
# :attr" cache_condition
|
35
|
+
#
|
36
|
+
# Cache condition to be used to determine when to apply this gzip setting
|
38
37
|
end
|
39
38
|
end
|
data/lib/fastly/header.rb
CHANGED
@@ -3,86 +3,85 @@ class Fastly
|
|
3
3
|
class Header < BelongsToServiceAndVersion
|
4
4
|
attr_accessor :service_id, :name, :action, :cache_condition, :request_condition, :response_condition, :ignore_if_set, :type, :dst, :src, :substitution, :priority, :regexp
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
##
|
7
|
+
# :attr: service_id
|
8
|
+
#
|
9
|
+
# The id of the service this belongs to.
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
##
|
12
|
+
# :attr: version
|
13
|
+
#
|
14
|
+
# The number of the version this belongs to.
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
##
|
17
|
+
# :attr: name
|
18
|
+
#
|
19
|
+
# The name of the header setting
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
##
|
22
|
+
# :attr: action
|
23
|
+
#
|
24
|
+
# Action to perform on the header. Can be:
|
25
|
+
# - 'set' - Sets (or resets) a header
|
26
|
+
# - 'append' - Appends to an existing header
|
27
|
+
# - 'delete' - Delete a header
|
28
|
+
# - 'regex' - Perform a single regex replacement on a header
|
29
|
+
# - 'regex_repeat' - Perform a global regex replacement on a header
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
##
|
32
|
+
# :attr: ignore_if_set
|
33
|
+
#
|
34
|
+
# Don't add the header if it is already set. Only applies to the 'set'
|
35
|
+
# action
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
##
|
38
|
+
# :attr: type
|
39
|
+
#
|
40
|
+
# - 'request' - Performs on the request before lookup occurs
|
41
|
+
# - 'fetch' - Performs on the request to the origin server
|
42
|
+
# - 'cache' - Performs on the response before it's stored in the cache
|
43
|
+
# - 'response' - Performs on the response before delivering to the client
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
##
|
46
|
+
# :attr: dst
|
47
|
+
#
|
48
|
+
# Header to set
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
##
|
51
|
+
# :attr: src
|
52
|
+
#
|
53
|
+
# Variable to be used as a source for the header content. Does not apply
|
54
|
+
# to the 'delete' action.
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
##
|
57
|
+
# :attr: regexp
|
58
|
+
#
|
59
|
+
# Regular expression to use with the 'regex' and 'regex_repeat' actions.
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
##
|
62
|
+
# :attr: substitution
|
63
|
+
#
|
64
|
+
# Value to substitute in place of regular expression. (Only applies to
|
65
|
+
# 'regex' and 'regex_repeat'.)
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
##
|
68
|
+
# :attr: priority
|
69
|
+
#
|
70
|
+
# Lower priorities execute first.
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
##
|
73
|
+
# :attr: request_condition
|
74
|
+
#
|
75
|
+
# Optional name of a request condition to apply
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
##
|
83
|
-
# :attr: response_condition
|
84
|
-
#
|
85
|
-
# Optional name of a response condition to apply
|
77
|
+
##
|
78
|
+
# :attr: cache_condition
|
79
|
+
#
|
80
|
+
# Optional name of a cache condition to apply
|
86
81
|
|
82
|
+
##
|
83
|
+
# :attr: response_condition
|
84
|
+
#
|
85
|
+
# Optional name of a response condition to apply
|
87
86
|
end
|
88
87
|
end
|
data/lib/fastly/invoice.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# Invoice object
|
1
2
|
class Fastly
|
2
3
|
# An invoice for a time period
|
3
4
|
class Invoice < Base
|
@@ -38,7 +39,6 @@ class Fastly
|
|
38
39
|
#
|
39
40
|
# A hash reference with all the different regions and their subtotals
|
40
41
|
|
41
|
-
|
42
42
|
# Get the start time of this invoice as a DateTime object in UTC
|
43
43
|
def start
|
44
44
|
DateTime.parse(start_time).new_offset(0)
|
@@ -52,14 +52,16 @@ class Fastly
|
|
52
52
|
private
|
53
53
|
|
54
54
|
def self.get_path(*args)
|
55
|
-
opts = args.size>0 ? args[0] : {}
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
opts = args.size > 0 ? args[0] : {}
|
56
|
+
|
57
|
+
url = '/billing'
|
58
|
+
|
59
|
+
url += "/service/#{opts[:service_id]}" if opts.key?(:service_id)
|
60
|
+
|
61
|
+
if opts.key?(:year) && opts.key?(:month)
|
61
62
|
url += "/year/#{opts[:year]}/month/#{opts[:month]}"
|
62
63
|
end
|
64
|
+
|
63
65
|
url
|
64
66
|
end
|
65
67
|
|
@@ -68,39 +70,38 @@ class Fastly
|
|
68
70
|
end
|
69
71
|
|
70
72
|
def self.post_path
|
71
|
-
|
73
|
+
fail "You can't POST to an invoice"
|
72
74
|
end
|
73
75
|
|
74
76
|
def self.put_path
|
75
|
-
|
77
|
+
fail "You can't PUT to an invoice"
|
76
78
|
end
|
77
79
|
|
78
80
|
def self.delete_path
|
79
|
-
|
81
|
+
fail "You can't DELETE to an invoice"
|
80
82
|
end
|
81
83
|
|
82
84
|
def save!
|
83
|
-
|
85
|
+
fail "You can't save an invoice"
|
84
86
|
end
|
85
87
|
|
86
88
|
def delete!
|
87
|
-
|
89
|
+
fail "You can't delete an invoice"
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
91
|
-
|
92
93
|
# Return an array of Invoice objects representing invoices for all services.
|
93
94
|
#
|
94
95
|
# If a year and month are passed in returns the invoices for that whole month.
|
95
96
|
#
|
96
97
|
# Otherwise it returns the invoices for the current month so far.
|
97
|
-
def get_invoice(year=nil, month=nil)
|
98
|
+
def get_invoice(year = nil, month = nil)
|
98
99
|
opts = {}
|
99
100
|
unless year.nil? || month.nil?
|
100
101
|
opts[:year] = year
|
101
102
|
opts[:month] = month
|
102
103
|
end
|
103
|
-
get(Fastly::Invoice, opts)
|
104
|
-
end
|
105
104
|
|
105
|
+
get(Invoice, opts)
|
106
|
+
end
|
106
107
|
end
|