Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(ans => {
const datasource = new Buttercup.FileDatasource(bcupPath);
datasource.load(ans.master_password).then((archive) => {
// This is only guaranteed to work on buttercup 0.14.0, awaiting PR in buttercup
const groups = archive.getGroups();
const group = groups.filter((g) => g._remoteObject.title === 'git-labelmaker')[0];
const token = group.getAttribute('token');
res(token);
})
.catch(e => {
if (e.message === 'Failed opening archive: Error: Encrypted content has been tampered with') {
return rej({
id: 'PASSWORD',
});
}
return rej(err(e.message));
});
})
save: function(datasourcePath, password) {
var archive = Buttercup.Archive.createWithDefaults(),
datasource = new Buttercup.FileDatasource(datasourcePath);
return datasource.save(archive, password);
}
};
const writeToken = (password, token) => new Promise((res, rej) => {
const datasource = new Buttercup.FileDatasource(bcupPath);
if (!datasource) return rej('No datasource');
const archive = Buttercup.Archive.createWithDefaults();
const group = archive.createGroup('git-labelmaker');
group.setAttribute('token', token);
datasource.save(archive, password);
return res(token);
});
load: function(datasourcePath, password) {
var workspace = new Buttercup.Workspace(),
datasource = new Buttercup.FileDatasource(datasourcePath);
return datasource.load(password).then(function(archive) {
workspace
.setArchive(archive)
.setDatasource(datasource)
.setPassword(password);
return workspace;
});
},