Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
3893f5c
chore(cookbook): circleCi
jonny22094 Nov 5, 2018
7bd348f
chore(cookbook): amendments
jonny22094 Nov 5, 2018
6314155
chore(cookbook): amendments
jonny22094 Nov 6, 2018
601cf9a
chore(): update
jonny22094 Nov 6, 2018
121db4a
fix(): Broken link
jonny22094 Nov 13, 2018
fc14d7d
feat(core): Backups
jonny22094 Nov 13, 2018
8050be0
chore(): Test name
jonny22094 Nov 13, 2018
9a7de8d
Merge pull request #320 from Syncano/feat/Backups
jonny22094 Nov 14, 2018
95270ce
Merge pull request #319 from Syncano/fix/broken-link-
jonny22094 Nov 15, 2018
bdecb27
feat(cli): add backups
jonny22094 Nov 15, 2018
c8f54fa
chore(cli): remove debug
jonny22094 Nov 15, 2018
013ea90
chore(cli): amendments
jonny22094 Nov 15, 2018
e706b8c
chore(core): groups amendments
jonny22094 Nov 15, 2018
359e001
chore(cli): remove-components
jonny22094 Nov 15, 2018
40b9e79
chore(): remove component-list
jonny22094 Nov 15, 2018
dc2660e
chore(cli): return component-list
jonny22094 Nov 15, 2018
7b914b6
chore(cli): import
jonny22094 Nov 15, 2018
5526360
chore(cli): remove component from context
jonny22094 Nov 15, 2018
090ed3c
feat(cli): deleting backups
jonny22094 Nov 16, 2018
8cb05f7
chore(core): syntax
jonny22094 Nov 16, 2018
53e7144
chore(cli): indentations
jonny22094 Nov 16, 2018
a433947
Merge pull request #324 from Syncano/chore/core-groups-amendments
jonny22094 Nov 16, 2018
d4fe868
feat(docs): Add backups in cheatsheet
jonny22094 Nov 16, 2018
05017b7
feat(dosc): groups cheatsheet
jonny22094 Nov 16, 2018
448a505
Merge branch 'master' into feat/cli-backups
jonny22094 Nov 16, 2018
3040ae7
Merge pull request #323 from Syncano/chore/remove-components-from-cli
jonny22094 Nov 16, 2018
fbae5d7
fix(cli): camel case
jonny22094 Nov 16, 2018
ca69086
Merge pull request #326 from Syncano/feat/groups-cheatsheet
jonny22094 Nov 17, 2018
2efe58d
Merge pull request #325 from Syncano/feat/cli-backups
jonny22094 Nov 17, 2018
71ad30c
chore(cookbook): amendments
jonny22094 Nov 19, 2018
dbe50f9
Merge pull request #316 from Syncano/chore/circleCi-cookbook
jonny22094 Nov 19, 2018
3b23f7a
fix(cli): remove add command
mkucharz Nov 20, 2018
d78b5d4
Merge pull request #328 from Syncano/fix/remove_add
mkucharz Nov 20, 2018
93c0664
feat(cli:list): add instance nam to list command
mkucharz Nov 20, 2018
69bfd85
Merge pull request #329 from Syncano/feat/instance_name_on_list
mkucharz Nov 20, 2018
9b178ea
chore(cli:templates): remove obsolete fields
mkucharz Nov 20, 2018
27be290
Merge pull request #330 from Syncano/chore/obsolete_fields_in_emplates
mkucharz Nov 20, 2018
8e92ccf
fix(cli): prevent wrong password moving you forward
mkucharz Nov 20, 2018
9bfa5b9
fix(cli:tests)
mkucharz Nov 20, 2018
d433e02
chore(cli:backup): small fixes to backup
mkucharz Nov 20, 2018
63afc4d
Merge pull request #331 from Syncano/fix/wrong_password_move_forward
mkucharz Nov 20, 2018
f0fa1b0
fix(cli): missing return
mkucharz Nov 21, 2018
84fd430
fix(cli:style)
mkucharz Nov 21, 2018
ac22ddf
Merge pull request #332 from Syncano/fix/wrong_prints_order
mkucharz Nov 21, 2018
f932297
fix(template-hello): remove root level .gitignore file
mkucharz Nov 21, 2018
48d0a1e
Merge pull request #333 from Syncano/fix/override_gitignore
mkucharz Nov 21, 2018
cc288a4
fix(cli): scripts paths
mkucharz Nov 21, 2018
9c3b0a8
Fix test-tools nixt package vulnerability (#334)
Idered Nov 26, 2018
29538f8
chore(): deps
mkucharz Nov 27, 2018
7809576
fix(lib-core): fixing for axios
mkucharz Nov 27, 2018
0ce6b42
fix(): conflict
mkucharz Nov 27, 2018
17763c8
fix(): remove npm-run-all
mkucharz Nov 27, 2018
844c580
fix(): concurency tests running
mkucharz Nov 27, 2018
03ca347
Merge pull request #335 from Syncano/chore/update_deps
mkucharz Nov 27, 2018
6221636
feat(cli): run init after install
mkucharz Nov 27, 2018
d14df13
fix(cli): skip post install in CI
mkucharz Nov 27, 2018
3b9b23f
fix(): update deps
mkucharz Nov 27, 2018
3876bd4
fix(): deps
mkucharz Nov 27, 2018
daf6250
fix(cli): tests
mkucharz Nov 27, 2018
e76e659
Merge pull request #336 from Syncano/feat/postinstall
mkucharz Nov 27, 2018
fec3dc9
chore(client): add support to v3 endpoints
mkucharz Nov 27, 2018
8d4df66
chore(): small improvements
mkucharz Nov 28, 2018
9ed71f1
Merge pull request #337 from Syncano/feat/v3_endpoints
mkucharz Nov 28, 2018
1c76336
fix(cli): backups date
jonny22094 Nov 29, 2018
73a8e58
chore(): toLocaleString
jonny22094 Nov 29, 2018
2dc429e
Merge pull request #338 from Syncano/fix/cli-backups-date
mkucharz Nov 30, 2018
9187aac
v0.15.0
mkucharz Nov 30, 2018
712d58c
chore(): update readme
mkucharz Nov 30, 2018
d11174b
Update readme.md
mkucharz Nov 30, 2018
d218f2c
Update readme.md
mkucharz Nov 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(core): Backups
  • Loading branch information
jonny22094 committed Nov 13, 2018
commit fc14d7d38e8beb26f04ebb15499436ed239dc3ea
82 changes: 82 additions & 0 deletions packages/lib-js-core/src/backups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import QueryBuilder from './query-builder'

/**
* Syncano Backups
*
* @property {Function}
*/
class Backups extends QueryBuilder {
url () {
const {instanceName} = this.instance

return `${this._getInstanceURL(instanceName)}/backups/full/`
}

/**
* Backups list helper
*
* @param {string} url
*
* @return {Array}
*/
async _getBackups (url) {
const fetch = this.fetch.bind(this)
const options = {
method: 'GET',
}

try {
const res = await fetch(url, options)
let backups = res.objects

if(res.next) {
backups = backups.concat(await this._getGroups(`${this.baseUrl}${res.next}`))
}

return backups
} catch(err) {
throw err
}
}

/**
* Backups list
*
* @return {Promise}
*/
async list () {
return this._getBackups(this.url())
}

/**
* Create new backup
*
* @return {Promise}
*/
async create () {
const fetch = this.fetch.bind(this)
const options = {
method: 'POST',
}

return fetch(this.url(), options)
}

/**
* Get backup
*
* @param {number} id - Backup id
*
* @return {Promise}
*/
async get (id) {
const fetch = this.fetch.bind(this)
const options = {
method: 'GET',
}

return fetch(`${this.url()}${id}/`, options)
}
}

export default Backups
2 changes: 2 additions & 0 deletions packages/lib-js-core/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Channel from './channel'
import Class from './class'
import Settings from './settings'
import Groups from './groups'
import Backups from './backups'

class Server {
constructor (ctx = {}) {
Expand All @@ -37,6 +38,7 @@ class Server {
this.logger = Logger(config)
this.users = new Users(config)
this.groups = new Groups(config)
this.backups = new Backups(config)
this.data = new Proxy(new Data(settings), {
get (target, className) {
return new Data(getConfig(className))
Expand Down
89 changes: 89 additions & 0 deletions packages/lib-js-core/test/unit/backups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import nock from 'nock'
import Server from '../../src'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'

chai.use(chaiAsPromised)
chai.should()

describe('Backups', () => {
const instanceName = 'testInstance'
const BACKUPS_URL = `/v2/instances/${instanceName}/backups/full/`
const backup = {
id: 703,
instance: instanceName,
created_at: '2018-11-13T10:29:32.598102Z',
updated_at: '2018-11-13T10:29:32.598126Z',
size: null,
status: 'success',
status_info: '',
description: '',
label: '',
author:
{ id: 3124,
email: '[email protected]',
first_name: '',
last_name: '',
is_active: false,
has_password: true,
metadata: {} },
details: {},
metadata: {},
links: { self: '/v2/backups/full/703/' }
}
let api
let Backups

beforeEach(() => {
const server = new Server({
token: 'testKey',
instanceName
})
Backups = server.backups
api = nock(`https://${process.env.SYNCANO_HOST || 'api.syncano.io'}`)
})

describe('#list', () => {
it('Get backups list', async () => {
api.get(BACKUPS_URL).reply(200, {
next: null,
prev: null,
objects: [backup, backup]
})

const data = await Backups.list()

data.should.be.a('array')
data.should.have.lengthOf(2)
})
})

describe('#create', () => {
it('Create backup', async () => {
api.post(BACKUPS_URL).reply(200, backup)

const data = await Backups.create()

data.should.be.a('object')
data.should.have.property('id')
data.should.have.property('instance')
data.should.have.property('author')
data.should.have.property('status')
})
})

describe('#get', () => {
it('Get backups list', async () => {
api.get(`${BACKUPS_URL}703/`).reply(200, backup)
const data = await Backups.get(703)

data.should.be.a('object')
data.should.have.property('id').equal(703)
data.should.have.property('instance')
data.should.have.property('author')
data.should.have.property('status')
})
})
})