Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Skey purge authentication #29

Merged
merged 3 commits into from
Oct 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastly-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |s|
s.test_files = Dir["test/**/*"]

s.add_dependency "rails"
s.add_dependency 'fastly', '~> 1.1.2'
s.add_dependency 'fastly', '~> 1.1.4'

s.add_development_dependency "sqlite3"
s.add_development_dependency "database_cleaner"
Expand Down
2 changes: 1 addition & 1 deletion lib/fastly-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.service_id
end

def self.client
raise NoAuthCredentialsProvidedError unless configuration.authenticatable?
raise NoAPIKeyProvidedError unless configuration.authenticatable?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will users need to change their applications to follow this change?

I ask because I don't know if we follow semantic versioning for fastly-rails

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. It's possible, probably unlikely though.

As for semantic versioning. Latest version is 0.1.6. We can bump to 1.0.0 or 0.2.0. Do you have a recommendation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantic versioning says we can break all the API we want during the 0.x series, so I have no objection to this change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


@client ||= Client.new(
:api_key => configuration.api_key,
Expand Down
1 change: 1 addition & 0 deletions lib/fastly-rails/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def initialize(opts={})
end

def purge_by_key(key)
client.require_key!
client.post purge_url(key)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fastly-rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize
end

def authenticatable?
!!(api_key || has_credentials?)
!!api_key
end

def invalid_service_id?
Expand Down
2 changes: 1 addition & 1 deletion lib/fastly-rails/errors.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module FastlyRails

class NoAuthCredentialsProvidedError < ArgumentError; end
class NoAPIKeyProvidedError < ArgumentError; end

class NoServiceIdProvidedError < ArgumentError; end
end
9 changes: 4 additions & 5 deletions test/fastly-rails/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
assert_respond_to configuration, :authenticatable?
end

it 'should return false if api_key, user, and password are nil' do
it 'should return false if api_key is nil' do
assert_equal false, configuration.authenticatable?
end

Expand All @@ -53,16 +53,15 @@
end

it 'should return true if only api_key is not nil' do
configuration.api_key = 'key'

configuration.api_key = 'test'
assert_equal true, configuration.authenticatable?
end

it 'should return true if if user and password are not nil' do
it 'should return false if only user and password are not nil' do
configuration.user = 'user'
configuration.password = 'password'

assert_equal true, configuration.authenticatable?
assert_equal false, configuration.authenticatable?
end
end

Expand Down
12 changes: 1 addition & 11 deletions test/fastly-rails_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'test_helper'

describe FastlyRails do

let(:api_key) { 'test' }
let(:user) { nil }
let(:password) { nil }
Expand All @@ -15,16 +14,14 @@
end

describe 'credentials not provided' do

before do
FastlyRails.instance_variable_set('@configuration', FastlyRails::Configuration.new)
end

it 'should raise an error if configuration is not authenticatable' do

assert_equal false, configuration.authenticatable?
assert_equal true, configuration.invalid_service_id?
assert_raises FastlyRails::NoAuthCredentialsProvidedError do
assert_raises FastlyRails::NoAPIKeyProvidedError do
client
end
assert_raises FastlyRails::NoServiceIdProvidedError do
Expand All @@ -34,33 +31,26 @@
end

describe 'credentials provided' do

before do

FastlyRails.configure do |c|
c.api_key = api_key
c.user = user
c.password = password
c.max_age = max_age
c.service_id = service_id
end

end


it 'should have configuration options set up' do

assert_equal api_key, configuration.api_key
assert_equal user, configuration.user
assert_equal password, configuration.password
assert_equal max_age, configuration.max_age
assert_equal service_id, configuration.service_id

end

it 'should return a valid client' do
assert_instance_of FastlyRails::Client, client
end

end
end