Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Turf lets you control the value of variables in different environments and makes it easy to override values locally. It's easy to set speak_in_chat
to true
when RAILS_ENV
equals "production" and false
otherwise. Turf is similar to the Rails secrets.yml
file, but more powerful because it can execute Ruby code and return arrays, hashes, etc.
Turf looks for methods in the following order:
Turf::Local
class.Turf::Test
, Turf::Development
, or Turf::Production
class. Turf uses the development environment by default, but this can be overridden by setting RAILS_ENV
to "production" or "test".Turf::Default
class.I recommend defining the Turf classes in the /config/turf
directory.
ENV["RAILS_ENV"] = "production"
class Turf::Local
def something
"something in local"
end
end
class Turf::Development
def blah
"blah in development"
end
end
class Turf::Production
def something
"something in production"
end
def blah
"blah in production"
end
end
class Turf::Default
def four
2 + 2
end
end
# Turf::Local is the first place Turf looks for a
# matching method
Turf.something # => "something in local"
# The RAILS_ENV is set to production, so Turf looks
# in Turf::Production second if the method is not
# found in Turf::Local
# Turf::Development is ignored in production
Turf.blah # => "blah in production"
# Turf::Default is the last place to look
Turf.four # => 4
# Turf raises an exception when it can't find
# a matching method
Turf.hi_there # => raises an exception
Add this line to your application's Gemfile:
gem 'turf'
Require turf:
require 'turf'
Include the Turf setup rake task in your project's Rakefile
:
load "tasks/setup.rake"
Run the rake task to create the classes in your project:
bundle exec rake turf:setup
Require all the files in the /lib/#{project_name}.rb
file:
require_relative "../config/turf/default.rb"
def require_all(pattern)
Dir.glob("#{Turf.root}/#{pattern}/**/*.rb").sort.each { |path| require path }
end
require_all("config/turf")
RAILS_ENV is used to manage the environment for compatibility with other gems
Set the RAILS_ENV
to "develoment" at the top of the /lib/#{project_name}.rb
file:
ENV['RAILS_ENV'] ||= "development"
Set the RAILS_ENV
to "test" in the spec_helper.rb
file:
ENV['RAILS_ENV'] = 'test'
Set the RAILS_ENV
to production on the remote host.
Require all the Turf
files in the config/application.rb
file:
Dir.glob("#{Rails.root}/config/turf/**/*.rb").each { |path| require path }
That's it!
Application secrets can be stored in Turf::Local
and the file can be gitignored so these secrets are not exposed in source control. Add this line (/config/turf/local.rb
) to your .gitignore
file and scp
the local.rb file to the remote host when changes are made.
Bug reports and pull requests are welcome on GitHub at https://github.com/MrPowers/turf.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that turf demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.