Skip to content

Commit

Permalink
Merge pull request #79 from dive-deeper/feat/tilde-expansion-for-auth…
Browse files Browse the repository at this point in the history
…-file

feat: do tilde expansion for yaml storage path
  • Loading branch information
MichaelEischer authored Jul 5, 2024
2 parents 81a3ed4 + 6ca368f commit 87d663a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The app will create a file in the execution folder called `auth-storage.yaml`. I

# Configuration

The CalendarSync config file consists of `four` building blocks:
The CalendarSync config file consists of several building blocks:

- `sync` - Controls the timeframe to be synced
- `source` - Controls the source calendar to be synced from
Expand All @@ -65,6 +65,7 @@ The CalendarSync config file consists of `four` building blocks:
- `transformations` - Controls the transformers applied to the events before
syncing
- `filters` - Controls filters, which allow events to be excluded from syncing
- `auth` - Controls settings regarding the encrypted auth storage file

## Sync

Expand Down Expand Up @@ -179,6 +180,19 @@ filters:
ExcludeRegexp: ".*test"
```

## Auth

In this section you can configure settings regarding the encrypted local auth storage

```yaml
auth:
storage_mode: yaml # Currently, only yaml is supported
config:
# Here you can use the standard unix abbreviation for home directory (~).
# This works also for Windows systems e.g. ~\calendar-sync\auth-storage.yaml
path: "./auth-storage.yaml"
```

# Cleaning Up

You just synced a lot of events in your calendar and decide you want to use a
Expand Down
4 changes: 3 additions & 1 deletion example.sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ sync:
offset: +1 # MonthEnd +1 month (end of next month)

auth:
storage_mode: yaml
storage_mode: yaml # Currently, only yaml is supported
config:
# Here you can use the standard unix abbreviation for home directory (~).
# This works also for Windows systems e.g. ~\calendar-sync\auth-storage.yaml
path: "./auth-storage.yaml"

# Unfortunately, at this point, we only support one source adapter.
Expand Down
9 changes: 9 additions & 0 deletions internal/auth/yaml_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"io"
"io/fs"
"os"
"path/filepath"
"strings"

"github.com/charmbracelet/log"
"github.com/inovex/CalendarSync/internal/config"
Expand All @@ -23,6 +25,13 @@ type YamlStorage struct {
func (y *YamlStorage) Setup(config config.AuthStorage, encryptionPassphrase string) error {
y.StorageEncryptionKey = encryptionPassphrase
y.StoragePath = config.Config["path"].(string)
if strings.HasPrefix(y.StoragePath, "~" + string(filepath.Separator)) {
homeDir, err := os.UserHomeDir()
if err != nil {
return err
}
y.StoragePath = filepath.Join(homeDir, y.StoragePath[2:])
}
return nil
}

Expand Down

0 comments on commit 87d663a

Please sign in to comment.