@@ -9,18 +9,18 @@ import (
9
9
"fmt"
10
10
"strings"
11
11
12
- "code.gitea.io/gitea/models/login "
12
+ "code.gitea.io/gitea/models/auth "
13
13
"code.gitea.io/gitea/services/auth/source/ldap"
14
14
15
15
"github.com/urfave/cli"
16
16
)
17
17
18
18
type (
19
19
authService struct {
20
- initDB func (ctx context.Context ) error
21
- createLoginSource func (loginSource * login .Source ) error
22
- updateLoginSource func (loginSource * login .Source ) error
23
- getLoginSourceByID func (id int64 ) (* login .Source , error )
20
+ initDB func (ctx context.Context ) error
21
+ createAuthSource func (* auth .Source ) error
22
+ updateAuthSource func (* auth .Source ) error
23
+ getAuthSourceByID func (id int64 ) (* auth .Source , error )
24
24
}
25
25
)
26
26
@@ -168,23 +168,23 @@ var (
168
168
// newAuthService creates a service with default functions.
169
169
func newAuthService () * authService {
170
170
return & authService {
171
- initDB : initDB ,
172
- createLoginSource : login .CreateSource ,
173
- updateLoginSource : login .UpdateSource ,
174
- getLoginSourceByID : login .GetSourceByID ,
171
+ initDB : initDB ,
172
+ createAuthSource : auth .CreateSource ,
173
+ updateAuthSource : auth .UpdateSource ,
174
+ getAuthSourceByID : auth .GetSourceByID ,
175
175
}
176
176
}
177
177
178
- // parseLoginSource assigns values on loginSource according to command line flags.
179
- func parseLoginSource (c * cli.Context , loginSource * login .Source ) {
178
+ // parseAuthSource assigns values on authSource according to command line flags.
179
+ func parseAuthSource (c * cli.Context , authSource * auth .Source ) {
180
180
if c .IsSet ("name" ) {
181
- loginSource .Name = c .String ("name" )
181
+ authSource .Name = c .String ("name" )
182
182
}
183
183
if c .IsSet ("not-active" ) {
184
- loginSource .IsActive = ! c .Bool ("not-active" )
184
+ authSource .IsActive = ! c .Bool ("not-active" )
185
185
}
186
186
if c .IsSet ("synchronize-users" ) {
187
- loginSource .IsSyncEnabled = c .Bool ("synchronize-users" )
187
+ authSource .IsSyncEnabled = c .Bool ("synchronize-users" )
188
188
}
189
189
}
190
190
@@ -275,23 +275,23 @@ func findLdapSecurityProtocolByName(name string) (ldap.SecurityProtocol, bool) {
275
275
return 0 , false
276
276
}
277
277
278
- // getLoginSource gets the login source by its id defined in the command line flags.
278
+ // getAuthSource gets the login source by its id defined in the command line flags.
279
279
// It returns an error if the id is not set, does not match any source or if the source is not of expected type.
280
- func (a * authService ) getLoginSource (c * cli.Context , loginType login .Type ) (* login .Source , error ) {
280
+ func (a * authService ) getAuthSource (c * cli.Context , authType auth .Type ) (* auth .Source , error ) {
281
281
if err := argsSet (c , "id" ); err != nil {
282
282
return nil , err
283
283
}
284
284
285
- loginSource , err := a .getLoginSourceByID (c .Int64 ("id" ))
285
+ authSource , err := a .getAuthSourceByID (c .Int64 ("id" ))
286
286
if err != nil {
287
287
return nil , err
288
288
}
289
289
290
- if loginSource .Type != loginType {
291
- return nil , fmt .Errorf ("Invalid authentication type. expected: %s, actual: %s" , loginType .String (), loginSource .Type .String ())
290
+ if authSource .Type != authType {
291
+ return nil , fmt .Errorf ("Invalid authentication type. expected: %s, actual: %s" , authType .String (), authSource .Type .String ())
292
292
}
293
293
294
- return loginSource , nil
294
+ return authSource , nil
295
295
}
296
296
297
297
// addLdapBindDn adds a new LDAP via Bind DN authentication source.
@@ -307,20 +307,20 @@ func (a *authService) addLdapBindDn(c *cli.Context) error {
307
307
return err
308
308
}
309
309
310
- loginSource := & login .Source {
311
- Type : login .LDAP ,
310
+ authSource := & auth .Source {
311
+ Type : auth .LDAP ,
312
312
IsActive : true , // active by default
313
313
Cfg : & ldap.Source {
314
314
Enabled : true , // always true
315
315
},
316
316
}
317
317
318
- parseLoginSource (c , loginSource )
319
- if err := parseLdapConfig (c , loginSource .Cfg .(* ldap.Source )); err != nil {
318
+ parseAuthSource (c , authSource )
319
+ if err := parseLdapConfig (c , authSource .Cfg .(* ldap.Source )); err != nil {
320
320
return err
321
321
}
322
322
323
- return a .createLoginSource ( loginSource )
323
+ return a .createAuthSource ( authSource )
324
324
}
325
325
326
326
// updateLdapBindDn updates a new LDAP via Bind DN authentication source.
@@ -332,17 +332,17 @@ func (a *authService) updateLdapBindDn(c *cli.Context) error {
332
332
return err
333
333
}
334
334
335
- loginSource , err := a .getLoginSource (c , login .LDAP )
335
+ authSource , err := a .getAuthSource (c , auth .LDAP )
336
336
if err != nil {
337
337
return err
338
338
}
339
339
340
- parseLoginSource (c , loginSource )
341
- if err := parseLdapConfig (c , loginSource .Cfg .(* ldap.Source )); err != nil {
340
+ parseAuthSource (c , authSource )
341
+ if err := parseLdapConfig (c , authSource .Cfg .(* ldap.Source )); err != nil {
342
342
return err
343
343
}
344
344
345
- return a .updateLoginSource ( loginSource )
345
+ return a .updateAuthSource ( authSource )
346
346
}
347
347
348
348
// addLdapSimpleAuth adds a new LDAP (simple auth) authentication source.
@@ -358,20 +358,20 @@ func (a *authService) addLdapSimpleAuth(c *cli.Context) error {
358
358
return err
359
359
}
360
360
361
- loginSource := & login .Source {
362
- Type : login .DLDAP ,
361
+ authSource := & auth .Source {
362
+ Type : auth .DLDAP ,
363
363
IsActive : true , // active by default
364
364
Cfg : & ldap.Source {
365
365
Enabled : true , // always true
366
366
},
367
367
}
368
368
369
- parseLoginSource (c , loginSource )
370
- if err := parseLdapConfig (c , loginSource .Cfg .(* ldap.Source )); err != nil {
369
+ parseAuthSource (c , authSource )
370
+ if err := parseLdapConfig (c , authSource .Cfg .(* ldap.Source )); err != nil {
371
371
return err
372
372
}
373
373
374
- return a .createLoginSource ( loginSource )
374
+ return a .createAuthSource ( authSource )
375
375
}
376
376
377
377
// updateLdapBindDn updates a new LDAP (simple auth) authentication source.
@@ -383,15 +383,15 @@ func (a *authService) updateLdapSimpleAuth(c *cli.Context) error {
383
383
return err
384
384
}
385
385
386
- loginSource , err := a .getLoginSource (c , login .DLDAP )
386
+ authSource , err := a .getAuthSource (c , auth .DLDAP )
387
387
if err != nil {
388
388
return err
389
389
}
390
390
391
- parseLoginSource (c , loginSource )
392
- if err := parseLdapConfig (c , loginSource .Cfg .(* ldap.Source )); err != nil {
391
+ parseAuthSource (c , authSource )
392
+ if err := parseLdapConfig (c , authSource .Cfg .(* ldap.Source )); err != nil {
393
393
return err
394
394
}
395
395
396
- return a .updateLoginSource ( loginSource )
396
+ return a .updateAuthSource ( authSource )
397
397
}
0 commit comments