@@ -38,18 +38,14 @@ const BUILTIN_ACCESS_LEVEL_ANONYMOUS = ['$anonymous', '$all'];
38
38
// Level to apply on 'allow_access' calls when a package definition does not define one
39
39
const DEFAULT_ALLOW_ACCESS_LEVEL = [ '$all' ] ;
40
40
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 > ) {
53
49
this . logger = options . logger ;
54
50
this . config = config ;
55
51
this . options = options ;
@@ -75,14 +71,13 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
75
71
this . logger . info ( `[gitlab] publish control level: ${ this . publishLevel } ` ) ;
76
72
}
77
73
78
- authenticate ( user : string , password : string , cb : Callback ) {
74
+ public authenticate ( user : string , password : string , cb : Callback ) {
79
75
this . logger . trace ( `[gitlab] authenticate called for user: ${ user } ` ) ;
80
76
81
77
// Try to find the user groups in the cache
82
78
const cachedUserGroups = this . _getCachedUserGroups ( user , password ) ;
83
79
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 ( ) ) ;
86
81
return cb ( null , cachedUserGroups . publish ) ;
87
82
}
88
83
@@ -107,8 +102,7 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
107
102
// - for publish, the logged in user id and all the groups they can reach as configured with access level `$auth.gitlab.publish`
108
103
const gitlabPublishQueryParams = { min_access_level : publishLevelId } ;
109
104
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 ( ) ) ;
112
106
113
107
const groupsPromise = GitlabAPI . Groups . all ( gitlabPublishQueryParams ) . then ( groups => {
114
108
return groups . filter ( group => group . path === group . full_path ) . map ( group => group . path ) ;
@@ -124,8 +118,7 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
124
118
this . _setCachedUserGroups ( user , password , { publish : realGroups } ) ;
125
119
126
120
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 ( ) ) ;
129
122
130
123
return cb ( null , realGroups ) ;
131
124
} )
@@ -140,17 +133,17 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
140
133
} ) ;
141
134
}
142
135
143
- adduser ( user : string , password : string , cb : Callback ) {
136
+ public adduser ( user : string , password : string , cb : Callback ) {
144
137
this . logger . trace ( `[gitlab] adduser called for user: ${ user } ` ) ;
145
138
return cb ( null , true ) ;
146
139
}
147
140
148
- changePassword ( user : string , password : string , newPassword : string , cb : Callback ) {
141
+ public changePassword ( user : string , password : string , newPassword : string , cb : Callback ) {
149
142
this . logger . trace ( `[gitlab] changePassword called for user: ${ user } ` ) ;
150
143
return cb ( getInternalError ( 'You are using verdaccio-gitlab integration. Please change your password in gitlab' ) ) ;
151
144
}
152
145
153
- allow_access ( user : RemoteUser , _package : VerdaccioGitlabPackageAccess & PackageAccess , cb : Callback ) {
146
+ public allow_access ( user : RemoteUser , _package : VerdaccioGitlabPackageAccess & PackageAccess , cb : Callback ) {
154
147
if ( ! _package . gitlab ) return cb ( null , false ) ;
155
148
156
149
const packageAccess = _package . access && _package . access . length > 0 ? _package . access : DEFAULT_ALLOW_ACCESS_LEVEL ;
@@ -171,7 +164,7 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
171
164
}
172
165
}
173
166
174
- allow_publish ( user : RemoteUser , _package : VerdaccioGitlabPackageAccess & PackageAccess , cb : Callback ) {
167
+ public allow_publish ( user : RemoteUser , _package : VerdaccioGitlabPackageAccess & PackageAccess , cb : Callback ) {
175
168
if ( ! _package . gitlab ) return cb ( null , false ) ;
176
169
177
170
const packageScopePermit = false ;
@@ -205,7 +198,7 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
205
198
}
206
199
}
207
200
208
- _matchGroupWithPackage ( real_group : string , package_name : string ) : boolean {
201
+ private _matchGroupWithPackage ( real_group : string , package_name : string ) : boolean {
209
202
if ( real_group === package_name ) {
210
203
return true ;
211
204
}
@@ -230,15 +223,15 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
230
223
return false ;
231
224
}
232
225
233
- _getCachedUserGroups ( username : string , password : string ) : UserDataGroups | null {
226
+ private _getCachedUserGroups ( username : string , password : string ) : UserDataGroups | null {
234
227
if ( ! this . authCache ) {
235
228
return null ;
236
229
}
237
230
const userData = this . authCache . findUser ( username , password ) ;
238
231
return ( userData || { } ) . groups || null ;
239
232
}
240
233
241
- _setCachedUserGroups ( username : string , password : string , groups : UserDataGroups ) : boolean {
234
+ private _setCachedUserGroups ( username : string , password : string , groups : UserDataGroups ) : boolean {
242
235
if ( ! this . authCache ) {
243
236
return false ;
244
237
}
0 commit comments