Skip to content

Commit 864d1b1

Browse files
strkandreynering
authored andcommitted
Fix type in unused constant name (#111)
* Write LDAP, SMTP, PAM, DLDAP back to all uppercase * Fix type in unused constant name * Other MixCased fixes * Complete MixerCasing of template constants * Re uppercase LTS and LDAPS suffixes * Uppercase JSON suffix in constant names * Proper case LoginNoType * Prefix unexported template path constants with "tpl"
1 parent c8c748a commit 864d1b1

File tree

10 files changed

+99
-99
lines changed

10 files changed

+99
-99
lines changed

models/issue_comment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const (
3232
// Reference from a commit (not part of a pull request)
3333
CommentTypeCommitRef
3434
// Reference from a comment
35-
CommentTypeComment_REF
35+
CommentTypeCommentRef
3636
// Reference from a pull request
3737
CommentTypePullRef
3838
)

models/login_source.go

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@ type LoginType int
2828

2929
// Note: new type must append to the end of list to maintain compatibility.
3030
const (
31-
LoginNotype LoginType = iota
31+
LoginNoType LoginType = iota
3232
LoginPlain // 1
33-
LoginLdap // 2
34-
LoginSmtp // 3
35-
LoginPam // 4
36-
LoginDldap // 5
33+
LoginLDAP // 2
34+
LoginSMTP // 3
35+
LoginPAM // 4
36+
LoginDLDAP // 5
3737
)
3838

3939
var LoginNames = map[LoginType]string{
40-
LoginLdap: "LDAP (via BindDN)",
41-
LoginDldap: "LDAP (simple auth)", // Via direct bind
42-
LoginSmtp: "SMTP",
43-
LoginPam: "PAM",
40+
LoginLDAP: "LDAP (via BindDN)",
41+
LoginDLDAP: "LDAP (simple auth)", // Via direct bind
42+
LoginSMTP: "SMTP",
43+
LoginPAM: "PAM",
4444
}
4545

4646
var SecurityProtocolNames = map[ldap.SecurityProtocol]string{
4747
ldap.SecurityProtocolUnencrypted: "Unencrypted",
48-
ldap.SecurityProtocolLdaps: "LDAPS",
49-
ldap.SecurityProtocolStartTls: "StartTLS",
48+
ldap.SecurityProtocolLDAPS: "LDAPS",
49+
ldap.SecurityProtocolStartTLS: "StartTLS",
5050
}
5151

5252
// Ensure structs implemented interface.
@@ -139,11 +139,11 @@ func (source *LoginSource) BeforeSet(colName string, val xorm.Cell) {
139139
switch colName {
140140
case "type":
141141
switch LoginType(Cell2Int64(val)) {
142-
case LoginLdap, LoginDldap:
142+
case LoginLDAP, LoginDLDAP:
143143
source.Cfg = new(LDAPConfig)
144-
case LoginSmtp:
144+
case LoginSMTP:
145145
source.Cfg = new(SMTPConfig)
146-
case LoginPam:
146+
case LoginPAM:
147147
source.Cfg = new(PAMConfig)
148148
default:
149149
panic("unrecognized login source type: " + com.ToStr(*val))
@@ -165,19 +165,19 @@ func (source *LoginSource) TypeName() string {
165165
}
166166

167167
func (source *LoginSource) IsLDAP() bool {
168-
return source.Type == LoginLdap
168+
return source.Type == LoginLDAP
169169
}
170170

171171
func (source *LoginSource) IsDLDAP() bool {
172-
return source.Type == LoginDldap
172+
return source.Type == LoginDLDAP
173173
}
174174

175175
func (source *LoginSource) IsSMTP() bool {
176-
return source.Type == LoginSmtp
176+
return source.Type == LoginSMTP
177177
}
178178

179179
func (source *LoginSource) IsPAM() bool {
180-
return source.Type == LoginPam
180+
return source.Type == LoginPAM
181181
}
182182

183183
func (source *LoginSource) HasTLS() bool {
@@ -188,9 +188,9 @@ func (source *LoginSource) HasTLS() bool {
188188

189189
func (source *LoginSource) UseTLS() bool {
190190
switch source.Type {
191-
case LoginLdap, LoginDldap:
191+
case LoginLDAP, LoginDLDAP:
192192
return source.LDAP().SecurityProtocol != ldap.SecurityProtocolUnencrypted
193-
case LoginSmtp:
193+
case LoginSMTP:
194194
return source.SMTP().TLS
195195
}
196196

@@ -199,9 +199,9 @@ func (source *LoginSource) UseTLS() bool {
199199

200200
func (source *LoginSource) SkipVerify() bool {
201201
switch source.Type {
202-
case LoginLdap, LoginDldap:
202+
case LoginLDAP, LoginDLDAP:
203203
return source.LDAP().SkipVerify
204-
case LoginSmtp:
204+
case LoginSMTP:
205205
return source.SMTP().SkipVerify
206206
}
207207

@@ -293,7 +293,7 @@ func composeFullName(firstname, surname, username string) string {
293293
// LoginViaLDAP queries if login/password is valid against the LDAP directory pool,
294294
// and create a local user if success when enabled.
295295
func LoginViaLDAP(user *User, login, passowrd string, source *LoginSource, autoRegister bool) (*User, error) {
296-
username, fn, sn, mail, isAdmin, succeed := source.Cfg.(*LDAPConfig).SearchEntry(login, passowrd, source.Type == LoginDldap)
296+
username, fn, sn, mail, isAdmin, succeed := source.Cfg.(*LDAPConfig).SearchEntry(login, passowrd, source.Type == LoginDLDAP)
297297
if !succeed {
298298
// User not in LDAP, do nothing
299299
return nil, ErrUserNotExist{0, login}
@@ -358,11 +358,11 @@ func (auth *smtpLoginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
358358
}
359359

360360
const (
361-
SmtpPlain = "PLAIN"
362-
SmtpLogin = "LOGIN"
361+
SMTPPlain = "PLAIN"
362+
SMTPLogin = "LOGIN"
363363
)
364364

365-
var SMTPAuths = []string{SmtpPlain, SmtpLogin}
365+
var SMTPAuths = []string{SMTPPlain, SMTPLogin}
366366

367367
func SMTPAuth(a smtp.Auth, cfg *SMTPConfig) error {
368368
c, err := smtp.Dial(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port))
@@ -411,9 +411,9 @@ func LoginViaSMTP(user *User, login, password string, sourceID int64, cfg *SMTPC
411411
}
412412

413413
var auth smtp.Auth
414-
if cfg.Auth == SmtpPlain {
414+
if cfg.Auth == SMTPPlain {
415415
auth = smtp.PlainAuth("", login, password, cfg.Host)
416-
} else if cfg.Auth == SmtpLogin {
416+
} else if cfg.Auth == SMTPLogin {
417417
auth = &smtpLoginAuth{login, password}
418418
} else {
419419
return nil, errors.New("Unsupported SMTP auth type")
@@ -445,7 +445,7 @@ func LoginViaSMTP(user *User, login, password string, sourceID int64, cfg *SMTPC
445445
Name: strings.ToLower(username),
446446
Email: login,
447447
Passwd: password,
448-
LoginType: LoginSmtp,
448+
LoginType: LoginSMTP,
449449
LoginSource: sourceID,
450450
LoginName: login,
451451
IsActive: true,
@@ -479,7 +479,7 @@ func LoginViaPAM(user *User, login, password string, sourceID int64, cfg *PAMCon
479479
Name: login,
480480
Email: login,
481481
Passwd: password,
482-
LoginType: LoginPam,
482+
LoginType: LoginPAM,
483483
LoginSource: sourceID,
484484
LoginName: login,
485485
IsActive: true,
@@ -493,11 +493,11 @@ func ExternalUserLogin(user *User, login, password string, source *LoginSource,
493493
}
494494

495495
switch source.Type {
496-
case LoginLdap, LoginDldap:
496+
case LoginLDAP, LoginDLDAP:
497497
return LoginViaLDAP(user, login, password, source, autoRegister)
498-
case LoginSmtp:
498+
case LoginSMTP:
499499
return LoginViaSMTP(user, login, password, source.ID, source.Cfg.(*SMTPConfig), autoRegister)
500-
case LoginPam:
500+
case LoginPAM:
501501
return LoginViaPAM(user, login, password, source.ID, source.Cfg.(*PAMConfig), autoRegister)
502502
}
503503

@@ -520,7 +520,7 @@ func UserSignIn(username, passowrd string) (*User, error) {
520520

521521
if hasUser {
522522
switch user.LoginType {
523-
case LoginNotype, LoginPlain:
523+
case LoginNoType, LoginPlain:
524524
if user.ValidatePassword(passowrd) {
525525
return user, nil
526526
}

models/webhook.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ var HookQueue = sync.NewUniqueQueue(setting.Webhook.QueueLength)
2828
type HookContentType int
2929

3030
const (
31-
ContentTypeJson HookContentType = iota + 1
31+
ContentTypeJSON HookContentType = iota + 1
3232
ContentTypeForm
3333
)
3434

3535
var hookContentTypes = map[string]HookContentType{
36-
"json": ContentTypeJson,
36+
"json": ContentTypeJSON,
3737
"form": ContentTypeForm,
3838
}
3939

@@ -44,7 +44,7 @@ func ToHookContentType(name string) HookContentType {
4444

4545
func (t HookContentType) Name() string {
4646
switch t {
47-
case ContentTypeJson:
47+
case ContentTypeJSON:
4848
return "json"
4949
case ContentTypeForm:
5050
return "form"
@@ -511,7 +511,7 @@ func (t *HookTask) deliver() {
511511
SetTLSClientConfig(&tls.Config{InsecureSkipVerify: setting.Webhook.SkipTLSVerify})
512512

513513
switch t.ContentType {
514-
case ContentTypeJson:
514+
case ContentTypeJSON:
515515
req = req.Header("Content-Type", "application/json").Body(t.PayloadContent)
516516
case ContentTypeForm:
517517
req.Param("payload", t.PayloadContent)

modules/auth/ldap/ldap.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ type SecurityProtocol int
2121
// Note: new type must be added at the end of list to maintain compatibility.
2222
const (
2323
SecurityProtocolUnencrypted SecurityProtocol = iota
24-
SecurityProtocolLdaps
25-
SecurityProtocolStartTls
24+
SecurityProtocolLDAPS
25+
SecurityProtocolStartTLS
2626
)
2727

2828
// Basic LDAP authentication service
@@ -118,7 +118,7 @@ func dial(ls *Source) (*ldap.Conn, error) {
118118
ServerName: ls.Host,
119119
InsecureSkipVerify: ls.SkipVerify,
120120
}
121-
if ls.SecurityProtocol == SecurityProtocolLdaps {
121+
if ls.SecurityProtocol == SecurityProtocolLDAPS {
122122
return ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", ls.Host, ls.Port), tlsCfg)
123123
}
124124

@@ -127,7 +127,7 @@ func dial(ls *Source) (*ldap.Conn, error) {
127127
return nil, fmt.Errorf("Dial: %v", err)
128128
}
129129

130-
if ls.SecurityProtocol == SecurityProtocolStartTls {
130+
if ls.SecurityProtocol == SecurityProtocolStartTLS {
131131
if err = conn.StartTLS(tlsCfg); err != nil {
132132
conn.Close()
133133
return nil, fmt.Errorf("StartTLS: %v", err)

modules/log/smtp.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const (
1717
)
1818

1919
// smtpWriter implements LoggerInterface and is used to send emails via given SMTP-server.
20-
type SmtpWriter struct {
20+
type SMTPWriter struct {
2121
Username string `json:"Username"`
2222
Password string `json:"password"`
2323
Host string `json:"Host"`
@@ -27,8 +27,8 @@ type SmtpWriter struct {
2727
}
2828

2929
// create smtp writer.
30-
func NewSmtpWriter() LoggerInterface {
31-
return &SmtpWriter{Level: TRACE}
30+
func NewSMTPWriter() LoggerInterface {
31+
return &SMTPWriter{Level: TRACE}
3232
}
3333

3434
// init smtp writer with json config.
@@ -41,13 +41,13 @@ func NewSmtpWriter() LoggerInterface {
4141
// "sendTos":["email1","email2"],
4242
// "level":LevelError
4343
// }
44-
func (sw *SmtpWriter) Init(jsonconfig string) error {
44+
func (sw *SMTPWriter) Init(jsonconfig string) error {
4545
return json.Unmarshal([]byte(jsonconfig), sw)
4646
}
4747

4848
// write message in smtp writer.
4949
// it will send an email with subject and only this message.
50-
func (s *SmtpWriter) WriteMsg(msg string, skip, level int) error {
50+
func (s *SMTPWriter) WriteMsg(msg string, skip, level int) error {
5151
if level < s.Level {
5252
return nil
5353
}
@@ -76,12 +76,12 @@ func (s *SmtpWriter) WriteMsg(msg string, skip, level int) error {
7676
)
7777
}
7878

79-
func (_ *SmtpWriter) Flush() {
79+
func (_ *SMTPWriter) Flush() {
8080
}
8181

82-
func (_ *SmtpWriter) Destroy() {
82+
func (_ *SMTPWriter) Destroy() {
8383
}
8484

8585
func init() {
86-
Register("smtp", NewSmtpWriter)
86+
Register("smtp", NewSMTPWriter)
8787
}

public/css/semantic-2.2.1.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

routers/admin/auths.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ type dropdownItem struct {
4848

4949
var (
5050
authSources = []dropdownItem{
51-
{models.LoginNames[models.LoginLdap], models.LoginLdap},
52-
{models.LoginNames[models.LoginDldap], models.LoginDldap},
53-
{models.LoginNames[models.LoginSmtp], models.LoginSmtp},
54-
{models.LoginNames[models.LoginPam], models.LoginPam},
51+
{models.LoginNames[models.LoginLDAP], models.LoginLDAP},
52+
{models.LoginNames[models.LoginDLDAP], models.LoginDLDAP},
53+
{models.LoginNames[models.LoginSMTP], models.LoginSMTP},
54+
{models.LoginNames[models.LoginPAM], models.LoginPAM},
5555
}
5656
securityProtocols = []dropdownItem{
5757
{models.SecurityProtocolNames[ldap.SecurityProtocolUnencrypted], ldap.SecurityProtocolUnencrypted},
58-
{models.SecurityProtocolNames[ldap.SecurityProtocolLdaps], ldap.SecurityProtocolLdaps},
59-
{models.SecurityProtocolNames[ldap.SecurityProtocolStartTls], ldap.SecurityProtocolStartTls},
58+
{models.SecurityProtocolNames[ldap.SecurityProtocolLDAPS], ldap.SecurityProtocolLDAPS},
59+
{models.SecurityProtocolNames[ldap.SecurityProtocolStartTLS], ldap.SecurityProtocolStartTLS},
6060
}
6161
)
6262

@@ -65,8 +65,8 @@ func NewAuthSource(ctx *context.Context) {
6565
ctx.Data["PageIsAdmin"] = true
6666
ctx.Data["PageIsAdminAuthentications"] = true
6767

68-
ctx.Data["type"] = models.LoginLdap
69-
ctx.Data["CurrentTypeName"] = models.LoginNames[models.LoginLdap]
68+
ctx.Data["type"] = models.LoginLDAP
69+
ctx.Data["CurrentTypeName"] = models.LoginNames[models.LoginLDAP]
7070
ctx.Data["CurrentSecurityProtocol"] = models.SecurityProtocolNames[ldap.SecurityProtocolUnencrypted]
7171
ctx.Data["smtp_auth"] = "PLAIN"
7272
ctx.Data["is_active"] = true
@@ -125,13 +125,13 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
125125
hasTLS := false
126126
var config core.Conversion
127127
switch models.LoginType(form.Type) {
128-
case models.LoginLdap, models.LoginDldap:
128+
case models.LoginLDAP, models.LoginDLDAP:
129129
config = parseLDAPConfig(form)
130130
hasTLS = ldap.SecurityProtocol(form.SecurityProtocol) > ldap.SecurityProtocolUnencrypted
131-
case models.LoginSmtp:
131+
case models.LoginSMTP:
132132
config = parseSMTPConfig(form)
133133
hasTLS = true
134-
case models.LoginPam:
134+
case models.LoginPAM:
135135
config = &models.PAMConfig{
136136
ServiceName: form.PAMServiceName,
137137
}
@@ -208,11 +208,11 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
208208

209209
var config core.Conversion
210210
switch models.LoginType(form.Type) {
211-
case models.LoginLdap, models.LoginDldap:
211+
case models.LoginLDAP, models.LoginDLDAP:
212212
config = parseLDAPConfig(form)
213-
case models.LoginSmtp:
213+
case models.LoginSMTP:
214214
config = parseSMTPConfig(form)
215-
case models.LoginPam:
215+
case models.LoginPAM:
216216
config = &models.PAMConfig{
217217
ServiceName: form.PAMServiceName,
218218
}

0 commit comments

Comments
 (0)