Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = (app, cookieFile, login) => {
let username, password, accessKey
const hasFile = cookieFile && fs.existsSync(cookieFile)
if (login) { // provided via --login (or LOGIN)
;[ username, password, accessKey ] = login.split(':', 3)
assert(password, `Invalid login format, expecting "username:pwd"`)
} else if (hasFile) {
console.log(`Loading login credentials from ${cookieFile}`)
;[ username, password, accessKey ] = fs.readFileSync(cookieFile).toString('utf-8').trim().split(':')
assert(password, `Invalid login file at ${cookieFile}, expecting "username:pwd[:access-key]"`)
} else { // generate random
username = nanogen('abcdefghijklmnopqrstuvwxyz', 5)
password = nanoid(15)
accessKey = hmacStr(`${username}:${password}`, 'access-key')
console.log(`No LOGIN or --login specified, picked username "${username}" with password "${password}"`)
if (cookieFile) {
console.log(`Writing login credentials to ${cookieFile}`)
!fs.existsSync(path.dirname(cookieFile)) && mkdirp.sync(path.dirname(cookieFile))
fs.writeFileSync(cookieFile, [ username, password, accessKey ].join(':'))
}
}
// HMAC derive the access key from the user/pwd combo, if not explicitly defined
accessKey || (accessKey = hmacStr(`${username}:${password}`, 'access-key'))
const manifestKey = hmacStr(accessKey, 'manifest-key').substr(0, 10)
, manifestRe = new RegExp(`^/manifest-${manifestKey}/`)
Cat extends Category,
Variables extends { [key: string]: string },
Functions extends {
[key: string]: (arg: any) => MaybePromise
},
Dest extends string,
> {
constructor(public config: Config) {
// who the f needs a constructor anyways?
}
public functions = this.config.functions;
public postInstall: (app: this) => any
public readonly id: appName | string = process.env.NODE_ENV === 'test'
? `${this.config.name}-${nanoid('0123456789abcdefghijklmnopqrstuvwxyz', 20)}`
: this.config.name
public category = this.config.category;
public name = this.config.name;
public variables = new VariablesBackend(this.id, this.config.variables)
private appdataToPath() {
// removed linux platform as /opt/appdata requires extra permissions
return join(homedir(), '.getholo', 'dashboard', 'containers', this.id);
}
public paths: Path[] = this.config.paths.map(
path => ({
dest: path.dest,
src: path.src === 'appdata' ? this.appdataToPath() : path.src,
readOnly: path.readOnly,
export const seedNewDialog = (
$type: string,
designerAttributes: Partial = {},
optionalAttributes: object = {}
): object => {
return {
$type,
$designer: {
id: nanoid('1234567890', 6),
...designerAttributes,
},
...(initialDialogShape[$type] || {}),
...optionalAttributes,
};
};
export function readInstallationID() {
if (!mainStore.has("installation-id")) {
mainStore.set("installation-id", generateID("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 8))
}
return mainStore.get("installation-id")
}
export let makeId = () => generate("0123456789abcdef", 10)
export async function makeId(len = 12): Promise {
const id = await nanoid(len);
const result = badIdRegex.exec(id);
if (result && result[0].length) {
const chars = generate('1234567890abcdef', result[0].length);
return id.replace(badIdRegex, chars);
}
return id;
}
const generateId = async () => {
const address = generate(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
Number(process.env.LINK_LENGTH) || 6
);
const link = await findLink({ address });
if (!link) return address;
return generateId();
};
: user.email;
if (!user.progressTimestamps) {
user.progressTimestamps = [];
}
if (user.progressTimestamps.length === 0) {
user.progressTimestamps.push(Date.now());
}
if (!user.externalId) {
user.externalId = uuid();
}
if (!user.unsubscribeId) {
user.unsubscribeId = generate(nanoidCharSet, 20);
}
return;
}
export let makeId = () => generate("0123456789abcdef", 10)
export function genCode(len = 4) {
return generate('1234567890', len);
}