|
10 | 10 | * Module dependencies. |
11 | 11 | */ |
12 | 12 | var prompt = require('prompt'); |
13 | | -var request = require('request'); |
| 13 | +var request = require('./request'); |
14 | 14 | var _ = require('lodash'); |
15 | 15 | var debug = require('debug')('publish:general'); |
16 | 16 | var debug_assets = require('debug')('publish:asset'); |
@@ -192,38 +192,37 @@ Publish.prototype.init = function() { |
192 | 192 | //proceed after confirmation |
193 | 193 | return helper.confirm(config, inputs.language, backup, cb); |
194 | 194 | }, |
195 | | - // function(cb) { |
196 | | - // // login into cms, to get authtoken |
197 | | - // api.credentials = { |
198 | | - // user: { |
199 | | - // email: inputs.username, |
200 | | - // password: inputs.password |
201 | | - // } |
202 | | - // }; |
203 | | - // return utility.login(api.credentials, function(err, body) { |
204 | | - // if (err) { |
205 | | - // return cb(err); |
206 | | - // } else if (body && body.user && body.user.authtoken) { |
207 | | - // return cb(null, body.user.authtoken); |
208 | | - // } |
209 | | - // log(error(`Something went wrong while logging in..`)); |
210 | | - // return cb(body); |
211 | | - // }); |
212 | | - // }, |
213 | | - function( /*authtoken, */ cb) { |
214 | | - // headers.authtoken = authtoken; |
215 | | - headers.authtoken = '***REMOVED***'; |
| 195 | + function(cb) { |
| 196 | + // login into cms, to get authtoken |
| 197 | + api.credentials = { |
| 198 | + user: { |
| 199 | + email: inputs.username, |
| 200 | + password: inputs.password |
| 201 | + } |
| 202 | + }; |
| 203 | + return utility.login(api.credentials, function(err, body) { |
| 204 | + if (err) { |
| 205 | + return cb(err); |
| 206 | + } else if (body && body.user && body.user.authtoken) { |
| 207 | + return cb(null, body.user.authtoken); |
| 208 | + } |
| 209 | + log(error(`Something went wrong while logging in..`)); |
| 210 | + return cb(body); |
| 211 | + }); |
| 212 | + }, |
| 213 | + function(authtoken, cb) { |
| 214 | + headers.authtoken = authtoken; |
216 | 215 | // get environment names from Contentstack |
217 | 216 | return request({ |
218 | 217 | uri: `${api.host}/${api.version}${api.urls.environments}?$in=${inputs.environment.toString()}`, |
219 | 218 | headers: headers, |
220 | 219 | method: 'GET', |
221 | 220 | json: true |
222 | | - }, function(error, response) { |
| 221 | + }, function(error, body) { |
223 | 222 | if (error) { |
224 | 223 | return cb(error); |
225 | | - } else if (response && response.body.environments && response.body.environments.length) { |
226 | | - inputs.environment_ids = _.map(response.body.environments, 'uid'); |
| 224 | + } else if (body.environments && body.environments.length) { |
| 225 | + inputs.environment_ids = _.map(body.environments, 'uid'); |
227 | 226 | return cb(null, null); |
228 | 227 | } |
229 | 228 | return cb(response.body); |
|
0 commit comments