Skip to content

Commit db496d5

Browse files
committed
Fix new lint rules
1 parent 0d28854 commit db496d5

5 files changed

Lines changed: 26 additions & 21 deletions

File tree

pkg/privateactionrunner/adapters/config/transform.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package config
77

88
import (
99
"crypto/ecdsa"
10+
"errors"
1011
"fmt"
1112
"strconv"
1213
"strings"
@@ -46,15 +47,15 @@ func FromDDConfig(config config.Component) (*Config, error) {
4647
urn := config.GetString("privateactionrunner.urn")
4748

4849
if encodedPrivateKey == "" {
49-
return nil, fmt.Errorf("private action runner not configured: either run enrollment or provide privateactionrunner.private_key")
50+
return nil, errors.New("private action runner not configured: either run enrollment or provide privateactionrunner.private_key")
5051
}
5152
privateKey, err := util.Base64ToJWK(encodedPrivateKey)
5253
if err != nil {
5354
return nil, fmt.Errorf("failed to decode privateactionrunner.private_key: %w", err)
5455
}
5556

5657
if urn == "" {
57-
return nil, fmt.Errorf("private action runner not configured: URN is required")
58+
return nil, errors.New("private action runner not configured: URN is required")
5859
}
5960

6061
orgID, runnerID, err := parseURN(urn)
@@ -113,7 +114,7 @@ func parseURN(urn string) (int64, string, error) {
113114

114115
runnerID := parts[6]
115116
if runnerID == "" {
116-
return 0, "", fmt.Errorf("runner_id cannot be empty in URN")
117+
return 0, "", errors.New("runner_id cannot be empty in URN")
117118
}
118119

119120
return orgID, runnerID, nil

pkg/privateactionrunner/credentials/resolver/credentials_resolver.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package resolver
88
import (
99
"context"
1010
"encoding/json"
11+
"errors"
1112
"fmt"
1213
"io"
1314
"os"
@@ -127,7 +128,7 @@ func resolveBasicAuthTokens(ctx context.Context, tokens []*privateactionspb.Conn
127128
}
128129
}
129130
if pwdToken == nil || username == "" {
130-
return []privateconnection.PrivateCredentialsToken{}, fmt.Errorf("no credential found")
131+
return []privateconnection.PrivateCredentialsToken{}, errors.New("no credential found")
131132
}
132133
secret, err := getSecretFromDockerLocation(ctx, pwdToken.GetFileSecret().GetPath(), username)
133134
if err != nil {
@@ -218,7 +219,7 @@ func loadConnectionCredentials(ctx context.Context, path string) (config *Privat
218219

219220
func validateAndReadFile(ctx context.Context, path string) ([]byte, error) {
220221
if path == "" {
221-
return nil, fmt.Errorf("credential file path is empty")
222+
return nil, errors.New("credential file path is empty")
222223
}
223224
file, err := os.Open(path)
224225
if err != nil {
@@ -231,10 +232,10 @@ func validateAndReadFile(ctx context.Context, path string) ([]byte, error) {
231232
return nil, err
232233
}
233234
if stat.Size() == 0 {
234-
return nil, fmt.Errorf("the credentials file is empty")
235+
return nil, errors.New("the credentials file is empty")
235236
}
236237
if stat.Size() > maxCredentialsFileSize {
237-
return nil, fmt.Errorf("the credentials file is too large")
238+
return nil, errors.New("the credentials file is too large")
238239
}
239240

240241
data, err := os.ReadFile(path)

pkg/privateactionrunner/remote-config/keys_manager.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"crypto/x509"
1212
"encoding/json"
1313
"encoding/pem"
14+
"errors"
1415
"fmt"
1516
"sync"
1617

@@ -114,7 +115,7 @@ func decode(rawConfig state.RawConfig) (types.DecodedKey, error) {
114115
func decodeX509RSA(k types.RawKey) (*types.X509RSAKey, error) {
115116
blocks, _ := pem.Decode(k.Key)
116117
if blocks == nil {
117-
return nil, fmt.Errorf("failed to decode PEM block")
118+
return nil, errors.New("failed to decode PEM block")
118119
}
119120
cert, err := x509.ParseCertificate(blocks.Bytes)
120121
if err != nil {
@@ -129,15 +130,15 @@ func decodeX509RSA(k types.RawKey) (*types.X509RSAKey, error) {
129130
func decodeED25519(k types.RawKey) (*types.ED25519Key, error) {
130131
blocks, _ := pem.Decode(k.Key)
131132
if blocks == nil {
132-
return nil, fmt.Errorf("failed to decode PEM block")
133+
return nil, errors.New("failed to decode PEM block")
133134
}
134135
keyAny, err := x509.ParsePKIXPublicKey(blocks.Bytes)
135136
if err != nil {
136137
return nil, fmt.Errorf("failed to parse ED25519 public key: %w", err)
137138
}
138139
keyED25519, ok := keyAny.(ed25519.PublicKey)
139140
if !ok {
140-
return nil, fmt.Errorf("failed to cast to ed25519.PublicKey")
141+
return nil, errors.New("failed to cast to ed25519.PublicKey")
141142
}
142143
return &types.ED25519Key{
143144
KeyType: k.KeyType,

pkg/privateactionrunner/runners/workflow_runner.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package runners
77

88
import (
99
"context"
10+
"errors"
1011
"fmt"
1112
"time"
1213

@@ -99,10 +100,10 @@ func (n *WorkflowRunner) RunTask(
99100
if actions.IsHttpBundle(bundleName) {
100101
url, ok := task.Data.Attributes.Inputs["url"].(string)
101102
if !ok {
102-
return nil, util.DefaultActionError(fmt.Errorf("missing required field url"))
103+
return nil, util.DefaultActionError(errors.New("missing required field url"))
103104
}
104105
if !n.config.IsURLInAllowlist(url) {
105-
return nil, util.DefaultActionError(fmt.Errorf("request url is not allowed by runner policy: check your configuration file"))
106+
return nil, util.DefaultActionError(errors.New("request url is not allowed by runner policy: check your configuration file"))
106107
}
107108
}
108109

pkg/privateactionrunner/task-verifier/verifier.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package taskverifier
77

88
import (
99
"crypto/sha256"
10+
"errors"
1011
"fmt"
1112
"time"
1213

@@ -31,15 +32,15 @@ func NewTaskVerifier(keysManager remoteconfig.KeysManager, config *config.Config
3132

3233
func (t *TaskVerifier) UnwrapTaskFromSignedEnvelope(envelope *privateactionspb.RemoteConfigSignatureEnvelope) (*types.Task, error) {
3334
if envelope == nil {
34-
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_INTERNAL_ERROR, fmt.Errorf("task is missing signed envelope"))
35+
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_INTERNAL_ERROR, errors.New("task is missing signed envelope"))
3536
}
3637

3738
if len(envelope.Data) == 0 {
38-
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_INTERNAL_ERROR, fmt.Errorf("data is missing"))
39+
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_INTERNAL_ERROR, errors.New("data is missing"))
3940
}
4041

4142
if len(envelope.Signatures) == 0 {
42-
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_INTERNAL_ERROR, fmt.Errorf("signatures are missing"))
43+
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_INTERNAL_ERROR, errors.New("signatures are missing"))
4344
}
4445

4546
if envelope.HashType != privateactionspb.HashType_SHA256 {
@@ -50,20 +51,20 @@ func (t *TaskVerifier) UnwrapTaskFromSignedEnvelope(envelope *privateactionspb.R
5051
var task privateactionspb.PrivateActionTask
5152
err := proto.Unmarshal(envelope.Data, &task)
5253
if err != nil {
53-
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_INTERNAL_ERROR, fmt.Errorf("failed to unmarshal task"))
54+
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_INTERNAL_ERROR, errors.New("failed to unmarshal task"))
5455
}
5556

5657
if task.ExpirationTime == nil {
57-
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_INTERNAL_ERROR, fmt.Errorf("expiration time is missing"))
58+
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_INTERNAL_ERROR, errors.New("expiration time is missing"))
5859
}
5960

6061
if task.ExpirationTime.AsTime().Before(time.Now()) {
61-
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_EXPIRED_TASK, fmt.Errorf("task is expired"))
62+
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_EXPIRED_TASK, errors.New("task is expired"))
6263
}
6364

6465
signature, localKey := t.getCandidateSignatureWithKey(envelope)
6566
if localKey == nil {
66-
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_SIGNATURE_KEY_NOT_FOUND, fmt.Errorf("no matching key found"))
67+
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_SIGNATURE_KEY_NOT_FOUND, errors.New("no matching key found"))
6768
}
6869

6970
localKeyType := localKey.GetKeyType()
@@ -77,11 +78,11 @@ func (t *TaskVerifier) UnwrapTaskFromSignedEnvelope(envelope *privateactionspb.R
7778
}
7879

7980
if task.OrgId != t.config.OrgId {
80-
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_MISMATCHED_ORG_ID, fmt.Errorf("task orgId doesn't match the orgId of the runner"))
81+
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_MISMATCHED_ORG_ID, errors.New("task orgId doesn't match the orgId of the runner"))
8182
}
8283

8384
if task.GetConnectionInfo().RunnerId != t.config.RunnerId {
84-
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_MISMATCHED_RUNNER_ID, fmt.Errorf("connection runnerId doesn't match the id of the runner"))
85+
return nil, util.NewPARError(aperrorpb.ActionPlatformErrorCode_MISMATCHED_RUNNER_ID, errors.New("connection runnerId doesn't match the id of the runner"))
8586
}
8687

8788
return mapPbTaskToStruct(&task), nil

0 commit comments

Comments
 (0)