mirror of
https://github.com/immich-app/yucca.git
synced 2026-09-30 21:37:50 +08:00
* 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)
46 lines
859 B
Go
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)
|
|
}
|