Skip to content

Commit f411396

Browse files
fix: flow
1 parent 255f85b commit f411396

File tree

7 files changed

+87
-79
lines changed

7 files changed

+87
-79
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"javascript.validate.enable": false
3-
}
3+
}

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ npm install
2828
npm start
2929
```
3030

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

package-lock.json

+22-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
"node": ">=6.12.0"
4444
},
4545
"dependencies": {
46+
"@verdaccio/types": "^3.0.0",
4647
"gitlab": "^3.4.2",
48+
"global-tunnel-ng": "^2.1.1",
4749
"verdaccio": "^3.1.1"
4850
},
4951
"devDependencies": {
@@ -55,7 +57,7 @@
5557
"babel-preset-flow": "^6.23.0",
5658
"eclint": "^2.5.0",
5759
"eslint": "^4.19.1",
58-
"flow-bin": "^0.74.0",
60+
"flow-bin": "^0.75.0",
5961
"flow-runtime": "^0.17.0",
6062
"generate-changelog": "^1.7.0",
6163
"husky": "^0.14.3",

src/gitlab.js

+55-66
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,14 @@
44

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

9-
export default class GitLab {
10-
/**
11-
*
12-
* @param {*} config
13-
* @param {object} stuff config.yaml in object from
14-
*/
15-
16-
// flow types
9+
export default class VerdaccioGitLab {
1710
users: {};
1811
stuff: {};
19-
config: Config;
12+
config: {};
2013
logger: Logger;
2114

22-
// constructor
2315
constructor(
2416
config: {
2517
url: string
@@ -33,84 +25,81 @@ export default class GitLab {
3325
) {
3426
this.users = {};
3527

36-
// config for this module
3728
this.config = config;
3829
this.stuff = stuff;
3930

40-
// verdaccio logger
4131
this.logger = stuff.logger;
4232

4333
}
4434

45-
authenticate(user: string, password: string, cb: Callback) {
35+
authenticate(user: string, password: string, cb: Callback) {
4636

47-
var GitlabAPI = new Gitlab({
48-
url: this.config.url,
49-
token: password
50-
});
37+
var GitlabAPI = new Gitlab({
38+
url: this.config.url,
39+
token: password
40+
});
5141

52-
GitlabAPI.Users.current().then((response) => {
53-
if (user !== response.username) return cb(httperror[403]('wrong gitlab username'));
54-
var ownedGroups = [user];
55-
GitlabAPI.Groups.all({'owned': 'true'}).then((groups) => {
56-
groups.forEach(function(item) {
57-
if (item.path === item.full_path) {
58-
ownedGroups.push(item.path);
59-
}
42+
GitlabAPI.Users.current().then((response) => {
43+
if (user !== response.username) return cb(httperror[403]('wrong gitlab username'));
44+
var ownedGroups = [user];
45+
GitlabAPI.Groups.all({'owned': 'true'}).then((groups) => {
46+
groups.forEach(function(item) {
47+
if (item.path === item.full_path) {
48+
ownedGroups.push(item.path);
49+
}
50+
});
51+
cb(null, ownedGroups);
6052
});
61-
cb(null, ownedGroups);
53+
}).
54+
catch(error => {
55+
if (error) return cb('Personal access token invalid');
6256
});
63-
}).
64-
catch(error => {
65-
if (error) return cb('Personal access token invalid');
66-
});
67-
}
57+
}
6858

69-
adduser(user: string, password: string, cb: Callback) {
70-
cb(null, false);
71-
}
59+
adduser(user: string, password: string, cb: Callback) {
60+
cb(null, false);
61+
}
7262

73-
allow_access(user: string, _package: string , cb: Callback) {
74-
if (!_package.gitlab) return cb();
75-
if (_package.access.includes('$authenticated') && user.name !== undefined) {
76-
return cb(null, true);
77-
} else {
78-
return cb(null, false);
63+
allow_access(user, _package: PackageAccess, cb: Callback) {
64+
if (!_package.gitlab) return cb();
65+
if (_package.access.includes('$authenticated') && user.name !== undefined) {
66+
return cb(null, true);
67+
} else {
68+
return cb(null, false);
69+
}
7970
}
80-
}
8171

82-
allow_publish(user: string, _package: string, cb: Callback) { // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
83-
if (!_package.gitlab) return cb();
84-
var packageScopeOwner = false;
85-
var packageOwner = false;
72+
allow_publish(user, _package: PackageAccess, cb: Callback) { // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
73+
if (!_package.gitlab) return cb();
74+
var packageScopeOwner = false;
75+
var packageOwner = false;
8676

87-
user.real_groups.forEach(function(item) { // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
88-
if (item === _package.name) {
89-
packageOwner = true;
90-
return false;
91-
} else {
92-
if (_package.name.indexOf('@') === 0) {
93-
if (item === _package.name.slice(1, _package.name.lastIndexOf('/'))) {
94-
packageScopeOwner = true;
95-
return false;
77+
user.real_groups.forEach(function(item) { // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
78+
if (item === _package.name) {
79+
packageOwner = true;
80+
return false;
81+
} else {
82+
if (_package.name.indexOf('@') === 0) {
83+
if (item === _package.name.slice(1, _package.name.lastIndexOf('/'))) {
84+
packageScopeOwner = true;
85+
return false;
86+
}
9687
}
9788
}
98-
}
99-
});
89+
});
10090

101-
if (packageOwner === true) {
102-
return cb(null, false);
103-
} else {
104-
if (packageScopeOwner === true) {
91+
if (packageOwner === true) {
10592
return cb(null, false);
10693
} else {
107-
if (_package.name.indexOf('@') === 0) {
108-
return cb(httperror[403]('must be owner of package-scope'));
94+
if (packageScopeOwner === true) {
95+
return cb(null, false);
10996
} else {
110-
return cb(httperror[403]('must be owner of package-name'));
97+
if (_package.name.indexOf('@') === 0) {
98+
return cb(httperror[403]('must be owner of package-scope'));
99+
} else {
100+
return cb(httperror[403]('must be owner of package-name'));
101+
}
111102
}
112103
}
113104
}
114105
}
115-
116-
}

src/index.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
// Copyright 2018 Roger Meier <[email protected]>
22
// SPDX-License-Identifier: MIT
3-
import GitLab from './gitlab';
3+
import VerdaccioGitLab from './gitlab';
44

5-
/**
6-
* A new instance of HTPasswd class.
7-
* @param {object} config
8-
* @param {object} stuff
9-
* @returns {object}
10-
*/
115
export default function(config, stuff) {
12-
return new GitLab(config, stuff);
6+
return new VerdaccioGitLab(config, stuff);
137
}

src/verdaccio.js

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
const globalTunnel = require('global-tunnel-ng');
2+
globalTunnel.initialize();
13
require('verdaccio/build/lib/cli');

0 commit comments

Comments
 (0)