backup site: add contents
it is a json that can be one of the three: * null - include everything * include - only include these ids * exclude - everything except these ids
This commit is contained in:
@@ -15,6 +15,7 @@ exports = module.exports = {
|
||||
setRetention,
|
||||
setPrimary,
|
||||
setName,
|
||||
setContents,
|
||||
setEncryption,
|
||||
|
||||
createBackup,
|
||||
@@ -65,11 +66,12 @@ async function list(req, res, next) {
|
||||
async function add(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
const { name, format, provider, config, schedule, retention } = req.body;
|
||||
const { name, format, provider, contents, config, schedule, retention } = req.body;
|
||||
|
||||
if (typeof format !== 'string') return next(new HttpError(400, 'format must be a string'));
|
||||
if (typeof name !== 'string') return next(new HttpError(400, 'name must be a string'));
|
||||
if (typeof provider !== 'string') return next(new HttpError(400, 'provider is required'));
|
||||
if (typeof contents !== 'object') return next(new HttpError(400, 'contents is required'));
|
||||
|
||||
// provider specific options are validated by provider backends
|
||||
if (!config || typeof config !== 'object') return next(new HttpError(400, 'config is required'));
|
||||
@@ -183,6 +185,17 @@ async function setPrimary(req, res, next) {
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
async function setContents(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.contents !== 'object') return next(new HttpError(400, 'contents must be an object'));
|
||||
|
||||
const [error] = await safe(backupSites.setContents(req.resources.backupSite, req.body.contents, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
async function setEncryption(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ describe('Backups API', function () {
|
||||
config: { backupDir: '/tmp/boxtest-newsite' },
|
||||
format: 'tgz',
|
||||
retention: { keepWithinSecs: 60 * 60 },
|
||||
schedule: '00 01 * * * *'
|
||||
schedule: '00 01 * * * *',
|
||||
contents: null
|
||||
};
|
||||
|
||||
const encryptedSite = {
|
||||
@@ -29,6 +30,7 @@ describe('Backups API', function () {
|
||||
format: 'rsync',
|
||||
retention: { keepMonthly: 60 },
|
||||
schedule: '* 1 * * * *',
|
||||
contents: { exclude: [ 'thatapp' ] }
|
||||
};
|
||||
|
||||
describe('add', function () {
|
||||
@@ -210,6 +212,59 @@ describe('Backups API', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('contents', function () {
|
||||
it('cannot set invalid contents', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backup_sites/${newSite.id}/configure/contents`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ contents: 'garbage' })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.status).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set invalid include', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backup_sites/${newSite.id}/configure/contents`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ contents: { include: 'something' } })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.status).to.equal(400);
|
||||
});
|
||||
|
||||
it('can set include', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backup_sites/${newSite.id}/configure/contents`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ contents: { include: [ 'something' ]} })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.status).to.equal(200);
|
||||
const result = await backupSites.get(newSite.id);
|
||||
expect(result.contents).to.eql({ include: [ 'something' ]});
|
||||
});
|
||||
|
||||
it('can set exclude', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backup_sites/${newSite.id}/configure/contents`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ contents: { exclude: [ 'something' ]} })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.status).to.equal(200);
|
||||
const result = await backupSites.get(newSite.id);
|
||||
expect(result.contents).to.eql({ exclude: [ 'something' ] });
|
||||
});
|
||||
|
||||
it('can set null', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backup_sites/${newSite.id}/configure/contents`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ contents: null })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.status).to.equal(200);
|
||||
const result = await backupSites.get(newSite.id);
|
||||
expect(result.contents).to.eql(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('primary', function () {
|
||||
it('cannot set invalid id', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/backup_sites/${newSite.id}xx/configure/primary`)
|
||||
|
||||
Reference in New Issue
Block a user