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.
Hashr is a very simple and tiny class which makes using nested hashes for configuration (and other purposes) easier.
It supports the following features:
?
) methodsDirectly use Hashr instances like this:
config = Hashr.new(foo: { bar: 'bar' })
config.foo? # => true
config.foo # => { bar: 'bar' }
config.foo.bar? # => true
config.foo.bar # => 'bar'
config.foo.bar = 'bar'
config.foo.bar # => 'bar'
config.foo.baz = 'baz'
config.foo.baz # => 'baz'
Hash core methods are not available but assume you mean to look up keys with the same name:
config = Hashr.new(count: 1, key: 'key')
config.count # => 1
config.key # => 'key'
In order to check a hash stored on a certain key you can convert it to a Ruby Hash:
config = Hashr.new(count: 1, key: 'key')
config.to_h.count # => 2
config.to_h.key # => raises ArgumentError: "wrong number of arguments (0 for 1)"
Missing keys won't raise an exception but instead behave like Hash access:
config = Hashr.new
config.foo? # => false
config.foo # => nil
Defaults can be defined per class:
class Config < Hashr
default boxes: { memory: '1024' }
end
config = Config.new
config.boxes.memory # => 1024
Or passed to the instance:
data = {}
defaults = { boxes: { memory: '1024' } }
config = Hashr.new(data, defaults)
config.boxes.memory # => 1024
Hashr includes a simple module that makes it easy to overwrite configuration defaults from environment variables:
class Config < Hashr
extend Hashr::Env
self.env_namespace = 'foo'
default boxes: { memory: '1024' }
end
Now when an environment variable is defined then it will overwrite the default:
ENV['FOO_BOXES_MEMORY'] = '2048'
config = Config.new
config.boxes.memory # => '2048'
You also might want to check out OpenStruct and Hashie.
Mash
, Dash
, Trash
) which all support different features that you might need.FAQs
Unknown package
We found that hashr 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.