fastly 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +35 -0
- data/.travis.yml +3 -4
- data/Gemfile +1 -0
- data/HISTORY.md +11 -1
- data/README.md +5 -1
- data/Rakefile +27 -2
- data/bin/fastly_create_domain +67 -0
- data/lib/fastly.rb +114 -114
- data/lib/fastly/backend.rb +51 -51
- data/lib/fastly/base.rb +9 -9
- data/lib/fastly/belongs_to_service_and_version.rb +10 -10
- data/lib/fastly/cache_setting.rb +3 -3
- data/lib/fastly/client.rb +11 -11
- data/lib/fastly/condition.rb +7 -7
- data/lib/fastly/customer.rb +6 -6
- data/lib/fastly/director.rb +25 -25
- data/lib/fastly/domain.rb +13 -13
- data/lib/fastly/fetcher.rb +7 -7
- data/lib/fastly/gem_version.rb +1 -1
- data/lib/fastly/gzip.rb +5 -5
- data/lib/fastly/header.rb +5 -5
- data/lib/fastly/healthcheck.rb +28 -28
- data/lib/fastly/invoice.rb +36 -36
- data/lib/fastly/match.rb +38 -38
- data/lib/fastly/origin.rb +14 -14
- data/lib/fastly/request_setting.rb +9 -9
- data/lib/fastly/response_object.rb +5 -5
- data/lib/fastly/s3_logging.rb +6 -6
- data/lib/fastly/service.rb +26 -26
- data/lib/fastly/settings.rb +14 -14
- data/lib/fastly/syslog.rb +37 -37
- data/lib/fastly/user.rb +18 -18
- data/lib/fastly/vcl.rb +12 -12
- data/lib/fastly/version.rb +32 -32
- data/test/common.rb +1 -1
- metadata +14 -11
data/lib/fastly/backend.rb
CHANGED
@@ -1,113 +1,113 @@
|
|
1
1
|
class Fastly
|
2
2
|
# An individual host you want to serve assets off
|
3
3
|
class Backend < BelongsToServiceAndVersion
|
4
|
-
attr_accessor :service_id, :name, :address, :ipv4, :ipv6, :hostname, :use_ssl, :client_cert, :port,
|
4
|
+
attr_accessor :service_id, :name, :address, :ipv4, :ipv6, :hostname, :use_ssl, :client_cert, :port,
|
5
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
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# The id of the service this belongs to.
|
11
|
-
#
|
11
|
+
#
|
12
12
|
|
13
|
-
##
|
13
|
+
##
|
14
14
|
# :attr: version
|
15
|
-
#
|
15
|
+
#
|
16
16
|
# The number of the version this belongs to.
|
17
|
-
#
|
17
|
+
#
|
18
18
|
|
19
|
-
##
|
19
|
+
##
|
20
20
|
# :attr: name
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# The name of this backend.
|
23
|
-
#
|
23
|
+
#
|
24
24
|
|
25
|
-
##
|
25
|
+
##
|
26
26
|
# :attr: address
|
27
|
-
#
|
27
|
+
#
|
28
28
|
# A magic field - will automagically be set to whichever of ipv4, ipv6 or hostname is currently set.
|
29
|
-
#
|
29
|
+
#
|
30
30
|
# Conversely if you set the address field then the correct field from ipv4, ipv6 or hostname will be set.
|
31
|
-
#
|
31
|
+
#
|
32
32
|
|
33
|
-
##
|
33
|
+
##
|
34
34
|
# :attr: ipv4
|
35
|
-
#
|
35
|
+
#
|
36
36
|
# the ipv4 address of the host to serve assets (this, hostname or ipv6 must be set)
|
37
|
-
#
|
37
|
+
#
|
38
38
|
|
39
|
-
##
|
39
|
+
##
|
40
40
|
# :attr: ipv6
|
41
|
-
#
|
41
|
+
#
|
42
42
|
# the ipv6 address of the host to serve assets (this, hostname or ipv4 must be set)
|
43
|
-
#
|
43
|
+
#
|
44
44
|
|
45
|
-
##
|
45
|
+
##
|
46
46
|
# :attr: hostname
|
47
|
-
#
|
47
|
+
#
|
48
48
|
# the hostname to serve assets from (this, ipv4 or ipv6 must be set)
|
49
|
-
#
|
49
|
+
#
|
50
50
|
|
51
|
-
##
|
51
|
+
##
|
52
52
|
# :attr: port
|
53
|
-
#
|
53
|
+
#
|
54
54
|
# the port to connect to (default 80)
|
55
|
-
#
|
55
|
+
#
|
56
56
|
|
57
|
-
##
|
57
|
+
##
|
58
58
|
# :attr: use_ssl
|
59
|
-
#
|
59
|
+
#
|
60
60
|
# whether to use ssl to get to the backend (default 0 i.e false)
|
61
|
-
#
|
61
|
+
#
|
62
62
|
|
63
|
-
##
|
63
|
+
##
|
64
64
|
# :attr: connect_timeout
|
65
|
-
#
|
65
|
+
#
|
66
66
|
# how long in milliseconds to wait for a connect before declaring the backend out of rotation (default 1,000)
|
67
|
-
#
|
67
|
+
#
|
68
68
|
|
69
|
-
##
|
69
|
+
##
|
70
70
|
# :attr: first_byte_timeout
|
71
|
-
#
|
71
|
+
#
|
72
72
|
# how long in milliseconds to wait for the first bytes before declaring the host out of rotation (default 15,000)
|
73
|
-
#
|
73
|
+
#
|
74
74
|
|
75
|
-
##
|
75
|
+
##
|
76
76
|
# :attr: between_bytes_timeout
|
77
|
-
#
|
77
|
+
#
|
78
78
|
# how long in milliseconds to wait between bytes before declaring the backend out of rotation (default 10,000)
|
79
|
-
#
|
79
|
+
#
|
80
80
|
|
81
|
-
##
|
81
|
+
##
|
82
82
|
# :attr: error_threshold
|
83
|
-
#
|
83
|
+
#
|
84
84
|
# how many errors before declaring the backend out of rotation (default 0, 0 meaning turned off)
|
85
|
-
#
|
85
|
+
#
|
86
86
|
|
87
|
-
##
|
87
|
+
##
|
88
88
|
# :attr: max_conn
|
89
|
-
#
|
89
|
+
#
|
90
90
|
# the maximum number of connections to this backend (default 20)
|
91
|
-
#
|
91
|
+
#
|
92
92
|
|
93
|
-
##
|
93
|
+
##
|
94
94
|
# :attr: weight
|
95
|
-
#
|
95
|
+
#
|
96
96
|
# the weight assigned to this backend (default 100)
|
97
|
-
|
97
|
+
|
98
98
|
##
|
99
99
|
# :attr: healthcheck
|
100
100
|
#
|
101
101
|
# the name of a healthcheck to associate with this backend. See the Healthcheck object
|
102
|
-
|
103
|
-
##
|
102
|
+
|
103
|
+
##
|
104
104
|
# :attr: auto_loadbalance
|
105
105
|
#
|
106
106
|
# set to true if you want to auto_loadbalance, set to false if you don't want to auto_loadbalance
|
107
|
-
|
107
|
+
|
108
108
|
##
|
109
109
|
# :attr: request_condition
|
110
110
|
#
|
111
111
|
# name of a request_condition to filter the backend on
|
112
112
|
end
|
113
|
-
end
|
113
|
+
end
|
data/lib/fastly/base.rb
CHANGED
@@ -2,7 +2,7 @@ class Fastly
|
|
2
2
|
# Base class for all Fastly objects
|
3
3
|
class Base # :nodoc: all
|
4
4
|
attr_accessor :fetcher
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(opts, fetcher)
|
7
7
|
@keys = []
|
8
8
|
opts.each do |key,val|
|
@@ -12,7 +12,7 @@ class Fastly
|
|
12
12
|
end
|
13
13
|
self.fetcher = fetcher
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
# Save this object
|
17
17
|
def save!
|
18
18
|
fetcher.update(self.class, self)
|
@@ -22,7 +22,7 @@ class Fastly
|
|
22
22
|
def delete!
|
23
23
|
fetcher.delete(self.class, self)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
##
|
27
27
|
# :nodoc:
|
28
28
|
def as_hash
|
@@ -36,26 +36,26 @@ class Fastly
|
|
36
36
|
def self.path
|
37
37
|
Util.class_to_path(self)
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def self.get_path(id)
|
41
41
|
"/#{path}/#{id}"
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def self.post_path(opts={})
|
45
45
|
"/#{path}"
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def self.list_path(opts={})
|
49
49
|
post_path(opts)
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def self.put_path(obj)
|
53
53
|
get_path(obj.id)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def self.delete_path(obj)
|
57
57
|
put_path(obj)
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
end
|
61
61
|
end
|
@@ -4,44 +4,44 @@ class Fastly
|
|
4
4
|
def service
|
5
5
|
@service ||= fetcher.get(Fastly::Service, service_id)
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
# Set the Version object this belongs to
|
9
9
|
def version=(version)
|
10
10
|
@version = version
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
# Get the Version object this belongs to
|
14
14
|
def version
|
15
15
|
@version_obj ||= fetcher.get(Fastly::Version, service_id, version_number)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Get the number of the Version this belongs to
|
19
19
|
def version_number
|
20
20
|
@version
|
21
21
|
end
|
22
22
|
|
23
23
|
# :nodoc:
|
24
|
-
def as_hash
|
24
|
+
def as_hash
|
25
25
|
super.delete_if { |var| ["service_id", "version"].include?(var) }
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
private
|
29
|
-
|
29
|
+
|
30
30
|
def self.get_path(service, version, name, options={})
|
31
31
|
"/service/#{service}/version/#{version}/#{path}/#{name}"
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def self.post_path(opts)
|
35
35
|
"/service/#{opts[:service_id]}/version/#{opts[:version]}/#{path}"
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def self.put_path(obj)
|
39
39
|
get_path(obj.service_id, obj.version_number,obj.name)
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def self.delete_path(obj)
|
43
43
|
put_path(obj)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
end
|
47
47
|
end
|
data/lib/fastly/cache_setting.rb
CHANGED
@@ -2,17 +2,17 @@ class Fastly
|
|
2
2
|
# customize cache handling. Best used with conditions.
|
3
3
|
class CacheSetting < BelongsToServiceAndVersion
|
4
4
|
attr_accessor :service_id, :name, :action, :cache_condition, :ttl, :stale_ttl
|
5
|
-
##
|
5
|
+
##
|
6
6
|
# :attr: service_id
|
7
7
|
#
|
8
8
|
# The id of the service this belongs to.
|
9
9
|
|
10
|
-
##
|
10
|
+
##
|
11
11
|
# :attr: version
|
12
12
|
#
|
13
13
|
# The number of the version this belongs to.
|
14
14
|
|
15
|
-
##
|
15
|
+
##
|
16
16
|
# :attr: name
|
17
17
|
#
|
18
18
|
# The name of the gzip setting
|
data/lib/fastly/client.rb
CHANGED
@@ -8,7 +8,7 @@ require 'uri'
|
|
8
8
|
class Fastly
|
9
9
|
# The UserAgent to communicate with the API
|
10
10
|
class Client #:nodoc: all
|
11
|
-
begin
|
11
|
+
begin
|
12
12
|
require 'curb-fu'
|
13
13
|
CURB_FU=true
|
14
14
|
rescue LoadError
|
@@ -50,19 +50,19 @@ class Fastly
|
|
50
50
|
def fully_authed?
|
51
51
|
!(user.nil? || password.nil?)
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def set_customer(id)
|
55
|
-
|
55
|
+
|
56
56
|
end
|
57
57
|
|
58
58
|
def get(path, params={})
|
59
|
-
path += "?"+make_params(params) unless params.empty?
|
59
|
+
path += "?"+make_params(params) unless params.empty?
|
60
60
|
resp = self.http.get(path, headers)
|
61
61
|
return nil if 404 == resp.status
|
62
62
|
raise Fastly::Error, resp.message unless resp.success?
|
63
63
|
JSON.parse(resp.body)
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
def get_stats(path, params={})
|
67
67
|
content = get(path, params)
|
68
68
|
raise Fastly::Error, content["message"] unless content["status"] == 'success'
|
@@ -98,19 +98,19 @@ class Fastly
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def make_params(params)
|
101
|
-
params.map { |key,val|
|
101
|
+
params.map { |key,val|
|
102
102
|
next if val.nil?
|
103
103
|
unless val.is_a?(Hash)
|
104
104
|
"#{CGI.escape(key.to_s)}=#{CGI.escape(val.to_s)}"
|
105
|
-
else
|
105
|
+
else
|
106
106
|
val.map { |sub_key, sub_val|
|
107
107
|
new_key = "#{key}[#{sub_key}]"
|
108
108
|
"#{CGI.escape(new_key)}=#{CGI.escape(sub_val.to_s)}"
|
109
|
-
}
|
109
|
+
}
|
110
110
|
end
|
111
111
|
}.flatten.delete_if { |v| v.nil? }.join("&")
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
# :nodoc: all
|
115
115
|
class Curl
|
116
116
|
attr_accessor :host, :port, :protocol
|
@@ -145,7 +145,7 @@ class Fastly
|
|
145
145
|
end
|
146
146
|
|
147
147
|
# :nodoc: all
|
148
|
-
class Net::HTTPResponse
|
148
|
+
class Net::HTTPResponse
|
149
149
|
def success?
|
150
150
|
return Net::HTTPSuccess === self
|
151
151
|
end
|
@@ -158,7 +158,7 @@ end
|
|
158
158
|
|
159
159
|
|
160
160
|
# :nodoc: all
|
161
|
-
class CurbFu::Response::Base
|
161
|
+
class CurbFu::Response::Base
|
162
162
|
def get_fields(key)
|
163
163
|
if ( match = @headers.find{|k,v| k.downcase == key.downcase} )
|
164
164
|
[match.last].flatten
|
data/lib/fastly/condition.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
class Fastly
|
2
|
-
# An endpoint to stream syslogs to
|
2
|
+
# An endpoint to stream syslogs to
|
3
3
|
class Condition < BelongsToServiceAndVersion
|
4
4
|
attr_accessor :service_id, :name, :priority, :statement, :type
|
5
5
|
|
6
|
-
##
|
6
|
+
##
|
7
7
|
# :attr: service_id
|
8
8
|
#
|
9
9
|
# The id of the service this belongs to.
|
10
10
|
|
11
|
-
##
|
11
|
+
##
|
12
12
|
# :attr: version
|
13
13
|
#
|
14
14
|
# The number of the version this belongs to.
|
15
15
|
|
16
|
-
##
|
16
|
+
##
|
17
17
|
# :attr: name
|
18
18
|
#
|
19
19
|
# The name of the condition
|
20
20
|
|
21
|
-
##
|
21
|
+
##
|
22
22
|
# :attr: statement
|
23
23
|
#
|
24
24
|
# The statement of the condition, should be a varnish if statement line
|
25
25
|
|
26
|
-
##
|
26
|
+
##
|
27
27
|
# :attr: priority
|
28
28
|
#
|
29
29
|
# What order to run them in, higher priority gets executed after lower priority
|
30
30
|
|
31
|
-
##
|
31
|
+
##
|
32
32
|
# :attr: type
|
33
33
|
#
|
34
34
|
# request, cache or response
|
data/lib/fastly/customer.rb
CHANGED
@@ -5,17 +5,17 @@ class Fastly
|
|
5
5
|
|
6
6
|
##
|
7
7
|
# :attr: id
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# The id of this customer
|
10
10
|
|
11
|
-
##
|
11
|
+
##
|
12
12
|
# :attr: name
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# The name of this customer
|
15
15
|
|
16
|
-
##
|
16
|
+
##
|
17
17
|
# :attr: owner_id
|
18
|
-
#
|
18
|
+
#
|
19
19
|
# The id of the user that owns this customer
|
20
20
|
|
21
21
|
# Return a user object representing the owner of this Customer
|
@@ -23,4 +23,4 @@ class Fastly
|
|
23
23
|
self.fetcher.get(User,self.owner_id)
|
24
24
|
end
|
25
25
|
end
|
26
|
-
end
|
26
|
+
end
|
data/lib/fastly/director.rb
CHANGED
@@ -3,59 +3,59 @@ class Fastly
|
|
3
3
|
class Director < BelongsToServiceAndVersion
|
4
4
|
attr_accessor :service_id, :name, :type, :comment, :retries, :capacity, :quorum
|
5
5
|
|
6
|
-
##
|
6
|
+
##
|
7
7
|
# :attr: service
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# The id of the service this belongs to.
|
10
|
-
#
|
10
|
+
#
|
11
11
|
|
12
|
-
##
|
12
|
+
##
|
13
13
|
# :attr: version
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# The number of the version this belongs to.
|
16
|
-
#
|
16
|
+
#
|
17
17
|
|
18
|
-
##
|
18
|
+
##
|
19
19
|
# :attr: name
|
20
|
-
#
|
20
|
+
#
|
21
21
|
# The domain name of this domain
|
22
|
-
#
|
22
|
+
#
|
23
23
|
|
24
|
-
##
|
24
|
+
##
|
25
25
|
# :attr: type
|
26
|
-
#
|
26
|
+
#
|
27
27
|
# what kind of Load Balancer group (currently always 1 meaning random)
|
28
|
-
#
|
28
|
+
#
|
29
29
|
|
30
|
-
##
|
30
|
+
##
|
31
31
|
# :attr: retries
|
32
|
-
#
|
32
|
+
#
|
33
33
|
# how many backends to search if it fails (default 5)
|
34
|
-
#
|
34
|
+
#
|
35
35
|
|
36
|
-
##
|
36
|
+
##
|
37
37
|
# :attr: quorum
|
38
|
-
#
|
38
|
+
#
|
39
39
|
# the percentage of capacity that needs to be up for a director to be considered up (default 75)
|
40
|
-
#
|
40
|
+
#
|
41
41
|
|
42
|
-
##
|
43
|
-
# :attr: comment
|
44
|
-
#
|
42
|
+
##
|
43
|
+
# :attr: comment
|
44
|
+
#
|
45
45
|
# a free form comment field
|
46
|
-
|
46
|
+
|
47
47
|
# Add a Backend object to a Director
|
48
48
|
#
|
49
49
|
# Return true on success and false on failure
|
50
|
-
def add_backend(backend)
|
50
|
+
def add_backend(backend)
|
51
51
|
hash = fetcher.client.post(Fastly::Director.put_path(self)+"/backend/#{backend.name}")
|
52
52
|
return !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
|
-
def delete_backend(backend)
|
58
|
+
def delete_backend(backend)
|
59
59
|
hash = fetcher.client.delete(Fastly::Director.put_path(self)+"/backend/#{backend.name}")
|
60
60
|
return !hash.nil?
|
61
61
|
end
|