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
data/lib/fastly/settings.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# Settings Object
|
1
2
|
class Fastly
|
2
3
|
# Represent arbitary key value settings for a given Version
|
3
4
|
class Settings < Base
|
@@ -31,23 +32,23 @@ class Fastly
|
|
31
32
|
end
|
32
33
|
|
33
34
|
# :nodoc:
|
34
|
-
def self.list_path(
|
35
|
+
def self.list_path(_opts = {})
|
35
36
|
nil
|
36
37
|
end
|
37
38
|
|
38
39
|
# :nodoc:
|
39
40
|
def self.post_path
|
40
|
-
|
41
|
+
fail "You can't POST to an setting"
|
41
42
|
end
|
42
43
|
|
43
44
|
# :nodoc:
|
44
45
|
def self.delete_path
|
45
|
-
|
46
|
+
fail "You can't DELETE to an setting"
|
46
47
|
end
|
47
48
|
|
48
49
|
# :nodoc:
|
49
50
|
def delete!
|
50
|
-
|
51
|
+
fail "You can't delete an invoice"
|
51
52
|
end
|
52
53
|
|
53
54
|
# :nodoc:
|
@@ -58,17 +59,15 @@ class Fastly
|
|
58
59
|
|
59
60
|
# Get the Settings object for the specified Version
|
60
61
|
def get_settings(service, number)
|
61
|
-
|
62
|
-
hash = client.get(Fastly::Settings.get_path(service, number))
|
63
|
-
|
62
|
+
hash = client.get(Settings.get_path(service, number))
|
64
63
|
return nil if hash.nil?
|
65
|
-
hash["settings"] = Hash[["general.default_host", "general.default_ttl"].collect { |var| [var, hash.delete(var)] }]
|
66
64
|
|
67
|
-
|
65
|
+
hash['settings'] = Hash[['general.default_host', 'general.default_ttl'].collect { |var| [var, hash.delete(var)] }]
|
66
|
+
Settings.new(hash, self)
|
68
67
|
end
|
69
68
|
|
70
69
|
# Update the Settings object for the specified Version
|
71
|
-
def update_settings(opts={})
|
72
|
-
update(
|
70
|
+
def update_settings(opts = {})
|
71
|
+
update(Settings, opts)
|
73
72
|
end
|
74
73
|
end
|
data/lib/fastly/syslog.rb
CHANGED
@@ -1,70 +1,66 @@
|
|
1
1
|
class Fastly
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
# An endpoint to stream syslogs to
|
3
|
+
class Syslog < BelongsToServiceAndVersion
|
4
|
+
attr_accessor :service_id, :name, :comment, :ipv4, :ipv6, :hostname, :port, :format, :response_conditions
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
##
|
7
|
+
# :attr: service_id
|
8
|
+
#
|
9
|
+
# The id of the service this belongs to.
|
10
|
+
#
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
##
|
13
|
+
# :attr: version
|
14
|
+
#
|
15
|
+
# The number of the version this belongs to.
|
16
|
+
#
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
##
|
19
|
+
# :attr: name
|
20
|
+
#
|
21
|
+
# The domain name of this domain
|
22
|
+
#
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
##
|
25
|
+
# :attr: comment
|
26
|
+
#
|
27
|
+
# a free form comment field
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
##
|
30
|
+
# :attr: address
|
31
|
+
#
|
32
|
+
# A magic field - will automagically be set to whichever of ipv4, ipv6 or hostname is currently set.
|
33
|
+
#
|
34
|
+
# Conversely if you set the address field then the correct field from ipv4, ipv6 or hostname will be set.
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
##
|
37
|
+
# :attr: ipv4
|
38
|
+
#
|
39
|
+
# the ipv4 address of the host to stream logs to (this, hostname or ipv6 must be set)
|
40
40
|
|
41
|
+
##
|
42
|
+
# :attr: ipv6
|
43
|
+
#
|
44
|
+
# the ipv6 address of the host to stream logs to (this, hostname or ipv4 must be set)
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
##
|
47
|
+
# :attr: hostname
|
48
|
+
#
|
49
|
+
# the hostname to to stream logs to (this, ipv4 or ipv6 must be set)
|
46
50
|
|
51
|
+
##
|
52
|
+
# :attr: port
|
53
|
+
#
|
54
|
+
# the port to stream logs to (defaults to 514)
|
47
55
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
56
|
+
##
|
57
|
+
# :attr: format
|
58
|
+
#
|
59
|
+
# Format to log like in apache format
|
52
60
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
##
|
61
|
-
# :attr: format
|
62
|
-
#
|
63
|
-
# Format to log like in apache format
|
64
|
-
|
65
|
-
##
|
66
|
-
# :attr: response_condition
|
67
|
-
#
|
68
|
-
# name of a response_condition to filter the log on, if empty it always logs
|
69
|
-
end
|
61
|
+
##
|
62
|
+
# :attr: response_condition
|
63
|
+
#
|
64
|
+
# name of a response_condition to filter the log on, if empty it always logs
|
65
|
+
end
|
70
66
|
end
|
data/lib/fastly/user.rb
CHANGED
@@ -25,10 +25,9 @@ class Fastly
|
|
25
25
|
#
|
26
26
|
# The role this user has (one of admin, owner, superuser, user, engineer, billing)
|
27
27
|
|
28
|
-
|
29
28
|
# Get the Customer object this user belongs to
|
30
29
|
def customer
|
31
|
-
@customer ||= fetcher.get(Customer,
|
30
|
+
@customer ||= fetcher.get(Customer, customer_id)
|
32
31
|
end
|
33
32
|
|
34
33
|
# Whether or not this User is the owner of the Customer they belong to
|
@@ -43,20 +42,19 @@ class Fastly
|
|
43
42
|
:superuser => 10,
|
44
43
|
:user => 20,
|
45
44
|
:engineer => 30,
|
46
|
-
:billing => 30
|
45
|
+
:billing => 30
|
47
46
|
}
|
48
47
|
|
49
48
|
# Does this User have sufficient permissions to perform the given role
|
50
49
|
def can_do?(test_role)
|
51
50
|
test_priority = PRIORITIES[test_role.to_sym] || 1000
|
52
|
-
my_priority = PRIORITIES[
|
51
|
+
my_priority = PRIORITIES[role.to_sym] || 1000
|
53
52
|
|
54
53
|
if test_priority == my_priority
|
55
|
-
test_role.to_s == :owner ? owner? : test_role.to_sym ==
|
54
|
+
test_role.to_s == :owner ? owner? : test_role.to_sym == role.to_sym
|
56
55
|
else
|
57
56
|
my_priority < test_priority
|
58
57
|
end
|
59
58
|
end
|
60
|
-
|
61
59
|
end
|
62
60
|
end
|
data/lib/fastly/util.rb
CHANGED
data/lib/fastly/version.rb
CHANGED
@@ -16,25 +16,21 @@ class Fastly
|
|
16
16
|
#
|
17
17
|
# The name of this version.
|
18
18
|
|
19
|
-
|
20
19
|
##
|
21
20
|
# :attr: active
|
22
21
|
#
|
23
22
|
# Whether this version is active or not.
|
24
23
|
|
25
|
-
|
26
24
|
##
|
27
25
|
# :attr: locked
|
28
26
|
#
|
29
27
|
# Whether this version is locked or not.
|
30
28
|
|
31
|
-
|
32
29
|
##
|
33
30
|
# :attr: staging
|
34
31
|
#
|
35
32
|
# Whether this version is in staging or not.
|
36
33
|
|
37
|
-
|
38
34
|
##
|
39
35
|
# :attr: testing
|
40
36
|
#
|
@@ -54,17 +50,17 @@ class Fastly
|
|
54
50
|
|
55
51
|
# Is this Version locked
|
56
52
|
def locked?
|
57
|
-
|
53
|
+
@locked.to_i > 0
|
58
54
|
end
|
59
55
|
|
60
56
|
# Set whether this Version is locked
|
61
57
|
def locked=(is_locked)
|
62
|
-
@locked = is_locked ?
|
58
|
+
@locked = is_locked ? '1' : '0'
|
63
59
|
end
|
64
60
|
|
65
61
|
# Get the Service object this Version belongs to
|
66
62
|
def service
|
67
|
-
fetcher.get(
|
63
|
+
fetcher.get(Service, service_id)
|
68
64
|
end
|
69
65
|
|
70
66
|
# Get the Settings object for this Version
|
@@ -74,33 +70,34 @@ class Fastly
|
|
74
70
|
|
75
71
|
# Is version active?
|
76
72
|
def active?
|
77
|
-
|
73
|
+
@active.to_i > 0
|
78
74
|
end
|
79
75
|
|
80
76
|
# Activate this version
|
81
77
|
def activate!
|
82
|
-
hash = fetcher.client.put(
|
83
|
-
|
78
|
+
hash = fetcher.client.put("#{Version.put_path(self)}/activate")
|
79
|
+
!hash.nil?
|
84
80
|
end
|
85
81
|
|
86
82
|
# Deactivate this version
|
87
83
|
def deactivate!
|
88
|
-
|
89
|
-
|
84
|
+
hash = fetcher.client.put("#{Version.put_path(self)}/deactivate")
|
85
|
+
!hash.nil?
|
90
86
|
end
|
91
87
|
|
92
88
|
# Clone this Version
|
93
89
|
def clone
|
94
|
-
hash = fetcher.client.put(
|
90
|
+
hash = fetcher.client.put("#{Version.put_path(self)}/clone")
|
95
91
|
return nil if hash.nil?
|
96
|
-
|
92
|
+
Version.new(hash, fetcher)
|
97
93
|
end
|
98
94
|
|
99
95
|
# Create an entirely new version, not cloned from the previous one.
|
100
96
|
def self.create_new(fetcher, opts)
|
101
|
-
hash = fetcher.client.post(
|
97
|
+
hash = fetcher.client.post(Version.post_path(opts))
|
102
98
|
return nil if hash.nil?
|
103
|
-
|
99
|
+
|
100
|
+
Version.new(hash, fetcher)
|
104
101
|
end
|
105
102
|
|
106
103
|
# Get the generated VCL object for this Version (which must have been activated first)
|
@@ -108,22 +105,23 @@ class Fastly
|
|
108
105
|
# Won't return the content of the VCL unless you pass in
|
109
106
|
# :include_content => true
|
110
107
|
# in the opts
|
111
|
-
def generated_vcl(opts={})
|
112
|
-
hash = fetcher.client.get(
|
108
|
+
def generated_vcl(opts = {})
|
109
|
+
hash = fetcher.client.get("#{Version.put_path(self)}/generated_vcl", opts)
|
113
110
|
opts = {
|
114
111
|
'content' => hash['vcl'] || hash['content'],
|
115
112
|
'name' => hash['md5'],
|
116
113
|
'version' => hash['version'],
|
117
114
|
'service_id' => hash['service']
|
118
115
|
}
|
119
|
-
|
116
|
+
|
117
|
+
VCL.new(opts, fetcher)
|
120
118
|
end
|
121
119
|
|
122
120
|
# Upload a VCL file for this Version
|
123
121
|
def upload_vcl(name, content)
|
124
|
-
hash = fetcher.client.post(
|
122
|
+
hash = fetcher.client.post("#{Version.put_path(self)}/vcl", name: name, content: content)
|
125
123
|
return nil if hash.nil?
|
126
|
-
|
124
|
+
VCL.new(hash, fetcher)
|
127
125
|
end
|
128
126
|
|
129
127
|
# Upload a VCL file for this Version and set as the main VCL
|
@@ -136,30 +134,27 @@ class Fastly
|
|
136
134
|
# Won't return the content of the VCL unless you pass in
|
137
135
|
# :include_content => true
|
138
136
|
# in the opts
|
139
|
-
def vcl(name, opts={})
|
137
|
+
def vcl(name, opts = {})
|
140
138
|
fetcher.get_vcl(service_id, number, name, opts)
|
141
139
|
end
|
142
140
|
|
143
141
|
# Delete a VCL file for this Version
|
144
142
|
def delete_vcl(name)
|
145
|
-
hash = fetcher.client.delete(
|
146
|
-
|
147
|
-
return hash
|
143
|
+
hash = fetcher.client.delete("#{Version.put_path(self)}/vcl/#{name}")
|
144
|
+
hash.nil? ? nil : hash
|
148
145
|
end
|
149
146
|
|
150
147
|
# Validate this Version
|
151
148
|
def validate
|
152
|
-
hash = fetcher.client.get(
|
153
|
-
|
149
|
+
hash = fetcher.client.get("#{Version.put_path(self)}/validate")
|
150
|
+
!hash.nil?
|
154
151
|
end
|
155
152
|
|
156
|
-
private
|
157
|
-
|
158
153
|
def self.get_path(service, number)
|
159
154
|
"/service/#{service}/version/#{number}"
|
160
155
|
end
|
161
156
|
|
162
|
-
def self.post_path(opts)
|
157
|
+
def self.post_path(opts = {})
|
163
158
|
"/service/#{opts[:service_id]}/version"
|
164
159
|
end
|
165
160
|
|
data/test/admin_test.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
+
# Admin-related tests
|
3
4
|
class AdminTest < Fastly::TestCase
|
4
5
|
def setup
|
5
|
-
opts = login_opts(:full)
|
6
|
+
opts = login_opts(:full)
|
6
7
|
begin
|
7
8
|
@client = Fastly::Client.new(opts)
|
8
9
|
@fastly = Fastly.new(opts)
|
9
|
-
rescue
|
10
|
+
rescue => e
|
10
11
|
warn e.inspect
|
11
12
|
warn e.backtrace.join("\n")
|
12
13
|
exit(-1)
|
@@ -15,9 +16,9 @@ class AdminTest < Fastly::TestCase
|
|
15
16
|
|
16
17
|
def test_creating_and_updating_customer
|
17
18
|
return unless @fastly.current_user.can_do?(:admin)
|
18
|
-
customer = @fastly.create_customer(:name => "fastly-ruby-test-customer-#{
|
19
|
-
email = "fastly-ruby-test-#{
|
20
|
-
user = @fastly.create_user(:login => email, :name =>
|
19
|
+
customer = @fastly.create_customer(:name => "fastly-ruby-test-customer-#{random_string}")
|
20
|
+
email = "fastly-ruby-test-#{random_string}-new@example.com"
|
21
|
+
user = @fastly.create_user(:login => email, :name => 'New User')
|
21
22
|
customer.owner_id = user.id
|
22
23
|
|
23
24
|
tmp = @fastly.update_customer(customer)
|
@@ -28,10 +29,9 @@ class AdminTest < Fastly::TestCase
|
|
28
29
|
|
29
30
|
def test_creating_and_updating_customer_with_owner
|
30
31
|
return unless @fastly.current_user.can_do?(:admin)
|
31
|
-
email = "fastly-ruby-test-#{
|
32
|
-
customer = @fastly.create_customer(:name => "fastly-ruby-test-customer-#{
|
32
|
+
email = "fastly-ruby-test-#{random_string}-new@example.com"
|
33
|
+
customer = @fastly.create_customer(:name => "fastly-ruby-test-customer-#{random_string}", :owner => { :login => email, :name => 'Test NewOwner' })
|
33
34
|
assert customer
|
34
35
|
assert_equal customer.owner.login, email
|
35
36
|
end
|
36
|
-
|
37
37
|
end
|
data/test/api_key_test.rb
CHANGED
@@ -1,46 +1,27 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
# API Key Tests
|
4
|
+
class Fastly
|
5
|
+
describe 'ApiKeyTest' do
|
6
|
+
let(:opts) { login_opts(:api_key) }
|
7
|
+
let(:client) { Client.new(opts) }
|
8
|
+
let(:fastly) { Fastly.new(opts) }
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
rescue Exception => e
|
12
|
-
pp e
|
13
|
-
exit(-1)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_raw_client
|
18
|
-
user = customer = nil
|
19
|
-
assert_raise(Fastly::Error) {
|
20
|
-
user = @client.get('/current_user')
|
21
|
-
}
|
22
|
-
assert_equal nil, user
|
23
|
-
|
24
|
-
customer = @client.get('/current_customer')
|
25
|
-
assert customer
|
26
|
-
assert_equal @opts[:customer], customer['name']
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_current_user_and_customer
|
30
|
-
current_user = current_customer = nil
|
31
|
-
assert_raise(Fastly::FullAuthRequired) {
|
32
|
-
current_user = @fastly.current_user
|
33
|
-
}
|
34
|
-
assert_equal nil, current_user
|
10
|
+
describe '#current_{user,customer}' do
|
11
|
+
it 'should not have access to current user 'do
|
12
|
+
assert_raises(Error) do
|
13
|
+
client.get('/current_user')
|
14
|
+
end
|
35
15
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
16
|
+
assert_raises(FullAuthRequired) do
|
17
|
+
fastly.current_user
|
18
|
+
end
|
19
|
+
end
|
40
20
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
21
|
+
it 'should have access to current customer' do
|
22
|
+
assert_instance_of Hash, client.get('/current_customer')
|
23
|
+
assert_instance_of Customer, fastly.current_customer
|
24
|
+
end
|
25
|
+
end
|
45
26
|
end
|
46
27
|
end
|