Skip to content
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

all: use errors.New() which has no param instead of fmt.Errorf() #47

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package vault_auth_tee
import (
"context"
"crypto/tls"
"errors"
"fmt"
"io"
"testing"
Expand Down Expand Up @@ -189,7 +190,7 @@ func testAccStepTEE(_ *testing.T, name string, types string, mrSigner string, mr
Data: data,
Check: func(resp *logical.Response) error {
if resp == nil && expectError {
return fmt.Errorf("expected error but received nil")
return errors.New("expected error but received nil")
}
return nil
},
Expand Down
11 changes: 6 additions & 5 deletions path_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"encoding/binary"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -73,7 +74,7 @@ func (b *backend) loginPathWrapper(wrappedOp func(ctx context.Context, req *logi
func (b *backend) pathLoginResolveRole(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
quoteBase64 := data.Get("quote").(string)
if quoteBase64 == "" {
return nil, fmt.Errorf("missing quote")
return nil, errors.New("missing quote")
}

quoteBytes, err := base64.StdEncoding.DecodeString(quoteBase64)
Expand Down Expand Up @@ -127,7 +128,7 @@ func (b *backend) pathLoginResolveRole(ctx context.Context, req *logical.Request
func (b *backend) pathLoginAliasLookahead(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
name := d.Get("name").(string)
if name == "" {
return nil, fmt.Errorf("missing name")
return nil, errors.New("missing name")
}

return &logical.Response{
Expand Down Expand Up @@ -161,7 +162,7 @@ func Contains[T comparable](s []T, e T) bool {
func (b *backend) pathLogin(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
name := data.Get("name").(string)
if name == "" {
return nil, fmt.Errorf("missing name")
return nil, errors.New("missing name")
}

// Allow constraining the login request to a single TeeEntry
Expand Down Expand Up @@ -371,7 +372,7 @@ func (b *backend) pathLoginRenew(ctx context.Context, req *logical.Request, d *f
// Certificate should not only match a registered tee policy.
// Also, the identity of the certificate presented should match the identity of the certificate used during login
if req.Auth.InternalData["subject_key_id"] != skid && req.Auth.InternalData["authority_key_id"] != akid && req.Auth.InternalData["hash_public_key"] != pkid {
return nil, fmt.Errorf("client identity during renewal not matching client identity used during login")
return nil, errors.New("client identity during renewal not matching client identity used during login")
}

// Get the tee and use its TTL
Expand All @@ -385,7 +386,7 @@ func (b *backend) pathLoginRenew(ctx context.Context, req *logical.Request, d *f
}

if !policyutil.EquivalentPolicies(tee.TokenPolicies, req.Auth.TokenPolicies) {
return nil, fmt.Errorf("policies have changed, not renewing")
return nil, errors.New("policies have changed, not renewing")
}

expirationDate, err := time.Parse(time.RFC3339, req.Auth.Metadata["collateral_expiration_date"])
Expand Down
11 changes: 6 additions & 5 deletions roughntstime.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ package vault_auth_tee

import (
"crypto/tls"
"fmt"
"gitlab.com/hacklunch/ntp"
"gitlab.com/hacklunch/ntske"
"errors"
"log"
"math/rand"
"time"

"gitlab.com/hacklunch/ntp"
"gitlab.com/hacklunch/ntske"
)

// Gets the rough network time using NTS-KE.
Expand Down Expand Up @@ -105,11 +106,11 @@ func getRoughNtsUnixTime() (time.Time, error) {
}

if queried < numToQuery {
return retTime, fmt.Errorf("failed to query enough servers")
return retTime, errors.New("failed to query enough servers")
}

if sumOffset > time.Minute {
return retTime, fmt.Errorf("queried time fluctuates too much")
return retTime, errors.New("queried time fluctuates too much")
}

return retTime, nil
Expand Down
Loading