Skip to content

Commit bb1ff63

Browse files
committed
Extract out login-sources from models
Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent 1116a1f commit bb1ff63

28 files changed

+657
-473
lines changed

cmd/admin.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515

1616
"code.gitea.io/gitea/models"
1717
"code.gitea.io/gitea/modules/auth/oauth2"
18+
oauth2Service "code.gitea.io/gitea/services/auth/source/oauth2"
19+
1820
"code.gitea.io/gitea/modules/git"
1921
"code.gitea.io/gitea/modules/graceful"
2022
"code.gitea.io/gitea/modules/log"
@@ -597,7 +599,7 @@ func runRegenerateKeys(_ *cli.Context) error {
597599
return models.RewriteAllPublicKeys()
598600
}
599601

600-
func parseOAuth2Config(c *cli.Context) *models.OAuth2Config {
602+
func parseOAuth2Config(c *cli.Context) *oauth2Service.Source {
601603
var customURLMapping *oauth2.CustomURLMapping
602604
if c.IsSet("use-custom-urls") {
603605
customURLMapping = &oauth2.CustomURLMapping{
@@ -609,7 +611,7 @@ func parseOAuth2Config(c *cli.Context) *models.OAuth2Config {
609611
} else {
610612
customURLMapping = nil
611613
}
612-
return &models.OAuth2Config{
614+
return &oauth2Service.Source{
613615
Provider: c.String("provider"),
614616
ClientID: c.String("key"),
615617
ClientSecret: c.String("secret"),
@@ -646,7 +648,7 @@ func runUpdateOauth(c *cli.Context) error {
646648
return err
647649
}
648650

649-
oAuth2Config := source.OAuth2()
651+
oAuth2Config := source.Cfg.(*oauth2Service.Source)
650652

651653
if c.IsSet("name") {
652654
source.Name = c.String("name")

cmd/admin_auth_ldap.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"code.gitea.io/gitea/models"
1212
"code.gitea.io/gitea/modules/auth/ldap"
13+
ldapService "code.gitea.io/gitea/services/auth/source/ldap"
1314

1415
"github.com/urfave/cli"
1516
)
@@ -180,7 +181,7 @@ func parseLoginSource(c *cli.Context, loginSource *models.LoginSource) {
180181
}
181182

182183
// parseLdapConfig assigns values on config according to command line flags.
183-
func parseLdapConfig(c *cli.Context, config *models.LDAPConfig) error {
184+
func parseLdapConfig(c *cli.Context, config *ldapService.Source) error {
184185
if c.IsSet("name") {
185186
config.Source.Name = c.String("name")
186187
}
@@ -251,7 +252,7 @@ func parseLdapConfig(c *cli.Context, config *models.LDAPConfig) error {
251252
// findLdapSecurityProtocolByName finds security protocol by its name ignoring case.
252253
// It returns the value of the security protocol and if it was found.
253254
func findLdapSecurityProtocolByName(name string) (ldap.SecurityProtocol, bool) {
254-
for i, n := range models.SecurityProtocolNames {
255+
for i, n := range ldap.SecurityProtocolNames {
255256
if strings.EqualFold(name, n) {
256257
return i, true
257258
}
@@ -291,15 +292,15 @@ func (a *authService) addLdapBindDn(c *cli.Context) error {
291292
loginSource := &models.LoginSource{
292293
Type: models.LoginLDAP,
293294
IsActived: true, // active by default
294-
Cfg: &models.LDAPConfig{
295+
Cfg: &ldapService.Source{
295296
Source: &ldap.Source{
296297
Enabled: true, // always true
297298
},
298299
},
299300
}
300301

301302
parseLoginSource(c, loginSource)
302-
if err := parseLdapConfig(c, loginSource.LDAP()); err != nil {
303+
if err := parseLdapConfig(c, loginSource.Cfg.(*ldapService.Source)); err != nil {
303304
return err
304305
}
305306

@@ -318,7 +319,7 @@ func (a *authService) updateLdapBindDn(c *cli.Context) error {
318319
}
319320

320321
parseLoginSource(c, loginSource)
321-
if err := parseLdapConfig(c, loginSource.LDAP()); err != nil {
322+
if err := parseLdapConfig(c, loginSource.Cfg.(*ldapService.Source)); err != nil {
322323
return err
323324
}
324325

@@ -338,15 +339,15 @@ func (a *authService) addLdapSimpleAuth(c *cli.Context) error {
338339
loginSource := &models.LoginSource{
339340
Type: models.LoginDLDAP,
340341
IsActived: true, // active by default
341-
Cfg: &models.LDAPConfig{
342+
Cfg: &ldapService.Source{
342343
Source: &ldap.Source{
343344
Enabled: true, // always true
344345
},
345346
},
346347
}
347348

348349
parseLoginSource(c, loginSource)
349-
if err := parseLdapConfig(c, loginSource.LDAP()); err != nil {
350+
if err := parseLdapConfig(c, loginSource.Cfg.(*ldapService.Source)); err != nil {
350351
return err
351352
}
352353

@@ -365,7 +366,7 @@ func (a *authService) updateLdapSimpleAuth(c *cli.Context) error {
365366
}
366367

367368
parseLoginSource(c, loginSource)
368-
if err := parseLdapConfig(c, loginSource.LDAP()); err != nil {
369+
if err := parseLdapConfig(c, loginSource.Cfg.(*ldapService.Source)); err != nil {
369370
return err
370371
}
371372

0 commit comments

Comments
 (0)