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.
apollo-declare
Advanced tools
ctrip-apollo(the Ctrip's apollo client) with pre-declared configuration keys.
$ npm i apollo-declare
const declare = require('apollo-declare')
const host = 'http://localhost:8070'
const appId = '100004458'
const namespace = 'default'
declare({
host, appId, namespace,
keys: {
// Define `SENTRY_HOST` as
// the value of the configuration key `sentry.host`
REDIS_HOST: 'redis.host'
}
})
// Emits when the value of a config key changes
.on('change', e => {
// Do something with `e`
})
.ready()
.then(client => {
// Get value by key
client.get('REDIS_HOST')
// For each KV pair
client.each((value, key) => {
console.log(value, key)
// output: 192.168.10.1 REDIS_HOST
})
})
declare({
host, appId, namespace,
keys: {
// Equivalent to:
// REDIS_HOST: {
// key: 'redis.host'
// }
REDIS_HOST: 'redis.host',
SENTRY_HOST: {
key: 'sentry.host',
// Which override namespace `default` with `common` for SENTRY_HOST
namespace: 'common'
}
}
})
If we have two namespaces, 'default'
and 'common'
.
In namespace 'default'
, there is no config key named 'dynamodb.region'
. While in namespace 'common'
, the value of 'dynamodb.region'
is 'ap-northeast-10'
.
// Inside a async function
const client = apollo({
host, appId,
namespace: 'default',
keys: {
DYNAMO_DB_HOST: [
// The config key `dynamodb.region` in namespace `default`
// has higher priority than the one in namespace `common`
{
key: 'dynamodb.region'
// namespace: inherit from the default namespace
},
// If `dynamodb.region` is not defined in namespace `default`,
// then common.dynamodb.region will be used
{
key: 'dynamodb.region',
namespace: 'common'
}
]
}
})
await client.ready()
console.log(client.get('DYNAMO_DB_HOST'))
// ap-northeast-10
DeclareOptions
interface DeclareOptions extends ApolloOptions {
// The default cluster name which defaults to `default`
cluster?: string
// The default namespace name which defaults to `application`
namespace?: string
// The key declarations
keys: {
[string]: string // config key
| KeyDeclaration
// Priority list
| Array<string | KeyDeclaration>
}
}
interface KeyDeclaration {
key: string
cluster?: string
namespace?: string
}
ApolloOptions
is the options of ctrip-apollo
Returns ApolloClient
the apollo client. ApolloClient
is a subclass of EventEmitter
Prepare and finish the initial fetching.
All methods except for client.on(type, handler)
should be called after await client.ready()
Get the value of config key
Function(value: string, key: string)
Executes the provided function callback
once for each defined key.
string
config keystring
the new value of the keystring
the old value of the keyEmits when the value of a config key changes
client.on('change', ({
key,
newValue,
oldValue
}) => {
console.log(`key "${key}" changes: "${oldValue}" -> "${newValue}"`)
// Update process.env
process.env[key] = newValue
})
FAQs
The Ctrip's apollo client with pre-declared configuration keys
The npm package apollo-declare receives a total of 114 weekly downloads. As such, apollo-declare popularity was classified as not popular.
We found that apollo-declare 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.