Skip to content

Commit f6252e8

Browse files
committed
rename TokenType to Type under token pkg
1 parent 09a4f1a commit f6252e8

30 files changed

+211
-211
lines changed

entry_role.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import (
1111
)
1212

1313
type EntryRole struct {
14-
RoleName string `json:"role_name" structs:"role_name" mapstructure:"role_name"`
15-
TTL time.Duration `json:"ttl" structs:"ttl" mapstructure:"ttl"`
16-
Path string `json:"path" structs:"path" mapstructure:"path"`
17-
Name string `json:"name" structs:"name" mapstructure:"name"`
18-
Scopes []string `json:"scopes" structs:"scopes" mapstructure:"scopes"`
19-
AccessLevel AccessLevel `json:"access_level" structs:"access_level" mapstructure:"access_level,omitempty"`
20-
TokenType token.TokenType `json:"token_type" structs:"token_type" mapstructure:"token_type"`
21-
GitlabRevokesTokens bool `json:"gitlab_revokes_token" structs:"gitlab_revokes_token" mapstructure:"gitlab_revokes_token"`
22-
ConfigName string `json:"config_name" structs:"config_name" mapstructure:"config_name"`
14+
RoleName string `json:"role_name" structs:"role_name" mapstructure:"role_name"`
15+
TTL time.Duration `json:"ttl" structs:"ttl" mapstructure:"ttl"`
16+
Path string `json:"path" structs:"path" mapstructure:"path"`
17+
Name string `json:"name" structs:"name" mapstructure:"name"`
18+
Scopes []string `json:"scopes" structs:"scopes" mapstructure:"scopes"`
19+
AccessLevel AccessLevel `json:"access_level" structs:"access_level" mapstructure:"access_level,omitempty"`
20+
TokenType token.Type `json:"token_type" structs:"token_type" mapstructure:"token_type"`
21+
GitlabRevokesTokens bool `json:"gitlab_revokes_token" structs:"gitlab_revokes_token" mapstructure:"gitlab_revokes_token"`
22+
ConfigName string `json:"config_name" structs:"config_name" mapstructure:"config_name"`
2323
}
2424

2525
func (e EntryRole) LogicalResponseData() map[string]any {

gitlab_client.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (gc *gitlabClient) CreateGroupDeployToken(ctx context.Context, path string,
9696
Path: path,
9797
Name: name,
9898
Token: dt.Token,
99-
TokenType: t.TokenTypeGroupDeploy,
99+
TokenType: t.TypeGroupDeploy,
100100
CreatedAt: g.Ptr(time.Now()),
101101
},
102102
Scopes: scopes,
@@ -129,7 +129,7 @@ func (gc *gitlabClient) CreateProjectDeployToken(ctx context.Context, path strin
129129
Path: path,
130130
Name: name,
131131
Token: dt.Token,
132-
TokenType: t.TokenTypeProjectDeploy,
132+
TokenType: t.TypeProjectDeploy,
133133
CreatedAt: g.Ptr(time.Now()),
134134
},
135135
Scopes: scopes,
@@ -185,7 +185,7 @@ func (gc *gitlabClient) CreatePipelineProjectTriggerAccessToken(ctx context.Cont
185185
Path: path,
186186
Name: name,
187187
Token: pt.Token,
188-
TokenType: t.TokenTypePipelineProjectTrigger,
188+
TokenType: t.TypePipelineProjectTrigger,
189189
CreatedAt: g.Ptr(time.Now()),
190190
ExpiresAt: expiresAt,
191191
},
@@ -248,7 +248,7 @@ func (gc *gitlabClient) CreateGroupServiceAccountAccessToken(ctx context.Context
248248
Path: path,
249249
Name: name,
250250
Token: at.Token,
251-
TokenType: t.TokenTypeGroupServiceAccount,
251+
TokenType: t.TypeGroupServiceAccount,
252252
CreatedAt: at.CreatedAt,
253253
ExpiresAt: (*time.Time)(at.ExpiresAt),
254254
},
@@ -275,7 +275,7 @@ func (gc *gitlabClient) CreateUserServiceAccountAccessToken(ctx context.Context,
275275
Path: etp.Path,
276276
Name: etp.Name,
277277
Token: etp.Token.Token,
278-
TokenType: t.TokenTypeUserServiceAccount,
278+
TokenType: t.TypeUserServiceAccount,
279279
CreatedAt: etp.CreatedAt,
280280
ExpiresAt: etp.ExpiresAt,
281281
},
@@ -332,7 +332,7 @@ func (gc *gitlabClient) CurrentTokenInfo(ctx context.Context) (et *TokenConfig,
332332
TokenID: pat.ID,
333333
Name: pat.Name,
334334
Token: pat.Token,
335-
TokenType: t.TokenTypePersonal,
335+
TokenType: t.TypePersonal,
336336
CreatedAt: pat.CreatedAt,
337337
ExpiresAt: (*time.Time)(pat.ExpiresAt),
338338
},
@@ -388,7 +388,7 @@ func (gc *gitlabClient) RotateCurrentToken(ctx context.Context) (token *TokenCon
388388
Path: usr.Username,
389389
Name: pat.Name,
390390
Token: pat.Token,
391-
TokenType: t.TokenTypePersonal,
391+
TokenType: t.TypePersonal,
392392
CreatedAt: pat.CreatedAt,
393393
ExpiresAt: (*time.Time)(pat.ExpiresAt),
394394
},
@@ -448,7 +448,7 @@ func (gc *gitlabClient) CreatePersonalAccessToken(ctx context.Context, username
448448
Path: username,
449449
Name: name,
450450
Token: at.Token,
451-
TokenType: t.TokenTypePersonal,
451+
TokenType: t.TypePersonal,
452452
CreatedAt: at.CreatedAt,
453453
ExpiresAt: (*time.Time)(at.ExpiresAt),
454454
},
@@ -481,7 +481,7 @@ func (gc *gitlabClient) CreateGroupAccessToken(ctx context.Context, groupId stri
481481
Path: groupId,
482482
Name: name,
483483
Token: at.Token,
484-
TokenType: t.TokenTypeGroup,
484+
TokenType: t.TypeGroup,
485485
CreatedAt: at.CreatedAt,
486486
ExpiresAt: (*time.Time)(at.ExpiresAt),
487487
},
@@ -514,7 +514,7 @@ func (gc *gitlabClient) CreateProjectAccessToken(ctx context.Context, projectId
514514
Path: projectId,
515515
Name: name,
516516
Token: at.Token,
517-
TokenType: t.TokenTypeProject,
517+
TokenType: t.TypeProject,
518518
CreatedAt: at.CreatedAt,
519519
ExpiresAt: (*time.Time)(at.ExpiresAt),
520520
},

gitlab_client_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func TestGitlabClient_CurrentTokenInfo(t *testing.T) {
217217
token, err := client.CurrentTokenInfo(ctx)
218218
require.NoError(t, err)
219219
require.NotNil(t, token)
220-
assert.EqualValues(t, token2.TokenTypePersonal, token.TokenType)
220+
assert.EqualValues(t, token2.TypePersonal, token.TokenType)
221221
}
222222

223223
func TestGitlabClient_Metadata(t *testing.T) {
@@ -262,7 +262,7 @@ func TestGitlabClient_CreateAccessToken_And_Revoke(t *testing.T) {
262262
)
263263
require.NoError(t, err)
264264
require.NotNil(t, gatToken)
265-
require.EqualValues(t, token2.TokenTypeGroup, gatToken.TokenType)
265+
require.EqualValues(t, token2.TypeGroup, gatToken.TokenType)
266266
require.NotEmpty(t, gatToken.Token)
267267
require.NoError(t, client.RevokeGroupAccessToken(ctx, gatToken.TokenID, "example"))
268268

@@ -276,7 +276,7 @@ func TestGitlabClient_CreateAccessToken_And_Revoke(t *testing.T) {
276276
)
277277
require.NoError(t, err)
278278
require.NotNil(t, prjatToken)
279-
require.EqualValues(t, token2.TokenTypeProject, prjatToken.TokenType)
279+
require.EqualValues(t, token2.TypeProject, prjatToken.TokenType)
280280
require.NotEmpty(t, prjatToken.Token)
281281
require.NoError(t, client.RevokeProjectAccessToken(ctx, prjatToken.TokenID, "example/example"))
282282

@@ -290,7 +290,7 @@ func TestGitlabClient_CreateAccessToken_And_Revoke(t *testing.T) {
290290
)
291291
require.NoError(t, err)
292292
require.NotNil(t, patToken)
293-
require.EqualValues(t, token2.TokenTypePersonal, patToken.TokenType)
293+
require.EqualValues(t, token2.TypePersonal, patToken.TokenType)
294294
require.NotEmpty(t, patToken.Token)
295295
require.NoError(t, client.RevokePersonalAccessToken(ctx, patToken.TokenID))
296296
}

helpers_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (i *inMemoryClient) CreateProjectDeployToken(ctx context.Context, path stri
227227
}
228228
i.internalCounter++
229229
var tokenId = i.internalCounter
230-
key := fmt.Sprintf("%s_%v_%v", t.TokenTypeProjectDeploy.String(), projectId, tokenId)
230+
key := fmt.Sprintf("%s_%v_%v", t.TypeProjectDeploy.String(), projectId, tokenId)
231231
var entryToken = &gitlab.TokenProjectDeploy{
232232
TokenWithScopes: gitlab.TokenWithScopes{
233233
Token: gitlab.Token{
@@ -236,7 +236,7 @@ func (i *inMemoryClient) CreateProjectDeployToken(ctx context.Context, path stri
236236
Path: path,
237237
Name: name,
238238
Token: fmt.Sprintf("glpat-%s", uuid.New().String()),
239-
TokenType: t.TokenTypeProjectDeploy,
239+
TokenType: t.TypeProjectDeploy,
240240
ExpiresAt: expiresAt,
241241
CreatedAt: g.Ptr(time.Now())},
242242
Scopes: scopes,
@@ -255,7 +255,7 @@ func (i *inMemoryClient) CreateGroupDeployToken(ctx context.Context, path string
255255
}
256256
i.internalCounter++
257257
var tokenId = i.internalCounter
258-
key := fmt.Sprintf("%s_%v_%v", t.TokenTypeGroupDeploy.String(), groupId, tokenId)
258+
key := fmt.Sprintf("%s_%v_%v", t.TypeGroupDeploy.String(), groupId, tokenId)
259259
var entryToken = &gitlab.TokenGroupDeploy{
260260
TokenWithScopes: gitlab.TokenWithScopes{
261261
Token: gitlab.Token{
@@ -264,7 +264,7 @@ func (i *inMemoryClient) CreateGroupDeployToken(ctx context.Context, path string
264264
Path: path,
265265
Name: name,
266266
Token: fmt.Sprintf("glpat-%s", uuid.New().String()),
267-
TokenType: t.TokenTypeGroupDeploy,
267+
TokenType: t.TypeGroupDeploy,
268268
ExpiresAt: expiresAt,
269269
CreatedAt: g.Ptr(time.Now()),
270270
},
@@ -282,7 +282,7 @@ func (i *inMemoryClient) RevokeProjectDeployToken(ctx context.Context, projectId
282282
if i.revokeProjectDeployTokenError {
283283
return errors.New("revoke project deploy token error")
284284
}
285-
key := fmt.Sprintf("%s_%v_%v", t.TokenTypeProjectDeploy.String(), projectId, deployTokenId)
285+
key := fmt.Sprintf("%s_%v_%v", t.TypeProjectDeploy.String(), projectId, deployTokenId)
286286
delete(i.accessTokens, key)
287287
return nil
288288
}
@@ -293,7 +293,7 @@ func (i *inMemoryClient) RevokeGroupDeployToken(ctx context.Context, groupId, de
293293
if i.revokeGroupDeployTokenError {
294294
return errors.New("revoke group deploy token error")
295295
}
296-
key := fmt.Sprintf("%s_%v_%v", t.TokenTypeGroupDeploy.String(), groupId, deployTokenId)
296+
key := fmt.Sprintf("%s_%v_%v", t.TypeGroupDeploy.String(), groupId, deployTokenId)
297297
delete(i.accessTokens, key)
298298
return nil
299299
}
@@ -317,15 +317,15 @@ func (i *inMemoryClient) CreatePipelineProjectTriggerAccessToken(ctx context.Con
317317
}
318318
i.internalCounter++
319319
var tokenId = i.internalCounter
320-
key := fmt.Sprintf("%s_%v_%v", t.TokenTypePipelineProjectTrigger.String(), projectId, tokenId)
320+
key := fmt.Sprintf("%s_%v_%v", t.TypePipelineProjectTrigger.String(), projectId, tokenId)
321321
var entryToken = &gitlab.TokenPipelineProjectTrigger{
322322
Token: gitlab.Token{
323323
TokenID: tokenId,
324324
ParentID: strconv.Itoa(projectId),
325325
Path: strconv.Itoa(projectId),
326326
Name: name,
327327
Token: fmt.Sprintf("glptt-%s", uuid.New().String()),
328-
TokenType: t.TokenTypePipelineProjectTrigger,
328+
TokenType: t.TypePipelineProjectTrigger,
329329
ExpiresAt: expiresAt,
330330
CreatedAt: g.Ptr(time.Now()),
331331
},
@@ -340,7 +340,7 @@ func (i *inMemoryClient) RevokePipelineProjectTriggerAccessToken(ctx context.Con
340340
if i.revokePipelineProjectTriggerAccessTokenError {
341341
return fmt.Errorf("RevokePipelineProjectTriggerAccessToken")
342342
}
343-
key := fmt.Sprintf("%s_%v_%v", t.TokenTypePipelineProjectTrigger.String(), projectId, tokenId)
343+
key := fmt.Sprintf("%s_%v_%v", t.TypePipelineProjectTrigger.String(), projectId, tokenId)
344344
delete(i.accessTokens, key)
345345
return nil
346346
}
@@ -383,7 +383,7 @@ func (i *inMemoryClient) CreateUserServiceAccountAccessToken(ctx context.Context
383383
Token: gitlab.Token{
384384
CreatedAt: cpat.CreatedAt,
385385
ExpiresAt: cpat.ExpiresAt,
386-
TokenType: t.TokenTypeUserServiceAccount,
386+
TokenType: t.TypeUserServiceAccount,
387387
Token: cpat.Token.Token,
388388
TokenID: cpat.TokenID,
389389
ParentID: cpat.ParentID,
@@ -404,7 +404,7 @@ func (i *inMemoryClient) RevokeUserServiceAccountAccessToken(ctx context.Context
404404
if i.revokeUserServiceAccountPersonalAccessTokenError {
405405
return errors.New("RevokeServiceAccountPersonalAccessToken")
406406
}
407-
delete(i.accessTokens, fmt.Sprintf("%s_%v", t.TokenTypeUserServiceAccount.String(), token))
407+
delete(i.accessTokens, fmt.Sprintf("%s_%v", t.TypeUserServiceAccount.String(), token))
408408
return nil
409409
}
410410

@@ -414,7 +414,7 @@ func (i *inMemoryClient) RevokeGroupServiceAccountAccessToken(ctx context.Contex
414414
if i.revokeGroupServiceAccountPersonalAccessTokenError {
415415
return errors.New("RevokeServiceAccountPersonalAccessToken")
416416
}
417-
delete(i.accessTokens, fmt.Sprintf("%s_%v", t.TokenTypeGroupServiceAccount.String(), token))
417+
delete(i.accessTokens, fmt.Sprintf("%s_%v", t.TypeGroupServiceAccount.String(), token))
418418
return nil
419419
}
420420

@@ -455,15 +455,15 @@ func (i *inMemoryClient) CreatePersonalAccessToken(ctx context.Context, username
455455
Path: username,
456456
Name: name,
457457
Token: fmt.Sprintf("glpat-%s", uuid.New().String()),
458-
TokenType: t.TokenTypePersonal,
458+
TokenType: t.TypePersonal,
459459
CreatedAt: g.Ptr(time.Now()),
460460
ExpiresAt: &expiresAt,
461461
},
462462
Scopes: scopes,
463463
},
464464
UserID: userId,
465465
}
466-
i.accessTokens[fmt.Sprintf("%s_%v", t.TokenTypePersonal.String(), tokenId)] = entryToken
466+
i.accessTokens[fmt.Sprintf("%s_%v", t.TypePersonal.String(), tokenId)] = entryToken
467467
return entryToken, nil
468468
}
469469

@@ -483,15 +483,15 @@ func (i *inMemoryClient) CreateGroupAccessToken(ctx context.Context, groupId str
483483
Path: groupId,
484484
Name: name,
485485
Token: fmt.Sprintf("glgat-%s", uuid.New().String()),
486-
TokenType: t.TokenTypeGroup,
486+
TokenType: t.TypeGroup,
487487
CreatedAt: g.Ptr(time.Now()),
488488
ExpiresAt: &expiresAt,
489489
},
490490
Scopes: scopes,
491491
AccessLevel: accessLevel,
492492
},
493493
}
494-
i.accessTokens[fmt.Sprintf("%s_%v", t.TokenTypeGroup.String(), tokenId)] = entryToken
494+
i.accessTokens[fmt.Sprintf("%s_%v", t.TypeGroup.String(), tokenId)] = entryToken
495495
return entryToken, nil
496496
}
497497

@@ -507,7 +507,7 @@ func (i *inMemoryClient) CreateProjectAccessToken(ctx context.Context, projectId
507507
TokenWithScopesAndAccessLevel: gitlab.TokenWithScopesAndAccessLevel{
508508
Token: gitlab.Token{
509509
Token: fmt.Sprintf("glpat-%s", uuid.New().String()),
510-
TokenType: t.TokenTypeProject,
510+
TokenType: t.TypeProject,
511511
CreatedAt: g.Ptr(time.Now()),
512512
ExpiresAt: &expiresAt,
513513
TokenID: tokenId,
@@ -519,7 +519,7 @@ func (i *inMemoryClient) CreateProjectAccessToken(ctx context.Context, projectId
519519
AccessLevel: accessLevel,
520520
},
521521
}
522-
i.accessTokens[fmt.Sprintf("%s_%v", t.TokenTypeProject.String(), tokenId)] = entryToken
522+
i.accessTokens[fmt.Sprintf("%s_%v", t.TypeProject.String(), tokenId)] = entryToken
523523
return entryToken, nil
524524
}
525525

@@ -529,7 +529,7 @@ func (i *inMemoryClient) RevokePersonalAccessToken(ctx context.Context, tokenId
529529
if i.personalAccessTokenRevokeError {
530530
return fmt.Errorf("RevokePersonalAccessToken")
531531
}
532-
delete(i.accessTokens, fmt.Sprintf("%s_%v", t.TokenTypePersonal.String(), tokenId))
532+
delete(i.accessTokens, fmt.Sprintf("%s_%v", t.TypePersonal.String(), tokenId))
533533
return nil
534534
}
535535

@@ -539,7 +539,7 @@ func (i *inMemoryClient) RevokeProjectAccessToken(ctx context.Context, tokenId i
539539
if i.projectAccessTokenRevokeError {
540540
return fmt.Errorf("RevokeProjectAccessToken")
541541
}
542-
delete(i.accessTokens, fmt.Sprintf("%s_%v", t.TokenTypeProject.String(), tokenId))
542+
delete(i.accessTokens, fmt.Sprintf("%s_%v", t.TypeProject.String(), tokenId))
543543
return nil
544544
}
545545

@@ -549,7 +549,7 @@ func (i *inMemoryClient) RevokeGroupAccessToken(ctx context.Context, tokenId int
549549
if i.groupAccessTokenRevokeError {
550550
return fmt.Errorf("RevokeGroupAccessToken")
551551
}
552-
delete(i.accessTokens, fmt.Sprintf("%s_%v", t.TokenTypeGroup.String(), tokenId))
552+
delete(i.accessTokens, fmt.Sprintf("%s_%v", t.TypeGroup.String(), tokenId))
553553
return nil
554554
}
555555

0 commit comments

Comments
 (0)