Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaeta committed Aug 23, 2024
1 parent 6b9d6a5 commit 384deb0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 53 deletions.
53 changes: 0 additions & 53 deletions pkg/connector/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ import (
"context"
"fmt"
"slices"
"strconv"
"strings"

"github.com/conductorone/baton-databricks/pkg/databricks"
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
"github.com/conductorone/baton-sdk/pkg/annotations"
"github.com/conductorone/baton-sdk/pkg/pagination"
rs "github.com/conductorone/baton-sdk/pkg/types/resource"
"google.golang.org/protobuf/types/known/structpb"
)

const ResourcesPageSize uint = 50

func parseResourceId(resourceId string) (*v2.ResourceId, *v2.ResourceId, error) {
parts := strings.Split(resourceId, "/")
switch len(parts) {
Expand Down Expand Up @@ -66,55 +62,6 @@ func annotationsForUserResourceType() annotations.Annotations {
return annos
}

func parsePageToken(i string, resourceID *v2.ResourceId) (*pagination.Bag, uint, error) {
b := &pagination.Bag{}
err := b.Unmarshal(i)
if err != nil {
return nil, 0, err
}

if b.Current() == nil {
b.Push(pagination.PageState{
ResourceTypeID: resourceID.ResourceType,
ResourceID: resourceID.Resource,
})
}

page, err := convertPageToken(b.PageToken())
if err != nil {
return nil, 0, err
}

return b, page, nil
}

// convertPageToken converts a string token into an int.
func convertPageToken(token string) (uint, error) {
if token == "" {
return 1, nil
}

page, err := strconv.ParseUint(token, 10, 32)
if err != nil {
return 0, fmt.Errorf("failed to parse page token: %w", err)
}

return uint(page), nil
}

// prepareNextToken prepares the next page token.
// It calculates the next page number and returns it as a string.
func prepareNextToken(page uint, pageTotal int, total uint) string {
var token string

next := page + uint(pageTotal)
if next < total+1 {
token = strconv.Itoa(int(next))
}

return token
}

// prepareResourceID prepares a resource ID for a user, group, or service principal.
// It's used when we need to parse results from listing rule sets.
func prepareResourceID(ctx context.Context, c *databricks.Client, principal string) (*v2.ResourceId, error) {
Expand Down
60 changes: 60 additions & 0 deletions pkg/connector/pagination.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package connector

import (
"fmt"
"strconv"

v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
"github.com/conductorone/baton-sdk/pkg/pagination"
)

const ResourcesPageSize uint = 50

func parsePageToken(i string, resourceID *v2.ResourceId) (*pagination.Bag, uint, error) {
b := &pagination.Bag{}
err := b.Unmarshal(i)
if err != nil {
return nil, 0, err
}

if b.Current() == nil {
b.Push(pagination.PageState{
ResourceTypeID: resourceID.ResourceType,
ResourceID: resourceID.Resource,
})
}

page, err := convertPageToken(b.PageToken())
if err != nil {
return nil, 0, err
}

return b, page, nil
}

// convertPageToken converts a string token into an int.
func convertPageToken(token string) (uint, error) {
if token == "" {
return 1, nil
}

page, err := strconv.ParseUint(token, 10, 32)
if err != nil {
return 0, fmt.Errorf("failed to parse page token: %w", err)
}

return uint(page), nil
}

// prepareNextToken prepares the next page token.
// It calculates the next page number and returns it as a string.
func prepareNextToken(page uint, pageTotal int, total uint) string {
var token string

next := page + uint(pageTotal)
if next < total+1 {
token = strconv.FormatUint(uint64(next), 10)
}

return token
}

0 comments on commit 384deb0

Please sign in to comment.