mirror of
https://github.com/chenasraf/snpr.git
synced 2026-05-18 01:39:01 +00:00
Move configuration into environment
This commit is contained in:
14
.env.example
Normal file
14
.env.example
Normal file
@@ -0,0 +1,14 @@
|
||||
export SECRET_KEY_BASE=foo
|
||||
export SECRET_TOKEN=bar
|
||||
export RAILS_ENV=development
|
||||
export POSTGRES_URL="postgres://localhost/snpr_$RAILS_ENV"
|
||||
#export REDIS_URL=
|
||||
export FITBIT_CONSUMER_KEY=foo
|
||||
export FITBIT_CONSUMER_SECRET=bar
|
||||
export PLOS_API_KEY=foo
|
||||
export RECAPTCHA_PRIVATE_KEY=foo
|
||||
export RECAPTCHA_PUBLIC_KEY=bar
|
||||
export SIDEKIQ_PASSWORD=foo
|
||||
export MENDELEY_CONSUMER_KEY=foo
|
||||
export ERRBIT_API_KEY=foo
|
||||
export ERRBIT_HOST=localhost
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -31,3 +31,4 @@ tmp/pids/server.pid
|
||||
vendor/bundle
|
||||
vendor/cache
|
||||
logfile
|
||||
.env
|
||||
|
||||
13
.travis.yml
13
.travis.yml
@@ -1,11 +1,11 @@
|
||||
language: ruby # Defaults to ruby, but travis-ci recommends making this explicit.
|
||||
language: ruby
|
||||
sudo: false
|
||||
cache: bundler
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libhiredis-dev
|
||||
postgresql: "9.2"
|
||||
postgresql: '9.3'
|
||||
services:
|
||||
- redis-server
|
||||
rvm:
|
||||
@@ -14,11 +14,6 @@ env: DB=postgres CI=1
|
||||
bundler_args: --without development debug
|
||||
before_script:
|
||||
- cp config/database.yml.ci config/database.yml
|
||||
- cp config/app_config.yml.example config/app_config.yml
|
||||
- echo "foo" > mail_username.txt
|
||||
- echo "bar" > mail_password.txt
|
||||
- echo "secret-token" > secret_token
|
||||
- echo "secret-key-base" > secret_key_base
|
||||
- psql -c 'create database snpr_test;' -U postgres
|
||||
- cp .env.example .env
|
||||
- bundle exec rake db:setup
|
||||
script: "bundle exec rake test"
|
||||
script: bundle exec rake
|
||||
|
||||
2
Gemfile
2
Gemfile
@@ -1,5 +1,7 @@
|
||||
source 'http://rubygems.org'
|
||||
|
||||
gem 'dotenv-rails', groups: %i(development test)
|
||||
|
||||
gem 'rails', '~> 4.2.0'
|
||||
gem 'authlogic' # lots of user-related magic
|
||||
gem 'i18n', '>= 0.6.6'
|
||||
|
||||
@@ -106,6 +106,10 @@ GEM
|
||||
docile (1.1.5)
|
||||
domain_name (0.5.24)
|
||||
unf (>= 0.0.5, < 1.0.0)
|
||||
dotenv (2.0.2)
|
||||
dotenv-rails (2.0.2)
|
||||
dotenv (= 2.0.2)
|
||||
railties (~> 4.0)
|
||||
dynamic_form (1.1.4)
|
||||
erubis (2.7.0)
|
||||
execjs (2.6.0)
|
||||
@@ -375,6 +379,7 @@ DEPENDENCIES
|
||||
capybara
|
||||
composite_primary_keys (~> 8.0)
|
||||
database_cleaner
|
||||
dotenv-rails
|
||||
dynamic_form
|
||||
execjs
|
||||
factory_girl_rails
|
||||
@@ -426,3 +431,6 @@ DEPENDENCIES
|
||||
whenever
|
||||
will_paginate
|
||||
yui-compressor
|
||||
|
||||
BUNDLED WITH
|
||||
1.10.6
|
||||
|
||||
@@ -38,13 +38,7 @@ rake db:seed OR rake db:setup (which also sets up the entire db)
|
||||
# edit database.yml to point to your postgresql database
|
||||
cp config/database.yml.example config/database.yml
|
||||
|
||||
cp config/app_config.yml.example config/app_config.yml
|
||||
```
|
||||
|
||||
## Generate Secret Token
|
||||
|
||||
```
|
||||
bundle rake secret > secret_token
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
## Initialize Database
|
||||
@@ -58,6 +52,7 @@ bundle exec rake db:setup
|
||||
```
|
||||
bundle exec rake
|
||||
```
|
||||
This runs RSpec tests as well as the **legacy** test/unit ones.
|
||||
|
||||
# Usage
|
||||
|
||||
|
||||
3
Rakefile
3
Rakefile
@@ -6,4 +6,5 @@ require 'rake'
|
||||
|
||||
Snpr::Application.load_tasks
|
||||
|
||||
task :test => :spec
|
||||
task test: :spec
|
||||
task default: :test
|
||||
|
||||
@@ -162,7 +162,8 @@ class FitbitProfilesController < ApplicationController
|
||||
print @user
|
||||
@fitbit_profile = @user.fitbit_profile
|
||||
print @fitbit_profile
|
||||
client = Fitgem::Client.new({:consumer_key => APP_CONFIG[:fitbit_consumer_key], :consumer_secret => APP_CONFIG[:fitbit_consumer_secret]})
|
||||
client = Fitgem::Client.new(consumer_key: ENV.fetch('FITBIT_CONSUMER_KEY'),
|
||||
consumer_secret: ENV.fetch('FITBIT_CONSUMER_SECRET'))
|
||||
request_token = client.request_token
|
||||
@fitbit_profile.request_token = request_token.token
|
||||
@fitbit_profile.request_secret = request_token.secret
|
||||
@@ -174,7 +175,8 @@ class FitbitProfilesController < ApplicationController
|
||||
@user = current_user
|
||||
@fitbit_profile = @user.fitbit_profile
|
||||
if params[:oauth_token] && params[:oauth_verifier]
|
||||
@client = Fitgem::Client.new(:consumer_key => APP_CONFIG[:fitbit_consumer_key], :consumer_secret => APP_CONFIG[:fitbit_consumer_secret])
|
||||
@client = Fitgem::Client.new(consumer_key: ENV.fetch('FITBIT_CONSUMER_KEY'),
|
||||
consumer_secret: ENV.fetch('FITBIT_CONSUMER_SECRET'))
|
||||
token = params[:oauth_token]
|
||||
secret = @fitbit_profile.request_secret
|
||||
verifier = params[:oauth_verifier]
|
||||
|
||||
@@ -6,7 +6,8 @@ class FitbitEdit
|
||||
|
||||
def perform(fitbit_profile_id)
|
||||
@fitbit_profile = FitbitProfile.find_by_id(fitbit_profile_id)
|
||||
@client = Fitgem::Client.new(:consumer_key => APP_CONFIG[:fitbit_consumer_key], :consumer_secret => APP_CONFIG[:fitbit_consumer_secret])
|
||||
@client = Fitgem::Client.new(consumer_key: ENV.fetch('FITBIT_CONSUMER_KEY'),
|
||||
consumer_secret: ENV.fetch('FITBIT_CONSUMER_SECRET'))
|
||||
@client.reconnect(@fitbit_profile.access_token, @fitbit_profile.access_secret)
|
||||
@return_value = @client.create_subscription({:type => :all, :subscription_id => @fitbit_profile.id})
|
||||
puts "subscription returned: "+ @return_value[0]
|
||||
|
||||
@@ -6,7 +6,8 @@ class FitbitEndSubscription
|
||||
|
||||
def perform(fitbit_profile_id)
|
||||
@fitbit_profile = FitbitProfile.find_by_id(fitbit_profile_id)
|
||||
@client = Fitgem::Client.new(:consumer_key => APP_CONFIG[:fitbit_consumer_key], :consumer_secret => APP_CONFIG[:fitbit_consumer_secret])
|
||||
@client = Fitgem::Client.new(consumer_key: ENV.fetch('FITBIT_CONSUMER_KEY'),
|
||||
consumer_secret: ENV.fetch('FITBIT_CONSUMER_SECRET'))
|
||||
@client.reconnect(@fitbit_profile.access_token, @fitbit_profile.access_secret)
|
||||
@client.remove_subscription({:type => :all, :subscriber_id => "general", :subscription_id => @fitbit_profile.id})
|
||||
@fitbit_profile.destroy()
|
||||
|
||||
@@ -5,7 +5,8 @@ class FitbitInit
|
||||
sidekiq_options :queue => :fitbit, :retry => 5, :unique => true
|
||||
|
||||
def perform(fitbit_profile_id)
|
||||
@client = Fitgem::Client.new(:consumer_key => APP_CONFIG[:fitbit_consumer_key], :consumer_secret => APP_CONFIG[:fitbit_consumer_secret])
|
||||
@client = Fitgem::Client.new(consumer_key: ENV.fetch('FITBIT_CONSUMER_KEY'),
|
||||
consumer_secret: ENV.fetch('FITBIT_CONSUMER_SECRET'))
|
||||
fitbit_profile = FitbitProfile.find_by_id(fitbit_profile_id)
|
||||
@client.reconnect(fitbit_profile.access_token, fitbit_profile.access_secret)
|
||||
fitbit_id = @client.user_info["user"]["encodedId"]
|
||||
|
||||
@@ -9,7 +9,8 @@ class FitbitNotification
|
||||
notification.each do |n|
|
||||
@fitbit_profile = FitbitProfile.find_by_id(n["subscriptionId"])
|
||||
if @fitbit_profile != nil
|
||||
@client = Fitgem::Client.new(:consumer_key => APP_CONFIG[:fitbit_consumer_key], :consumer_secret => APP_CONFIG[:fitbit_consumer_secret])
|
||||
@client = Fitgem::Client.new(consumer_key: ENV.fetch('FITBIT_CONSUMER_KEY'),
|
||||
consumer_secret: ENV.fetch('FITBIT_CONSUMER_SECRET'))
|
||||
@client.reconnect(@fitbit_profile.access_token, @fitbit_profile.access_secret)
|
||||
puts n
|
||||
puts n["collectionType"]
|
||||
|
||||
@@ -84,7 +84,6 @@ class PlosSearch
|
||||
end
|
||||
|
||||
def self.api_key
|
||||
# TODO: put in APP_CONFIG
|
||||
File.read(Rails.root.join("key_plos.txt")).strip
|
||||
ENV.fetch('PLOS_API_KEY')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
default: &default
|
||||
fitbit_consumer_key:
|
||||
fitbit_consumer_secret:
|
||||
mendeley:
|
||||
consumer_key:
|
||||
recaptcha:
|
||||
public_key: foo
|
||||
private_key: bar
|
||||
sidekiq:
|
||||
user: admin
|
||||
password: password
|
||||
devise: password
|
||||
errbit:
|
||||
api_key: gobbledigook
|
||||
host: url
|
||||
|
||||
production:
|
||||
<<: *default
|
||||
|
||||
development:
|
||||
<<: *default
|
||||
|
||||
test:
|
||||
<<: *default
|
||||
|
||||
@@ -2,11 +2,7 @@ require File.expand_path('../boot', __FILE__)
|
||||
|
||||
require 'rails/all'
|
||||
|
||||
if defined?(Bundler)
|
||||
# Require the gems listed in Gemfile, including any gems
|
||||
# you've limited to :test, :development, or :production.
|
||||
Bundler.require(*Rails.groups)
|
||||
end
|
||||
Bundler.require(*Rails.groups)
|
||||
|
||||
module Snpr
|
||||
class Application < Rails::Application
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
raw_config = File.read("#{Rails.root}/config/app_config.yml")
|
||||
APP_CONFIG = YAML.load(raw_config)[Rails.env].symbolize_keys
|
||||
@@ -1,7 +1,7 @@
|
||||
# This is the config to talk to opensnperr.herokuapp.com
|
||||
Airbrake.configure do |config|
|
||||
config.api_key = APP_CONFIG[:errbit]['api_key']
|
||||
config.host = APP_CONFIG[:errbit]['host']
|
||||
config.api_key = ENV.fetch('ERRBIT_API_KEY')
|
||||
config.host = ENV.fetch('ERRBIT_HOST')
|
||||
config.port = 80
|
||||
config.secure = config.port == 443
|
||||
config.environment_name = Rails.env.production? ? `hostname` : Rails.env
|
||||
|
||||
@@ -1 +1 @@
|
||||
Mendeley.consumer_key = APP_CONFIG[:mendeley]['consumer_key']
|
||||
Mendeley.consumer_key = ENV.fetch('MENDELEY_CONSUMER_KEY')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Recaptcha.configure do |config|
|
||||
config.public_key = APP_CONFIG[:recaptcha]['public_key']
|
||||
config.private_key = APP_CONFIG[:recaptcha]['private_key']
|
||||
config.public_key = ENV.fetch('RECAPTCHA_PUBLIC_KEY')
|
||||
config.private_key = ENV.fetch('RECAPTCHA_PRIVATE_KEY')
|
||||
end
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
# TODO: Move to environment variables
|
||||
begin
|
||||
Snpr::Application.configure do
|
||||
config.secret_token = File.read(Rails.root.join('secret_token'))
|
||||
config.secret_key_base = File.read(Rails.root.join('secret_key_base'))
|
||||
end
|
||||
rescue LoadError, Errno::ENOENT => e
|
||||
raise "Secret token couldn't be loaded! Error: #{e}"
|
||||
Snpr::Application.configure do
|
||||
config.secret_token = ENV.fetch('SECRET_TOKEN')
|
||||
config.secret_key_base = ENV.fetch('SECRET_KEY_BASE')
|
||||
end
|
||||
|
||||
@@ -3,8 +3,6 @@ require 'sidekiq/web'
|
||||
require 'sidekiq/limit_fetch'
|
||||
|
||||
|
||||
Sidekiq::Web.use(Rack::Auth::Basic) do |user, password|
|
||||
u = (APP_CONFIG[:sidekiq].try(:[], "user") || "admin")
|
||||
p = (APP_CONFIG[:sidekiq].try(:[], "password") || "password")
|
||||
[user, password] == [u, p]
|
||||
Sidekiq::Web.use(Rack::Auth::Basic) do |_user, password|
|
||||
password == ENV.fetch('SIDEKIQ_PASSWORD')
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user