diff options
author | isaacs <i@izs.me> | 2010-05-02 04:21:31 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-05-03 05:07:46 +0400 |
commit | f263b793922f4bdc14f5c48474a678a26a376679 (patch) | |
tree | 5daea0c90998efda1b8e00f9033282242e00c9df /lib | |
parent | a9ab525f8c12609a3f79a0b33c0e1d9938394cd9 (diff) |
Add a registryGET function to mirror registryPUT
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils/registry.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/utils/registry.js b/lib/utils/registry.js index 643944984..841ce5470 100644 --- a/lib/utils/registry.js +++ b/lib/utils/registry.js @@ -4,6 +4,7 @@ exports.publish = publish exports.tag = tag exports.adduser = adduser +exports.get = get var npm = require("../../npm") , http = require("http") @@ -14,6 +15,8 @@ var npm = require("../../npm") , sys = require("sys") , ini = require("./ini") +function get (project, version, cb) { registryGET(project+"/"+version, cb) } + function tag (project, version, tag, cb) { PUT(project+"/"+tag, version, cb) } function publish (data, tarball, cb) { @@ -56,6 +59,45 @@ function publish (data, tarball, cb) { }) } +function GET (where, cb) { + reg() + where = ini.config.registry + where + var u = url.parse(where) + , headers = { "host" : u.host + , "accept" : "application/json" + } + if (ini.config.auth) { + headers.authorization = 'Basic ' + ini.config.auth + } + log(u, "registryGET") + var client = http.createClient(u.port || (u.protocol === "https:" ? 443 : 80), u.hostname) + if (u.protocol === "https:") { + client.setSecure("X509_PEM") + } + var request = client.request("GET", u.pathname, headers) + + request.addListener("response", function (response) { + // if (response.statusCode !== 200) return cb(new Error( + // "Status code " + response.statusCode + " from PUT "+where)) + var data = "" + response.setBodyEncoding("utf8") + response.addListener("data", function (chunk) { data += chunk }) + response.addListener("end", function () { + try { + data = JSON.parse(data) + } catch (ex) { + ex.message += "\n" + data + return cb(ex, data, response) + } + if (data.error) return cb(new Error( + data.error + (" "+data.reason || ""))) + cb(null, data, response) + }) + }) + request.end() +} + + function PUT (where, what, cb) { reg() what = JSON.stringify(what) |