Skip to content

Commit

Permalink
fix: flow
Browse files Browse the repository at this point in the history
  • Loading branch information
bufferoverflow committed Jun 21, 2018
1 parent 255f85b commit f411396
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"javascript.validate.enable": false
}
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ npm install
npm start
```

> **NOTE**: Define `http_proxy` environment variable if you are behind a proxy.
verdaccio is now up and running, now configure the following within
your `~/.config/verdaccio/config.yaml` to use this plugin

Expand Down
25 changes: 22 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"node": ">=6.12.0"
},
"dependencies": {
"@verdaccio/types": "^3.0.0",
"gitlab": "^3.4.2",
"global-tunnel-ng": "^2.1.1",
"verdaccio": "^3.1.1"
},
"devDependencies": {
Expand All @@ -55,7 +57,7 @@
"babel-preset-flow": "^6.23.0",
"eclint": "^2.5.0",
"eslint": "^4.19.1",
"flow-bin": "^0.74.0",
"flow-bin": "^0.75.0",
"flow-runtime": "^0.17.0",
"generate-changelog": "^1.7.0",
"husky": "^0.14.3",
Expand Down
121 changes: 55 additions & 66 deletions src/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,14 @@

import Gitlab from 'gitlab';
import {httperror} from 'http-errors';
import type {Config, Logger, Callback} from '@verdaccio/types';
import type { PackageAccess, Config, Logger, Callback } from '@verdaccio/types';

export default class GitLab {
/**
*
* @param {*} config
* @param {object} stuff config.yaml in object from
*/

// flow types
export default class VerdaccioGitLab {
users: {};
stuff: {};
config: Config;
config: {};
logger: Logger;

// constructor
constructor(
config: {
url: string
Expand All @@ -33,84 +25,81 @@ export default class GitLab {
) {
this.users = {};

// config for this module
this.config = config;
this.stuff = stuff;

// verdaccio logger
this.logger = stuff.logger;

}

authenticate(user: string, password: string, cb: Callback) {
authenticate(user: string, password: string, cb: Callback) {

var GitlabAPI = new Gitlab({
url: this.config.url,
token: password
});
var GitlabAPI = new Gitlab({
url: this.config.url,
token: password
});

GitlabAPI.Users.current().then((response) => {
if (user !== response.username) return cb(httperror[403]('wrong gitlab username'));
var ownedGroups = [user];
GitlabAPI.Groups.all({'owned': 'true'}).then((groups) => {
groups.forEach(function(item) {
if (item.path === item.full_path) {
ownedGroups.push(item.path);
}
GitlabAPI.Users.current().then((response) => {
if (user !== response.username) return cb(httperror[403]('wrong gitlab username'));
var ownedGroups = [user];
GitlabAPI.Groups.all({'owned': 'true'}).then((groups) => {
groups.forEach(function(item) {
if (item.path === item.full_path) {
ownedGroups.push(item.path);
}
});
cb(null, ownedGroups);
});
cb(null, ownedGroups);
}).
catch(error => {
if (error) return cb('Personal access token invalid');
});
}).
catch(error => {
if (error) return cb('Personal access token invalid');
});
}
}

adduser(user: string, password: string, cb: Callback) {
cb(null, false);
}
adduser(user: string, password: string, cb: Callback) {
cb(null, false);
}

allow_access(user: string, _package: string , cb: Callback) {
if (!_package.gitlab) return cb();
if (_package.access.includes('$authenticated') && user.name !== undefined) {
return cb(null, true);
} else {
return cb(null, false);
allow_access(user, _package: PackageAccess, cb: Callback) {
if (!_package.gitlab) return cb();
if (_package.access.includes('$authenticated') && user.name !== undefined) {
return cb(null, true);
} else {
return cb(null, false);
}
}
}

allow_publish(user: string, _package: string, cb: Callback) { // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
if (!_package.gitlab) return cb();
var packageScopeOwner = false;
var packageOwner = false;
allow_publish(user, _package: PackageAccess, cb: Callback) { // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
if (!_package.gitlab) return cb();
var packageScopeOwner = false;
var packageOwner = false;

user.real_groups.forEach(function(item) { // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
if (item === _package.name) {
packageOwner = true;
return false;
} else {
if (_package.name.indexOf('@') === 0) {
if (item === _package.name.slice(1, _package.name.lastIndexOf('/'))) {
packageScopeOwner = true;
return false;
user.real_groups.forEach(function(item) { // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
if (item === _package.name) {
packageOwner = true;
return false;
} else {
if (_package.name.indexOf('@') === 0) {
if (item === _package.name.slice(1, _package.name.lastIndexOf('/'))) {
packageScopeOwner = true;
return false;
}
}
}
}
});
});

if (packageOwner === true) {
return cb(null, false);
} else {
if (packageScopeOwner === true) {
if (packageOwner === true) {
return cb(null, false);
} else {
if (_package.name.indexOf('@') === 0) {
return cb(httperror[403]('must be owner of package-scope'));
if (packageScopeOwner === true) {
return cb(null, false);
} else {
return cb(httperror[403]('must be owner of package-name'));
if (_package.name.indexOf('@') === 0) {
return cb(httperror[403]('must be owner of package-scope'));
} else {
return cb(httperror[403]('must be owner of package-name'));
}
}
}
}
}

}
10 changes: 2 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
// Copyright 2018 Roger Meier <[email protected]>
// SPDX-License-Identifier: MIT
import GitLab from './gitlab';
import VerdaccioGitLab from './gitlab';

/**
* A new instance of HTPasswd class.
* @param {object} config
* @param {object} stuff
* @returns {object}
*/
export default function(config, stuff) {
return new GitLab(config, stuff);
return new VerdaccioGitLab(config, stuff);
}
2 changes: 2 additions & 0 deletions src/verdaccio.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
const globalTunnel = require('global-tunnel-ng');
globalTunnel.initialize();
require('verdaccio/build/lib/cli');

0 comments on commit f411396

Please sign in to comment.