Skip to content

Commit cfd38f6

Browse files
authored
[CLOUDTRUST-8300] Run go fix (#754)
1 parent f2784a0 commit cfd38f6

92 files changed

Lines changed: 818 additions & 939 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/account/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type UpdatableAccountRepresentation struct {
7777
IDDocumentExpiration *string `json:"idDocumentExpiration,omitempty"`
7878
IDDocumentCountry *string `json:"idDocumentCountry,omitempty"`
7979
Locale *string `json:"locale,omitempty"`
80-
BusinessID csjson.OptionalString `json:"businessId,omitempty"`
80+
BusinessID csjson.OptionalString `json:"businessId"`
8181
Accreditations *[]AccreditationRepresentation `json:"accreditations,omitempty"`
8282
Dynamic map[string]any `json:"-"`
8383
}
@@ -298,7 +298,7 @@ func MergeUserWithoutEmailAndPhoneNumber(userRep *kc.UserRepresentation, user Up
298298
// Validators
299299

300300
// GetField is used to validate a user against a UserProfile
301-
func (user *UpdatableAccountRepresentation) GetField(field string) interface{} {
301+
func (user *UpdatableAccountRepresentation) GetField(field string) any {
302302
switch field {
303303
case fields.Username.Key():
304304
return profile.IfNotNil(user.Username)
@@ -339,7 +339,7 @@ func (user *UpdatableAccountRepresentation) GetField(field string) interface{} {
339339
}
340340

341341
// SetField is used to validate a user against a UserProfile
342-
func (user *UpdatableAccountRepresentation) SetField(field string, value interface{}) {
342+
func (user *UpdatableAccountRepresentation) SetField(field string, value any) {
343343
switch field {
344344
case fields.Username.Key():
345345
user.Username = cs.ToStringPtr(value)

api/account/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func TestGetSetField(t *testing.T) {
141141
assert.Nil(t, user.GetField("not-existing-field"))
142142
}
143143

144-
func testGetSetField(t *testing.T, fieldName string, value interface{}) {
144+
func testGetSetField(t *testing.T, fieldName string, value any) {
145145
var user UpdatableAccountRepresentation
146146
t.Run("Field "+fieldName, func(t *testing.T) {
147147
assert.Nil(t, user.GetField(fieldName))

api/common/api-profile.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package apicommon
22

33
import (
4+
"maps"
45
"strings"
56

67
"github.com/cloudtrust/common-service/v2/validation"
@@ -39,7 +40,7 @@ type ProfileAttributeRepresentation struct {
3940
}
4041

4142
// ProfileAttrbValidatorRepresentation type
42-
type ProfileAttrbValidatorRepresentation map[string]interface{}
43+
type ProfileAttrbValidatorRepresentation map[string]any
4344

4445
// ProfileGroupRepresentation struct
4546
type ProfileGroupRepresentation struct {
@@ -129,9 +130,7 @@ func ToValidator(validator kc.ProfileAttrValidatorRepresentation) ProfileAttrbVa
129130
return nil
130131
}
131132
var res = make(ProfileAttrbValidatorRepresentation)
132-
for k, v := range validator {
133-
res[k] = v
134-
}
133+
maps.Copy(res, validator)
135134
return res
136135
}
137136

api/common/api-profile_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import (
77
"github.com/stretchr/testify/assert"
88
)
99

10-
func ptr(value string) *string {
11-
return &value
12-
}
13-
1410
func TestProfileToAPI(t *testing.T) {
1511
t.Run("Nil content", func(t *testing.T) {
1612
var profile = kc.UserProfileRepresentation{Attributes: nil, Groups: nil}
@@ -37,7 +33,7 @@ func TestAttributesToAPI(t *testing.T) {
3733
assert.Nil(t, res)
3834
})
3935
t.Run("Two elements", func(t *testing.T) {
40-
var attrbs = []kc.ProfileAttrbRepresentation{{}, {Name: ptr("dummy")}}
36+
var attrbs = []kc.ProfileAttrbRepresentation{{}, {Name: new("dummy")}}
4137
var res = AttributesToAPI(attrbs, "")
4238
assert.Len(t, res, len(attrbs))
4339
})
@@ -157,9 +153,9 @@ func TestAttributeAnnotationsToAPI(t *testing.T) {
157153
func TestGroupsToAPI(t *testing.T) {
158154
var grps = []kc.ProfileGroupRepresentation{
159155
{
160-
Name: ptr("name"),
161-
DisplayHeader: ptr("display header"),
162-
DisplayDescription: ptr("display description"),
156+
Name: new("name"),
157+
DisplayHeader: new("display header"),
158+
DisplayDescription: new("display description"),
163159
Annotations: map[string]string{"key1": "value1", "key2": "value2"},
164160
},
165161
{},

api/idp/api_test.go

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ var (
2525
trustEmail = false
2626
)
2727

28-
func ptr(value string) *string {
29-
return &value
30-
}
31-
32-
func ptrBool(value bool) *bool {
33-
return &value
34-
}
35-
3628
func createTestIdpConfig() map[string]string {
3729
return map[string]string{
3830
"postBindingLogout": "true",
@@ -69,7 +61,7 @@ func createTestIdpConfig() map[string]string {
6961

7062
func createValideHrdSettings() HrdSettingModel {
7163
return HrdSettingModel{
72-
IPRangesList: ptr("192.168.0.1/24,127.0.0.1/8"),
64+
IPRangesList: new("192.168.0.1/24,127.0.0.1/8"),
7365
Priority: 0,
7466
}
7567
}
@@ -100,21 +92,21 @@ func createTestAPIIdp() IdentityProviderRepresentation {
10092
func createValidIdpMapper() IdentityProviderMapperRepresentation {
10193
return IdentityProviderMapperRepresentation{
10294
Config: map[string]string{"key1": "value1", "key2": "value2"},
103-
ID: ptr("88888888-4444-4444-4444-121212121212"),
104-
IdentityProviderAlias: ptr("alias"),
105-
IdentityProviderMapper: ptr("mapper"),
106-
Name: ptr("name"),
95+
ID: new("88888888-4444-4444-4444-121212121212"),
96+
IdentityProviderAlias: new("alias"),
97+
IdentityProviderMapper: new("mapper"),
98+
Name: new("name"),
10799
}
108100
}
109101

110102
func createValidUserRepresentation() UserRepresentation {
111103
return UserRepresentation{
112-
ID: ptr("user-id"),
113-
Username: ptr("username"),
114-
FirstName: ptr("first name"),
115-
LastName: ptr("last name"),
116-
Email: ptr("em@il.ch"),
117-
Enabled: ptrBool(true),
104+
ID: new("user-id"),
105+
Username: new("username"),
106+
FirstName: new("first name"),
107+
LastName: new("last name"),
108+
Email: new("em@il.ch"),
109+
Enabled: new(true),
118110
RealmRoles: []string{"role1", "role2"},
119111
Attributes: map[string][]string{"key": []string{"value1", "value2"}},
120112
}
@@ -146,8 +138,8 @@ func TestHRDSettingValidate(t *testing.T) {
146138
for range 4 {
147139
items = append(items, createValideHrdSettings())
148140
}
149-
items[0].IPRangesList = ptr("")
150-
items[1].IPRangesList = ptr("`!not a valid ipRangesList!`")
141+
items[0].IPRangesList = new("")
142+
items[1].IPRangesList = new("`!not a valid ipRangesList!`")
151143
items[2].Priority = -10571
152144
items[3].Priority = 27903
153145

@@ -185,7 +177,7 @@ func TestValidateIdentityProviderRepresentation(t *testing.T) {
185177
t.Run("valid domains list", func(t *testing.T) {
186178
idp := createTestAPIIdp()
187179

188-
idp.HrdSettings.DomainsList = ptr("example.com,example.org")
180+
idp.HrdSettings.DomainsList = new("example.com,example.org")
189181

190182
err := idp.Validate()
191183
assert.NoError(t, err)
@@ -224,7 +216,7 @@ func TestValidateIdentityProviderRepresentation(t *testing.T) {
224216
t.Run("invalid HRD IP ranges list", func(t *testing.T) {
225217
idp := createTestAPIIdp()
226218

227-
idp.HrdSettings.IPRangesList = ptr("not a list of IP ranges")
219+
idp.HrdSettings.IPRangesList = new("not a list of IP ranges")
228220

229221
err := idp.Validate()
230222
assert.Error(t, err)
@@ -233,7 +225,7 @@ func TestValidateIdentityProviderRepresentation(t *testing.T) {
233225
t.Run("invalid HRD domains list", func(t *testing.T) {
234226
idp := createTestAPIIdp()
235227

236-
idp.HrdSettings.DomainsList = ptr("not a list of domains")
228+
idp.HrdSettings.DomainsList = new("not a list of domains")
237229

238230
err := idp.Validate()
239231
assert.Error(t, err)
@@ -279,14 +271,14 @@ func TestIdentityProviderMapperValidate(t *testing.T) {
279271
for range 8 {
280272
items = append(items, createValidIdpMapper())
281273
}
282-
items[0].ID = ptr("")
283-
items[1].ID = ptr("idp-mapper")
274+
items[0].ID = new("")
275+
items[1].ID = new("idp-mapper")
284276
items[2].IdentityProviderAlias = nil
285-
items[3].IdentityProviderAlias = ptr("")
277+
items[3].IdentityProviderAlias = new("")
286278
items[4].IdentityProviderMapper = nil
287-
items[5].IdentityProviderMapper = ptr("")
279+
items[5].IdentityProviderMapper = new("")
288280
items[6].Name = nil
289-
items[7].Name = ptr("")
281+
items[7].Name = new("")
290282

291283
for idx, item := range items {
292284
t.Run(fmt.Sprintf("IdentityProviderRepresentation case idx: %d", idx), func(t *testing.T) {

api/kyc/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func (u *UserRepresentation) Validate(ctx context.Context, upc profile.UserProfi
255255
}
256256

257257
// GetField is used to validate a user against a UserProfile
258-
func (u *UserRepresentation) GetField(field string) interface{} {
258+
func (u *UserRepresentation) GetField(field string) any {
259259
switch field {
260260
case fields.Username.Key():
261261
return profile.IfNotNil(u.Username)
@@ -293,7 +293,7 @@ func (u *UserRepresentation) GetField(field string) interface{} {
293293
}
294294

295295
// SetField is used to validate a user against a UserProfile
296-
func (u *UserRepresentation) SetField(field string, value interface{}) {
296+
func (u *UserRepresentation) SetField(field string, value any) {
297297
switch field {
298298
case fields.Username.Key():
299299
u.Username = cs.ToStringPtr(value)

api/kyc/api_test.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ import (
1313
"github.com/stretchr/testify/assert"
1414
)
1515

16-
func ptr(value string) *string {
17-
return &value
18-
}
19-
2016
func createValidUser(dynamicAttribute string) UserRepresentation {
2117
var (
2218
bFalse = false
@@ -34,8 +30,8 @@ func createValidUser(dynamicAttribute string) UserRepresentation {
3430
idDocExpiration = "23.02.2039"
3531
locale = "fr"
3632
businessID = "123456789"
37-
accred1 = AccreditationRepresentation{Type: ptr("short"), ExpiryDate: ptr("31.12.2024")}
38-
accred2 = AccreditationRepresentation{Type: ptr("long"), ExpiryDate: ptr("31.12.2039")}
33+
accred1 = AccreditationRepresentation{Type: new("short"), ExpiryDate: new("31.12.2024")}
34+
accred2 = AccreditationRepresentation{Type: new("long"), ExpiryDate: new("31.12.2039")}
3935
creds = []AccreditationRepresentation{accred1, accred2}
4036
attachments = []AttachmentRepresentation{createValidAttachment()}
4137
dynamicValue = "customValue"
@@ -70,7 +66,7 @@ func createValidAttachment() AttachmentRepresentation {
7066
contentBase = "basicvalueofsomecharacters"
7167
contentBytes = []byte(contentBase + contentBase + contentBase + contentBase)
7268
)
73-
return AttachmentRepresentation{Filename: ptr("filename.pdf"), ContentType: ptr("application/pdf"), Content: &contentBytes}
69+
return AttachmentRepresentation{Filename: new("filename.pdf"), ContentType: new("application/pdf"), Content: &contentBytes}
7470
}
7571

7672
func createValidKeycloakUser(dynamicAttribute string) kc.UserRepresentation {
@@ -231,7 +227,7 @@ func TestValidateUserRepresentation(t *testing.T) {
231227
t.Run("Valid users with max attachments", func(t *testing.T) {
232228
var user = createValidUser("")
233229
var attachment []AttachmentRepresentation
234-
for i := 0; i < maxNumberAttachments; i++ {
230+
for range maxNumberAttachments {
235231
attachment = append(attachment, createValidAttachment())
236232
}
237233
user.Attachments = &attachment
@@ -240,7 +236,7 @@ func TestValidateUserRepresentation(t *testing.T) {
240236
t.Run("Valid users with too many attachments", func(t *testing.T) {
241237
var user = createValidUser("")
242238
var attachment []AttachmentRepresentation
243-
for i := 0; i < maxNumberAttachments+1; i++ {
239+
for range maxNumberAttachments + 1 {
244240
attachment = append(attachment, createValidAttachment())
245241
}
246242
user.Attachments = &attachment
@@ -271,7 +267,7 @@ func TestGetSetField(t *testing.T) {
271267
assert.Nil(t, user.GetField("not-existing-field"))
272268
}
273269

274-
func testGetSetField(t *testing.T, fieldName string, value interface{}) {
270+
func testGetSetField(t *testing.T, fieldName string, value any) {
275271
var user UserRepresentation
276272
t.Run("Field "+fieldName, func(t *testing.T) {
277273
assert.Nil(t, user.GetField(fieldName))
@@ -287,7 +283,7 @@ func TestValidateAttachment(t *testing.T) {
287283
})
288284
t.Run("Successful evaluation of content type", func(t *testing.T) {
289285
var attachment = createValidAttachment()
290-
attachment.Filename = ptr("image.JPG")
286+
attachment.Filename = new("image.JPG")
291287
attachment.ContentType = nil
292288
assert.Nil(t, attachment.Validate())
293289
assert.Equal(t, "image/jpeg", *attachment.ContentType)
@@ -300,19 +296,19 @@ func TestValidateAttachment(t *testing.T) {
300296
})
301297
t.Run("Invalid content type", func(t *testing.T) {
302298
var attachment = createValidAttachment()
303-
attachment.ContentType = ptr("not-a-valid-content-type")
299+
attachment.ContentType = new("not-a-valid-content-type")
304300
assert.NotNil(t, attachment.Validate())
305301
})
306302
t.Run("Can't find known content type from filename", func(t *testing.T) {
307303
var attachment = createValidAttachment()
308-
attachment.Filename = ptr("image.gif")
304+
attachment.Filename = new("image.gif")
309305
attachment.ContentType = nil
310306
assert.NotNil(t, attachment.Validate())
311307
})
312308
t.Run("Unsupported content type", func(t *testing.T) {
313309
var attachment = createValidAttachment()
314310
attachment.Filename = nil
315-
attachment.ContentType = ptr("text/plain")
311+
attachment.ContentType = new("text/plain")
316312
assert.NotNil(t, attachment.Validate())
317313
})
318314
t.Run("Invalid content length", func(t *testing.T) {

0 commit comments

Comments
 (0)