Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion pkg/connector/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"github.com/conductorone/baton-sdk/pkg/pagination"
rs "github.com/conductorone/baton-sdk/pkg/types/resource"
"github.com/conductorone/baton-snowflake/pkg/snowflake"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

const (
Expand Down Expand Up @@ -93,11 +97,11 @@

func tableResource(_ context.Context, table *snowflake.Table, id *v2.ResourceId, isSharedOrSystemDB bool) (*v2.Resource, error) {
profile := map[string]interface{}{
"name": table.Name,

Check failure on line 100 in pkg/connector/tables.go

View workflow job for this annotation

GitHub Actions / go-lint

string `name` has 4 occurrences, make it a constant (goconst)
"schema_name": table.SchemaName,
"database_name": table.DatabaseName,
"kind": table.Kind,
"comment": table.Comment,

Check failure on line 104 in pkg/connector/tables.go

View workflow job for this annotation

GitHub Actions / go-lint

string `comment` has 3 occurrences, make it a constant (goconst)
"owner": table.Owner,
"created_on": table.CreatedOn.Format("2006-01-02 15:04:05.999"),
"database_is_shared_system": isSharedOrSystemDB,
Expand Down Expand Up @@ -134,7 +138,9 @@
return nil, nil, wrapError(fmt.Errorf("invalid parent resource type: %s", parentResourceID.ResourceType), "invalid parent resource type")
}

l := ctxzap.Extract(ctx)
databaseName := parentResourceID.Resource
dbField := zap.String("database_name", databaseName)

bag := &pagination.Bag{}
if err := bag.Unmarshal(opts.PageToken.Token); err != nil {
Expand All @@ -154,13 +160,22 @@
return nil, nil, wrapError(err, "failed to get parent database")
}

if snowflake.IsUnprocessableEntity(statusCode, err) {
l.Warn("Skipping database: insufficient privileges for GetDatabase", dbField)
return nil, &rs.SyncOpResults{}, nil
}

schemas, err := o.client.ListSchemasInDatabase(ctx, databaseName)
if err != nil {
if status.Code(err) == codes.PermissionDenied {
l.Warn("Skipping database: insufficient privileges for ListSchemasInDatabase", dbField)
return nil, &rs.SyncOpResults{}, nil
}
return nil, nil, wrapError(err, "failed to list schemas in database")
}

sharedFlag := ""
if snowflake.IsUnprocessableEntity(statusCode, nil) || (parentDB != nil && parentDB.IsSharedOrSystem()) {
if parentDB != nil && parentDB.IsSharedOrSystem() {
sharedFlag = "shared"
}

Expand Down Expand Up @@ -188,6 +203,15 @@
const pageSize = 200
tables, nextTableCursor, err := o.client.ListTablesInSchema(ctx, databaseName, schemaName, tableCursor, pageSize)
if err != nil {
if status.Code(err) == codes.PermissionDenied {
l.Warn("Skipping schema: insufficient privileges for ListTablesInSchema",
dbField, zap.String("schema_name", schemaName))
nextToken, tokenErr := bag.NextToken("")
if tokenErr != nil {
return nil, nil, wrapError(tokenErr, "failed to create next page token")
}
return nil, &rs.SyncOpResults{NextPageToken: nextToken}, nil
}
return nil, nil, wrapError(err, "failed to list tables in schema")
}

Expand Down
Loading