mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-12 02:15:01 +00:00
[v18] chore: Bump golangci-lint to v2.12.2 (#68809)
* chore: Bump golangci-lint to v2.12.2 (#68802) * Use reflect.Pointer * Fix sloglint offenders * Bump golangci-lint to v2.12.2 * Run `golangci-lint run --fix` (select packages) * golangci-lint run --fix (integrations/terraform)
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
# Sync with devbox.json.
|
||||
GOLANG_VERSION ?= go1.25.12
|
||||
GOLANGCI_LINT_VERSION ?= v2.7.2
|
||||
GOLANGCI_LINT_VERSION ?= v2.12.2
|
||||
|
||||
# NOTE: Remember to update engines.node in package.json to match the major version.
|
||||
NODE_VERSION ?= 24.18.0
|
||||
|
||||
@@ -505,7 +505,7 @@ func generateDynamoExportData(n int) string {
|
||||
lineFmt := `{ "Item": { "EventIndex": { "N": "2147483647" }, "SessionID": { "S": "4298bd54-a747-4d53-b850-83ba17caae5a" }, "CreatedAtDate": { "S": "2023-05-22" }, "FieldsMap": { "M": { "cluster_name": { "S": "test.example.local" }, "uid": { "S": "%s" }, "code": { "S": "T2005I" }, "ei": { "N": "2147483647" }, "time": { "S": "2023-05-22T12:12:21.966Z" }, "event": { "S": "session.upload" }, "sid": { "S": "4298bd54-a747-4d53-b850-83ba17caae5a" } } }, "EventType": { "S": "session.upload" }, "EventNamespace": { "S": "default" }, "CreatedAt": { "N": "1684757541" } } }`
|
||||
sb := strings.Builder{}
|
||||
for i := 0; i < n; i++ {
|
||||
sb.WriteString(fmt.Sprintf(lineFmt+"\n", uuid.NewString()))
|
||||
fmt.Fprintf(&sb, lineFmt+"\n", uuid.NewString())
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func GetEventSchemaFromType(eventType string) (*Event, error) {
|
||||
// getMessageName takes a message struct and returns its name.
|
||||
// The struct name is also the protobuf message name.
|
||||
func getMessageName(eventStruct interface{}) string {
|
||||
if t := reflect.TypeOf(eventStruct); t.Kind() == reflect.Ptr {
|
||||
if t := reflect.TypeOf(eventStruct); t.Kind() == reflect.Pointer {
|
||||
return t.Elem().Name()
|
||||
} else {
|
||||
return t.Name()
|
||||
|
||||
@@ -173,7 +173,7 @@ func (c *Client) buildBody(reqID string, reqData RequestData, subject string) st
|
||||
var builder strings.Builder
|
||||
builder.Grow(128)
|
||||
|
||||
builder.WriteString(fmt.Sprintf("%v:\n\n", subject))
|
||||
fmt.Fprintf(&builder, "%v:\n\n", subject)
|
||||
|
||||
resolution := reqData.Resolution
|
||||
|
||||
|
||||
@@ -43,10 +43,10 @@ type ErrorResult struct {
|
||||
func (e ErrorResult) Error() string {
|
||||
sb := strings.Builder{}
|
||||
if len(e.ErrorMessages) > 0 {
|
||||
sb.WriteString(fmt.Sprintf("error messages: %s ", strings.Join(e.ErrorMessages, ";")))
|
||||
fmt.Fprintf(&sb, "error messages: %s ", strings.Join(e.ErrorMessages, ";"))
|
||||
}
|
||||
if details := e.Details.String(); details != "" {
|
||||
sb.WriteString(fmt.Sprintf("error details: %s", details))
|
||||
fmt.Fprintf(&sb, "error details: %s", details)
|
||||
}
|
||||
result := sb.String()
|
||||
if result == "" {
|
||||
|
||||
@@ -76,7 +76,7 @@ func newKubeResource[K any]() K {
|
||||
interfaceType := reflect.TypeOf(resource)
|
||||
// If K is not a pointer we don't need to do anything
|
||||
// If K is a pointer, new(K) is only initializing a nil pointer, we need to manually initialize its destination
|
||||
if interfaceType.Kind() == reflect.Ptr {
|
||||
if interfaceType.Kind() == reflect.Pointer {
|
||||
// We create a new Value of the type pointed by K. reflect.New returns a pointer to this value
|
||||
initializedResource := reflect.New(interfaceType.Elem())
|
||||
// We cast back to K
|
||||
|
||||
@@ -65,7 +65,7 @@ func (s CredentialSources) ActiveSources(ctx context.Context, config providerDat
|
||||
}
|
||||
if !active {
|
||||
tflog.Info(ctx, "credentials source is not active, skipping", logFields)
|
||||
inactiveReason.WriteString(fmt.Sprintf(" - cannot read credentials %s because %s\n", source.Name(), reason))
|
||||
fmt.Fprintf(&inactiveReason, " - cannot read credentials %s because %s\n", source.Name(), reason)
|
||||
continue
|
||||
}
|
||||
tflog.Info(ctx, "credentials source is active", logFields)
|
||||
|
||||
@@ -269,7 +269,7 @@ func valuesHelpString[K constraints.Integer](possibleValues map[K]string) string
|
||||
// maps are nor ordered, so we must sort keys to consistently generate the help message.
|
||||
keys := maps.Keys(possibleValues)
|
||||
for _, k := range slices.Sorted(keys) {
|
||||
sb.WriteString(fmt.Sprintf(" %d:%s", k, possibleValues[k]))
|
||||
fmt.Fprintf(&sb, " %d:%s", k, possibleValues[k])
|
||||
}
|
||||
|
||||
sb.WriteRune('.')
|
||||
|
||||
@@ -507,7 +507,7 @@ func exportGitHubCAs(keySet *types.CAKeySet, req ExportIntegrationAuthoritiesReq
|
||||
|
||||
// GitHub only needs the keys like "ssh-rsa xxx" so print them without
|
||||
// cert-authority for easier copy-and-paste.
|
||||
ret.WriteString(fmt.Sprintf("%s integration=%s\n", strings.TrimSpace(string(key.PublicKey)), req.Integration))
|
||||
fmt.Fprintf(&ret, "%s integration=%s\n", strings.TrimSpace(string(key.PublicKey)), req.Integration)
|
||||
}
|
||||
if req.MatchFingerprint != "" && ret.Len() == 0 {
|
||||
return "", trace.NotFound("no authorities found matching the provided fingerprint")
|
||||
|
||||
@@ -79,7 +79,7 @@ func initCommands() map[string]*command {
|
||||
// - another item
|
||||
var limitations strings.Builder
|
||||
for _, l := range descriptiveLimitations {
|
||||
limitations.WriteString(fmt.Sprintf("- %s\n", strings.ReplaceAll(l, lineBreak, lineBreak+" ")))
|
||||
fmt.Fprintf(&limitations, "- %s\n", strings.ReplaceAll(l, lineBreak, lineBreak+" "))
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
|
||||
@@ -265,7 +265,7 @@ func (c *CLIPrompt) Run(ctx context.Context, chal *proto.MFAAuthenticateChalleng
|
||||
ctx,
|
||||
"Disabling Browser MFA: user needs at least one webauthn device and client needs to support SSO MFA Ceremony",
|
||||
"webauthn_available", chal.WebauthnChallenge != nil,
|
||||
"mfa_ceremony_available (if false, this is a bug)", c.cfg.CallbackCeremony != nil,
|
||||
"mfa_ceremony_available", c.cfg.CallbackCeremony != nil,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -265,7 +265,7 @@ func CreateSession(ctx context.Context, req CreateSessionRequest) (*CreateSessio
|
||||
// List of signed headers
|
||||
canonicalReqStrBuilder.WriteString(signedHeaders + "\n")
|
||||
// Body hash encoded as hex
|
||||
canonicalReqStrBuilder.WriteString(fmt.Sprintf("%x", canonicalRequestBodyHash))
|
||||
fmt.Fprintf(&canonicalReqStrBuilder, "%x", canonicalRequestBodyHash)
|
||||
|
||||
// Task 1-8
|
||||
canonicalRequestStr := canonicalReqStrBuilder.String()
|
||||
|
||||
@@ -106,7 +106,7 @@ func WriteCmd(wr *redis.Writer, vals interface{}) error {
|
||||
var err error
|
||||
v := reflect.ValueOf(val)
|
||||
|
||||
if v.Kind() == reflect.Ptr {
|
||||
if v.Kind() == reflect.Pointer {
|
||||
v = v.Elem()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ var serverSessions = prometheus.NewGauge(
|
||||
|
||||
func MsgParticipantCtrls(w io.Writer, m types.SessionParticipantMode) error {
|
||||
var modeCtrl bytes.Buffer
|
||||
modeCtrl.WriteString(fmt.Sprintf("\r\nTeleport > Joining session with participant mode: %s\r\n", string(m)))
|
||||
fmt.Fprintf(&modeCtrl, "\r\nTeleport > Joining session with participant mode: %s\r\n", string(m))
|
||||
modeCtrl.WriteString("Teleport > Controls\r\n")
|
||||
modeCtrl.WriteString("Teleport > - CTRL-C: Leave the session\r\n")
|
||||
if m == types.SessionModeratorMode {
|
||||
|
||||
+1
-1
@@ -268,7 +268,7 @@ func sanitizeSudoersName(username string) string {
|
||||
func (u *HostSudoersManagement) WriteSudoers(name string, sudoers []string) error {
|
||||
var sudoersOut strings.Builder
|
||||
for _, entry := range sudoers {
|
||||
sudoersOut.WriteString(fmt.Sprintf("%s %s\n", name, entry))
|
||||
fmt.Fprintf(&sudoersOut, "%s %s\n", name, entry)
|
||||
}
|
||||
err := u.backend.WriteSudoersFile(name, []byte(sudoersOut.String()))
|
||||
if errors.Is(err, host.ErrInvalidSudoers) {
|
||||
|
||||
@@ -215,7 +215,7 @@ func WriteYAML(w io.Writer, values interface{}) error {
|
||||
// isDoc detects whether value constitutes a document
|
||||
func isDoc(val reflect.Value) bool {
|
||||
iterations := 0
|
||||
for val.Kind() == reflect.Interface || val.Kind() == reflect.Ptr {
|
||||
for val.Kind() == reflect.Interface || val.Kind() == reflect.Pointer {
|
||||
val = val.Elem()
|
||||
// preventing cycles
|
||||
iterations++
|
||||
|
||||
@@ -144,7 +144,7 @@ func FindAllEmpty(item any, ignoreOpts ...string) []string {
|
||||
// dereference pointers and interfaces so that the root find logic starts from
|
||||
// a concrete type (makes the returned paths more consistent/understandable).
|
||||
switch value.Kind() {
|
||||
case reflect.Ptr, reflect.Interface:
|
||||
case reflect.Pointer, reflect.Interface:
|
||||
if value.IsNil() {
|
||||
panic("FindAllEmpty called with nil top-level pointer/interface")
|
||||
}
|
||||
|
||||
@@ -346,11 +346,11 @@ func (c *AutoUpdateCommand) omittedSummary(reports []*autoupdatev1pb.AutoUpdateA
|
||||
|
||||
var sb strings.Builder
|
||||
sb.WriteRune('\n')
|
||||
sb.WriteString(fmt.Sprintf("%d agents were omitted from the reports:\n", totalOmitted))
|
||||
fmt.Fprintf(&sb, "%d agents were omitted from the reports:\n", totalOmitted)
|
||||
// We sort reasons alphabetically as this ensures the output is consistent
|
||||
// And makes snapshot testing easier.
|
||||
for _, reason := range slices.Sorted(maps.Keys(aggregated)) {
|
||||
sb.WriteString(fmt.Sprintf("- %d omitted because: %s\n", aggregated[reason], reason))
|
||||
fmt.Fprintf(&sb, "- %d omitted because: %s\n", aggregated[reason], reason)
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user