Skip to content

Commit

Permalink
Updating to use gzipped fronts config
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed Jan 14, 2025
1 parent 78ef12d commit e58ae63
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4,079 deletions.
17 changes: 14 additions & 3 deletions fronted.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fronted

import (
"bytes"
"compress/gzip"
"context"
"crypto/x509"
"embed"
Expand Down Expand Up @@ -76,7 +77,7 @@ type Fronted interface {
Close()
}

//go:embed fronted.yaml
//go:embed fronted.yaml.gz
var embedFS embed.FS

// NewFronted creates a new Fronted instance with the given cache file.
Expand Down Expand Up @@ -111,14 +112,24 @@ func NewFronted(cacheFile string) Fronted {
}

func (f *fronted) readFrontsFromEmbeddedConfig() {
yml, err := embedFS.ReadFile("fronted.yaml")
yml, err := embedFS.ReadFile("fronted.yaml.gz")
if err != nil {
slog.Error("Failed to read smart dialer config", "error", err)
}
f.OnNewFrontsConfig(yml, "")
}

func (f *fronted) OnNewFrontsConfig(yml []byte, countryCode string) {
func (f *fronted) OnNewFrontsConfig(compressedYaml []byte, countryCode string) {
r, gzipErr := gzip.NewReader(bytes.NewReader(compressedYaml))
if gzipErr != nil {
slog.Error("Failed to create gzip reader", "error", gzipErr)
return
}
yml, err := io.ReadAll(r)
if err != nil {
slog.Error("Failed to read gzipped file", "error", err)
return
}
path, err := yaml.PathString("$.providers")
if err != nil {
slog.Error("Failed to create providers dpath", "error", err)
Expand Down
4,072 changes: 0 additions & 4,072 deletions fronted.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions fronted.yaml.gz
Git LFS file not shown
11 changes: 7 additions & 4 deletions updateFrontedConfig.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ echo "trustedcas:" > fronted.yaml
curl https://globalconfig.flashlightproxy.com/global.yaml.gz | gunzip | yq '.trustedcas' >> fronted.yaml
curl https://globalconfig.flashlightproxy.com/global.yaml.gz | gunzip | yq '.client.fronted' >> fronted.yaml

# Compress the generated file
gzip -c fronted.yaml > fronted.yaml.gz

# If the generated file is different from the current one, commit and push the changes
if ! git diff --quiet fronted.yaml; then
git add fronted.yaml
git commit -m "Update fronted.yaml"
if ! git diff --quiet fronted.yaml.gz; then
git add fronted.yaml.gz
git commit -m "Update fronted.yaml.gz"
git push
else
echo "No changes detected in fronted.yaml"
echo "No changes detected in fronted.yaml.gz"
fi

0 comments on commit e58ae63

Please sign in to comment.