Skip to content

Commit 14c783c

Browse files
committed
Fix golangci-lint issues
1 parent 378f24f commit 14c783c

2 files changed

Lines changed: 42 additions & 33 deletions

File tree

internal/provider/cisco/nxos/aaa.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ const (
3131
TACACSFeatureDisabled TACACSFeature = "disabled"
3232
)
3333

34+
// AAA configuration constants
35+
const (
36+
AAARealmTacacs = "tacacs"
37+
AAARealmLocal = "local"
38+
AAARealmNone = "none"
39+
AAAValueYes = "yes"
40+
AAAValueNo = "no"
41+
)
42+
3443
// TacacsPlusProvider represents a TACACS+ server host configuration.
3544
// Path: System/userext-items/tacacsext-items/tacacsplusprovider-items/TacacsPlusProvider-list[name=<address>]
3645
type TacacsPlusProvider struct {
@@ -52,11 +61,11 @@ func (p *TacacsPlusProvider) XPath() string {
5261
// TacacsPlusProviderGroup represents a TACACS+ server group configuration.
5362
// Path: System/userext-items/tacacsext-items/tacacsplusprovidergroup-items/TacacsPlusProviderGroup-list[name=<name>]
5463
type TacacsPlusProviderGroup struct {
55-
Name string `json:"name"`
56-
Vrf string `json:"vrf,omitempty"`
57-
SrcIf string `json:"srcIf,omitempty"`
58-
Deadtime int32 `json:"deadtime,omitempty"`
59-
ProviderRefItems TacacsPlusProviderGroupRefItems `json:"providerref-items,omitzero"`
64+
Name string `json:"name"`
65+
Vrf string `json:"vrf,omitempty"`
66+
SrcIf string `json:"srcIf,omitempty"`
67+
Deadtime int32 `json:"deadtime,omitempty"`
68+
ProviderRefItems TacacsPlusProviderGroupRefItems `json:"providerref-items,omitzero"`
6069
}
6170

6271
func (*TacacsPlusProviderGroup) IsListItem() {}
@@ -156,31 +165,31 @@ func MapKeyEncryption(enc v1alpha1.TACACSKeyEncryption) string {
156165
func MapRealmFromMethodType(method v1alpha1.AAAMethodType, groupName string) string {
157166
switch method {
158167
case v1alpha1.AAAMethodTypeGroup:
159-
return "tacacs"
168+
return AAARealmTacacs
160169
case v1alpha1.AAAMethodTypeLocal:
161-
return "local"
170+
return AAARealmLocal
162171
case v1alpha1.AAAMethodTypeNone:
163-
return "none"
172+
return AAARealmNone
164173
default:
165-
return "local"
174+
return AAARealmLocal
166175
}
167176
}
168177

169178
// MapLocalFromMethodList checks if local is in the method list.
170179
func MapLocalFromMethodList(methods []v1alpha1.AAAMethod) string {
171180
for _, m := range methods {
172181
if m.Type == v1alpha1.AAAMethodTypeLocal {
173-
return "yes"
182+
return AAAValueYes
174183
}
175184
}
176-
return "no"
185+
return AAAValueNo
177186
}
178187

179188
// MapFallbackFromMethodList determines fallback setting from method list.
180189
func MapFallbackFromMethodList(methods []v1alpha1.AAAMethod) string {
181190
// If there's more than one method, enable fallback
182191
if len(methods) > 1 {
183-
return "yes"
192+
return AAAValueYes
184193
}
185-
return "no"
194+
return AAAValueNo
186195
}

internal/provider/cisco/nxos/provider.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,18 +2690,18 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
26902690

26912691
// Configure TACACS+ server hosts
26922692
for _, server := range req.AAA.Spec.TACACSServers {
2693-
provider := &TacacsPlusProvider{
2693+
srv := &TacacsPlusProvider{
26942694
Name: server.Address,
26952695
Port: server.Port,
26962696
KeyEnc: MapKeyEncryption(server.KeyEncryption),
26972697
}
26982698
if key, ok := req.TACACSServerKeys[server.Address]; ok {
2699-
provider.Key = key
2699+
srv.Key = key
27002700
}
27012701
if server.Timeout != nil {
2702-
provider.Timeout = *server.Timeout
2702+
srv.Timeout = *server.Timeout
27032703
}
2704-
conf = append(conf, provider)
2704+
conf = append(conf, srv)
27052705
}
27062706

27072707
// Configure TACACS+ server group
@@ -2728,7 +2728,7 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
27282728
}
27292729
// Set realm and provider group based on first method
27302730
if methods[0].Type == v1alpha1.AAAMethodTypeGroup {
2731-
authen.Realm = "tacacs"
2731+
authen.Realm = AAARealmTacacs
27322732
authen.ProviderGroup = methods[0].GroupName
27332733
} else {
27342734
authen.Realm = MapRealmFromMethodType(methods[0].Type, "")
@@ -2745,7 +2745,7 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
27452745
Local: MapLocalFromMethodList(methods),
27462746
}
27472747
if methods[0].Type == v1alpha1.AAAMethodTypeGroup {
2748-
consoleAuth.Realm = "tacacs"
2748+
consoleAuth.Realm = AAARealmTacacs
27492749
consoleAuth.ProviderGroup = methods[0].GroupName
27502750
} else {
27512751
consoleAuth.Realm = MapRealmFromMethodType(methods[0].Type, "")
@@ -2761,10 +2761,10 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
27612761
author := &AAADefaultAuthor{
27622762
Name: "Author",
27632763
CmdType: "config",
2764-
LocalRbac: MapLocalFromMethodList(methods) == "yes",
2764+
LocalRbac: MapLocalFromMethodList(methods) == AAAValueYes,
27652765
}
27662766
if methods[0].Type == v1alpha1.AAAMethodTypeGroup {
2767-
author.Realm = "tacacs"
2767+
author.Realm = AAARealmTacacs
27682768
author.ProviderGroup = methods[0].GroupName
27692769
} else {
27702770
author.Realm = MapRealmFromMethodType(methods[0].Type, "")
@@ -2778,10 +2778,10 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
27782778
methods := req.AAA.Spec.Accounting.Default.Methods
27792779
acct := &AAADefaultAcc{
27802780
Name: "Accounting",
2781-
LocalRbac: MapLocalFromMethodList(methods) == "yes",
2781+
LocalRbac: MapLocalFromMethodList(methods) == AAAValueYes,
27822782
}
27832783
if methods[0].Type == v1alpha1.AAAMethodTypeGroup {
2784-
acct.Realm = "tacacs"
2784+
acct.Realm = AAARealmTacacs
27852785
acct.ProviderGroup = methods[0].GroupName
27862786
} else {
27872787
acct.Realm = MapRealmFromMethodType(methods[0].Type, "")
@@ -2797,7 +2797,7 @@ func (p *Provider) DeleteAAA(ctx context.Context, req *provider.DeleteAAARequest
27972797
if req.AAA.Spec.Accounting != nil && req.AAA.Spec.Accounting.Default != nil {
27982798
acct := &AAADefaultAcc{
27992799
Name: "Accounting",
2800-
Realm: "local",
2800+
Realm: AAARealmLocal,
28012801
LocalRbac: true,
28022802
}
28032803
if err := p.Patch(ctx, acct); err != nil {
@@ -2810,7 +2810,7 @@ func (p *Provider) DeleteAAA(ctx context.Context, req *provider.DeleteAAARequest
28102810
author := &AAADefaultAuthor{
28112811
Name: "Author",
28122812
CmdType: "config",
2813-
Realm: "local",
2813+
Realm: AAARealmLocal,
28142814
LocalRbac: true,
28152815
}
28162816
if err := p.Patch(ctx, author); err != nil {
@@ -2821,9 +2821,9 @@ func (p *Provider) DeleteAAA(ctx context.Context, req *provider.DeleteAAARequest
28212821
// Reset AAA authentication to local
28222822
if req.AAA.Spec.Authentication != nil {
28232823
authen := &AAADefaultAuth{
2824-
Realm: "local",
2825-
Local: "yes",
2826-
Fallback: "yes",
2824+
Realm: AAARealmLocal,
2825+
Local: AAAValueYes,
2826+
Fallback: AAAValueYes,
28272827
ErrEn: false,
28282828
}
28292829
if err := p.Patch(ctx, authen); err != nil {
@@ -2832,9 +2832,9 @@ func (p *Provider) DeleteAAA(ctx context.Context, req *provider.DeleteAAARequest
28322832

28332833
if req.AAA.Spec.Authentication.Login != nil && req.AAA.Spec.Authentication.Login.Console != nil {
28342834
consoleAuth := &AAAConsoleAuth{
2835-
Realm: "local",
2836-
Local: "yes",
2837-
Fallback: "yes",
2835+
Realm: AAARealmLocal,
2836+
Local: AAAValueYes,
2837+
Fallback: AAAValueYes,
28382838
ErrEn: false,
28392839
}
28402840
if err := p.Patch(ctx, consoleAuth); err != nil {
@@ -2853,8 +2853,8 @@ func (p *Provider) DeleteAAA(ctx context.Context, req *provider.DeleteAAARequest
28532853

28542854
// Delete TACACS+ server hosts
28552855
for _, server := range req.AAA.Spec.TACACSServers {
2856-
provider := &TacacsPlusProvider{Name: server.Address}
2857-
if err := p.client.Delete(ctx, provider); err != nil {
2856+
srv := &TacacsPlusProvider{Name: server.Address}
2857+
if err := p.client.Delete(ctx, srv); err != nil {
28582858
return err
28592859
}
28602860
}

0 commit comments

Comments
 (0)