This repository was archived by the owner on Jan 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Refactor base env names and specs #66
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
15accdc
Add helper methods for mapping account stores and enabling email veri…
cilim bb1b781
Remove all uses of the base env variables in code
cilim 97eff55
Merge branch 'master' into mc-base-env-var-names
cilim 508cbf1
Enable spec for verifying account and autologin
cilim 033ba53
Fix email verification specs
cilim 8d77646
Set new application url in .travis
cilim 6c3a8de
Merge branch 'master' into mc-base-env-var-names
cilim 3c8c86b
Finish refactoring base env names
cilim a08827d
Use factories for directory creation in specs
cilim 8eb508d
Merge branch 'master' into mc-base-env-var-names
cilim 4dcd048
Use attributes from FactoryGirl while creating directories with verif…
cilim 200cc58
Refactor client.rb and checking environment variable names
cilim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
module Stormpath | ||
module Rails | ||
class ApiKey | ||
TEST_ENV_VARS = { | ||
required: { | ||
STORMPATH_CLIENT_APIKEY_ID: 'The id from your Stormpath API Key', | ||
STORMPATH_CLIENT_APIKEY_SECRET: 'The secret from your Stormpath API Key', | ||
STORMPATH_APPLICATION_HREF: 'The href to your application' | ||
}, | ||
deprecated: { | ||
STORMPATH_API_KEY_ID: 'The id from your Stormpath API Key', | ||
STORMPATH_API_KEY_SECRET: 'The secret from your Stormpath API Key', | ||
STORMPATH_APPLICATION_URL: 'The url to your application' | ||
} | ||
}.freeze | ||
|
||
def credentials | ||
check_env_variable_names | ||
credentials_from_env_variables | ||
end | ||
|
||
private | ||
|
||
def check_env_variable_names | ||
unless test_missing_required_env_vars.empty? | ||
show_deprecation_warning unless env_vars_not_set? | ||
end | ||
|
||
raise set_up_message if env_vars_not_set? | ||
end | ||
|
||
def credentials_from_env_variables | ||
{ | ||
id: ENV['STORMPATH_CLIENT_APIKEY_ID'] || ENV['STORMPATH_API_KEY_ID'], | ||
secret: ENV['STORMPATH_CLIENT_APIKEY_SECRET'] || ENV['STORMPATH_API_KEY_SECRET'] | ||
} | ||
end | ||
|
||
def test_missing_deprecated_env_vars | ||
TEST_ENV_VARS[:deprecated].reject do |var, _| | ||
ENV[var.to_s] | ||
end | ||
end | ||
|
||
def test_missing_required_env_vars | ||
TEST_ENV_VARS[:required].reject do |var, _| | ||
ENV[var.to_s] | ||
end | ||
end | ||
|
||
def env_vars_not_set? | ||
!test_missing_deprecated_env_vars.empty? && !test_missing_required_env_vars.empty? | ||
end | ||
|
||
def show_deprecation_warning | ||
warn deprecation_warning | ||
end | ||
|
||
def deprecation_warning | ||
warn_message = "\n\n" | ||
40.times { warn_message << '*' } | ||
warn_message << 'STORMPATH RAILS' | ||
52.times { warn_message << '*' } | ||
warn_message << "\n\n" | ||
warn_message << TEST_ENV_VARS[:deprecated].map do |var, _| | ||
"\t#{var} is deprecated since the new version of the gem." | ||
end.join("\n") | ||
warn_message << "\n\tPlease update your environment variables to use the new names:\n" | ||
warn_message << "\n\t\texport STORMPATH_CLIENT_APIKEY_ID=your_api_key_id" | ||
warn_message << "\n\t\texport STORMPATH_CLIENT_APIKEY_SECRET=your_api_key_secret" | ||
warn_message << "\n\t\texport STORMPATH_APPLICATION_HREF=href_to_application\n\n" | ||
110.times { warn_message << '*' } | ||
warn_message << "\n\n" | ||
warn_message | ||
end | ||
|
||
def set_up_message | ||
set_up_message = "In order to use the stormpath-rails gem you need to set the following environment variables:\n\t" | ||
set_up_message << test_missing_required_env_vars.map do |var, message| | ||
"#{var} : #{message}" | ||
end.join("\n\t") | ||
set_up_message << "\nBe sure to configure these before trying to run your application.\n\n" | ||
set_up_message | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module Stormpath | ||
module Rails | ||
module EnvNamesWarning | ||
TEST_ENV_VARS = { | ||
required: { | ||
STORMPATH_CLIENT_APIKEY_ID: 'The id from your Stormpath API Key', | ||
STORMPATH_CLIENT_APIKEY_SECRET: 'The secret from your Stormpath API Key', | ||
STORMPATH_APPLICATION_HREF: 'The href to your application' | ||
}, | ||
deprecated: { | ||
STORMPATH_API_KEY_ID: 'The id from your Stormpath API Key', | ||
STORMPATH_API_KEY_SECRET: 'The secret from your Stormpath API Key', | ||
STORMPATH_APPLICATION_URL: 'The url to your application' | ||
} | ||
}.freeze | ||
|
||
def self.test_missing_deprecated_env_vars | ||
TEST_ENV_VARS[:deprecated].reject do |var, _| | ||
ENV[var.to_s] | ||
end | ||
end | ||
|
||
def self.test_missing_required_env_vars | ||
TEST_ENV_VARS[:required].reject do |var, _| | ||
ENV[var.to_s] | ||
end | ||
end | ||
|
||
def self.env_vars_not_set? | ||
!test_missing_deprecated_env_vars.empty? && !test_missing_required_env_vars.empty? | ||
end | ||
|
||
def self.check_env_variable_names | ||
unless Stormpath::Rails::EnvNamesWarning.test_missing_required_env_vars.empty? | ||
warn_message = "\n\n" | ||
40.times { warn_message << '*' } | ||
warn_message << 'STORMPATH RAILS' | ||
52.times { warn_message << '*' } | ||
warn_message << "\n\n" | ||
warn_message << TEST_ENV_VARS[:deprecated].map do |var, _| | ||
"\t#{var} is deprecated since the new version of the gem." | ||
end.join("\n") | ||
warn_message << "\n\tPlease update your environment variables to use the new names:\n" | ||
warn_message << "\n\t\texport STORMPATH_CLIENT_APIKEY_ID=your_api_key_id" | ||
warn_message << "\n\t\texport STORMPATH_CLIENT_APIKEY_SECRET=your_api_key_secret" | ||
warn_message << "\n\t\texport STORMPATH_APPLICATION_HREF=href_to_application\n\n" | ||
110.times { warn_message << '*' } | ||
warn "#{warn_message}\n\n" unless Stormpath::Rails::EnvNamesWarning.env_vars_not_set? | ||
end | ||
|
||
if Stormpath::Rails::EnvNamesWarning.env_vars_not_set? | ||
set_up_message = "In order to use the stormpath-rails gem you need to set the following environment variables:\n\t" | ||
set_up_message << Stormpath::Rails::EnvNamesWarning.test_missing_required_env_vars.map do |var, message| | ||
"#{var} : #{message}" | ||
end.join("\n\t") | ||
set_up_message << "\nBe sure to configure these before trying to run your application.\n\n" | ||
raise set_up_message | ||
end | ||
end | ||
end | ||
end | ||
end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.