Skip to content

Commit

Permalink
Revert "Fix folder list"
Browse files Browse the repository at this point in the history
This reverts commit 3f0ad11.
  • Loading branch information
MarcusGoldschmidt committed Jan 28, 2025
1 parent 3f0ad11 commit a574b47
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package main

import (
"github.com/conductorone/baton-sdk/pkg/field"
Expand Down Expand Up @@ -46,7 +46,6 @@ var (
// connector to run. Note: these fields can be marked as optional or
// required.
ConfigurationFields = []field.SchemaField{
LucidApiKeyField,
LucidCodeKeyField,
LucidClientIdField,
LucidClientSecretField,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package main

import (
"testing"
Expand Down
17 changes: 8 additions & 9 deletions cmd/baton-lucidchart/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
config2 "github.com/conductorone/baton-lucidchart/cmd/baton-lucidchart/config"
"os"

"github.com/conductorone/baton-lucidchart/pkg/connector"
Expand All @@ -26,7 +25,7 @@ func main() {
"baton-lucidchart",
getConnector,
field.Configuration{
Fields: config2.ConfigurationFields,
Fields: ConfigurationFields,
},
)
if err != nil {
Expand All @@ -45,16 +44,16 @@ func main() {

func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, error) {
l := ctxzap.Extract(ctx)
if err := config2.ValidateConfig(v); err != nil {
if err := ValidateConfig(v); err != nil {
return nil, err
}

apiKey := v.GetString(config2.LucidApiKeyField.FieldName)
code := v.GetString(config2.LucidCodeKeyField.FieldName)
clientID := v.GetString(config2.LucidClientIdField.FieldName)
clientSecret := v.GetString(config2.LucidClientSecretField.FieldName)
redirectURL := v.GetString(config2.LucidRedirectUrlField.FieldName)
refreshToken := v.GetString(config2.LucidRefreshTokenField.FieldName)
apiKey := v.GetString(LucidApiKeyField.FieldName)
code := v.GetString(LucidCodeKeyField.FieldName)
clientID := v.GetString(LucidClientIdField.FieldName)
clientSecret := v.GetString(LucidClientSecretField.FieldName)
redirectURL := v.GetString(LucidRedirectUrlField.FieldName)
refreshToken := v.GetString(LucidRefreshTokenField.FieldName)

cb, err := connector.New(ctx, apiKey, code, clientID, clientSecret, redirectURL, refreshToken)
if err != nil {
Expand Down
29 changes: 6 additions & 23 deletions pkg/connector/client/models.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package client

import (
"fmt"
"strconv"
"time"
)
import "time"

type User struct {
AccountId int `json:"accountId"`
Expand All @@ -25,24 +21,11 @@ type Folder struct {
}

type FolderContent struct {
Id interface{} `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Shortcut bool `json:"shortcut"`
Product string `json:"product"`
}

func (f *FolderContent) ID() string {
switch v := f.Id.(type) {
case int:
return strconv.Itoa(v)
case string:
return v
case fmt.Stringer:
return v.String()
default:
return ""
}
Id string `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Shortcut bool `json:"shortcut"`
Product string `json:"product"`
}

type AccountDocument struct {
Expand Down
1 change: 0 additions & 1 deletion pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type Connector struct {
func (d *Connector) ResourceSyncers(ctx context.Context) []connectorbuilder.ResourceSyncer {
return []connectorbuilder.ResourceSyncer{
newUserBuilder(d.client),
newFolderBuilder(d.client),
}
}

Expand Down
30 changes: 21 additions & 9 deletions pkg/connector/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ type folderBuilder struct {
}

func (o *folderBuilder) ResourceType(ctx context.Context) *v2.ResourceType {

Check failure on line 18 in pkg/connector/folder.go

View workflow job for this annotation

GitHub Actions / go-lint

func `(*folderBuilder).ResourceType` is unused (unused)
return folderResourceType
return userResourceType
}

// List returns all the users from the database as resource objects.
// Users include a UserTrait because they are the 'shape' of a standard user.
func (o *folderBuilder) List(ctx context.Context, parentResourceID *v2.ResourceId, pToken *pagination.Token) ([]*v2.Resource, string, annotations.Annotations, error) {

Check failure on line 24 in pkg/connector/folder.go

View workflow job for this annotation

GitHub Actions / go-lint

func `(*folderBuilder).List` is unused (unused)
l := ctxzap.Extract(ctx)

Expand All @@ -29,17 +31,22 @@ func (o *folderBuilder) List(ctx context.Context, parentResourceID *v2.ResourceI
return nil, "", nil, err
}

l.Info("folderContent", zap.Any("folderContent", folderContent))
resources := make([]*v2.Resource, 0, len(folderContent))

root, err := folderResource("root", "root", nil)
if err != nil {
return nil, "", nil, err
}

resources := []*v2.Resource{
root,
resources = append(resources, root)

innerFolders, err := folderResources(folderContent, root.Id)
if err != nil {
return nil, "", nil, err
}

resources = append(resources, innerFolders...)

return resources, nextToken, nil, err
}

Expand All @@ -63,10 +70,12 @@ func (o *folderBuilder) List(ctx context.Context, parentResourceID *v2.ResourceI
return nil, "", nil, nil
}

// Entitlements always returns an empty slice for users.
func (o *folderBuilder) Entitlements(_ context.Context, resource *v2.Resource, _ *pagination.Token) ([]*v2.Entitlement, string, annotations.Annotations, error) {

Check failure on line 74 in pkg/connector/folder.go

View workflow job for this annotation

GitHub Actions / go-lint

func `(*folderBuilder).Entitlements` is unused (unused)
return nil, "", nil, nil
}

// Grants always returns an empty slice for users since they don't have any entitlements.
func (o *folderBuilder) Grants(ctx context.Context, resource *v2.Resource, pToken *pagination.Token) ([]*v2.Grant, string, annotations.Annotations, error) {

Check failure on line 79 in pkg/connector/folder.go

View workflow job for this annotation

GitHub Actions / go-lint

func `(*folderBuilder).Grants` is unused (unused)
return nil, "", nil, nil
}
Expand All @@ -75,11 +84,11 @@ func folderResources(folderContent []client.FolderContent, parentResourceID *v2.
var resources []*v2.Resource

for _, folder := range folderContent {
if folder.Type != "folder" {
if folder.Name != "folder" {
continue
}

newResource, err := folderResource(folder.ID(), folder.Name, parentResourceID)
newResource, err := folderResource(folder.Id, folder.Name, parentResourceID)
if err != nil {
return nil, err
}
Expand All @@ -93,11 +102,14 @@ func folderResources(folderContent []client.FolderContent, parentResourceID *v2.
func folderResource(id, name string, parentResourceID *v2.ResourceId) (*v2.Resource, error) {

Check failure on line 102 in pkg/connector/folder.go

View workflow job for this annotation

GitHub Actions / go-lint

func `folderResource` is unused (unused)
resourceOptions := []resource.ResourceOption{
resource.WithParentResourceID(parentResourceID),
resource.WithAnnotation(
}

if parentResourceID != nil {
resourceOptions = append(resourceOptions, resource.WithAnnotation(
&v2.ChildResourceType{
ResourceTypeId: folderResourceType.Id,
},
),
))
}

return resource.NewResource(
Expand All @@ -108,7 +120,7 @@ func folderResource(id, name string, parentResourceID *v2.ResourceId) (*v2.Resou
)
}

func newFolderBuilder(client *client.LucidchartClient) *folderBuilder {
func newfolderBuilder(client *client.LucidchartClient) *folderBuilder {
return &folderBuilder{
client: client,
}
Expand Down

0 comments on commit a574b47

Please sign in to comment.