fastly 2.5.3 → 3.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff6374dedf0a4320acb1bb370b700f31dffbb841ad039e717c9b6bd713a6cb5a
4
- data.tar.gz: f53667b8fa95b6e9cf013ec23c94feee19b860c28de60aba3fee4ddd17ffaa4c
3
+ metadata.gz: d0331b2215d245985194128508980192db08a0ae94c0da70c1f3b417a4309df7
4
+ data.tar.gz: d3ab806682ed8e8141a301886fb2bf21b91102f478866dee281b3be2c7480a5c
5
5
  SHA512:
6
- metadata.gz: f3115a7e69149466f180e3d823c13ef9d4a895178a6e33e02522afa1b5551df59da7655dd3c316eba9cb0be0df2494b2b2f4a6803a2ec6b04cb8f4f1b06be11f
7
- data.tar.gz: c7a1a39686da60e1986b24d7ef7d94cdba247e29117a99bed51924e23716da3dc72cc44869e1b711f75745309ff71597c165d2048fb5b43ed38fa6d0d2fc4e88
6
+ metadata.gz: 4e738dcf185c95ff25b675f2795fbdd62154894c1c00098dccd48f39d1dfb854491f8f007b5a1c1bef1c0689aad5392b0b5c3facb22ed0a956b501a7300017c3
7
+ data.tar.gz: f76512046a815ab57aa559abc71f9ab9108246defb81f2c710579f0d11296eb2f422897bb97440aa8a18f9c57b363ae1570db95257e50e9f1ed12736a7a959ac
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # Change Log
2
2
 
3
+ ## [v3.0.0](https://github.com/fastly/fastly-ruby/tree/v3.0.0) (2021-02-03)
4
+
5
+ [Full Changelog](https://github.com/fastly/fastly-ruby/compare/v2.5.3...v3.0.0)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Removes session authentication [\#170](https://github.com/fastly/fastly-ruby/pull/170) ([conniechu929](https://github.com/conniechu929))
10
+
3
11
  ## [v2.5.0](https://github.com/fastly/fastly-ruby/tree/v2.5.0) (2020-01-16)
12
+
4
13
  [Full Changelog](https://github.com/fastly/fastly-ruby/compare/v2.4.0...v2.5.0)
5
14
 
6
15
  **Merged pull requests:**
data/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Client library for interacting with the Fastly web acceleration service [API](http://docs.fastly.com/api)
4
4
 
5
+ ### A Note About Authentication
6
+
7
+ Authenticating with a username/password is deprecated and will no longer be available starting September 2020.
8
+
9
+ Authenticating with an API Token is shown in the example section below. For more information on API Tokens, please see [Fastly's API Token documentation](https://developer.fastly.com/reference/api/auth/). For more information about authenticating to our API, please see our [Authentication section](https://developer.fastly.com/reference/api/#authentication).
10
+
5
11
  ## Examples
6
12
 
7
13
  Add fastly to your Gemfile:
@@ -13,7 +19,8 @@ Create a fastly client:
13
19
 
14
20
  ```ruby
15
21
  # some_file.rb
16
- # use {api_key: 'your-key'} or {user: 'username', password: 'password'} as login options
22
+ # username/password authentication is deprecated and will not be available
23
+ # starting September 2020; use {api_key: 'your-key'} as the login option
17
24
  fastly = Fastly.new(login_opts)
18
25
 
19
26
  current_user = fastly.current_user
data/lib/fastly.rb CHANGED
@@ -55,8 +55,8 @@ class Fastly
55
55
  #
56
56
  # Some methods require full username and password rather than just auth token.
57
57
  def initialize(opts)
58
- if opts[:api_key].nil? && (opts[:password].nil? || opts[:user].nil?)
59
- raise ArgumentError, "Required options missing. Please pass either ':api_key' or both ':user' and ':password'."
58
+ if opts[:api_key].nil?
59
+ raise ArgumentError, "Required option missing. Please pass ':api_key'."
60
60
  end
61
61
 
62
62
  client(opts)
data/lib/fastly/client.rb CHANGED
@@ -11,7 +11,7 @@ class Fastly
11
11
 
12
12
  DEFAULT_URL = 'https://api.fastly.com'.freeze
13
13
 
14
- attr_accessor :api_key, :base_url, :debug, :user, :password, :cookie, :customer
14
+ attr_accessor :api_key, :base_url, :debug, :user, :password, :customer
15
15
 
16
16
  def initialize(opts)
17
17
  @api_key = opts.fetch(:api_key, nil)
@@ -25,22 +25,12 @@ class Fastly
25
25
  Concurrent::ThreadLocalVar.new { build_http_client }
26
26
  end
27
27
 
28
- return self unless fully_authed?
29
-
30
28
  warn("DEPRECATION WARNING: Username/password authentication is deprecated
31
29
  and will not be available starting September 2020;
32
30
  please migrate to API tokens as soon as possible.")
33
-
34
- # If full auth creds (user/pass) then log in and set a cookie
35
- resp = http.post(
36
- '/login',
37
- make_params(user: user, password: password),
38
- {'Content-Type' => 'application/x-www-form-urlencoded'}
39
- )
40
- if resp.kind_of?(Net::HTTPSuccess)
41
- @cookie = resp['Set-Cookie']
42
- else
43
- fail Unauthorized, "Invalid auth credentials. Check username/password."
31
+
32
+ if api_key.nil?
33
+ fail Unauthorized, "Invalid auth credentials. Check api_key."
44
34
  end
45
35
 
46
36
  self
@@ -150,9 +140,7 @@ class Fastly
150
140
 
151
141
  def headers(extras={}, include_auth=true)
152
142
  headers = {}
153
- # Some endpoints (POST /tokens) break if any auth headers including cookies are sent
154
143
  if include_auth
155
- headers['Cookie'] = cookie if fully_authed?
156
144
  headers['Fastly-Key'] = api_key if api_key
157
145
  end
158
146
  headers.merge('Content-Accept' => 'application/json', 'User-Agent' => "fastly-ruby-v#{Fastly::VERSION}").merge(extras.keep_if {|k,v| !v.nil? })
@@ -1,4 +1,4 @@
1
1
  # The current version of the library
2
2
  class Fastly
3
- VERSION = "2.5.3"
3
+ VERSION = "3.0.0"
4
4
  end
data/lib/fastly/token.rb CHANGED
@@ -21,12 +21,16 @@ class Fastly
21
21
  end
22
22
 
23
23
  def new_token(opts)
24
- opts[:username] = client.user
25
- opts[:password] = client.password
26
- opts[:include_auth] = false
27
-
28
- token = create(Token, opts)
29
- token.nil? ? nil : token
24
+ if client.fully_authed?
25
+ opts[:username] = client.user
26
+ opts[:password] = client.password
27
+ opts[:include_auth] = false
28
+
29
+ token = create(Token, opts)
30
+ token.nil? ? nil : token
31
+ else
32
+ raise ArgumentError, "Required options missing. Please pass :api_key, :user and :password."
33
+ end
30
34
  end
31
35
 
32
36
  def customer_tokens(opts)
data/test/api_key_test.rb CHANGED
@@ -50,7 +50,7 @@ class Fastly
50
50
  end
51
51
  end
52
52
 
53
- describe 'with cookie and api key' do
53
+ describe 'with username/password and api key' do
54
54
  before do
55
55
  @opts = login_opts(:both)
56
56
  @client = Fastly::Client.new(@opts)
@@ -75,26 +75,6 @@ class Fastly
75
75
  assert_equal 'ok', response['status']
76
76
  end
77
77
  end
78
-
79
- describe 'with cookie only' do
80
- before do
81
- @opts = login_opts(:full)
82
- @client = Fastly::Client.new(@opts)
83
- @fastly = Fastly.new(@opts)
84
- service_name = "fastly-test-service-#{random_string}"
85
- @service = @fastly.create_service(:name => service_name)
86
- end
87
-
88
- after do
89
- @fastly.delete_service(@service)
90
- end
91
-
92
- it 'does not allow purging' do
93
- assert_raises Fastly::KeyAuthRequired do
94
- @service.purge_by_key('somekey')
95
- end
96
- end
97
- end
98
78
  end
99
79
  end
100
80
  end
@@ -20,20 +20,17 @@ describe Fastly::Client do
20
20
  assert_equal nil, client.password
21
21
  end
22
22
 
23
+ it 'raises Unauthorized if api_key is not passed in the options' do
24
+ assert_raises(Fastly::Unauthorized) { Fastly::Client.new(user: user, password: password)}
25
+ end
26
+
23
27
  it 'raises Unauthorized if user/pass provided but are invalid' do
24
28
  stub_request(:any, /api.fastly.com/).to_return(status: 400)
25
29
 
26
30
  e = assert_raises(Fastly::Unauthorized) {
27
- Fastly::Client.new(user: user, password: pass)
31
+ Fastly::Client.new(user: user, password: password)
28
32
  }
29
- assert_equal "Invalid auth credentials. Check username/password.", e.message
30
- end
31
-
32
- it 'surfaces a deprecation message when a username or password is provided' do
33
- stub_request(:any, /api.fastly.com/).
34
- to_return(body: JSON.generate(i: "dont care"), status: 200)
35
-
36
- assert_output('', /DEPRECATION WARNING:/) { Fastly::Client.new(user: user, password: pass) }
33
+ assert_equal "Invalid auth credentials. Check api_key.", e.message
37
34
  end
38
35
 
39
36
  it 'initializes an http client' do
@@ -45,23 +42,13 @@ describe Fastly::Client do
45
42
  assert client.http.use_ssl?
46
43
  end
47
44
 
48
- it 'sets a cookie when auth with valid user/pass' do
49
- stub_request(:any, /api.fastly.com/).
50
- to_return(body: JSON.generate(i: "dont care"), status: 200, headers: { 'Set-Cookie' => 'tasty!' })
51
-
52
- client = Fastly::Client.new(user: user, password: pass)
53
- assert_equal "tasty!", client.cookie
54
- end
55
-
56
45
  it 'raises an Error if username is used in place of user as an option' do
57
46
  stub_request(:any, /api.fastly.com/).
58
- to_return(body: JSON.generate(i: "dont care"), status: 200, headers: { 'Set-Cookie' => 'tasty!' })
47
+ to_return(body: JSON.generate(i: "dont care"), status: 200)
59
48
 
60
- assert_raises(ArgumentError) { Fastly.new(username: user, password: pass) }
49
+ assert_raises(ArgumentError) { Fastly.new(username: user, password: password) }
61
50
 
62
- Fastly.new(user: user, password: pass)
63
- Fastly.new(api_key: api_key)
64
- Fastly.new(api_key: api_key, user: user, password: pass)
51
+ Fastly.new(api_key: api_key, user: user, password: password)
65
52
  end
66
53
  end
67
54
 
@@ -7,7 +7,7 @@ describe Fastly::Customer do
7
7
  let(:owner_id) { SecureRandom.hex(6) }
8
8
 
9
9
  let(:customer) do
10
- stub_request(:post, "#{Fastly::Client::DEFAULT_URL}/login").to_return(body: '{}', status: 200, headers: { 'Set-Cookie' => 'tasty!' })
10
+ stub_request(:post, "#{Fastly::Client::DEFAULT_URL}/login").to_return(body: '{}', status: 200)
11
11
 
12
12
  customer_body = JSON.dump(
13
13
  'id' => customer_id,
@@ -2,13 +2,13 @@ require_relative '../test_helper'
2
2
 
3
3
  describe Fastly::Dictionary do
4
4
 
5
- let(:client) { Fastly.new(user: 'test@example.com', password: 'password') }
5
+ let(:client) { Fastly.new(api_key: 'notasecrettestkey') }
6
6
  let(:service_id) { SecureRandom.hex(6) }
7
7
  let(:version) { 1 }
8
8
  let(:dictionary) { Fastly::Dictionary.new({id: SecureRandom.hex(6), service_id: service_id, version: 1}, client) }
9
9
 
10
10
  before {
11
- stub_request(:post, "#{Fastly::Client::DEFAULT_URL}/login").to_return(body: '{}', status: 200, headers: { 'Set-Cookie' => 'tasty!' })
11
+ stub_request(:post, "#{Fastly::Client::DEFAULT_URL}/login").to_return(body: '{}', status: 200)
12
12
  }
13
13
 
14
14
  describe '#item' do
@@ -2,13 +2,13 @@ require_relative '../test_helper'
2
2
 
3
3
  describe Fastly::Syslog do
4
4
 
5
- let(:client) { Fastly.new(user: 'test@example.com', password: 'password') }
5
+ let(:client) { Fastly.new(api_key: 'notasecrettestkey', user: 'test@example.com', password: 'password') }
6
6
  let(:service_id) { SecureRandom.hex(6) }
7
7
  let(:version) { 1 }
8
8
  let(:syslog) { Fastly::Syslog.new({ name: 'test_syslog', service_id: service_id, version: 1 }, client) }
9
9
 
10
10
  before {
11
- stub_request(:post, "#{Fastly::Client::DEFAULT_URL}/login").to_return(body: '{}', status: 200, headers: { 'Set-Cookie' => 'tasty!' })
11
+ stub_request(:post, "#{Fastly::Client::DEFAULT_URL}/login").to_return(body: '{}', status: 200)
12
12
  }
13
13
 
14
14
  describe '#item' do
@@ -1,17 +1,14 @@
1
1
  require_relative '../test_helper'
2
2
 
3
3
  describe Fastly::Token do
4
-
5
- let(:elevated_fastly) { Fastly.new(user: 'test@example.com', password: 'password') }
6
- let(:fastly) { Fastly.new(api_key:'my_api_key') }
4
+ let(:fastly) { Fastly.new(api_key:'my_api_key', user: 'test@example.com', password: 'password') }
7
5
 
8
6
  before {
9
- stub_request(:post, "#{Fastly::Client::DEFAULT_URL}/login").to_return(body: '{}', status: 200, headers: { 'Set-Cookie' => 'tasty!' })
7
+ stub_request(:post, "#{Fastly::Client::DEFAULT_URL}/login").to_return(body: '{}', status: 200)
10
8
  }
11
9
 
12
10
  describe '#fastly' do
13
-
14
- it 'cannot create itself because POST /tokens must have no auth headers)' do
11
+ it 'cannot create itself because POST /tokens must have no auth headers' do
15
12
  stub_request(:post, "https://api.fastly.com/tokens").
16
13
  with(
17
14
  body: {"name"=>"name_of_token", "scope"=>"token_scope such_as purge_all purge_select", "services"=>"service_id_that_token_can_access"},
@@ -20,13 +17,12 @@ describe Fastly::Token do
20
17
  'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
21
18
  'Content-Accept'=>'application/json',
22
19
  'Content-Type'=>'application/x-www-form-urlencoded',
23
- 'Cookie'=>'tasty!',
24
20
  'User-Agent'=> /fastly-ruby/
25
21
  }).
26
22
  to_return(status: 403, body: '{"msg":"You must POST /sudo to access this endpoint"}', headers: {})
27
23
 
28
24
  assert_raises(Fastly::Error,'{"msg":"You must POST /sudo to access this endpoint"}') do
29
- elevated_fastly.create_token(
25
+ fastly.create_token(
30
26
  name: 'name_of_token',
31
27
  services: 'service_id_that_token_can_access',
32
28
  scope: 'token_scope such_as purge_all purge_select'
@@ -63,7 +59,7 @@ describe Fastly::Token do
63
59
  }).
64
60
  to_return(status: 200, body: response_body, headers: {})
65
61
 
66
- token = elevated_fastly.new_token(
62
+ token = fastly.new_token(
67
63
  name: 'name_of_token',
68
64
  services: 'service_id_that_token_can_access',
69
65
  scope: 'optional token_scope such_as purge_all purge_select'
@@ -3,7 +3,7 @@ require 'helper'
3
3
  # Test username/password login access to user and customer objects
4
4
  class Fastly
5
5
  describe 'FullLoginTest' do
6
- let(:opts) { login_opts(:full) }
6
+ let(:opts) { login_opts(:both) }
7
7
  let(:client) { Client.new(opts) }
8
8
  let(:fastly) { Fastly.new(opts) }
9
9
  let(:current_user) { fastly.current_user }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastly
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.3
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fastly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-09 00:00:00.000000000 Z
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Client library for the Fastly acceleration system
14
14
  email:
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  requirements: []
113
- rubygems_version: 3.0.6
113
+ rubygems_version: 3.0.1
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: Client library for the Fastly acceleration system