Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
feat: normalize KEY API (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias authored and daviddias committed Jan 5, 2018
1 parent a39a315 commit 1b10821
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
12 changes: 10 additions & 2 deletions src/key/gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@

const promisify = require('promisify-es6')

const transform = function (res, callback) {
callback(null, {
id: res.Id,
name: res.Name
})
}

module.exports = (send) => {
return promisify((args, opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}
send({

send.andTransform({
path: 'key/gen',
args: args,
qs: opts
}, callback)
}, transform, callback)
})
}
11 changes: 9 additions & 2 deletions src/key/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

const promisify = require('promisify-es6')

const transform = function (res, callback) {
callback(null, {
id: res.Id,
name: res.Name
})
}

module.exports = (send) => {
return promisify((name, pem, password, callback) => {
send({
send.andTransform({
path: 'key/import',
args: name,
qs: {
pem: pem,
password: password
}
}, callback)
}, transform, callback)
})
}
14 changes: 12 additions & 2 deletions src/key/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@

const promisify = require('promisify-es6')

const transform = function (res, callback) {
callback(null, res.Keys.map(key => {
return {
id: key.Id,
name: key.Name
}
}))
}

module.exports = (send) => {
return promisify((opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}
send({

send.andTransform({
path: 'key/list',
qs: opts
}, callback)
}, transform, callback)
})
}
13 changes: 11 additions & 2 deletions src/key/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

const promisify = require('promisify-es6')

const transform = function (res, callback) {
callback(null, {
id: res.Id,
was: res.Was,
now: res.Now,
overwrite: res.Overwrite
})
}

module.exports = (send) => {
return promisify((oldName, newName, callback) => {
send({
send.andTransform({
path: 'key/rename',
args: [oldName, newName]
}, callback)
}, transform, callback)
})
}
11 changes: 9 additions & 2 deletions src/key/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

const promisify = require('promisify-es6')

const transform = function (res, callback) {
callback(null, {
id: res.Keys[0].Id,
name: res.Keys[0].Name
})
}

module.exports = (send) => {
return promisify((args, callback) => {
send({
send.andTransform({
path: 'key/rm',
args: args
}, callback)
}, transform, callback)
})
}

0 comments on commit 1b10821

Please sign in to comment.