Skip to content

Commit

Permalink
Add const for unknown grant id. (#222)
Browse files Browse the repository at this point in the history
* Add const for unknown grant id.

* Fix linter errors that now show up in golangci-lint v1.61.0

* Fix test.
  • Loading branch information
ggreer authored Sep 9, 2024
1 parent dcf4ea6 commit ec584af
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions pkg/dotc1z/c1file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ func TestC1ZDecoder(t *testing.T) {
require.Equal(t, dbFile, b.Bytes())
b.Reset()

require.GreaterOrEqual(t, n, int64(0))

// Test max size exact
//nolint:gosec // No risk of overflow because n is always >= 0.
d, err = NewDecoder(c1zf, WithDecoderMaxDecodedSize(uint64(n)))
require.NoError(t, err)
_, err = io.Copy(b, d)
Expand All @@ -203,6 +206,8 @@ func TestC1ZDecoder(t *testing.T) {
b.Reset()

// Test max size - 1
require.GreaterOrEqual(t, n, int64(1))
//nolint:gosec // No risk of overflow because n is always > 0.
d, err = NewDecoder(c1zf, WithDecoderMaxDecodedSize(uint64(n-1)))
require.NoError(t, err)
_, err = io.Copy(io.Discard, d)
Expand Down
1 change: 1 addition & 0 deletions pkg/dotc1z/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func (d *decoder) Read(p []byte) (int, error) {

// Do underlying read
n, err := d.zd.Read(p)
//nolint:gosec // No risk of overflow/underflow because n is always >= 0.
d.decodedBytes += uint64(n)
if err != nil {
// NOTE(morgabra) This happens if you set a small DecoderMaxMemory
Expand Down
4 changes: 2 additions & 2 deletions pkg/dotc1z/sql_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (c *C1File) listConnectorObjects(ctx context.Context, tableName string, req
}

// Clamp the page size
pageSize := int(listReq.GetPageSize())
pageSize := listReq.GetPageSize()
if pageSize > maxPageSize || pageSize == 0 {
pageSize = maxPageSize
}
Expand All @@ -206,7 +206,7 @@ func (c *C1File) listConnectorObjects(ctx context.Context, tableName string, req
}
defer rows.Close()

count := 0
var count uint32 = 0
lastRow := 0
for rows.Next() {
count++
Expand Down
6 changes: 3 additions & 3 deletions pkg/dotc1z/sync_runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (c *C1File) getFinishedSync(ctx context.Context, offset uint) (*syncRun, er
return ret, nil
}

func (c *C1File) ListSyncRuns(ctx context.Context, pageToken string, pageSize int) ([]*syncRun, string, error) {
func (c *C1File) ListSyncRuns(ctx context.Context, pageToken string, pageSize uint) ([]*syncRun, string, error) {
err := c.validateDb(ctx)
if err != nil {
return nil, "", err
Expand All @@ -138,7 +138,7 @@ func (c *C1File) ListSyncRuns(ctx context.Context, pageToken string, pageSize in
}

q = q.Order(goqu.C("id").Asc())
q = q.Limit(uint(pageSize + 1))
q = q.Limit(pageSize + 1)

var ret []*syncRun

Expand All @@ -153,7 +153,7 @@ func (c *C1File) ListSyncRuns(ctx context.Context, pageToken string, pageSize in
}
defer rows.Close()

count := 0
var count uint = 0
lastRow := 0
for rows.Next() {
count++
Expand Down
3 changes: 3 additions & 0 deletions pkg/types/grant/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type GrantPrincipal interface {
GetBatonResource() bool
}

// Sometimes C1 doesn't have the grant ID, but does have the principal and entitlement.
const UnknownGrantId string = "🧸_UNKNOWN_GRANT_ID"

func WithGrantMetadata(metadata map[string]interface{}) GrantOption {
return func(g *v2.Grant) error {
md, err := structpb.NewStruct(metadata)
Expand Down

0 comments on commit ec584af

Please sign in to comment.