Files
yucca/packages/restic-proxy/internal/meta/wellknown.go
T
Paul Makles 76d48c26b4 feat: restic proxy (#611)
* feat(restic proxy): initial commit

* feat(restic proxy): working impl.

* fix(restic proxy): use repoId as grant key

* fix(restic proxy): handle http errors for meta

* fix(restic proxy): close http response body

* fix(restic proxy): use path not encoded path

* fix(restic proxy): unset RawPath

* docs(restic proxy): notes for later work

* fix(restic proxy): timeout on meta requests

* fix(restic proxy): concurrent minting

* fix(restic proxy): don't nil error

* fix(restic proxy): robust claims/exp check

* docs(restic proxy): document next work

* fix(restic proxy): respect log level

* chore(restic proxy): set default log level to info

* fix(restic proxy): permit temporary failures

* refactor(restic proxy): remove exit dead code

* chore: mise config

* feat(restic proxy): configurable well known URL

* chore(restic proxy): use real Exp

* refactor(restic proxy): use username as repoId

* fix(restic proxy): check repositoryId is set

* test(restic proxy): generate tests

* feat(restic proxy): publish Dockerfile

* feat(standalone app): include restic-proxy binary

* refactor(restic proxy): allow configuring api & meta URLs
test: generate accompanying tests

* chore: set config_roots

* test: drop comments from generated tests

* docs(restic proxy): add to USER_MANUAL

* fix(restic proxy): remint grant if auth token changes

* chore(restic proxy): update mise.toml

* refactor(restic proxy): differentiate session token w. 'token'
feat(restic proxy): denial cache
test(restic proxy): update generated tests for deny cache

* chore: remove `restic-proxy:check` from `check` dependencies (covered by
lint)
2026-09-02 16:37:31 +01:00

46 lines
859 B
Go

package meta
import (
"encoding/json"
"fmt"
"io"
"net/http"
"restic-proxy/internal/config"
"time"
)
type WellKnown struct {
MetaUrl string `json:"meta_url"`
}
func GetWellKnown(wellKnownUrl string) (WellKnown, error) {
client := http.Client{Timeout: 30 * time.Second}
response, err := client.Get(wellKnownUrl)
if err != nil {
return WellKnown{}, err
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
return WellKnown{}, fmt.Errorf("could not fetch well-known: %s", response.Status)
}
body, err := io.ReadAll(response.Body)
if err != nil {
return WellKnown{}, err
}
wellKnown := WellKnown{}
if err := json.Unmarshal(body, &wellKnown); err != nil {
return wellKnown, err
}
return wellKnown, nil
}
func WellKnownFromConfig(cfg config.Config) (WellKnown, error) {
return GetWellKnown(cfg.WellKnown)
}