@@ -9,18 +9,18 @@ import (
99 "fmt"
1010 "strings"
1111
12- "code.gitea.io/gitea/models/login "
12+ "code.gitea.io/gitea/models/auth "
1313 "code.gitea.io/gitea/services/auth/source/ldap"
1414
1515 "github.com/urfave/cli"
1616)
1717
1818type (
1919 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 )
2424 }
2525)
2626
@@ -168,23 +168,23 @@ var (
168168// newAuthService creates a service with default functions.
169169func newAuthService () * authService {
170170 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 ,
175175 }
176176}
177177
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 ) {
180180 if c .IsSet ("name" ) {
181- loginSource .Name = c .String ("name" )
181+ authSource .Name = c .String ("name" )
182182 }
183183 if c .IsSet ("not-active" ) {
184- loginSource .IsActive = ! c .Bool ("not-active" )
184+ authSource .IsActive = ! c .Bool ("not-active" )
185185 }
186186 if c .IsSet ("synchronize-users" ) {
187- loginSource .IsSyncEnabled = c .Bool ("synchronize-users" )
187+ authSource .IsSyncEnabled = c .Bool ("synchronize-users" )
188188 }
189189}
190190
@@ -275,23 +275,23 @@ func findLdapSecurityProtocolByName(name string) (ldap.SecurityProtocol, bool) {
275275 return 0 , false
276276}
277277
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.
279279// 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 ) {
281281 if err := argsSet (c , "id" ); err != nil {
282282 return nil , err
283283 }
284284
285- loginSource , err := a .getLoginSourceByID (c .Int64 ("id" ))
285+ authSource , err := a .getAuthSourceByID (c .Int64 ("id" ))
286286 if err != nil {
287287 return nil , err
288288 }
289289
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 ())
292292 }
293293
294- return loginSource , nil
294+ return authSource , nil
295295}
296296
297297// addLdapBindDn adds a new LDAP via Bind DN authentication source.
@@ -307,20 +307,20 @@ func (a *authService) addLdapBindDn(c *cli.Context) error {
307307 return err
308308 }
309309
310- loginSource := & login .Source {
311- Type : login .LDAP ,
310+ authSource := & auth .Source {
311+ Type : auth .LDAP ,
312312 IsActive : true , // active by default
313313 Cfg : & ldap.Source {
314314 Enabled : true , // always true
315315 },
316316 }
317317
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 {
320320 return err
321321 }
322322
323- return a .createLoginSource ( loginSource )
323+ return a .createAuthSource ( authSource )
324324}
325325
326326// updateLdapBindDn updates a new LDAP via Bind DN authentication source.
@@ -332,17 +332,17 @@ func (a *authService) updateLdapBindDn(c *cli.Context) error {
332332 return err
333333 }
334334
335- loginSource , err := a .getLoginSource (c , login .LDAP )
335+ authSource , err := a .getAuthSource (c , auth .LDAP )
336336 if err != nil {
337337 return err
338338 }
339339
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 {
342342 return err
343343 }
344344
345- return a .updateLoginSource ( loginSource )
345+ return a .updateAuthSource ( authSource )
346346}
347347
348348// addLdapSimpleAuth adds a new LDAP (simple auth) authentication source.
@@ -358,20 +358,20 @@ func (a *authService) addLdapSimpleAuth(c *cli.Context) error {
358358 return err
359359 }
360360
361- loginSource := & login .Source {
362- Type : login .DLDAP ,
361+ authSource := & auth .Source {
362+ Type : auth .DLDAP ,
363363 IsActive : true , // active by default
364364 Cfg : & ldap.Source {
365365 Enabled : true , // always true
366366 },
367367 }
368368
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 {
371371 return err
372372 }
373373
374- return a .createLoginSource ( loginSource )
374+ return a .createAuthSource ( authSource )
375375}
376376
377377// updateLdapBindDn updates a new LDAP (simple auth) authentication source.
@@ -383,15 +383,15 @@ func (a *authService) updateLdapSimpleAuth(c *cli.Context) error {
383383 return err
384384 }
385385
386- loginSource , err := a .getLoginSource (c , login .DLDAP )
386+ authSource , err := a .getAuthSource (c , auth .DLDAP )
387387 if err != nil {
388388 return err
389389 }
390390
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 {
393393 return err
394394 }
395395
396- return a .updateLoginSource ( loginSource )
396+ return a .updateAuthSource ( authSource )
397397}
0 commit comments