]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/config/get-credentials-by-uri.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / lib / config / get-credentials-by-uri.js
1 var assert = require("assert")
2
3 var toNerfDart = require("./nerf-dart.js")
4
5 module.exports = getCredentialsByURI
6
7 function getCredentialsByURI (uri) {
8   assert(uri && typeof uri === "string", "registry URL is required")
9   var nerfed = toNerfDart(uri)
10   var defnerf = toNerfDart(this.get("registry"))
11
12   // hidden class micro-optimization
13   var c = {
14     scope      : nerfed,
15     token      : undefined,
16     password   : undefined,
17     username   : undefined,
18     email      : undefined,
19     auth       : undefined,
20     alwaysAuth : undefined
21   }
22
23   // used to override scope matching for tokens as well as legacy auth
24   if (this.get(nerfed + ':always-auth') !== undefined) {
25     var val = this.get(nerfed + ':always-auth')
26     c.alwaysAuth = val === 'false' ? false : !!val
27   } else if (this.get('always-auth') !== undefined) {
28     c.alwaysAuth = this.get('always-auth')
29   }
30
31   if (this.get(nerfed + ':_authToken')) {
32     c.token = this.get(nerfed + ':_authToken')
33     // the bearer token is enough, don't confuse things
34     return c
35   }
36
37   // Handle the old-style _auth=<base64> style for the default
38   // registry, if set.
39   //
40   // XXX(isaacs): Remove when npm 1.4 is no longer relevant
41   var authDef = this.get("_auth")
42   var userDef = this.get("username")
43   var passDef = this.get("_password")
44   if (authDef && !(userDef && passDef)) {
45     authDef = new Buffer(authDef, "base64").toString()
46     authDef = authDef.split(":")
47     userDef = authDef.shift()
48     passDef = authDef.join(":")
49   }
50
51   if (this.get(nerfed + ":_password")) {
52     c.password = new Buffer(this.get(nerfed + ":_password"), "base64").toString("utf8")
53   } else if (nerfed === defnerf && passDef) {
54     c.password = passDef
55   }
56
57   if (this.get(nerfed + ":username")) {
58     c.username = this.get(nerfed + ":username")
59   } else if (nerfed === defnerf && userDef) {
60     c.username = userDef
61   }
62
63   if (this.get(nerfed + ":email")) {
64     c.email = this.get(nerfed + ":email")
65   } else if (this.get("email")) {
66     c.email = this.get("email")
67   }
68
69   if (c.username && c.password) {
70     c.auth = new Buffer(c.username + ":" + c.password).toString("base64")
71   }
72
73   return c
74 }