Skip to content

Commit 21afb3d

Browse files
style: set member accessibility explicit
1 parent a9e1246 commit 21afb3d

File tree

5 files changed

+46
-54
lines changed

5 files changed

+46
-54
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@
106106
"@typescript-eslint/no-var-requires": 0,
107107
"@typescript-eslint/ban-ts-ignore": 0,
108108
"@typescript-eslint/no-explicit-any": 0,
109-
"@typescript-eslint/explicit-function-return-type": 0,
110-
"@typescript-eslint/explicit-member-accessibility": 0
109+
"@typescript-eslint/explicit-function-return-type": 0
111110
},
112111
"ignorePatterns": ["build/", "node_modules/"]
113112
}

src/authcache.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ import { Logger } from '@verdaccio/types';
77
import NodeCache from 'node-cache';
88

99
export class AuthCache {
10-
logger: Logger;
11-
ttl: number;
12-
storage: NodeCache;
10+
private logger: Logger;
11+
private ttl: number;
12+
private storage: NodeCache;
1313

14-
static get DEFAULT_TTL() {
14+
public static get DEFAULT_TTL() {
1515
return 300;
1616
}
1717

18-
static _generateKeyHash(username: string, password: string) {
18+
private static _generateKeyHash(username: string, password: string) {
1919
const sha = Crypto.createHash('sha256');
2020
sha.update(JSON.stringify({ username: username, password: password }));
2121
return sha.digest('hex');
2222
}
2323

24-
constructor(logger: Logger, ttl?: number) {
24+
public constructor(logger: Logger, ttl?: number) {
2525
this.logger = logger;
2626
this.ttl = ttl || AuthCache.DEFAULT_TTL;
2727

@@ -34,11 +34,11 @@ export class AuthCache {
3434
});
3535
}
3636

37-
findUser(username: string, password: string): UserData {
37+
public findUser(username: string, password: string): UserData {
3838
return this.storage.get(AuthCache._generateKeyHash(username, password)) as UserData;
3939
}
4040

41-
storeUser(username: string, password: string, userData: UserData): boolean {
41+
public storeUser(username: string, password: string, userData: UserData): boolean {
4242
return this.storage.set(AuthCache._generateKeyHash(username, password), userData);
4343
}
4444
}
@@ -48,20 +48,20 @@ export type UserDataGroups = {
4848
};
4949

5050
export class UserData {
51-
_username: string;
52-
_groups: UserDataGroups;
51+
private _username: string;
52+
private _groups: UserDataGroups;
5353

54-
get username(): string {
54+
public get username(): string {
5555
return this._username;
5656
}
57-
get groups(): UserDataGroups {
57+
public get groups(): UserDataGroups {
5858
return this._groups;
5959
}
60-
set groups(groups: UserDataGroups) {
60+
public set groups(groups: UserDataGroups) {
6161
this._groups = groups;
6262
}
6363

64-
constructor(username: string, groups: UserDataGroups) {
64+
public constructor(username: string, groups: UserDataGroups) {
6565
this._username = username;
6666
this._groups = groups;
6767
}

src/gitlab.ts

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,14 @@ const BUILTIN_ACCESS_LEVEL_ANONYMOUS = ['$anonymous', '$all'];
3838
// Level to apply on 'allow_access' calls when a package definition does not define one
3939
const DEFAULT_ALLOW_ACCESS_LEVEL = ['$all'];
4040

41-
export interface VerdaccioGitLabPlugin extends IPluginAuth<VerdaccioGitlabConfig> {
42-
authCache?: AuthCache;
43-
}
44-
45-
export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
46-
options: PluginOptions<VerdaccioGitlabConfig>;
47-
config: VerdaccioGitlabConfig;
48-
authCache?: AuthCache;
49-
logger: Logger;
50-
publishLevel: VerdaccioGitlabAccessLevel;
51-
52-
constructor(config: VerdaccioGitlabConfig, options: PluginOptions<VerdaccioGitlabConfig>) {
41+
export default class VerdaccioGitLab implements IPluginAuth<VerdaccioGitlabConfig> {
42+
private options: PluginOptions<VerdaccioGitlabConfig>;
43+
private config: VerdaccioGitlabConfig;
44+
private authCache?: AuthCache;
45+
private logger: Logger;
46+
private publishLevel: VerdaccioGitlabAccessLevel;
47+
48+
public constructor(config: VerdaccioGitlabConfig, options: PluginOptions<VerdaccioGitlabConfig>) {
5349
this.logger = options.logger;
5450
this.config = config;
5551
this.options = options;
@@ -75,14 +71,13 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
7571
this.logger.info(`[gitlab] publish control level: ${this.publishLevel}`);
7672
}
7773

78-
authenticate(user: string, password: string, cb: Callback) {
74+
public authenticate(user: string, password: string, cb: Callback) {
7975
this.logger.trace(`[gitlab] authenticate called for user: ${user}`);
8076

8177
// Try to find the user groups in the cache
8278
const cachedUserGroups = this._getCachedUserGroups(user, password);
8379
if (cachedUserGroups) {
84-
// @ts-ignore
85-
this.logger.debug(`[gitlab] user: ${user} found in cache, authenticated with groups:`, cachedUserGroups);
80+
this.logger.debug(`[gitlab] user: ${user} found in cache, authenticated with groups:`, cachedUserGroups.toString());
8681
return cb(null, cachedUserGroups.publish);
8782
}
8883

@@ -107,8 +102,7 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
107102
// - for publish, the logged in user id and all the groups they can reach as configured with access level `$auth.gitlab.publish`
108103
const gitlabPublishQueryParams = { min_access_level: publishLevelId };
109104

110-
// @ts-ignore
111-
this.logger.trace('[gitlab] querying gitlab user groups with params:', gitlabPublishQueryParams);
105+
this.logger.trace('[gitlab] querying gitlab user groups with params:', gitlabPublishQueryParams.toString());
112106

113107
const groupsPromise = GitlabAPI.Groups.all(gitlabPublishQueryParams).then(groups => {
114108
return groups.filter(group => group.path === group.full_path).map(group => group.path);
@@ -124,8 +118,7 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
124118
this._setCachedUserGroups(user, password, { publish: realGroups });
125119

126120
this.logger.info(`[gitlab] user: ${user} successfully authenticated`);
127-
// @ts-ignore
128-
this.logger.debug(`[gitlab] user: ${user}, with groups:`, realGroups);
121+
this.logger.debug(`[gitlab] user: ${user}, with groups:`, realGroups.toString());
129122

130123
return cb(null, realGroups);
131124
})
@@ -140,17 +133,17 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
140133
});
141134
}
142135

143-
adduser(user: string, password: string, cb: Callback) {
136+
public adduser(user: string, password: string, cb: Callback) {
144137
this.logger.trace(`[gitlab] adduser called for user: ${user}`);
145138
return cb(null, true);
146139
}
147140

148-
changePassword(user: string, password: string, newPassword: string, cb: Callback) {
141+
public changePassword(user: string, password: string, newPassword: string, cb: Callback) {
149142
this.logger.trace(`[gitlab] changePassword called for user: ${user}`);
150143
return cb(getInternalError('You are using verdaccio-gitlab integration. Please change your password in gitlab'));
151144
}
152145

153-
allow_access(user: RemoteUser, _package: VerdaccioGitlabPackageAccess & PackageAccess, cb: Callback) {
146+
public allow_access(user: RemoteUser, _package: VerdaccioGitlabPackageAccess & PackageAccess, cb: Callback) {
154147
if (!_package.gitlab) return cb(null, false);
155148

156149
const packageAccess = _package.access && _package.access.length > 0 ? _package.access : DEFAULT_ALLOW_ACCESS_LEVEL;
@@ -171,7 +164,7 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
171164
}
172165
}
173166

174-
allow_publish(user: RemoteUser, _package: VerdaccioGitlabPackageAccess & PackageAccess, cb: Callback) {
167+
public allow_publish(user: RemoteUser, _package: VerdaccioGitlabPackageAccess & PackageAccess, cb: Callback) {
175168
if (!_package.gitlab) return cb(null, false);
176169

177170
const packageScopePermit = false;
@@ -205,7 +198,7 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
205198
}
206199
}
207200

208-
_matchGroupWithPackage(real_group: string, package_name: string): boolean {
201+
private _matchGroupWithPackage(real_group: string, package_name: string): boolean {
209202
if (real_group === package_name) {
210203
return true;
211204
}
@@ -230,15 +223,15 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
230223
return false;
231224
}
232225

233-
_getCachedUserGroups(username: string, password: string): UserDataGroups | null {
226+
private _getCachedUserGroups(username: string, password: string): UserDataGroups | null {
234227
if (!this.authCache) {
235228
return null;
236229
}
237230
const userData = this.authCache.findUser(username, password);
238231
return (userData || {}).groups || null;
239232
}
240233

241-
_setCachedUserGroups(username: string, password: string, groups: UserDataGroups): boolean {
234+
private _setCachedUserGroups(username: string, password: string, groups: UserDataGroups): boolean {
242235
if (!this.authCache) {
243236
return false;
244237
}

test/functional/lib/environment.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ import { PORT_GITLAB_EXPRESS_MOCK, DOMAIN_SERVERS, PORT_SERVER_1 } from '../conf
1212
import GitlabServer from './mock_gitlab_server';
1313

1414
class FunctionalEnvironment extends NodeEnvironment {
15-
config: any;
15+
private config: any;
1616

17-
constructor(config: any) {
17+
public constructor(config: any) {
1818
super(config);
1919
}
2020

21-
async startWeb() {
21+
public async startWeb() {
2222
const gitlab: any = new GitlabServer();
2323

2424
return await gitlab.start(PORT_GITLAB_EXPRESS_MOCK);
2525
}
2626

27-
async setup() {
27+
public async setup() {
2828
const SILENCE_LOG = !process.env.VERDACCIO_DEBUG;
2929
// @ts-ignore
3030
const DEBUG_INJECT: boolean = process.env.VERDACCIO_DEBUG_INJECT ? process.env.VERDACCIO_DEBUG_INJECT : false;
@@ -64,7 +64,7 @@ class FunctionalEnvironment extends NodeEnvironment {
6464
this.global.__SERVERS__ = serverList;
6565
}
6666

67-
async teardown() {
67+
public async teardown() {
6868
await super.teardown();
6969
console.log(chalk.yellow('Teardown Test Environment.'));
7070
// shutdown verdaccio
@@ -75,7 +75,7 @@ class FunctionalEnvironment extends NodeEnvironment {
7575
this.global.__GITLAB_SERVER__.server.close();
7676
}
7777

78-
runScript(script: string) {
78+
private runScript(script: string) {
7979
return super.runScript(script);
8080
}
8181
}

test/functional/lib/mock_gitlab_server.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import { GITLAB_DATA, CREDENTIALS } from '../config.functional';
66
import { GITLAB, HTTP_STATUS } from '../../lib/constants';
77

88
export default class GitlabServer {
9-
app: any;
10-
server: any;
11-
expectedToken: string;
9+
private app: any;
10+
private server: any;
11+
private expectedToken: string;
1212

13-
constructor() {
13+
public constructor() {
1414
this.app = express();
1515
this.expectedToken = CREDENTIALS.password;
1616
}
1717

18-
start(port: number): Promise<any> {
18+
public start(port: number): Promise<any> {
1919
return new Promise(resolve => {
2020
this.app.use(bodyParser.json());
2121
this.app.use(
@@ -50,7 +50,7 @@ export default class GitlabServer {
5050
});
5151
}
5252

53-
_checkAuthentication(req: any, res: any, cb: any) {
53+
private _checkAuthentication(req: any, res: any, cb: any) {
5454
if (req.get('private-token') === this.expectedToken) {
5555
cb();
5656
} else {

0 commit comments

Comments
 (0)