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
31 changes: 31 additions & 0 deletions cmd/sync_ooo_to_gcal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"time"

"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/corbaltcode/ooo-calendar-sync/core"
"github.com/joho/godotenv"
"golang.org/x/oauth2/google"
Expand Down Expand Up @@ -42,6 +44,11 @@ func (e *Event) Run(ctx context.Context) {
core.Die("missing env GOOGLE_SERVICE_ACCOUNT_JSON_B64")
}

tableName := os.Getenv("DYNAMODB_TABLE_NAME")
if tableName == "" {
core.Die("missing env DYNAMODB_TABLE_NAME")
}

if e.PageSize <= 0 {
core.Die("invalid pageSize: must be > 0")
}
Expand Down Expand Up @@ -152,6 +159,30 @@ func (e *Event) Run(ctx context.Context) {
return
}

awsCfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
core.Die("load AWS config: %v", err)
}

store := core.NewDynamoStore(
dynamodb.NewFromConfig(awsCfg),
tableName,
)

for _, req := range env.Requests {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking here is that this is just the first step in integrating the persistence layer. The next change will use this to filter out requests that have already been processed before creating gCal events. Once that's in place, I'll probably move this logic into core so main.go stays orchestration-focused.

existing, err := store.GetSyncedRequest(ctx, req.ID)
if err != nil {
core.Die("get synced request %s: %v", req.ID, err)
}

if existing != nil {
log.Printf("Clockify request %s already exists in DynamoDB", req.ID)
continue
}

log.Printf("Clockify request %s does not exist in DynamoDB yet", req.ID)
}

b, err := base64.StdEncoding.DecodeString(credB64)
if err != nil {
core.Die("invalid base64 GOOGLE_SERVICE_ACCOUNT_JSON_B64: %v", err)
Expand Down