![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
ssh-config
Advanced tools
const SSHConfig = require('ssh-config')
const config = SSHConfig.parse(`
IdentityFile ~/.ssh/id_rsa
Host tahoe
HostName tahoe.com
Host walden
HostName waldenlake.org
Host *
User keanu
ForwardAgent true
`)
expect(config).to.sql(
[ { "param": "IdentityFile",
"value": "~/.ssh/id_rsa" },
{ "param": "Host",
"value": "tahoe",
"config":
[ { "param": "HostName",
"value": "tahoe.com" } ] },
{ "param": "Host",
"value": "walden",
"config":
[ { "param": "HostName",
"value": "waldenlake.org" } ] },
{ "param": "Host",
"value": "*",
"config":
[ { "param": "User",
"value": "keanu" },
{ "param": "ForwardAgent",
"value": "true" } ] } ]
)
// Change the HostName in the Host walden section
const section = config.find({ Host: 'walden' })
for (const line of section.config) {
if (line.param === 'HostName') {
line.value = 'waldenlake.org'
break
}
}
// The original whitespaces and comments are preserved.
console.log(SSHConfig.stringify(config))
One needs to iterate over ssh configs mostly because of two reasons.
.find
the corresponding section and modify it, or.compute
the ssh config about certain Host
..compute
Parameters by HostYou can use config.compute
method to compute applied parameters of certain host.
expect(config.compute('walden')).to.eql({
IdentityFile: [
'~/.ssh/id_rsa'
],
Host: 'walden',
HostName: 'waldenlake.org',
User: 'nil',
ForwardAgent: 'true'
})
NOTICE According to ssh_config(5), the first obtained parameter value will be used. So we cannot override existing parameters. It is suggested that the general settings shall be at the end of your config file.
The IdentityFile
parameter always contain an array to make possible multiple
IdentityFile
settings to be able to coexist.
.find
sections by Host or MatchNOTICE: This method is provided to find the corresponding section in the
parsed config for config manipulation. It is NOT intended to compute config
of certain Host. For latter case, use .compute(host)
instead.
To ditch boilerplate codes like the for loop shown earlier, we can use the
.find(opts)
available in the parsed config object.
config.find({ Host: 'example1' })
Or you can just brew it yourself:
config.filter(line => line.param == 'Host' && line.value == 'example1')[0]
.remove
sections by Host or other criteriaTo remove sections, we can pass the section to .remove(opts)
.
const config = SSHConfig.parse(/* ssh config text */)
config.remove({ Host: 'example1' })
.append
sectionsSince the parsed config is a sub class if Array, you can append new sections with methods like .push
or .concat
.
config.push(SSHConfig.parse(`
Host ness
HostName lochness.com
User dinosaur
`))
expect(config.find({ Host: '*' })).to.eql(
{ "param": "Host",
"value": "ness",
"config":
[ { "param": "HostName",
"value": "lochness.com" } ] }
)
If the section to append is vanilla JSON, .append
is what you need.
const config = new SSHConfig()
config.append({
Host: 'ness',
HostName: 'lochness.com',
User: 'dinosaur'
})
SSHConfig.stringify(config)
// =>
// Host ness
// HostName lochness.com
// User dinosaur
FAQs
SSH config parser and stringifier
We found that ssh-config demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.