Skip to content

fix: handle unexpected missing token expiry by setting a default #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions gitlab_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,13 @@
},
UserID: pat.UserID,
}
// Set an artificial expiry date one year after creation if none is set.
// This addresses issue #178 where a token could be issued without an expiry.
// Note: As of GitLab 16.x, all tokens should have an expiry set.
if et.ExpiresAt == nil {
newDate := pat.CreatedAt.AddDate(1, 0, -2)
et.ExpiresAt = &newDate
}

Check warning on line 345 in gitlab_client.go

View check run for this annotation

Codecov / codecov/patch

gitlab_client.go#L343-L345

Added lines #L343 - L345 were not covered by tests
}
return et, err
}
Expand Down Expand Up @@ -567,11 +574,11 @@
var _ Client = new(gitlabClient)

func newGitlabClient(config *EntryConfig, httpClient *http.Client) (gc *g.Client, err error) {
if "" == strings.TrimSpace(config.BaseURL) {
if strings.TrimSpace(config.BaseURL) == "" {
err = errors.Join(err, fmt.Errorf("gitlab base url: %w", ErrInvalidValue))
}

if "" == strings.TrimSpace(config.Token) {
if strings.TrimSpace(config.Token) == "" {
err = errors.Join(err, fmt.Errorf("gitlab token: %w", ErrInvalidValue))
}

Expand Down