Skip to content

Commit

Permalink
Merge pull request #298 from overmindtech/use_centralized_golangci_co…
Browse files Browse the repository at this point in the history
…nfig

(maint) enable golangci-lint
  • Loading branch information
tphoney authored Aug 22, 2024
2 parents 7e9aec8 + 7d0dfd8 commit 35f9e3a
Show file tree
Hide file tree
Showing 26 changed files with 541 additions and 409 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ jobs:
- name: Go vet
run: go vet ./...

# get .golangci.yml from github.com/overmindtech/golangci-lint_config
- name: Get .golangci.yml from github.com/overmindtech/golangci-lint_configs
run: |
curl -sfL https://raw.githubusercontent.com/overmindtech/golangci-lint_config/main/.golangci.yml -o .golangci.yml
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60.1
args: --timeout 3m
skip-cache: true # the linters require all code generation and dependecies to be present, but the cache implementation completely falls over when there is already existing content. See https://github.com/golangci/golangci-lint-action/issues/23, https://github.com/golangci/golangci-lint-action/issues/863, https://github.com/golangci/golangci-lint-action/issues/984

- name: re-export environment
run: |
grep -h '^[^#]' .github/env/*.env | sort -u | tee -a "${GITHUB_ENV}"
Expand Down
16 changes: 8 additions & 8 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ func (n *natsTokenClient) generateJWT(ctx context.Context) error {
// Use the regular API and let the client authentication determine what our org should be
log.WithFields(log.Fields{
"account": n.Account,
"publicNKey": req.UserPublicNkey,
"UserName": req.UserName,
"publicNKey": req.GetUserPublicNkey(),
"UserName": req.GetUserName(),
}).Trace("Using regular API to get NATS token")
response, err = n.mgmtClient.CreateToken(ctx, connect.NewRequest(req))
} else {
log.WithFields(log.Fields{
"account": n.Account,
"publicNKey": req.UserPublicNkey,
"UserName": req.UserName,
"publicNKey": req.GetUserPublicNkey(),
"UserName": req.GetUserName(),
}).Trace("Using admin API to get NATS token")
// Explicitly request an org
response, err = n.adminClient.CreateToken(ctx, connect.NewRequest(&sdp.AdminCreateTokenRequest{
Expand All @@ -223,7 +223,7 @@ func (n *natsTokenClient) generateJWT(ctx context.Context) error {
return fmt.Errorf("getting NATS token failed: %w", err)
}

n.jwt = response.Msg.Token
n.jwt = response.Msg.GetToken()

return nil
}
Expand Down Expand Up @@ -323,12 +323,12 @@ func (ats *APIKeyTokenSource) Token() (*oauth2.Token, error) {
return nil, fmt.Errorf("error exchanging API key: %w", err)
}

if res.Msg.AccessToken == "" {
if res.Msg.GetAccessToken() == "" {
return nil, errors.New("no access token returned")
}

// Parse the expiry out of the token
token, err := josejwt.ParseSigned(res.Msg.AccessToken, []jose.SignatureAlgorithm{jose.RS256})
token, err := josejwt.ParseSigned(res.Msg.GetAccessToken(), []jose.SignatureAlgorithm{jose.RS256})

if err != nil {
return nil, fmt.Errorf("error parsing JWT: %w", err)
Expand All @@ -343,7 +343,7 @@ func (ats *APIKeyTokenSource) Token() (*oauth2.Token, error) {
}

ats.token = &oauth2.Token{
AccessToken: res.Msg.AccessToken,
AccessToken: res.Msg.GetAccessToken(),
TokenType: "Bearer",
Expiry: claims.Expiry.Time(),
}
Expand Down
4 changes: 2 additions & 2 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestBasicTokenClient(t *testing.T) {
t.Error(err)
}

if token != "tokeny_mc_tokenface" {
if token != "tokeny_mc_tokenface" { // nolint: gosec // This is a test
t.Error("token mismatch")
}

Expand Down Expand Up @@ -180,7 +180,7 @@ func testURL(testURL string) error {
url, err := url.Parse(testURL)

if err != nil {
return fmt.Errorf("could not parse NATS URL: %v. Error: %v", testURL, err)
return fmt.Errorf("could not parse NATS URL: %v. Error: %w", testURL, err)
}

conn, err := net.DialTimeout("tcp", net.JoinHostPort(url.Hostname(), url.Port()), time.Second)
Expand Down
17 changes: 8 additions & 9 deletions auth/nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package auth

import (
"context"
"errors"
"testing"
"time"

Expand Down Expand Up @@ -217,10 +218,8 @@ func TestNATSConnect(t *testing.T) {
t.Errorf("Reconnecting took too long, expected <3s got: %v", time.Since(start).String())
}

switch err.(type) {
case MaxRetriesError:
// This is good
default:
var maxRetriesError MaxRetriesError
if !errors.As(err, &maxRetriesError) {
t.Errorf("Unknown error type %T: %v", err, err)
}
})
Expand All @@ -243,8 +242,8 @@ func TestNATSConnect(t *testing.T) {

_, err = o.Connect()

switch err.(type) {
case MaxRetriesError:
var maxRetriesError MaxRetriesError
if errors.As(err, &maxRetriesError) {
// Make sure we have only got one token, not three
currentToken, err := o.TokenClient.GetJWT()

Expand All @@ -255,7 +254,7 @@ func TestNATSConnect(t *testing.T) {
if currentToken != startToken {
t.Error("Tokens have changed")
}
default:
} else {
t.Errorf("Unknown error type %T", err)
}
})
Expand Down Expand Up @@ -364,12 +363,12 @@ func ValidateNATSConnection(t *testing.T, ec sdp.EncodedConnection) {
done := make(chan struct{})

sub, err := ec.Subscribe("test", sdp.NewQueryResponseHandler("test", func(ctx context.Context, qr *sdp.QueryResponse) {
rt, ok := qr.ResponseType.(*sdp.QueryResponse_Response)
rt, ok := qr.GetResponseType().(*sdp.QueryResponse_Response)
if !ok {
t.Errorf("Received unexpected message: %v", qr)
}

if rt.Response.Responder == "test" {
if rt.Response.GetResponder() == "test" {
done <- struct{}{}
}
}))
Expand Down
16 changes: 8 additions & 8 deletions bookmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ package sdp

func (b *Bookmark) ToMap() map[string]any {
return map[string]any{
"metadata": b.Metadata.ToMap(),
"properties": b.Properties.ToMap(),
"metadata": b.GetMetadata().ToMap(),
"properties": b.GetProperties().ToMap(),
}
}

func (bm *BookmarkMetadata) ToMap() map[string]any {
return map[string]any{
"UUID": stringFromUuidBytes(bm.UUID),
"created": bm.Created.AsTime(),
"UUID": stringFromUuidBytes(bm.GetUUID()),
"created": bm.GetCreated().AsTime(),
}
}

func (bp *BookmarkProperties) ToMap() map[string]any {
return map[string]any{
"name": bp.Name,
"description": bp.Description,
"queries": bp.Queries,
"excludedItems": bp.ExcludedItems,
"name": bp.GetName(),
"description": bp.GetDescription(),
"queries": bp.GetQueries(),
"excludedItems": bp.GetExcludedItems(),
}
}
Loading

0 comments on commit 35f9e3a

Please sign in to comment.