Skip to content

Commit

Permalink
Fix lint issues after using golangci-lint-1.52.2 (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkl73 authored Mar 31, 2023
1 parent 6f036c5 commit cdfbf3d
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (ae alwaysError) Write([]byte) (int, error) {
return 0, ae.error
}

func (ae alwaysError) Read(p []byte) (n int, err error) {
func (ae alwaysError) Read(_ []byte) (n int, err error) {
return 0, ae.error
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func init() {
addPublicKeyAlgoFlag(pubkeyCmd)
}

func getKey(rw io.ReadWriter, hierarchy tpmutil.Handle, algo tpm2.Algorithm) (*client.Key, error) {
func getKey(rw io.ReadWriter, hierarchy tpmutil.Handle, _ tpm2.Algorithm) (*client.Key, error) {
fmt.Fprintf(debugOutput(), "Using hierarchy 0x%x\n", hierarchy)
if nvIndex != 0 {
fmt.Fprintf(debugOutput(), "Reading from NVDATA index %d\n", nvIndex)
Expand Down
2 changes: 1 addition & 1 deletion launcher/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ func TestAttest(t *testing.T) {
fmt.Printf("token.Claims: %v\n", token.Claims)
}

func placeholderFetcher(audience string) ([][]byte, error) {
func placeholderFetcher(_ string) ([][]byte, error) {
return [][]byte{}, nil
}
4 changes: 2 additions & 2 deletions launcher/container_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func fetchImpersonatedToken(ctx context.Context, serviceAccount string, audience

// NewRunner returns a runner.
func NewRunner(ctx context.Context, cdClient *containerd.Client, token oauth2.Token, launchSpec spec.LaunchSpec, mdsClient *metadata.Client, tpm io.ReadWriteCloser, logger *log.Logger) (*ContainerRunner, error) {
image, err := initImage(ctx, cdClient, launchSpec, token, logger)
image, err := initImage(ctx, cdClient, launchSpec, token)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -515,7 +515,7 @@ func (r *ContainerRunner) Run(ctx context.Context) error {
return nil
}

func initImage(ctx context.Context, cdClient *containerd.Client, launchSpec spec.LaunchSpec, token oauth2.Token, logger *log.Logger) (containerd.Image, error) {
func initImage(ctx context.Context, cdClient *containerd.Client, launchSpec spec.LaunchSpec, token oauth2.Token) (containerd.Image, error) {
if token.Valid() {
remoteOpt := containerd.WithResolver(Resolver(token.AccessToken))

Expand Down
4 changes: 2 additions & 2 deletions launcher/container_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func TestInitImageDockerPublic(t *testing.T) {
ctx := namespaces.WithNamespace(context.Background(), "test")
// This is a "valid" token (formatwise)
validToken := oauth2.Token{AccessToken: "000000", Expiry: time.Now().Add(time.Hour)}
if _, err := initImage(ctx, containerdClient, spec.LaunchSpec{ImageRef: "docker.io/library/hello-world:latest"}, validToken, log.Default()); err != nil {
if _, err := initImage(ctx, containerdClient, spec.LaunchSpec{ImageRef: "docker.io/library/hello-world:latest"}, validToken); err != nil {
t.Error(err)
} else {
if err := containerdClient.ImageService().Delete(ctx, "docker.io/library/hello-world:latest"); err != nil {
Expand All @@ -489,7 +489,7 @@ func TestInitImageDockerPublic(t *testing.T) {
}

invalidToken := oauth2.Token{}
if _, err := initImage(ctx, containerdClient, spec.LaunchSpec{ImageRef: "docker.io/library/hello-world:latest"}, invalidToken, log.Default()); err != nil {
if _, err := initImage(ctx, containerdClient, spec.LaunchSpec{ImageRef: "docker.io/library/hello-world:latest"}, invalidToken); err != nil {
t.Error(err)
} else {
if err := containerdClient.ImageService().Delete(ctx, "docker.io/library/hello-world:latest"); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions launcher/verifier/fake/fakeverifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewClient(signer crypto.Signer) verifier.Client {
//
// If you have found this method is insufficient for your tests, this class must be updated to
// allow for better testing.
func (fc *fakeClient) CreateChallenge(ctx context.Context) (*verifier.Challenge, error) {
func (fc *fakeClient) CreateChallenge(_ context.Context) (*verifier.Challenge, error) {
bs := make([]byte, 2)
binary.LittleEndian.PutUint16(bs, 15)
return &verifier.Challenge{
Expand All @@ -37,7 +37,7 @@ func (fc *fakeClient) CreateChallenge(ctx context.Context) (*verifier.Challenge,
//
// If you have found this method is insufficient for your tests, this class must be updated to
// allow for better testing.
func (fc *fakeClient) VerifyAttestation(ctx context.Context, request verifier.VerifyAttestationRequest) (*verifier.VerifyAttestationResponse, error) {
func (fc *fakeClient) VerifyAttestation(_ context.Context, _ verifier.VerifyAttestationRequest) (*verifier.VerifyAttestationResponse, error) {
// Determine signing algorithm.
signingMethod := jwt.SigningMethodRS256
now := jwt.TimeFunc()
Expand Down
4 changes: 2 additions & 2 deletions launcher/verifier/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type restClient struct {
}

// CreateChallenge implements verifier.Client
func (c *restClient) CreateChallenge(ctx context.Context) (*verifier.Challenge, error) {
func (c *restClient) CreateChallenge(_ context.Context) (*verifier.Challenge, error) {
// Pass an empty Challenge for the input (all params are output-only)
chal, err := c.service.Projects.Locations.Challenges.Create(
c.location.Name,
Expand All @@ -89,7 +89,7 @@ func (c *restClient) CreateChallenge(ctx context.Context) (*verifier.Challenge,
}

// VerifyAttestation implements verifier.Client
func (c *restClient) VerifyAttestation(ctx context.Context, request verifier.VerifyAttestationRequest) (*verifier.VerifyAttestationResponse, error) {
func (c *restClient) VerifyAttestation(_ context.Context, request verifier.VerifyAttestationRequest) (*verifier.VerifyAttestationResponse, error) {
if request.Challenge == nil || request.Attestation == nil {
return nil, fmt.Errorf("nil value provided in challenge")
}
Expand Down
2 changes: 1 addition & 1 deletion launcher/verifier/rest/rest_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func testClient(t *testing.T) verifier.Client {
return vClient
}

func testFetcher(audience string) ([][]byte, error) {
func testFetcher(_ string) ([][]byte, error) {
return [][]byte{}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions server/eventlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func parseCanonicalEventLog(rawCanonicalEventLog []byte, pcrs *tpmpb.PCRs) (*pb.
return nil, err
}

cosState, err := getVerifiedCosState(decodedCEL, pcrs)
cosState, err := getVerifiedCosState(decodedCEL)
if err != nil {
return nil, err
}
Expand All @@ -117,7 +117,7 @@ func contains(set [][]byte, value []byte) bool {
return false
}

func getVerifiedCosState(coscel cel.CEL, pcrs *tpmpb.PCRs) (*pb.AttestedCosState, error) {
func getVerifiedCosState(coscel cel.CEL) (*pb.AttestedCosState, error) {
cosState := &pb.AttestedCosState{}
cosState.Container = &pb.ContainerState{}
cosState.Container.Args = make([]string, 0)
Expand Down
5 changes: 1 addition & 4 deletions server/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import (
// will describe in what way the state failed. See the Policy documentation for
// more information about the specifics of different policies.
func EvaluatePolicy(state *pb.MachineState, policy *pb.Policy) error {
if err := evaluatePlatformPolicy(state.GetPlatform(), policy.GetPlatform()); err != nil {
return err
}
return nil
return evaluatePlatformPolicy(state.GetPlatform(), policy.GetPlatform())
}

func evaluatePlatformPolicy(state *pb.PlatformState, policy *pb.PlatformPolicy) error {
Expand Down
2 changes: 1 addition & 1 deletion simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (s *Simulator) IsClosed() bool {
return s.closed
}

func (s *Simulator) on(manufactureReset bool) error {
func (s *Simulator) on(_ bool) error {
// TPM2_Startup must be the first command the TPM receives.
if err := tpm2.Startup(s, tpm2.StartupClear); err != nil {
return fmt.Errorf("startup: %w", err)
Expand Down

0 comments on commit cdfbf3d

Please sign in to comment.