fastly 1.00 → 1.1.0
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 +7 -7
- data/.gitignore +1 -0
- data/.travis.yml +6 -0
- data/Changes +14 -0
- data/LICENSE +20 -0
- data/README.md +94 -61
- data/Rakefile +9 -0
- data/fastly.gemspec +5 -3
- data/lib/fastly.rb +233 -18
- data/lib/fastly/backend.rb +11 -2
- data/lib/fastly/base.rb +1 -1
- data/lib/fastly/belongs_to_service_and_version.rb +7 -2
- data/lib/fastly/cache_setting.rb +47 -0
- data/lib/fastly/client.rb +7 -1
- data/lib/fastly/condition.rb +40 -0
- data/lib/fastly/director.rb +2 -2
- data/lib/fastly/fetcher.rb +2 -2
- data/lib/fastly/gem_version.rb +4 -0
- data/lib/fastly/gzip.rb +39 -0
- data/lib/fastly/header.rb +88 -0
- data/lib/fastly/request_setting.rb +90 -0
- data/lib/fastly/response_object.rb +54 -0
- data/lib/fastly/s3_logging.rb +68 -0
- data/lib/fastly/service.rb +4 -4
- data/lib/fastly/settings.rb +9 -4
- data/lib/fastly/string.rb +7 -0
- data/lib/fastly/syslog.rb +6 -1
- data/lib/fastly/version.rb +7 -0
- data/test/admin_test.rb +7 -11
- data/test/api_key_test.rb +11 -14
- data/test/common.rb +98 -38
- data/test/full_login_test.rb +17 -21
- data/test/helper.rb +19 -3
- data/test/stats_test.rb +85 -0
- metadata +95 -56
data/lib/fastly/backend.rb
CHANGED
@@ -2,7 +2,7 @@ class Fastly
|
|
2
2
|
# An individual host you want to serve assets off
|
3
3
|
class Backend < BelongsToServiceAndVersion
|
4
4
|
attr_accessor :service_id, :name, :address, :ipv4, :ipv6, :hostname, :use_ssl, :client_cert, :port,
|
5
|
-
:connect_timeout, :first_byte_timeout, :between_bytes_timeout, :error_threshold, :max_conn, :weight, :comment, :healthcheck
|
5
|
+
:connect_timeout, :first_byte_timeout, :between_bytes_timeout, :error_threshold, :max_conn, :weight, :comment, :healthcheck, :auto_loadbalance, :request_condition
|
6
6
|
|
7
7
|
##
|
8
8
|
# :attr: service_id
|
@@ -99,6 +99,15 @@ class Fastly
|
|
99
99
|
# :attr: healthcheck
|
100
100
|
#
|
101
101
|
# the name of a healthcheck to associate with this backend. See the Healthcheck object
|
102
|
-
|
102
|
+
|
103
|
+
##
|
104
|
+
# :attr: auto_loadbalance
|
105
|
+
#
|
106
|
+
# set to true if you want to auto_loadbalance, set to false if you don't want to auto_loadbalance
|
107
|
+
|
108
|
+
##
|
109
|
+
# :attr: request_condition
|
110
|
+
#
|
111
|
+
# name of a request_condition to filter the backend on
|
103
112
|
end
|
104
113
|
end
|
data/lib/fastly/base.rb
CHANGED
@@ -19,6 +19,11 @@ class Fastly
|
|
19
19
|
def version_number
|
20
20
|
@version
|
21
21
|
end
|
22
|
+
|
23
|
+
# :nodoc:
|
24
|
+
def as_hash
|
25
|
+
super.delete_if { |var| ["service_id", "version"].include?(var) }
|
26
|
+
end
|
22
27
|
|
23
28
|
private
|
24
29
|
|
@@ -27,7 +32,7 @@ class Fastly
|
|
27
32
|
end
|
28
33
|
|
29
34
|
def self.post_path(opts)
|
30
|
-
|
35
|
+
"/service/#{opts[:service_id]}/version/#{opts[:version]}/#{path}"
|
31
36
|
end
|
32
37
|
|
33
38
|
def self.put_path(obj)
|
@@ -39,4 +44,4 @@ class Fastly
|
|
39
44
|
end
|
40
45
|
|
41
46
|
end
|
42
|
-
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Fastly
|
2
|
+
# customize cache handling. Best used with conditions.
|
3
|
+
class CacheSetting < BelongsToServiceAndVersion
|
4
|
+
attr_accessor :service_id, :name, :action, :cache_condition, :ttl, :stale_ttl
|
5
|
+
##
|
6
|
+
# :attr: service_id
|
7
|
+
#
|
8
|
+
# The id of the service this belongs to.
|
9
|
+
|
10
|
+
##
|
11
|
+
# :attr: version
|
12
|
+
#
|
13
|
+
# The number of the version this belongs to.
|
14
|
+
|
15
|
+
##
|
16
|
+
# :attr: name
|
17
|
+
#
|
18
|
+
# The name of the gzip setting
|
19
|
+
|
20
|
+
##
|
21
|
+
# :attr: action
|
22
|
+
#
|
23
|
+
# Allows for termination of execution and either cache, pass, or restart
|
24
|
+
|
25
|
+
##
|
26
|
+
# :attr: ttl
|
27
|
+
#
|
28
|
+
# Sets the time to live
|
29
|
+
|
30
|
+
##
|
31
|
+
# :attr: stale_ttl
|
32
|
+
#
|
33
|
+
# Sets the max time to live for stale (unreachable) objects
|
34
|
+
|
35
|
+
##
|
36
|
+
# :attr: cache_condition
|
37
|
+
#
|
38
|
+
# Name of the cache condition used to test whether this settings object
|
39
|
+
# should be used.
|
40
|
+
|
41
|
+
private
|
42
|
+
# needs an 's' at the end of the url
|
43
|
+
def self.path
|
44
|
+
self.to_s.split("::")[-1].underscore + "s"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/fastly/client.rb
CHANGED
@@ -62,6 +62,12 @@ class Fastly
|
|
62
62
|
raise Fastly::Error, resp.message unless resp.success?
|
63
63
|
JSON.parse(resp.body)
|
64
64
|
end
|
65
|
+
|
66
|
+
def get_stats(path, params={})
|
67
|
+
content = get(path, params)
|
68
|
+
raise Fastly::Error, content["message"] unless content["status"] == 'success'
|
69
|
+
content["data"]
|
70
|
+
end
|
65
71
|
|
66
72
|
def post(path, params={})
|
67
73
|
post_and_put(:post, path, params)
|
@@ -164,4 +170,4 @@ class CurbFu::Response::Base
|
|
164
170
|
def [](key)
|
165
171
|
get_fields(key).last
|
166
172
|
end
|
167
|
-
end
|
173
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class Fastly
|
2
|
+
# An endpoint to stream syslogs to
|
3
|
+
class Condition < BelongsToServiceAndVersion
|
4
|
+
attr_accessor :service_id, :name, :priority, :statement, :type
|
5
|
+
|
6
|
+
##
|
7
|
+
# :attr: service_id
|
8
|
+
#
|
9
|
+
# The id of the service this belongs to.
|
10
|
+
|
11
|
+
##
|
12
|
+
# :attr: version
|
13
|
+
#
|
14
|
+
# The number of the version this belongs to.
|
15
|
+
|
16
|
+
##
|
17
|
+
# :attr: name
|
18
|
+
#
|
19
|
+
# The name of the condition
|
20
|
+
|
21
|
+
##
|
22
|
+
# :attr: statement
|
23
|
+
#
|
24
|
+
# The statement of the condition, should be a varnish if statement line
|
25
|
+
|
26
|
+
##
|
27
|
+
# :attr: priority
|
28
|
+
#
|
29
|
+
# What order to run them in, higher priority gets executed after lower priority
|
30
|
+
|
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
|
+
end
|
data/lib/fastly/director.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class Fastly
|
2
2
|
# A logical collection of backends - for example all the asset servers in one data center
|
3
3
|
class Director < BelongsToServiceAndVersion
|
4
|
-
attr_accessor :service_id, :name, :type, :comment, :retries, :capacity, :
|
4
|
+
attr_accessor :service_id, :name, :type, :comment, :retries, :capacity, :quorum
|
5
5
|
|
6
6
|
##
|
7
7
|
# :attr: service
|
@@ -60,4 +60,4 @@ class Fastly
|
|
60
60
|
return !hash.nil?
|
61
61
|
end
|
62
62
|
end
|
63
|
-
end
|
63
|
+
end
|
data/lib/fastly/fetcher.rb
CHANGED
@@ -18,7 +18,7 @@ class Fastly
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def list(klass, opts={})
|
21
|
-
list = client.get(klass.list_path
|
21
|
+
list = client.get(klass.list_path(opts))
|
22
22
|
return [] if list.nil?
|
23
23
|
list.map { |hash| klass.new(hash, self) }
|
24
24
|
end
|
@@ -48,4 +48,4 @@ class Fastly
|
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
51
|
-
end
|
51
|
+
end
|
data/lib/fastly/gzip.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
class Fastly
|
2
|
+
# customize gzipping content.
|
3
|
+
class Gzip < BelongsToServiceAndVersion
|
4
|
+
attr_accessor :service_id, :name, :extensions, :content_types, :cache_condition
|
5
|
+
|
6
|
+
##
|
7
|
+
# :attr: service_id
|
8
|
+
#
|
9
|
+
# The id of the service this belongs to.
|
10
|
+
|
11
|
+
##
|
12
|
+
# :attr: version
|
13
|
+
#
|
14
|
+
# The number of the version this belongs to.
|
15
|
+
|
16
|
+
##
|
17
|
+
# :attr: name
|
18
|
+
#
|
19
|
+
# The name of the condition
|
20
|
+
|
21
|
+
##
|
22
|
+
# :attr: extensions
|
23
|
+
#
|
24
|
+
# File extensions to be gzipped. Seems to want them in a list like
|
25
|
+
# "js css html"
|
26
|
+
|
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"
|
32
|
+
|
33
|
+
##
|
34
|
+
# :attr" cache_condition
|
35
|
+
#
|
36
|
+
# Cache condition to be used to determine when to apply this gzip setting
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
class Fastly
|
2
|
+
# customize headers. Best used with conditions.
|
3
|
+
class Header < BelongsToServiceAndVersion
|
4
|
+
attr_accessor :service_id, :name, :action, :cache_condition, :request_condition, :response_condition, :ignore_if_set, :type, :dst, :src, :substitution, :priority, :regexp
|
5
|
+
|
6
|
+
##
|
7
|
+
# :attr: service_id
|
8
|
+
#
|
9
|
+
# The id of the service this belongs to.
|
10
|
+
|
11
|
+
##
|
12
|
+
# :attr: version
|
13
|
+
#
|
14
|
+
# The number of the version this belongs to.
|
15
|
+
|
16
|
+
##
|
17
|
+
# :attr: name
|
18
|
+
#
|
19
|
+
# The name of the header setting
|
20
|
+
|
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
|
+
|
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
|
+
|
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
|
+
|
45
|
+
##
|
46
|
+
# :attr: dst
|
47
|
+
#
|
48
|
+
# Header to set
|
49
|
+
|
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
|
+
|
56
|
+
##
|
57
|
+
# :attr: regexp
|
58
|
+
#
|
59
|
+
# Regular expression to use with the 'regex' and 'regex_repeat' actions.
|
60
|
+
|
61
|
+
##
|
62
|
+
# :attr: substitution
|
63
|
+
#
|
64
|
+
# Value to substitute in place of regular expression. (Only applies to
|
65
|
+
# 'regex' and 'regex_repeat'.)
|
66
|
+
|
67
|
+
##
|
68
|
+
# :attr: priority
|
69
|
+
#
|
70
|
+
# Lower priorities execute first.
|
71
|
+
|
72
|
+
##
|
73
|
+
# :attr: request_condition
|
74
|
+
#
|
75
|
+
# Optional name of a request condition to apply
|
76
|
+
|
77
|
+
##
|
78
|
+
# :attr: cache_condition
|
79
|
+
#
|
80
|
+
# Optional name of a cache condition to apply
|
81
|
+
|
82
|
+
##
|
83
|
+
# :attr: response_condition
|
84
|
+
#
|
85
|
+
# Optional name of a response condition to apply
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
class Fastly
|
2
|
+
# customize request handing. Best used with conditions
|
3
|
+
class RequestSetting < BelongsToServiceAndVersion
|
4
|
+
attr_accessor :service_id, :name, :force_miss, :force_ssl, :action, :bypass_busy_wait, :max_stale_age, :hash_keys, :xff, :time_support, :geo_headers, :default_host, :request_condition
|
5
|
+
|
6
|
+
##
|
7
|
+
# :attr: service_id
|
8
|
+
#
|
9
|
+
# The id of the service this belongs to.
|
10
|
+
|
11
|
+
##
|
12
|
+
# :attr: version
|
13
|
+
#
|
14
|
+
# The number of the version this belongs to.
|
15
|
+
|
16
|
+
##
|
17
|
+
# :attr: name
|
18
|
+
#
|
19
|
+
# The name of the request setting
|
20
|
+
|
21
|
+
##
|
22
|
+
# :attr: force_miss
|
23
|
+
#
|
24
|
+
# Allows you to force a cache miss for the request. Replaces the item
|
25
|
+
# in the cache if the content is cacheable
|
26
|
+
|
27
|
+
##
|
28
|
+
# :attr: force_ssl
|
29
|
+
#
|
30
|
+
# Force the request to use SSL, redirecting a non-SSL request to SSL.
|
31
|
+
|
32
|
+
##
|
33
|
+
# :attr: action
|
34
|
+
#
|
35
|
+
# Allows you to terminate request handling and immediately perform an
|
36
|
+
# action. When set it can be lookup or pass (ignore the cache completely)
|
37
|
+
|
38
|
+
##
|
39
|
+
# :attr: bypass_busy_wait
|
40
|
+
#
|
41
|
+
# Disable collapsed forwarding, so you don't wait for other objects to
|
42
|
+
# origin
|
43
|
+
|
44
|
+
##
|
45
|
+
# :attr: max_stale_age
|
46
|
+
#
|
47
|
+
# How old an object is allowed to be to serve stale-if-error or
|
48
|
+
# state-while-revalidate
|
49
|
+
|
50
|
+
##
|
51
|
+
# :attr: hash_keys
|
52
|
+
#
|
53
|
+
# Comma separated list of varnish request object fields that should be
|
54
|
+
# in the hash key
|
55
|
+
|
56
|
+
##
|
57
|
+
# :attr: xff
|
58
|
+
#
|
59
|
+
# X-Forwarded-For: should be clear, leave, append, append_all, or
|
60
|
+
# overwrite
|
61
|
+
|
62
|
+
##
|
63
|
+
# :attr: timer_support
|
64
|
+
#
|
65
|
+
# Injects the X-Timer info into the request for viewing origin fetch
|
66
|
+
# durations
|
67
|
+
|
68
|
+
##
|
69
|
+
# :attr: geo_headers
|
70
|
+
#
|
71
|
+
# Injects Fastly-Geo-Country, Fastly-Geo-City, and Fastly-Geo-Region
|
72
|
+
# into the request headers
|
73
|
+
|
74
|
+
##
|
75
|
+
# :attr: default_host
|
76
|
+
#
|
77
|
+
# Sets the host header
|
78
|
+
|
79
|
+
##
|
80
|
+
# :attr: request_condition
|
81
|
+
#
|
82
|
+
# Name of condition object used to test whether or not these settings
|
83
|
+
# should be used
|
84
|
+
|
85
|
+
private
|
86
|
+
def self.path
|
87
|
+
self.to_s.split("::")[-1].underscore + "s"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Fastly
|
2
|
+
# Set up a response object. Best used with conditions.
|
3
|
+
class ResponseObject < BelongsToServiceAndVersion
|
4
|
+
attr_accessor :service_id, :name, :cache_condition, :request_condition, :status, :response, :content, :content_type
|
5
|
+
|
6
|
+
##
|
7
|
+
# :attr: service_id
|
8
|
+
#
|
9
|
+
# The id of the service this belongs to.
|
10
|
+
|
11
|
+
##
|
12
|
+
# :attr: version
|
13
|
+
#
|
14
|
+
# The number of the version this belongs to.
|
15
|
+
|
16
|
+
##
|
17
|
+
# :attr: name
|
18
|
+
#
|
19
|
+
# The name of the response object
|
20
|
+
|
21
|
+
##
|
22
|
+
# :attr: cache_condition
|
23
|
+
#
|
24
|
+
# Name of the cache condition used to test whether this response object
|
25
|
+
# should be used.
|
26
|
+
|
27
|
+
##
|
28
|
+
# :attr: request_condition
|
29
|
+
#
|
30
|
+
# Name of the request condition used to test whether this response object
|
31
|
+
# should be used.
|
32
|
+
|
33
|
+
##
|
34
|
+
# :attr: status
|
35
|
+
#
|
36
|
+
# The HTTP status code, defaults to 200
|
37
|
+
|
38
|
+
##
|
39
|
+
# :attr: response
|
40
|
+
#
|
41
|
+
# The HTTP response, defaults to "Ok"
|
42
|
+
|
43
|
+
##
|
44
|
+
# :attr: content
|
45
|
+
#
|
46
|
+
# The content to deliver for the response object, can be empty.
|
47
|
+
|
48
|
+
##
|
49
|
+
# :attr: content_type
|
50
|
+
#
|
51
|
+
# The MIME type of the content, can be empty.
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|