Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
allowing regsitry url to be configured as api
Browse files Browse the repository at this point in the history
  • Loading branch information
soldair committed May 3, 2016
1 parent 9dd5178 commit b3fd561
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions commands/hook.js
Expand Up @@ -12,7 +12,6 @@ function hooks(argv)

hooks.add = function add(argv)
{
// TODO match with service
report.success('hook add', 'hooking ' + chalk.yellow(argv.pkg) +
' to ' + chalk.yellow(argv.url) +
' with shared secret ' + chalk.red(argv.secret)
Expand All @@ -37,7 +36,7 @@ hooks.add = function add(argv)
if (!hook || res.statusCode < 200 || res.statusCode >= 400)
return report.failure('hook add', res.statusCode + ' ' + JSON.stringify(hook));

// TODO assumption here is that the body of the response is the updated hook

report.success('+', hook.name + ' ➜ ' + hook.endpoint);
});
};
Expand Down Expand Up @@ -66,6 +65,8 @@ hooks.rm = function rm(argv)

hooks.ls = function ls(argv)
{


var reg = new Registry(argv);
var uri = '/v1/hooks/hook';
if (argv.pkg)
Expand Down
18 changes: 14 additions & 4 deletions lib/registry.js
Expand Up @@ -38,17 +38,26 @@ Registry.prototype._registry = null;
Registry.prototype.authed = function authed(opts, callback)
{
var token = this.getAuthToken(this.registry);

if (!token)
return callback(new Error('you are not logged into the registry you are trying to use "' + this.registry + '"'));
var hostname = opts.legacy ? this.registry : this.api;


// add a slash if it missing.
// not using url.resolve so we can support api through the registry url paths. url.resolve(hostname, opts.uri),
// https://registry.npmjs.org/-/api/v1/hooks/hook etc.
// we should remove the default api url probably?
//
if(opts.uri.indexOf('/') !== 0)
opts.uri = '/' + opts.uri;

var options = {
url: url.resolve(hostname, opts.uri),
method: opts.method,
url: hostname + opts.uri,
method: opts.method || 'GET',
json: opts.json || opts.body || true,
auth: { bearer: token }
auth:{bearer:token}
};

this.requestfunc(options, callback);
};

Expand All @@ -64,6 +73,7 @@ Registry.prototype.anonymous = function anonymous(opts, callback)
this.requestfunc(options, callback);
};


function getReg()
{
return this._registry;
Expand Down

0 comments on commit b3fd561

Please sign in to comment.