Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const save = function(options, callback) {
let type = options.type;
let name = options.name;
let template = options.template;
let pat = options.pat;
try {
let client = getAuthenticatedClient(pat);
let b64text = base64.encode(yaml.dump(template));
client.repos.createFile({
owner: config.owner,
repo: config.repository,
path: `${type}/${name}.yaml`,
message: 'Create template from PAI Marketplace.',
content: b64text,
}, function(err, res) {
if (err) {
// Maybe existed, try to update
update({
type: type,
name: name,
b64text: b64text,
client: client,
}, callback);
} else {
this.on("input", function(msg) {
var value = RED.util.getMessageProperty(msg,node.property);
if (value !== undefined) {
if (typeof value === "string") {
try {
value = yaml.load(value);
RED.util.setMessageProperty(msg,node.property,value);
node.send(msg);
}
catch(e) { node.error(e.message,msg); }
}
else if (typeof value === "object") {
if (!Buffer.isBuffer(value)) {
try {
value = yaml.dump(value);
RED.util.setMessageProperty(msg,node.property,value);
node.send(msg);
}
catch(e) {
node.error(RED._("yaml.errors.dropped-error"));
}
}
else { node.warn(RED._("yaml.errors.dropped-object")); }
}
else { node.warn(RED._("yaml.errors.dropped")); }
}
else { node.send(msg); } // If no payload - just pass it on.
});
}
module.exports.setYmlConfig = function ({ ymlConfigPath, newConfig }) {
fs.writeFileSync(ymlConfigPath, yaml.dump(newConfig));
};
cleanConfig: function () {
if (this.symfonyWithAssetic) {
var confDev = yaml.safeLoad(fs.readFileSync('app/config/config_dev.yml'));
delete confDev.assetic;
var newConfDev = yaml.dump(confDev, {indent: 4});
fs.writeFileSync('app/config/config_dev.yml', newConfDev);
var conf = yaml.safeLoad(fs.readFileSync('app/config/config.yml'));
delete conf.assetic;
var newConf = yaml.dump(conf, {indent: 4});
fs.writeFileSync('app/config/config.yml', newConf);
}
},
createHtml() {
let oldstr: string, newStr: string;
try {
if (this.inputType === 'json') {
oldstr = this.formatString(this.diffTpl.oldStr);
newStr = this.formatString(this.diffTpl.newStr);
} else {
oldstr = YAML.dump(this.formatJson(this.diffTpl.oldStr));
newStr = YAML.dump(this.formatJson(this.diffTpl.newStr));
}
} catch {
oldstr = '';
newStr = '';
this.messageService.showError('SHARED.DIFF.CHECK_DATA');
}
try {
const dd = createPatch(
this.diffTpl.fileName,
oldstr,
newStr,
this.diffTpl.newHeader,
this.diffTpl.oldHeader
);
const outStr = Diff2Html.getJsonFromDiff(
const saveServerlessYml = (config) => {
/*
When dumping to yml, it puts quotation marks around Serverless variables. This
breaks variable resolution, so I clean it out after dumping to yml but before
writing to the config file.
*/
const dumped = YAML.dump(config);
const cleaned = dumped.replace("\'${self:provider.stage}\'", "${self:provider.stage}")
fs.writeFileSync('serverless.yml', cleaned);
}
private updateFunctionsYml(functionYml: any) {
const serverlessYml = this.getServerlessYml();
serverlessYml["functions"] = functionYml;
this.serverless.utils.writeFileSync(
this.configService.getConfigFile(),
yaml.dump(serverlessYml)
);
}
private updateText(): void {
if (this.selectedMode === EditorMode.YAML) {
this.text = toYaml(JSON.parse(this.text));
} else {
this.text = this.toRawJSON(fromYaml(this.text));
}
}
function jobJsonToYaml(jobJson: string): string {
return yaml.dump(JSON.parse(jobJson))
}
<div>
{detail && configOpen && (
<button size="small" color="primary">
{T('common.update')}
</button>
)}
</div>
{loading && }
)
}