This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add config profile endpoint (#1030)
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
- Loading branch information
Showing
4 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict' | ||
|
||
const promisify = require('promisify-es6') | ||
|
||
const toObject = function (res, callback) { | ||
if (Buffer.isBuffer(res)) { | ||
callback(null, JSON.parse(res.toString())) | ||
} else { | ||
callback(null, res) | ||
} | ||
} | ||
|
||
module.exports = (send) => { | ||
return promisify((profile, opts, callback) => { | ||
if (typeof opts === 'function') { | ||
callback = opts | ||
opts = {} | ||
} | ||
|
||
opts = normalizeOpts(opts) | ||
|
||
send.andTransform({ | ||
path: 'config/profile/apply', | ||
args: profile, | ||
qs: opts | ||
}, toObject, (err, response) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
callback(null, { oldCfg: response.OldCfg, newCfg: response.NewCfg }) | ||
}) | ||
}) | ||
} | ||
|
||
function normalizeOpts (opts) { | ||
opts = opts || {} | ||
if (typeof opts.dryRun !== 'undefined') { | ||
opts['dry-run'] = opts.dryRun | ||
} | ||
return opts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters