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