Skip to content

Commit

Permalink
Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Krstic committed Dec 16, 2024
1 parent 5fcd0d7 commit 38ecd3d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions client/pcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
// CertifyHashAlgTpm is the hard-coded algorithm used in certify PCRs.
const CertifyHashAlgTpm = tpm2.AlgSHA256

func min(a, b int) int {
func minimum(a, b int) int {
if a < b {
return a
}
Expand Down Expand Up @@ -66,7 +66,7 @@ func ReadPCRs(rw io.ReadWriter, sel tpm2.PCRSelection) (*pb.PCRs, error) {
}

for i := 0; i < len(sel.PCRs); i += 8 {
end := min(i+8, len(sel.PCRs))
end := minimum(i+8, len(sel.PCRs))
pcrSel := tpm2.PCRSelection{
Hash: sel.Hash,
PCRs: sel.PCRs[i:end],
Expand Down
3 changes: 3 additions & 0 deletions internal/models/token_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ type ContainerImageSignatures struct {
KeyIDs []string `json:"key_ids"`
}

// HasAWSPrincipalTagOptions returns true if PrincipalTagOptions is not nil.
func (t TokenOptions) HasAWSPrincipalTagOptions() bool {
return t.PrincipalTagOptions != nil
}

// HasAllowedPrincipalTags returns true if AllowedPrincipalTags is not nil.
func (a AWSPrincipalTagsOptions) HasAllowedPrincipalTags() bool {
return a.AllowedPrincipalTags != nil
}

// HasContainerImageSignatures returns true if ContainerImageSignatures is not nil.
func (a AllowedPrincipalTags) HasContainerImageSignatures() bool {
return a.ContainerImageSignatures != nil
}
8 changes: 4 additions & 4 deletions internal/pcrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (
const minPCRIndex = uint32(0)

func maxPCRIndex(p *pb.PCRs) uint32 {
max := minPCRIndex
high := minPCRIndex
for idx := range p.GetPcrs() {
if idx > max {
max = idx
if idx > high {
high = idx
}
}
return max
return high
}

// FormatPCRs writes a multiline representation of the PCR values to w.
Expand Down
12 changes: 6 additions & 6 deletions launcher/teeserver/tee_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (a *attestHandler) getToken(w http.ResponseWriter, r *http.Request) {

if err != nil {
err = fmt.Errorf("failed to get the token")
a.logAndWriteHttpError(w, http.StatusNotFound, err)
a.logAndWriteHTTPError(w, http.StatusNotFound, err)
return
}
w.WriteHeader(http.StatusOK)
Expand All @@ -91,21 +91,21 @@ func (a *attestHandler) getToken(w http.ResponseWriter, r *http.Request) {

err := decoder.Decode(&tokenOptions)
if err != nil {
a.logAndWriteHttpError(w, http.StatusBadRequest, err)
a.logAndWriteHTTPError(w, http.StatusBadRequest, err)
return
}

err = validateTokenOptions(tokenOptions)
if err != nil {
a.logAndWriteHttpError(w, http.StatusBadRequest, err)
a.logAndWriteHTTPError(w, http.StatusBadRequest, err)
return
}

tok, err := a.attestAgent.Attest(a.ctx, agent.AttestAgentOpts{
TokenOptions: &tokenOptions,
})
if err != nil {
a.logAndWriteHttpError(w, http.StatusBadRequest, err)
a.logAndWriteHTTPError(w, http.StatusBadRequest, err)
return
}

Expand All @@ -115,11 +115,11 @@ func (a *attestHandler) getToken(w http.ResponseWriter, r *http.Request) {
default:
// TODO: add an url pointing to the REST API document
err := fmt.Errorf("TEE server recieved an invalid HTTP method: %s", r.Method)

Check failure on line 117 in launcher/teeserver/tee_server.go

View workflow job for this annotation

GitHub Actions / Lint ./launcher (ubuntu-latest, Go 1.21.x)

`recieved` is a misspelling of `received` (misspell)
a.logAndWriteHttpError(w, http.StatusBadRequest, err)
a.logAndWriteHTTPError(w, http.StatusBadRequest, err)
}
}

func (a *attestHandler) logAndWriteHttpError(w http.ResponseWriter, statusCode int, err error) {
func (a *attestHandler) logAndWriteHTTPError(w http.ResponseWriter, statusCode int, err error) {
a.logger.Error(err.Error())
w.WriteHeader(statusCode)
w.Write([]byte(err.Error()))
Expand Down

0 comments on commit 38ecd3d

Please sign in to comment.