"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/config/set-credentials-by-uri.js" (8 Mar 2017, 1266 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 var assert = require('assert')
    2 
    3 var toNerfDart = require('./nerf-dart.js')
    4 
    5 module.exports = setCredentialsByURI
    6 
    7 function setCredentialsByURI (uri, c) {
    8   assert(uri && typeof uri === 'string', 'registry URL is required')
    9   assert(c && typeof c === 'object', 'credentials are required')
   10 
   11   var nerfed = toNerfDart(uri)
   12 
   13   if (c.token) {
   14     this.set(nerfed + ':_authToken', c.token, 'user')
   15     this.del(nerfed + ':_password', 'user')
   16     this.del(nerfed + ':username', 'user')
   17     this.del(nerfed + ':email', 'user')
   18     this.del(nerfed + ':always-auth', 'user')
   19   } else if (c.username || c.password || c.email) {
   20     assert(c.username, 'must include username')
   21     assert(c.password, 'must include password')
   22     assert(c.email, 'must include email address')
   23 
   24     this.del(nerfed + ':_authToken', 'user')
   25 
   26     var encoded = new Buffer(c.password, 'utf8').toString('base64')
   27     this.set(nerfed + ':_password', encoded, 'user')
   28     this.set(nerfed + ':username', c.username, 'user')
   29     this.set(nerfed + ':email', c.email, 'user')
   30 
   31     if (c.alwaysAuth !== undefined) {
   32       this.set(nerfed + ':always-auth', c.alwaysAuth, 'user')
   33     } else {
   34       this.del(nerfed + ':always-auth', 'user')
   35     }
   36   } else {
   37     throw new Error('No credentials to set.')
   38   }
   39 }