@@ -46,50 +46,41 @@ export default class VerdaccioGitLab implements IPluginAuth {
46
46
logger : Logger ;
47
47
publishLevel : VerdaccioGitlabAccessLevel ;
48
48
49
- constructor (
50
- config : VerdaccioGitlabConfig ,
51
- options : PluginOptions
52
- ) {
49
+ constructor ( config : VerdaccioGitlabConfig , options : PluginOptions ) {
53
50
this . logger = options . logger ;
54
-
55
51
this . config = config ;
56
52
this . options = options ;
57
-
58
53
this . logger . info ( `[gitlab] url: ${ this . config . url } ` ) ;
59
54
60
55
if ( ( this . config . authCache || { } ) . enabled === false ) {
61
56
this . logger . info ( '[gitlab] auth cache disabled' ) ;
62
57
} else {
63
58
const ttl = ( this . config . authCache || { } ) . ttl || AuthCache . DEFAULT_TTL ;
64
59
this . authCache = new AuthCache ( this . logger , ttl ) ;
65
-
66
60
this . logger . info ( `[gitlab] initialized auth cache with ttl: ${ ttl } seconds` ) ;
67
61
}
68
62
69
63
if ( this . config . legacy_mode ) {
70
64
this . publishLevel = '$owner' ;
71
-
72
65
this . logger . info ( '[gitlab] legacy mode active pre-gitlab v11.2 active, publish is only allowed to group owners' ) ;
73
66
} else {
74
67
this . publishLevel = '$maintainer' ;
75
68
if ( this . config . publish ) {
76
69
this . publishLevel = this . config . publish ;
77
70
}
78
71
79
- if ( ! Object . keys ( ACCESS_LEVEL_MAPPING ) . includes ( this . publishLevel ) ) {
72
+ if ( ! Object . keys ( ACCESS_LEVEL_MAPPING ) . includes ( this . publishLevel ) ) {
80
73
throw Error ( `[gitlab] invalid publish access level configuration: ${ this . publishLevel } ` ) ;
81
74
}
82
75
this . logger . info ( `[gitlab] publish control level: ${ this . publishLevel } ` ) ;
83
76
}
84
-
85
77
}
86
78
87
79
authenticate ( user : string , password : string , cb : Callback ) {
88
80
this . logger . trace ( `[gitlab] authenticate called for user: ${ user } ` ) ;
89
81
90
82
// Try to find the user groups in the cache
91
83
const cachedUserGroups = this . _getCachedUserGroups ( user , password ) ;
92
-
93
84
if ( cachedUserGroups ) {
94
85
this . logger . debug ( `[gitlab] user: ${ user } found in cache, authenticated with groups:` , cachedUserGroups ) ;
95
86
return cb ( null , cachedUserGroups . publish ) ;
@@ -121,11 +112,9 @@ export default class VerdaccioGitLab implements IPluginAuth {
121
112
// In legacy mode, the groups are:
122
113
// - for access, themselves and all groups with access level $owner
123
114
// - for publish, the logged in user id and all the groups they can reach as `$owner`
124
-
125
115
const gitlabPublishQueryParams = this . config . legacy_mode ? { owned : true } : { min_access_level : publishLevelId } ;
126
116
const pPublishGroups = GitlabAPI . Groups . all ( gitlabPublishQueryParams ) . then ( groups => {
127
117
this . logger . trace ( '[gitlab] querying gitlab user groups with params:' , gitlabPublishQueryParams ) ;
128
-
129
118
this . _addGroupsToArray ( groups , userGroups . publish ) ;
130
119
} ) . catch ( error => {
131
120
this . logger . error ( `[gitlab] user: ${ user } error querying publish groups: ${ error } ` ) ;
@@ -135,15 +124,13 @@ export default class VerdaccioGitLab implements IPluginAuth {
135
124
const pGroups = Promise . all ( [ pPublishGroups ] ) ;
136
125
return pGroups . then ( ( ) => {
137
126
this . _setCachedUserGroups ( user , password , userGroups ) ;
138
-
139
127
this . logger . info ( `[gitlab] user: ${ user } successfully authenticated` ) ;
140
128
this . logger . debug ( `[gitlab] user: ${ user } , with groups:` , userGroups ) ;
141
129
return cb ( null , userGroups . publish ) ;
142
130
} ) . catch ( error => {
143
131
this . logger . error ( `[gitlab] error authenticating: ${ error } ` ) ;
144
132
return cb ( httperror [ 500 ] ( 'error authenticating' ) ) ;
145
133
} ) ;
146
-
147
134
} ) . catch ( error => {
148
135
this . logger . info ( `[gitlab] user: ${ user } error authenticating: ${ error . message || { } } ` ) ;
149
136
if ( error ) {
@@ -202,15 +189,15 @@ export default class VerdaccioGitLab implements IPluginAuth {
202
189
}
203
190
204
191
_getCachedUserGroups ( username : string , password : string ) : ?UserDataGroups {
205
- if ( ! this . authCache ) {
192
+ if ( ! this . authCache ) {
206
193
return null ;
207
194
}
208
195
const userData = this . authCache . findUser ( username , password ) ;
209
196
return ( userData || { } ) . groups || null ;
210
197
}
211
198
212
199
_setCachedUserGroups ( username : string , password : string , groups : UserDataGroups ) : boolean {
213
- if ( ! this . authCache ) {
200
+ if ( ! this . authCache ) {
214
201
return false ;
215
202
}
216
203
this . logger . debug ( `[gitlab] saving data in cache for user: ${ username } ` ) ;
0 commit comments