Compare commits
1 Commits
dev
..
f46ba28aef
| Author | SHA1 | Date | |
|---|---|---|---|
| f46ba28aef |
@@ -5,8 +5,8 @@ on:
|
|||||||
branches: [master]
|
branches: [master]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: gitea.coracle.social
|
REGISTRY: ghcr.io
|
||||||
IMAGE_NAME: coracle/zooid
|
IMAGE_NAME: coracle-social/zooid
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push-image:
|
build-and-push-image:
|
||||||
@@ -23,8 +23,8 @@ jobs:
|
|||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY }}
|
registry: ${{ env.REGISTRY }}
|
||||||
username: hodlbod
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
password: ${{ secrets.PACKAGE_TOKEN }}
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
- name: Extract metadata (tags, labels) for Docker
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
id: meta
|
id: meta
|
||||||
@@ -48,4 +48,3 @@ jobs:
|
|||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
||||||
|
|||||||
@@ -4,4 +4,3 @@ config
|
|||||||
media
|
media
|
||||||
data
|
data
|
||||||
relay
|
relay
|
||||||
.claude
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ docker run -it \
|
|||||||
-v ./config:/app/config \
|
-v ./config:/app/config \
|
||||||
-v ./media:/app/media \
|
-v ./media:/app/media \
|
||||||
-v ./data:/app/data \
|
-v ./data:/app/data \
|
||||||
gitea.coracle.social/coracle/zooid
|
ghcr.io/coracle-social/zooid
|
||||||
```
|
```
|
||||||
|
|
||||||
Drop a TOML config file into `./config/` (see [Configuration](#configuration)) and the relay will be available at `ws://<host>:3334`.
|
Drop a TOML config file into `./config/` (see [Configuration](#configuration)) and the relay will be available at `ws://<host>:3334`.
|
||||||
@@ -50,7 +50,7 @@ Zooid supports a few environment variables, which configure shared resources lik
|
|||||||
- `MEDIA` - where to store blossom media files. Defaults to `./media`.
|
- `MEDIA` - where to store blossom media files. Defaults to `./media`.
|
||||||
- `DATA` - where to store database files. Defaults to `./data`.
|
- `DATA` - where to store database files. Defaults to `./data`.
|
||||||
- `API_HOST` - the hostname on which to expose the management API. If not set, the API is disabled.
|
- `API_HOST` - the hostname on which to expose the management API. If not set, the API is disabled.
|
||||||
- `API_WHITELIST` - a comma-separated list of nostr hex pubkeys authorized to use the management API.
|
- `API_WHITELIST` - a comma-separated list of nostr hex pubkeys authorized to use the management API. Required when `API_HOST` is set.
|
||||||
- `PPROF_ADDR` - an http host to serve pprof stats on.
|
- `PPROF_ADDR` - an http host to serve pprof stats on.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
@@ -95,19 +95,6 @@ Configures NIP 86 support.
|
|||||||
Configures blossom support.
|
Configures blossom support.
|
||||||
|
|
||||||
- `enabled` - whether blossom is enabled.
|
- `enabled` - whether blossom is enabled.
|
||||||
- `authenticated_read` - whether users must perform NIP 98 AUTH in order to fetch a file.
|
|
||||||
- `adapter` - where to store blobs. Either `local` (the default, stores files under `MEDIA`) or `s3` (stores files in an S3-compatible bucket).
|
|
||||||
|
|
||||||
#### `[blossom.s3]`
|
|
||||||
|
|
||||||
Configures S3-compatible object storage, used when `blossom.adapter` is `s3`.
|
|
||||||
|
|
||||||
- `endpoint` - the S3 endpoint URL. Optional; leave unset to use AWS S3.
|
|
||||||
- `region` - the bucket region. Required when `adapter` is `s3`.
|
|
||||||
- `bucket` - the bucket name. Required when `adapter` is `s3`.
|
|
||||||
- `access_key` - the access key ID. Required when `adapter` is `s3`.
|
|
||||||
- `secret_key` - the secret access key. Required when `adapter` is `s3`.
|
|
||||||
- `key_prefix` - an optional prefix prepended to every object key.
|
|
||||||
|
|
||||||
### `[push]`
|
### `[push]`
|
||||||
|
|
||||||
@@ -133,12 +120,7 @@ A special `[roles.member]` heading may be used to configure policies for all rel
|
|||||||
- `api_key` - a key identifying this relay, assigned by the Livekit server.
|
- `api_key` - a key identifying this relay, assigned by the Livekit server.
|
||||||
- `api_secret` - a secret key authenticating this relay, assigned by the Livekit server.
|
- `api_secret` - a secret key authenticating this relay, assigned by the Livekit server.
|
||||||
|
|
||||||
On your LiveKit server you should also set up a webhook so LiveKit can notify the relay when people join or leave rooms; the relay uses these notifications to publish a kind 39004 presence event. How you point the webhook depends on how many relays share a LiveKit project:
|
On your LiveKit server you should also set up a webhook that points to `https://yourrelay.com/.well-known/nip29/livekit/webhook`. This allows LiveKit to notify your relay when people join rooms so it can publish a kind 39004 event.
|
||||||
|
|
||||||
- **One relay, or a dedicated LiveKit project per relay** — point the webhook at that relay's own `https://yourrelay.com/.well-known/nip29/livekit/webhook`.
|
|
||||||
- **Several relays sharing one LiveKit project** — point the webhook at the management API's `https://api.relayplatform.com/.well-known/nip29/livekit/webhook` instead. zooid stamps each room's metadata with the owning relay's `schema` when it creates the room, so this shared endpoint routes every event to the relay that owns the room. This requires `API_HOST` to be set.
|
|
||||||
|
|
||||||
Either way the webhook is authenticated by LiveKit's own request signature (signed with the relay's `api_secret`) rather than NIP 98, so the shared endpoint is exempt from the `API_WHITELIST`. Configure LiveKit to sign webhooks with the same `api_key`/`api_secret` the relay uses, or the relay will reject them.
|
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
@@ -181,7 +163,7 @@ can_manage = true
|
|||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
When `API_HOST` is configured, a JSON REST API is available for managing virtual relays remotely. All API requests must be authenticated using [NIP 98](https://github.com/nostr-protocol/nips/blob/master/98.md) HTTP AUTH signed by a pubkey listed in `API_WHITELIST`.
|
When `API_HOST` and `API_WHITELIST` are configured, a JSON REST API is available for managing virtual relays remotely. All API requests must be authenticated using [NIP 98](https://github.com/nostr-protocol/nips/blob/master/98.md) HTTP AUTH.
|
||||||
|
|
||||||
The API accepts JSON config objects and stores them as TOML files in the `CONFIG` directory. Configs are validated for required fields (`host`, `schema`, `secret`) and duplicate checking (`schema` and `host` must be unique across all relays).
|
The API accepts JSON config objects and stores them as TOML files in the `CONFIG` directory. Configs are validated for required fields (`host`, `schema`, `secret`) and duplicate checking (`schema` and `host` must be unique across all relays).
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -25,11 +25,11 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
name := zooid.ConfigNameFromId(*relay)
|
// Load config for the specified relay
|
||||||
path := zooid.ConfigPathFromName(name)
|
filename := fmt.Sprintf("%s.toml", *relay)
|
||||||
config, err := zooid.LoadConfigFromPath(path)
|
config, err := zooid.LoadConfig(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, "No such config file", filename)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -39,11 +39,11 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
name := zooid.ConfigNameFromId(*relay)
|
// Load config for the specified relay
|
||||||
path := zooid.ConfigPathFromName(name)
|
filename := fmt.Sprintf("%s.toml", *relay)
|
||||||
config, err := zooid.LoadConfigFromPath(path)
|
config, err := zooid.LoadConfig(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, "No such config file", filename)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -21,6 +21,8 @@ func main() {
|
|||||||
|
|
||||||
port := zooid.Env("PORT")
|
port := zooid.Env("PORT")
|
||||||
apiHost := zooid.Env("API_HOST")
|
apiHost := zooid.Env("API_HOST")
|
||||||
|
apiWhitelist := zooid.Env("API_WHITELIST")
|
||||||
|
configDir := zooid.Env("CONFIG")
|
||||||
pprofAddr := zooid.Env("PPROF_ADDR")
|
pprofAddr := zooid.Env("PPROF_ADDR")
|
||||||
|
|
||||||
// pprof server — only starts when PPROF_ADDR is set. Bind to
|
// pprof server — only starts when PPROF_ADDR is set. Bind to
|
||||||
@@ -48,8 +50,8 @@ func main() {
|
|||||||
|
|
||||||
// Wrap with API handler if API_HOST is configured
|
// Wrap with API handler if API_HOST is configured
|
||||||
var handler http.Handler = mainHandler
|
var handler http.Handler = mainHandler
|
||||||
if apiHost != "" {
|
if apiHost != "" && apiWhitelist != "" {
|
||||||
apiHandler := zooid.NewAPIHandler()
|
apiHandler := zooid.NewAPIHandler(apiWhitelist, configDir)
|
||||||
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Check if this request is for the API host
|
// Check if this request is for the API host
|
||||||
if r.Host == apiHost {
|
if r.Host == apiHost {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ require (
|
|||||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.16
|
github.com/aws/aws-sdk-go-v2/credentials v1.19.16
|
||||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.101.0
|
github.com/aws/aws-sdk-go-v2/service/s3 v1.101.0
|
||||||
github.com/fsnotify/fsnotify v1.9.0
|
github.com/fsnotify/fsnotify v1.9.0
|
||||||
|
github.com/gosimple/slug v1.15.0
|
||||||
github.com/livekit/protocol v1.43.5-0.20260114074149-a8bb8204ce69
|
github.com/livekit/protocol v1.43.5-0.20260114074149-a8bb8204ce69
|
||||||
github.com/mattn/go-sqlite3 v1.14.32
|
github.com/mattn/go-sqlite3 v1.14.32
|
||||||
github.com/spf13/afero v1.15.0
|
github.com/spf13/afero v1.15.0
|
||||||
@@ -43,7 +44,6 @@ require (
|
|||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/bep/debounce v1.2.1 // indirect
|
github.com/bep/debounce v1.2.1 // indirect
|
||||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||||
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
|
|
||||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
|
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
github.com/coder/websocket v1.8.13 // indirect
|
github.com/coder/websocket v1.8.13 // indirect
|
||||||
@@ -58,6 +58,7 @@ require (
|
|||||||
github.com/go-logr/logr v1.4.3 // indirect
|
github.com/go-logr/logr v1.4.3 // indirect
|
||||||
github.com/google/cel-go v0.25.0 // indirect
|
github.com/google/cel-go v0.25.0 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/gosimple/unidecode v1.0.1 // indirect
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||||
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
|
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
@@ -131,4 +132,4 @@ require (
|
|||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
replace fiatjaf.com/nostr => gitea.coracle.social/Coracle/nostrlib v0.0.0-20260623001341-fa7d25a59b3d
|
replace fiatjaf.com/nostr => gitea.coracle.social/Coracle/nostrlib v0.0.0-20260505183642-fefc85d50080
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
|
|||||||
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
||||||
fiatjaf.com/lib v0.3.7 h1:mXZOn7NrUcjSdy4oNvwQyAmes7Ueb+Zr5hjqMIe2dxI=
|
fiatjaf.com/lib v0.3.7 h1:mXZOn7NrUcjSdy4oNvwQyAmes7Ueb+Zr5hjqMIe2dxI=
|
||||||
fiatjaf.com/lib v0.3.7/go.mod h1:UlHaZvPHj25PtKLh9GjZkUHRmQ2xZ8Jkoa4VRaLeeQ8=
|
fiatjaf.com/lib v0.3.7/go.mod h1:UlHaZvPHj25PtKLh9GjZkUHRmQ2xZ8Jkoa4VRaLeeQ8=
|
||||||
gitea.coracle.social/Coracle/nostrlib v0.0.0-20260623001341-fa7d25a59b3d h1:Ws4dqvn6Fou5DvrdrrctHfbXgENPpa+QBXXRb95P3Zw=
|
gitea.coracle.social/Coracle/nostrlib v0.0.0-20260505183642-fefc85d50080 h1:nNL6kqhG0U4dVHYoRULb/klaocv2NGEQm/qxFiZzbzY=
|
||||||
gitea.coracle.social/Coracle/nostrlib v0.0.0-20260623001341-fa7d25a59b3d/go.mod h1:b1EIUDnd133Ie8Pg8O/biaKdFyCMz28aD4n64g1GqvM=
|
gitea.coracle.social/Coracle/nostrlib v0.0.0-20260505183642-fefc85d50080/go.mod h1:b1EIUDnd133Ie8Pg8O/biaKdFyCMz28aD4n64g1GqvM=
|
||||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
|
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
|
||||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
||||||
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
||||||
@@ -26,7 +26,6 @@ github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEV
|
|||||||
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
|
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
|
||||||
github.com/PowerDNS/lmdb-go v1.9.3 h1:AUMY2pZT8WRpkEv39I9Id3MuoHd+NZbTVpNhruVkPTg=
|
github.com/PowerDNS/lmdb-go v1.9.3 h1:AUMY2pZT8WRpkEv39I9Id3MuoHd+NZbTVpNhruVkPTg=
|
||||||
github.com/PowerDNS/lmdb-go v1.9.3/go.mod h1:TE0l+EZK8Z1B4dx070ZxkWTlp8RG1mjN0/+FkFRQMtU=
|
github.com/PowerDNS/lmdb-go v1.9.3/go.mod h1:TE0l+EZK8Z1B4dx070ZxkWTlp8RG1mjN0/+FkFRQMtU=
|
||||||
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
|
|
||||||
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
|
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
|
||||||
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
|
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
|
||||||
github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=
|
github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=
|
||||||
@@ -77,30 +76,13 @@ github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
|||||||
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||||
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||||
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
github.com/btcsuite/btcd v0.24.2 h1:aLmxPguqxza+4ag8R1I2nnJjSu2iFn/kqtHTIImswcY=
|
||||||
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
|
|
||||||
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A=
|
|
||||||
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
|
|
||||||
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
|
|
||||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
|
||||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||||
github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A=
|
|
||||||
github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE=
|
|
||||||
github.com/btcsuite/btcd/btcutil v1.1.5 h1:+wER79R5670vs/ZusMTF1yTcRYE5GUsFbdjdisflzM8=
|
github.com/btcsuite/btcd/btcutil v1.1.5 h1:+wER79R5670vs/ZusMTF1yTcRYE5GUsFbdjdisflzM8=
|
||||||
github.com/btcsuite/btcd/btcutil v1.1.5/go.mod h1:PSZZ4UitpLBWzxGd5VGOrLnmOjtPP/a6HaFo12zMs00=
|
github.com/btcsuite/btcd/btcutil v1.1.5/go.mod h1:PSZZ4UitpLBWzxGd5VGOrLnmOjtPP/a6HaFo12zMs00=
|
||||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
|
|
||||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
|
|
||||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 h1:59Kx4K6lzOW5w6nFlA0v5+lk/6sjybR934QNHSJZPTQ=
|
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 h1:59Kx4K6lzOW5w6nFlA0v5+lk/6sjybR934QNHSJZPTQ=
|
||||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
|
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
|
||||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
|
|
||||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
|
||||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
|
|
||||||
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
|
|
||||||
github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I=
|
|
||||||
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
|
|
||||||
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
|
|
||||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
|
|
||||||
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
|
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
@@ -109,17 +91,13 @@ github.com/coder/websocket v1.8.13 h1:f3QZdXy7uGVz+4uCJy2nTZyM0yTBj8yANEHhqlXZ9F
|
|||||||
github.com/coder/websocket v1.8.13/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
|
github.com/coder/websocket v1.8.13/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
|
||||||
github.com/containerd/continuity v0.4.3 h1:6HVkalIp+2u1ZLH1J/pYX2oBVXlJZvh1X1A7bEZ9Su8=
|
github.com/containerd/continuity v0.4.3 h1:6HVkalIp+2u1ZLH1J/pYX2oBVXlJZvh1X1A7bEZ9Su8=
|
||||||
github.com/containerd/continuity v0.4.3/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ=
|
github.com/containerd/continuity v0.4.3/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ=
|
||||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
|
|
||||||
github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8=
|
github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8=
|
||||||
github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
|
|
||||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
|
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
|
||||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
|
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
|
||||||
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
|
|
||||||
github.com/dennwc/iters v1.1.0 h1:PsS3DbOU7GxSUQO0e7SGmzHkPhtwOlwbqggJ++Bgnr8=
|
github.com/dennwc/iters v1.1.0 h1:PsS3DbOU7GxSUQO0e7SGmzHkPhtwOlwbqggJ++Bgnr8=
|
||||||
github.com/dennwc/iters v1.1.0/go.mod h1:M9KuuMBeyEXYTmB7EnI9SCyALFCmPWOIxn5W1L0CjGg=
|
github.com/dennwc/iters v1.1.0/go.mod h1:M9KuuMBeyEXYTmB7EnI9SCyALFCmPWOIxn5W1L0CjGg=
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||||
@@ -139,8 +117,6 @@ github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
|
|||||||
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
|
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
|
||||||
github.com/frostbyte73/core v0.1.1 h1:ChhJOR7bAKOCPbA+lqDLE2cGKlCG5JXsDvvQr4YaJIA=
|
github.com/frostbyte73/core v0.1.1 h1:ChhJOR7bAKOCPbA+lqDLE2cGKlCG5JXsDvvQr4YaJIA=
|
||||||
github.com/frostbyte73/core v0.1.1/go.mod h1:mhfOtR+xWAvwXiwor7jnqPMnu4fxbv1F2MwZ0BEpzZo=
|
github.com/frostbyte73/core v0.1.1/go.mod h1:mhfOtR+xWAvwXiwor7jnqPMnu4fxbv1F2MwZ0BEpzZo=
|
||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
|
||||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
|
||||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||||
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||||
github.com/gammazero/deque v1.1.0 h1:OyiyReBbnEG2PP0Bnv1AASLIYvyKqIFN5xfl1t8oGLo=
|
github.com/gammazero/deque v1.1.0 h1:OyiyReBbnEG2PP0Bnv1AASLIYvyKqIFN5xfl1t8oGLo=
|
||||||
@@ -151,21 +127,10 @@ github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
|||||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
|
||||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
|
||||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
|
||||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
|
||||||
github.com/google/cel-go v0.25.0 h1:jsFw9Fhn+3y2kBbltZR4VEz5xKkcIFRPDnuEzAGv5GY=
|
github.com/google/cel-go v0.25.0 h1:jsFw9Fhn+3y2kBbltZR4VEz5xKkcIFRPDnuEzAGv5GY=
|
||||||
github.com/google/cel-go v0.25.0/go.mod h1:hjEb6r5SuOSlhCHmFoLzu8HGCERvIsDAbxDAyNU/MmI=
|
github.com/google/cel-go v0.25.0/go.mod h1:hjEb6r5SuOSlhCHmFoLzu8HGCERvIsDAbxDAyNU/MmI=
|
||||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
|
||||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
|
||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
@@ -174,24 +139,22 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaU
|
|||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gosimple/slug v1.15.0 h1:wRZHsRrRcs6b0XnxMUBM6WK1U1Vg5B0R7VkIf1Xzobo=
|
||||||
|
github.com/gosimple/slug v1.15.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
|
||||||
|
github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
|
||||||
|
github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc=
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
|
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
|
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
|
||||||
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
|
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
|
||||||
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
|
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
|
||||||
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
|
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
|
||||||
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
|
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
|
||||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
|
||||||
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
|
||||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
|
||||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||||
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
|
|
||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
github.com/jxskiss/base62 v1.1.0 h1:A5zbF8v8WXx2xixnAKD2w+abC+sIzYJX+nxmhA6HWFw=
|
github.com/jxskiss/base62 v1.1.0 h1:A5zbF8v8WXx2xixnAKD2w+abC+sIzYJX+nxmhA6HWFw=
|
||||||
github.com/jxskiss/base62 v1.1.0/go.mod h1:HhWAlUXvxKThfOlZbcuFzsqwtF5TcqS9ru3y5GfjWAc=
|
github.com/jxskiss/base62 v1.1.0/go.mod h1:HhWAlUXvxKThfOlZbcuFzsqwtF5TcqS9ru3y5GfjWAc=
|
||||||
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
|
|
||||||
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
||||||
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
||||||
github.com/klauspost/cpuid/v2 v2.2.11 h1:0OwqZRYI2rFrjS4kvkDnqJkKHdHaRnCm68/DY4OxRzU=
|
github.com/klauspost/cpuid/v2 v2.2.11 h1:0OwqZRYI2rFrjS4kvkDnqJkKHdHaRnCm68/DY4OxRzU=
|
||||||
@@ -241,15 +204,6 @@ github.com/nats-io/nkeys v0.4.11 h1:q44qGV008kYd9W1b1nEBkNzvnWxtRSQ7A8BoqRrcfa0=
|
|||||||
github.com/nats-io/nkeys v0.4.11/go.mod h1:szDimtgmfOi9n25JpfIdGw12tZFYXqhGxjhVxsatHVE=
|
github.com/nats-io/nkeys v0.4.11/go.mod h1:szDimtgmfOi9n25JpfIdGw12tZFYXqhGxjhVxsatHVE=
|
||||||
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
||||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
|
||||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
|
||||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
|
||||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
|
||||||
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
|
|
||||||
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
|
||||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
|
||||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
|
||||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
|
||||||
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
||||||
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
||||||
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
|
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
|
||||||
@@ -332,7 +286,6 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
|
|||||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
|
|
||||||
github.com/templexxx/cpu v0.0.1 h1:hY4WdLOgKdc8y13EYklu9OUTXik80BkxHoWvTO6MQQY=
|
github.com/templexxx/cpu v0.0.1 h1:hY4WdLOgKdc8y13EYklu9OUTXik80BkxHoWvTO6MQQY=
|
||||||
github.com/templexxx/cpu v0.0.1/go.mod h1:w7Tb+7qgcAlIyX4NhLuDKt78AHA5SzPmq0Wj6HiEnnk=
|
github.com/templexxx/cpu v0.0.1/go.mod h1:w7Tb+7qgcAlIyX4NhLuDKt78AHA5SzPmq0Wj6HiEnnk=
|
||||||
github.com/templexxx/xhex v0.0.0-20200614015412-aed53437177b h1:XeDLE6c9mzHpdv3Wb1+pWBaWv/BlHK0ZYIu/KaL6eHg=
|
github.com/templexxx/xhex v0.0.0-20200614015412-aed53437177b h1:XeDLE6c9mzHpdv3Wb1+pWBaWv/BlHK0ZYIu/KaL6eHg=
|
||||||
@@ -377,9 +330,7 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
|||||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||||
go.uber.org/zap/exp v0.3.0 h1:6JYzdifzYkGmTdRR59oYH+Ng7k49H9qVpWwNSsGJj3U=
|
go.uber.org/zap/exp v0.3.0 h1:6JYzdifzYkGmTdRR59oYH+Ng7k49H9qVpWwNSsGJj3U=
|
||||||
go.uber.org/zap/exp v0.3.0/go.mod h1:5I384qq7XGxYyByIhHm6jg5CHkGY0nsTfbDLgDDlgJQ=
|
go.uber.org/zap/exp v0.3.0/go.mod h1:5I384qq7XGxYyByIhHm6jg5CHkGY0nsTfbDLgDDlgJQ=
|
||||||
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||||
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
|
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
|
||||||
@@ -388,33 +339,19 @@ golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/y
|
|||||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
|
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
|
||||||
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||||
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
|
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
|
||||||
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
|
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
|
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
|
||||||
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
@@ -430,7 +367,6 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
|||||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
@@ -443,30 +379,17 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
|
|||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 h1:fCvbg86sFXwdrl5LgVcTEvNC+2txB5mgROGmRL5mrls=
|
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 h1:fCvbg86sFXwdrl5LgVcTEvNC+2txB5mgROGmRL5mrls=
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:+rXWjjaukWZun3mLfjmVnQi18E1AsFbDN9QdJ5YXLto=
|
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:+rXWjjaukWZun3mLfjmVnQi18E1AsFbDN9QdJ5YXLto=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 h1:gRkg/vSppuSQoDjxyiGfN4Upv/h/DQmIR10ZU8dh4Ww=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 h1:gRkg/vSppuSQoDjxyiGfN4Upv/h/DQmIR10ZU8dh4Ww=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
|
||||||
google.golang.org/grpc v1.77.0 h1:wVVY6/8cGA6vvffn+wWK5ToddbgdU3d8MNENr4evgXM=
|
google.golang.org/grpc v1.77.0 h1:wVVY6/8cGA6vvffn+wWK5ToddbgdU3d8MNENr4evgXM=
|
||||||
google.golang.org/grpc v1.77.0/go.mod h1:z0BY1iVj0q8E1uSQCjL9cppRj+gnZjzDnzV0dHhrNig=
|
google.golang.org/grpc v1.77.0/go.mod h1:z0BY1iVj0q8E1uSQCjL9cppRj+gnZjzDnzV0dHhrNig=
|
||||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
|
||||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
|
||||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
|
||||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
|
||||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
|
||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
|
||||||
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
|
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
|
||||||
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
|
||||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
+260
-186
@@ -1,49 +1,53 @@
|
|||||||
package zooid
|
package zooid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"fiatjaf.com/nostr"
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
|
"github.com/gosimple/slug"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// APIHandler handles REST API requests for managing virtual relays
|
||||||
type APIHandler struct {
|
type APIHandler struct {
|
||||||
whitelist map[string]bool
|
whitelist map[string]bool
|
||||||
|
configDir string
|
||||||
mux http.Handler
|
mux http.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAPIHandler() *APIHandler {
|
// NewAPIHandler creates a new API handler with the given whitelist
|
||||||
whitelist := make(map[string]bool)
|
func NewAPIHandler(whitelist string, configDir string) *APIHandler {
|
||||||
for _, pubkey := range Split(Env("API_WHITELIST"), ",") {
|
w := make(map[string]bool)
|
||||||
|
for _, pubkey := range Split(whitelist, ",") {
|
||||||
pubkey = strings.TrimSpace(pubkey)
|
pubkey = strings.TrimSpace(pubkey)
|
||||||
if pubkey != "" {
|
if pubkey != "" {
|
||||||
whitelist[pubkey] = true
|
w[pubkey] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
api := &APIHandler{
|
api := &APIHandler{
|
||||||
whitelist: whitelist,
|
whitelist: w,
|
||||||
|
configDir: configDir,
|
||||||
|
}
|
||||||
|
api.mux = api.buildMux()
|
||||||
|
return api
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *APIHandler) buildMux() http.Handler {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("POST /relay/{id}", api.auth(api.createRelay))
|
mux.HandleFunc("POST /relay/{id}", api.auth(api.createRelay))
|
||||||
mux.HandleFunc("PUT /relay/{id}", api.auth(api.putRelay))
|
mux.HandleFunc("PUT /relay/{id}", api.auth(api.updateRelay))
|
||||||
mux.HandleFunc("PATCH /relay/{id}", api.auth(api.patchRelay))
|
mux.HandleFunc("PATCH /relay/{id}", api.auth(api.patchRelay))
|
||||||
mux.HandleFunc("DELETE /relay/{id}", api.auth(api.deleteRelay))
|
mux.HandleFunc("DELETE /relay/{id}", api.auth(api.deleteRelay))
|
||||||
mux.HandleFunc("GET /relay/{id}/members", api.auth(api.listRelayMembers))
|
mux.HandleFunc("GET /relay/{id}/members", api.auth(api.listRelayMembers))
|
||||||
|
return mux
|
||||||
// Skip auth, the handler checks the webhook signature itself
|
|
||||||
mux.HandleFunc("POST /.well-known/nip29/livekit/webhook", api.livekitWebhook)
|
|
||||||
|
|
||||||
api.mux = mux
|
|
||||||
|
|
||||||
return api
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *APIHandler) auth(next http.HandlerFunc) http.HandlerFunc {
|
func (api *APIHandler) auth(next http.HandlerFunc) http.HandlerFunc {
|
||||||
@@ -61,89 +65,108 @@ func (api *APIHandler) auth(next http.HandlerFunc) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServeHTTP implements the http.Handler interface
|
||||||
func (api *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (api *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
api.mux.ServeHTTP(w, r)
|
api.mux.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// listRelayMembers returns members for a relay as an array of pubkeys.
|
||||||
|
func (api *APIHandler) listRelayMembers(w http.ResponseWriter, r *http.Request) {
|
||||||
|
id := r.PathValue("id")
|
||||||
|
members, err := api.resolveRelayMembers(id)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
writeError(w, http.StatusNotFound, "relay not found")
|
||||||
|
} else {
|
||||||
|
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to load relay members: %v", err))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writeJSON(w, http.StatusOK, map[string][]string{"members": members})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *APIHandler) resolveRelayMembers(id string) ([]string, error) {
|
||||||
|
if members, ok := api.getMembersFromLoadedInstance(id); ok {
|
||||||
|
return members, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
config, err := api.loadConfigFromPath(api.configPath(id))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
events := &EventStore{
|
||||||
|
Config: config,
|
||||||
|
Schema: &Schema{Name: slug.Make(config.Schema)},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := events.Init(); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to init event store: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
management := &ManagementStore{
|
||||||
|
Config: config,
|
||||||
|
Events: events,
|
||||||
|
}
|
||||||
|
|
||||||
|
return collectMembers(management), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *APIHandler) getMembersFromLoadedInstance(id string) ([]string, bool) {
|
||||||
|
instancesMux.RLock()
|
||||||
|
instance, exists := instancesByName[id+".toml"]
|
||||||
|
instancesMux.RUnlock()
|
||||||
|
|
||||||
|
if !exists || instance == nil || instance.Config == nil || instance.Management == nil {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
return collectMembers(instance.Management), true
|
||||||
|
}
|
||||||
|
|
||||||
|
func collectMembers(management *ManagementStore) []string {
|
||||||
|
memberSet := make(map[string]struct{})
|
||||||
|
for _, pubkey := range management.GetMembers() {
|
||||||
|
memberSet[pubkey.Hex()] = struct{}{}
|
||||||
|
}
|
||||||
|
members := Keys(memberSet)
|
||||||
|
sort.Strings(members)
|
||||||
|
return members
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeError writes a JSON error response
|
||||||
func writeError(w http.ResponseWriter, status int, message string) {
|
func writeError(w http.ResponseWriter, status int, message string) {
|
||||||
w.WriteHeader(status)
|
w.WriteHeader(status)
|
||||||
json.NewEncoder(w).Encode(map[string]string{"error": message})
|
json.NewEncoder(w).Encode(map[string]string{"error": message})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// writeJSON writes a JSON success response
|
||||||
func writeJSON(w http.ResponseWriter, status int, v any) {
|
func writeJSON(w http.ResponseWriter, status int, v any) {
|
||||||
w.WriteHeader(status)
|
w.WriteHeader(status)
|
||||||
json.NewEncoder(w).Encode(v)
|
json.NewEncoder(w).Encode(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Relay CRUD
|
// scheme returns the URL scheme based on the request
|
||||||
|
func scheme(r *http.Request) string {
|
||||||
func (api *APIHandler) configFromRequest(path string, r *http.Request) (*Config, error) {
|
if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" {
|
||||||
r.Body = http.MaxBytesReader(nil, r.Body, 1024*1024)
|
return "https"
|
||||||
defer r.Body.Close()
|
}
|
||||||
|
return "http"
|
||||||
body, err := io.ReadAll(r.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to read body: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return LoadConfigFromJson(path, body)
|
// createRelay creates a new relay config file
|
||||||
}
|
|
||||||
|
|
||||||
func (api *APIHandler) patchFromRequest(r *http.Request) (map[string]interface{}, error) {
|
|
||||||
r.Body = http.MaxBytesReader(nil, r.Body, 1024*1024)
|
|
||||||
defer r.Body.Close()
|
|
||||||
|
|
||||||
body, err := io.ReadAll(r.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to read body: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var patch map[string]interface{}
|
|
||||||
if err := json.Unmarshal(body, &patch); err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid json config: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return patch, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *APIHandler) checkDuplicateSchemaOrHost(config *Config, excludeFilename string) error {
|
|
||||||
entries, err := os.ReadDir(Env("CONFIG"))
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to read config directory: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, entry := range entries {
|
|
||||||
if entry.IsDir() || entry.Name() == excludeFilename || !strings.HasSuffix(entry.Name(), ".toml") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
path := ConfigPathFromName(entry.Name())
|
|
||||||
|
|
||||||
if existing, err := LoadConfigFromPath(path); err == nil {
|
|
||||||
if existing.Schema == config.Schema {
|
|
||||||
return fmt.Errorf("schema %q is already in use", config.Schema)
|
|
||||||
}
|
|
||||||
if existing.Host == config.Host {
|
|
||||||
return fmt.Errorf("host %q is already in use", config.Host)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create relay
|
|
||||||
|
|
||||||
func (api *APIHandler) createRelay(w http.ResponseWriter, r *http.Request) {
|
func (api *APIHandler) createRelay(w http.ResponseWriter, r *http.Request) {
|
||||||
name := ConfigNameFromId(r.PathValue("id"))
|
id := r.PathValue("id")
|
||||||
path := ConfigPathFromName(name)
|
configPath := api.configPath(id)
|
||||||
if _, err := os.Stat(path); err == nil {
|
|
||||||
|
if _, err := os.Stat(configPath); err == nil {
|
||||||
writeError(w, http.StatusConflict, "relay with this id already exists")
|
writeError(w, http.StatusConflict, "relay with this id already exists")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := api.configFromRequest(path, r)
|
config, err := api.parseAndValidateConfig(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusBadRequest, err.Error())
|
writeError(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
@@ -154,7 +177,7 @@ func (api *APIHandler) createRelay(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := config.Save(); err != nil {
|
if err := api.saveConfig(configPath, config); err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to write config: %v", err))
|
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to write config: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -162,29 +185,32 @@ func (api *APIHandler) createRelay(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJSON(w, http.StatusCreated, map[string]string{"message": "relay created successfully"})
|
writeJSON(w, http.StatusCreated, map[string]string{"message": "relay created successfully"})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put relay
|
// updateRelay updates an existing relay config file
|
||||||
|
func (api *APIHandler) updateRelay(w http.ResponseWriter, r *http.Request) {
|
||||||
func (api *APIHandler) putRelay(w http.ResponseWriter, r *http.Request) {
|
|
||||||
id := r.PathValue("id")
|
id := r.PathValue("id")
|
||||||
name := ConfigNameFromId(id)
|
configPath := api.configPath(id)
|
||||||
path := ConfigPathFromName(name)
|
|
||||||
if _, err := os.Stat(path); err != nil {
|
if err := api.checkConfigExists(configPath); err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
writeError(w, http.StatusNotFound, "relay not found")
|
writeError(w, http.StatusNotFound, "relay not found")
|
||||||
|
} else {
|
||||||
|
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to check config: %v", err))
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := api.configFromRequest(path, r)
|
config, err := api.parseAndValidateConfig(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusBadRequest, err.Error())
|
writeError(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.checkDuplicateSchemaOrHost(config, name); err != nil {
|
if err := api.checkDuplicateSchemaOrHost(config, id+".toml"); err != nil {
|
||||||
writeError(w, http.StatusConflict, err.Error())
|
writeError(w, http.StatusConflict, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := config.Save(); err != nil {
|
if err := api.saveConfig(configPath, config); err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to write config: %v", err))
|
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to write config: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -192,45 +218,52 @@ func (api *APIHandler) putRelay(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJSON(w, http.StatusOK, map[string]string{"message": "relay updated successfully"})
|
writeJSON(w, http.StatusOK, map[string]string{"message": "relay updated successfully"})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Patch relay
|
// patchRelay partially updates an existing relay config
|
||||||
|
|
||||||
func (api *APIHandler) patchRelay(w http.ResponseWriter, r *http.Request) {
|
func (api *APIHandler) patchRelay(w http.ResponseWriter, r *http.Request) {
|
||||||
id := r.PathValue("id")
|
id := r.PathValue("id")
|
||||||
name := ConfigNameFromId(id)
|
configPath := api.configPath(id)
|
||||||
path := ConfigPathFromName(name)
|
|
||||||
if _, err := os.Stat(path); err != nil {
|
if err := api.checkConfigExists(configPath); err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
writeError(w, http.StatusNotFound, "relay not found")
|
writeError(w, http.StatusNotFound, "relay not found")
|
||||||
|
} else {
|
||||||
|
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to check config: %v", err))
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := LoadConfigFromPath(path)
|
// Load existing config
|
||||||
|
existing, err := api.loadConfigFromPath(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to read existing config: %v", err))
|
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to read existing config: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
patch, err := api.patchFromRequest(r)
|
// Parse patch
|
||||||
|
patch, err := api.readPatch(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusBadRequest, err.Error())
|
writeError(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.applyPatch(config, patch); err != nil {
|
// Apply patch to existing config
|
||||||
|
if err := api.applyPatch(existing, patch); err != nil {
|
||||||
writeError(w, http.StatusBadRequest, err.Error())
|
writeError(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := config.Validate(); err != nil {
|
// Validate the patched config
|
||||||
|
if err := api.validateConfig(existing); err != nil {
|
||||||
writeError(w, http.StatusBadRequest, err.Error())
|
writeError(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.checkDuplicateSchemaOrHost(config, name); err != nil {
|
if err := api.checkDuplicateSchemaOrHost(existing, id+".toml"); err != nil {
|
||||||
writeError(w, http.StatusConflict, err.Error())
|
writeError(w, http.StatusConflict, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := config.Save(); err != nil {
|
if err := api.saveConfig(configPath, existing); err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to write config: %v", err))
|
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to write config: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -238,6 +271,25 @@ func (api *APIHandler) patchRelay(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJSON(w, http.StatusOK, map[string]string{"message": "relay patched successfully"})
|
writeJSON(w, http.StatusOK, map[string]string{"message": "relay patched successfully"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// readPatch reads and parses the patch JSON from the request
|
||||||
|
func (api *APIHandler) readPatch(r *http.Request) (map[string]interface{}, error) {
|
||||||
|
r.Body = http.MaxBytesReader(nil, r.Body, 1024*1024)
|
||||||
|
defer r.Body.Close()
|
||||||
|
|
||||||
|
body, err := io.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to read body: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var patch map[string]interface{}
|
||||||
|
if err := json.Unmarshal(body, &patch); err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid json: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return patch, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// applyPatch applies a JSON patch to a config using reflection via JSON marshaling
|
||||||
func (api *APIHandler) applyPatch(config *Config, patch map[string]interface{}) error {
|
func (api *APIHandler) applyPatch(config *Config, patch map[string]interface{}) error {
|
||||||
// Convert config to map for merging
|
// Convert config to map for merging
|
||||||
configJSON, _ := json.Marshal(config)
|
configJSON, _ := json.Marshal(config)
|
||||||
@@ -254,15 +306,12 @@ func (api *APIHandler) applyPatch(config *Config, patch map[string]interface{})
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preserve unexported fields, which don't survive the JSON round-trip
|
|
||||||
patched.path = config.path
|
|
||||||
patched.secret = config.secret
|
|
||||||
|
|
||||||
// Copy patched values to original config
|
// Copy patched values to original config
|
||||||
*config = patched
|
*config = patched
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deepMerge recursively merges patch into base
|
||||||
func deepMerge(base, patch map[string]interface{}) map[string]interface{} {
|
func deepMerge(base, patch map[string]interface{}) map[string]interface{} {
|
||||||
result := make(map[string]interface{})
|
result := make(map[string]interface{})
|
||||||
|
|
||||||
@@ -287,18 +336,50 @@ func deepMerge(base, patch map[string]interface{}) map[string]interface{} {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete relay
|
// validateConfig validates a config
|
||||||
|
func (api *APIHandler) validateConfig(config *Config) error {
|
||||||
|
if config.Host == "" {
|
||||||
|
return fmt.Errorf("host is required")
|
||||||
|
}
|
||||||
|
if config.Schema == "" {
|
||||||
|
return fmt.Errorf("schema is required")
|
||||||
|
}
|
||||||
|
if !regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*$`).MatchString(config.Schema) {
|
||||||
|
return fmt.Errorf("schema must contain only letters, numbers, and underscores")
|
||||||
|
}
|
||||||
|
if config.Secret == "" {
|
||||||
|
return fmt.Errorf("secret is required")
|
||||||
|
}
|
||||||
|
if _, err := nostr.SecretKeyFromHex(config.Secret); err != nil {
|
||||||
|
return fmt.Errorf("invalid secret key: %w", err)
|
||||||
|
}
|
||||||
|
if config.Info.Pubkey != "" {
|
||||||
|
if _, err := nostr.PubKeyFromHex(config.Info.Pubkey); err != nil {
|
||||||
|
return fmt.Errorf("invalid info.pubkey: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
normalizeBlossomConfig(config)
|
||||||
|
if err := validateBlossomFileStorage(config); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// deleteRelay deletes a relay config file
|
||||||
func (api *APIHandler) deleteRelay(w http.ResponseWriter, r *http.Request) {
|
func (api *APIHandler) deleteRelay(w http.ResponseWriter, r *http.Request) {
|
||||||
id := r.PathValue("id")
|
id := r.PathValue("id")
|
||||||
name := ConfigNameFromId(id)
|
configPath := api.configPath(id)
|
||||||
path := ConfigPathFromName(name)
|
|
||||||
if _, err := os.Stat(path); err != nil {
|
if err := api.checkConfigExists(configPath); err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
writeError(w, http.StatusNotFound, "relay not found")
|
writeError(w, http.StatusNotFound, "relay not found")
|
||||||
|
} else {
|
||||||
|
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to check config: %v", err))
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.Remove(path); err != nil {
|
if err := os.Remove(configPath); err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to delete config: %v", err))
|
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to delete config: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -306,103 +387,96 @@ func (api *APIHandler) deleteRelay(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJSON(w, http.StatusOK, map[string]string{"message": "relay deleted successfully"})
|
writeJSON(w, http.StatusOK, map[string]string{"message": "relay deleted successfully"})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Relay members endpoint
|
// configName returns the config file name
|
||||||
|
func (api *APIHandler) configName(id string) string {
|
||||||
func (api *APIHandler) listRelayMembers(w http.ResponseWriter, r *http.Request) {
|
return id+".toml"
|
||||||
id := r.PathValue("id")
|
|
||||||
name := ConfigNameFromId(id)
|
|
||||||
members, err := api.resolveRelayMembers(name)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
|
||||||
writeError(w, http.StatusNotFound, "relay not found")
|
|
||||||
} else {
|
|
||||||
writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to load relay members: %v", err))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
writeJSON(w, http.StatusOK, map[string][]string{"members": members})
|
// configPath returns the full path for a config file
|
||||||
|
func (api *APIHandler) configPath(id string) string {
|
||||||
|
return filepath.Join(api.configDir, api.configName(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *APIHandler) resolveRelayMembers(name string) ([]string, error) {
|
// checkConfigExists checks if a config file exists
|
||||||
instancesMux.RLock()
|
func (api *APIHandler) checkConfigExists(path string) error {
|
||||||
instance, exists := instancesByName[name]
|
_, err := os.Stat(path)
|
||||||
instancesMux.RUnlock()
|
return err
|
||||||
|
|
||||||
if exists {
|
|
||||||
return collectMembers(instance.Management), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
path := ConfigPathFromName(name)
|
// loadConfigFromPath loads a config from a file path
|
||||||
config, err := LoadConfigFromPath(path)
|
func (api *APIHandler) loadConfigFromPath(path string) (*Config, error) {
|
||||||
|
var config Config
|
||||||
|
_, err := toml.DecodeFile(path, &config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
normalizeBlossomConfig(&config)
|
||||||
events := &EventStore{
|
return &config, nil
|
||||||
Config: config,
|
|
||||||
Schema: &Schema{Name: config.Schema},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := events.Init(); err != nil {
|
// parseAndValidateConfig parses and validates the JSON config from the request body
|
||||||
return nil, fmt.Errorf("failed to init event store: %w", err)
|
func (api *APIHandler) parseAndValidateConfig(r *http.Request) (*Config, error) {
|
||||||
}
|
r.Body = http.MaxBytesReader(nil, r.Body, 1024*1024)
|
||||||
|
defer r.Body.Close()
|
||||||
|
|
||||||
management := &ManagementStore{
|
body, err := io.ReadAll(r.Body)
|
||||||
Config: config,
|
|
||||||
Events: events,
|
|
||||||
}
|
|
||||||
|
|
||||||
return collectMembers(management), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func collectMembers(management *ManagementStore) []string {
|
|
||||||
memberSet := make(map[string]struct{})
|
|
||||||
for _, pubkey := range management.GetMembers() {
|
|
||||||
memberSet[pubkey.Hex()] = struct{}{}
|
|
||||||
}
|
|
||||||
members := Keys(memberSet)
|
|
||||||
sort.Strings(members)
|
|
||||||
return members
|
|
||||||
}
|
|
||||||
|
|
||||||
// LiveKit webhook
|
|
||||||
|
|
||||||
// LiveKit webhooks are registered statically, so we add the relay's schema as metadata
|
|
||||||
// to the room and handle webhooks at the top level.
|
|
||||||
func (api *APIHandler) livekitWebhook(w http.ResponseWriter, r *http.Request) {
|
|
||||||
body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, 1024*1024))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusBadRequest, "failed to read body")
|
return nil, fmt.Errorf("failed to read body: %w", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the relay schema from the room metadata. This is parsed before
|
var config Config
|
||||||
// verification, but the instance handler below re-checks the signature over
|
if err := json.Unmarshal(body, &config); err != nil {
|
||||||
// the whole body (metadata included) with that relay's key, so a forged
|
return nil, fmt.Errorf("invalid json config: %w", err)
|
||||||
// schema cannot pass.
|
|
||||||
var probe struct {
|
|
||||||
Room struct {
|
|
||||||
Metadata string `json:"metadata"`
|
|
||||||
} `json:"room"`
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(body, &probe); err != nil {
|
|
||||||
writeError(w, http.StatusBadRequest, "invalid webhook body")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
schema := strings.TrimSpace(probe.Room.Metadata)
|
if err := api.validateConfig(&config); err != nil {
|
||||||
if schema == "" {
|
return nil, err
|
||||||
writeError(w, http.StatusBadRequest, "missing room metadata")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
instance, ok := DispatchBySchema(schema)
|
return &config, nil
|
||||||
if !ok {
|
|
||||||
writeError(w, http.StatusNotFound, "relay not found")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Body = io.NopCloser(bytes.NewReader(body))
|
// saveConfig saves a config to a file as TOML
|
||||||
instance.livekitWebhookHandler(w, r)
|
func (api *APIHandler) saveConfig(path string, config *Config) error {
|
||||||
|
file, err := os.Create(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create file: %w", err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
encoder := toml.NewEncoder(file)
|
||||||
|
if err := encoder.Encode(config); err != nil {
|
||||||
|
return fmt.Errorf("failed to encode toml: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkDuplicateSchemaOrHost checks if the schema or host is already in use by another config
|
||||||
|
func (api *APIHandler) checkDuplicateSchemaOrHost(config *Config, excludeFilename string) error {
|
||||||
|
entries, err := os.ReadDir(api.configDir)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to read config directory: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, entry := range entries {
|
||||||
|
if entry.IsDir() || entry.Name() == excludeFilename || !strings.HasSuffix(entry.Name(), ".toml") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
path := filepath.Join(api.configDir, entry.Name())
|
||||||
|
var existing Config
|
||||||
|
if _, err := toml.DecodeFile(path, &existing); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if existing.Schema == config.Schema {
|
||||||
|
return fmt.Errorf("schema %q is already in use", config.Schema)
|
||||||
|
}
|
||||||
|
if existing.Host == config.Host {
|
||||||
|
return fmt.Errorf("host %q is already in use", config.Host)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
+38
-68
@@ -13,17 +13,20 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
|
"github.com/gosimple/slug"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAPIHandler_Authentication(t *testing.T) {
|
func TestAPIHandler_Authentication(t *testing.T) {
|
||||||
useTestConfigDir(t)
|
// Create a temporary config directory
|
||||||
|
configDir := t.TempDir()
|
||||||
|
|
||||||
// Create a test keypair for authentication
|
// Create a test keypair for authentication
|
||||||
secretKey := nostr.Generate()
|
secretKey := nostr.Generate()
|
||||||
pubkey := secretKey.Public()
|
pubkey := secretKey.Public()
|
||||||
|
|
||||||
// Create API handler with whitelist containing our test pubkey
|
// Create API handler with whitelist containing our test pubkey
|
||||||
api := newTestAPIHandler(t, pubkey.Hex())
|
whitelist := pubkey.Hex()
|
||||||
|
api := NewAPIHandler(whitelist, configDir)
|
||||||
|
|
||||||
t.Run("missing authorization header", func(t *testing.T) {
|
t.Run("missing authorization header", func(t *testing.T) {
|
||||||
req := httptest.NewRequest(http.MethodPost, "/relay/test", strings.NewReader("{}"))
|
req := httptest.NewRequest(http.MethodPost, "/relay/test", strings.NewReader("{}"))
|
||||||
@@ -171,11 +174,12 @@ func TestAPIHandler_Authentication(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAPIHandler_CreateRelay(t *testing.T) {
|
func TestAPIHandler_CreateRelay(t *testing.T) {
|
||||||
configDir := useTestConfigDir(t)
|
configDir := t.TempDir()
|
||||||
|
|
||||||
secretKey := nostr.Generate()
|
secretKey := nostr.Generate()
|
||||||
pubkey := secretKey.Public()
|
pubkey := secretKey.Public()
|
||||||
api := newTestAPIHandler(t, pubkey.Hex())
|
whitelist := pubkey.Hex()
|
||||||
|
api := NewAPIHandler(whitelist, configDir)
|
||||||
|
|
||||||
validConfig := map[string]interface{}{
|
validConfig := map[string]interface{}{
|
||||||
"host": "relay.example.com",
|
"host": "relay.example.com",
|
||||||
@@ -223,9 +227,6 @@ func TestAPIHandler_CreateRelay(t *testing.T) {
|
|||||||
"host": "other.example.com",
|
"host": "other.example.com",
|
||||||
"schema": "testrelay", // Same schema as existing
|
"schema": "testrelay", // Same schema as existing
|
||||||
"secret": secretKey.Hex(),
|
"secret": secretKey.Hex(),
|
||||||
"info": map[string]interface{}{
|
|
||||||
"pubkey": pubkey.Hex(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
body, _ := json.Marshal(config)
|
body, _ := json.Marshal(config)
|
||||||
req := createAuthenticatedRequest(http.MethodPost, "http://api.example.com/relay/other", secretKey, body)
|
req := createAuthenticatedRequest(http.MethodPost, "http://api.example.com/relay/other", secretKey, body)
|
||||||
@@ -243,9 +244,6 @@ func TestAPIHandler_CreateRelay(t *testing.T) {
|
|||||||
"host": "relay.example.com", // Same host as existing
|
"host": "relay.example.com", // Same host as existing
|
||||||
"schema": "otherschema",
|
"schema": "otherschema",
|
||||||
"secret": secretKey.Hex(),
|
"secret": secretKey.Hex(),
|
||||||
"info": map[string]interface{}{
|
|
||||||
"pubkey": pubkey.Hex(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
body, _ := json.Marshal(config)
|
body, _ := json.Marshal(config)
|
||||||
req := createAuthenticatedRequest(http.MethodPost, "http://api.example.com/relay/other2", secretKey, body)
|
req := createAuthenticatedRequest(http.MethodPost, "http://api.example.com/relay/other2", secretKey, body)
|
||||||
@@ -304,11 +302,12 @@ func TestAPIHandler_CreateRelay(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAPIHandler_UpdateRelay(t *testing.T) {
|
func TestAPIHandler_UpdateRelay(t *testing.T) {
|
||||||
useTestConfigDir(t)
|
configDir := t.TempDir()
|
||||||
|
|
||||||
secretKey := nostr.Generate()
|
secretKey := nostr.Generate()
|
||||||
pubkey := secretKey.Public()
|
pubkey := secretKey.Public()
|
||||||
api := newTestAPIHandler(t, pubkey.Hex())
|
whitelist := pubkey.Hex()
|
||||||
|
api := NewAPIHandler(whitelist, configDir)
|
||||||
|
|
||||||
// Create initial relay
|
// Create initial relay
|
||||||
initialConfig := map[string]interface{}{
|
initialConfig := map[string]interface{}{
|
||||||
@@ -373,9 +372,6 @@ func TestAPIHandler_UpdateRelay(t *testing.T) {
|
|||||||
"host": "other.example.com",
|
"host": "other.example.com",
|
||||||
"schema": "otherrelay",
|
"schema": "otherrelay",
|
||||||
"secret": secretKey.Hex(),
|
"secret": secretKey.Hex(),
|
||||||
"info": map[string]interface{}{
|
|
||||||
"pubkey": pubkey.Hex(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
body, _ := json.Marshal(otherConfig)
|
body, _ := json.Marshal(otherConfig)
|
||||||
req := createAuthenticatedRequest(http.MethodPost, "http://api.example.com/relay/otherrelay", secretKey, body)
|
req := createAuthenticatedRequest(http.MethodPost, "http://api.example.com/relay/otherrelay", secretKey, body)
|
||||||
@@ -390,9 +386,6 @@ func TestAPIHandler_UpdateRelay(t *testing.T) {
|
|||||||
"host": "relay.example.com",
|
"host": "relay.example.com",
|
||||||
"schema": "otherrelay", // Duplicate
|
"schema": "otherrelay", // Duplicate
|
||||||
"secret": secretKey.Hex(),
|
"secret": secretKey.Hex(),
|
||||||
"info": map[string]interface{}{
|
|
||||||
"pubkey": pubkey.Hex(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
body, _ = json.Marshal(updateConfig)
|
body, _ = json.Marshal(updateConfig)
|
||||||
req = createAuthenticatedRequest(http.MethodPut, "http://api.example.com/relay/testrelay", secretKey, body)
|
req = createAuthenticatedRequest(http.MethodPut, "http://api.example.com/relay/testrelay", secretKey, body)
|
||||||
@@ -407,11 +400,12 @@ func TestAPIHandler_UpdateRelay(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAPIHandler_PatchRelay(t *testing.T) {
|
func TestAPIHandler_PatchRelay(t *testing.T) {
|
||||||
useTestConfigDir(t)
|
configDir := t.TempDir()
|
||||||
|
|
||||||
secretKey := nostr.Generate()
|
secretKey := nostr.Generate()
|
||||||
pubkey := secretKey.Public()
|
pubkey := secretKey.Public()
|
||||||
api := newTestAPIHandler(t, pubkey.Hex())
|
whitelist := pubkey.Hex()
|
||||||
|
api := NewAPIHandler(whitelist, configDir)
|
||||||
|
|
||||||
// Create initial relay with full config
|
// Create initial relay with full config
|
||||||
initialConfig := map[string]interface{}{
|
initialConfig := map[string]interface{}{
|
||||||
@@ -501,9 +495,6 @@ func TestAPIHandler_PatchRelay(t *testing.T) {
|
|||||||
"host": "other.example.com",
|
"host": "other.example.com",
|
||||||
"schema": "anotherrelay",
|
"schema": "anotherrelay",
|
||||||
"secret": secretKey.Hex(),
|
"secret": secretKey.Hex(),
|
||||||
"info": map[string]interface{}{
|
|
||||||
"pubkey": pubkey.Hex(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
body, _ := json.Marshal(otherConfig)
|
body, _ := json.Marshal(otherConfig)
|
||||||
req := createAuthenticatedRequest(http.MethodPost, "http://api.example.com/relay/anotherrelay", secretKey, body)
|
req := createAuthenticatedRequest(http.MethodPost, "http://api.example.com/relay/anotherrelay", secretKey, body)
|
||||||
@@ -560,11 +551,12 @@ func TestAPIHandler_PatchRelay(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAPIHandler_DeleteRelay(t *testing.T) {
|
func TestAPIHandler_DeleteRelay(t *testing.T) {
|
||||||
configDir := useTestConfigDir(t)
|
configDir := t.TempDir()
|
||||||
|
|
||||||
secretKey := nostr.Generate()
|
secretKey := nostr.Generate()
|
||||||
pubkey := secretKey.Public()
|
pubkey := secretKey.Public()
|
||||||
api := newTestAPIHandler(t, pubkey.Hex())
|
whitelist := pubkey.Hex()
|
||||||
|
api := NewAPIHandler(whitelist, configDir)
|
||||||
|
|
||||||
// Create a relay to delete
|
// Create a relay to delete
|
||||||
config := map[string]interface{}{
|
config := map[string]interface{}{
|
||||||
@@ -614,11 +606,12 @@ func TestAPIHandler_DeleteRelay(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAPIHandler_ListRelayMembers(t *testing.T) {
|
func TestAPIHandler_ListRelayMembers(t *testing.T) {
|
||||||
useTestConfigDir(t)
|
configDir := t.TempDir()
|
||||||
|
|
||||||
secretKey := nostr.Generate()
|
secretKey := nostr.Generate()
|
||||||
pubkey := secretKey.Public()
|
pubkey := secretKey.Public()
|
||||||
api := newTestAPIHandler(t, pubkey.Hex())
|
whitelist := pubkey.Hex()
|
||||||
|
api := NewAPIHandler(whitelist, configDir)
|
||||||
|
|
||||||
t.Run("list members from loaded relay instance", func(t *testing.T) {
|
t.Run("list members from loaded relay instance", func(t *testing.T) {
|
||||||
member1 := nostr.Generate().Public()
|
member1 := nostr.Generate().Public()
|
||||||
@@ -689,20 +682,18 @@ func TestAPIHandler_ListRelayMembers(t *testing.T) {
|
|||||||
|
|
||||||
config := &Config{
|
config := &Config{
|
||||||
Host: "members.example.com",
|
Host: "members.example.com",
|
||||||
Schema: "members_" + strings.ToLower(RandomString(8)),
|
Schema: "members_" + RandomString(8),
|
||||||
Secret: relaySecret.Hex(),
|
Secret: relaySecret.Hex(),
|
||||||
}
|
}
|
||||||
config.Info.Pubkey = nostr.Generate().Public().Hex()
|
|
||||||
config.path = ConfigPathFromName(ConfigNameFromId("fallback"))
|
|
||||||
|
|
||||||
if err := config.Save(); err != nil {
|
if err := api.saveConfig(api.configPath("fallback"), config); err != nil {
|
||||||
t.Fatalf("failed to save config: %v", err)
|
t.Fatalf("failed to save config: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seed DB with RELAY_MEMBERS to simulate a prior relay load.
|
// Seed DB with RELAY_MEMBERS to simulate a prior relay load.
|
||||||
seedEvents := &EventStore{
|
seedEvents := &EventStore{
|
||||||
Config: &Config{secret: relaySecret},
|
Config: &Config{secret: relaySecret},
|
||||||
Schema: &Schema{Name: config.Schema},
|
Schema: &Schema{Name: slug.Make(config.Schema)},
|
||||||
}
|
}
|
||||||
if err := seedEvents.Init(); err != nil {
|
if err := seedEvents.Init(); err != nil {
|
||||||
t.Fatalf("failed to init seed events: %v", err)
|
t.Fatalf("failed to init seed events: %v", err)
|
||||||
@@ -789,11 +780,12 @@ func TestAPIHandler_ListRelayMembers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAPIHandler_MethodNotAllowed(t *testing.T) {
|
func TestAPIHandler_MethodNotAllowed(t *testing.T) {
|
||||||
useTestConfigDir(t)
|
configDir := t.TempDir()
|
||||||
|
|
||||||
secretKey := nostr.Generate()
|
secretKey := nostr.Generate()
|
||||||
pubkey := secretKey.Public()
|
pubkey := secretKey.Public()
|
||||||
api := newTestAPIHandler(t, pubkey.Hex())
|
whitelist := pubkey.Hex()
|
||||||
|
api := NewAPIHandler(whitelist, configDir)
|
||||||
|
|
||||||
t.Run("GET method not allowed", func(t *testing.T) {
|
t.Run("GET method not allowed", func(t *testing.T) {
|
||||||
req := createAuthenticatedRequest(http.MethodGet, "http://api.example.com/relay/test", secretKey, nil)
|
req := createAuthenticatedRequest(http.MethodGet, "http://api.example.com/relay/test", secretKey, nil)
|
||||||
@@ -808,11 +800,12 @@ func TestAPIHandler_MethodNotAllowed(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAPIHandler_InvalidPath(t *testing.T) {
|
func TestAPIHandler_InvalidPath(t *testing.T) {
|
||||||
useTestConfigDir(t)
|
configDir := t.TempDir()
|
||||||
|
|
||||||
secretKey := nostr.Generate()
|
secretKey := nostr.Generate()
|
||||||
pubkey := secretKey.Public()
|
pubkey := secretKey.Public()
|
||||||
api := newTestAPIHandler(t, pubkey.Hex())
|
whitelist := pubkey.Hex()
|
||||||
|
api := NewAPIHandler(whitelist, configDir)
|
||||||
|
|
||||||
t.Run("invalid path returns not found", func(t *testing.T) {
|
t.Run("invalid path returns not found", func(t *testing.T) {
|
||||||
req := createAuthenticatedRequest(http.MethodPost, "http://api.example.com/invalid/path", secretKey, []byte("{}"))
|
req := createAuthenticatedRequest(http.MethodPost, "http://api.example.com/invalid/path", secretKey, []byte("{}"))
|
||||||
@@ -838,11 +831,12 @@ func TestAPIHandler_InvalidPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAPIHandler_ConfigValidation(t *testing.T) {
|
func TestAPIHandler_ConfigValidation(t *testing.T) {
|
||||||
configDir := useTestConfigDir(t)
|
configDir := t.TempDir()
|
||||||
|
|
||||||
secretKey := nostr.Generate()
|
secretKey := nostr.Generate()
|
||||||
pubkey := secretKey.Public()
|
pubkey := secretKey.Public()
|
||||||
api := newTestAPIHandler(t, pubkey.Hex())
|
whitelist := pubkey.Hex()
|
||||||
|
api := NewAPIHandler(whitelist, configDir)
|
||||||
|
|
||||||
t.Run("invalid info.pubkey", func(t *testing.T) {
|
t.Run("invalid info.pubkey", func(t *testing.T) {
|
||||||
config := map[string]interface{}{
|
config := map[string]interface{}{
|
||||||
@@ -983,33 +977,9 @@ func createAuthenticatedRequest(method, url string, secretKey nostr.SecretKey, b
|
|||||||
return req
|
return req
|
||||||
}
|
}
|
||||||
|
|
||||||
// setTestEnv overrides a value in the package-level env map. Env memoizes
|
|
||||||
// os.Environ via sync.Once, so once the test binary has started, os.Setenv is
|
|
||||||
// ignored — mutating the cached map directly is the only way to change config
|
|
||||||
// for an individual test. Safe because tests in this package run sequentially.
|
|
||||||
func setTestEnv(key, value string) {
|
|
||||||
_ = Env("DATA") // ensure the env map has been initialized
|
|
||||||
env[key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
// useTestConfigDir points Env("CONFIG") at a fresh temp dir for this test.
|
|
||||||
func useTestConfigDir(t *testing.T) string {
|
|
||||||
t.Helper()
|
|
||||||
dir := t.TempDir()
|
|
||||||
setTestEnv("CONFIG", dir)
|
|
||||||
return dir
|
|
||||||
}
|
|
||||||
|
|
||||||
// newTestAPIHandler builds a handler whose whitelist contains the given pubkeys.
|
|
||||||
func newTestAPIHandler(t *testing.T, whitelist ...string) *APIHandler {
|
|
||||||
t.Helper()
|
|
||||||
setTestEnv("API_WHITELIST", strings.Join(whitelist, ","))
|
|
||||||
return NewAPIHandler()
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNewAPIHandler(t *testing.T) {
|
func TestNewAPIHandler(t *testing.T) {
|
||||||
t.Run("empty whitelist", func(t *testing.T) {
|
t.Run("empty whitelist", func(t *testing.T) {
|
||||||
api := newTestAPIHandler(t)
|
api := NewAPIHandler("", "/tmp")
|
||||||
if len(api.whitelist) != 0 {
|
if len(api.whitelist) != 0 {
|
||||||
t.Error("expected empty whitelist")
|
t.Error("expected empty whitelist")
|
||||||
}
|
}
|
||||||
@@ -1017,7 +987,7 @@ func TestNewAPIHandler(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("single pubkey", func(t *testing.T) {
|
t.Run("single pubkey", func(t *testing.T) {
|
||||||
pubkey := nostr.Generate().Public().Hex()
|
pubkey := nostr.Generate().Public().Hex()
|
||||||
api := newTestAPIHandler(t, pubkey)
|
api := NewAPIHandler(pubkey, "/tmp")
|
||||||
if len(api.whitelist) != 1 {
|
if len(api.whitelist) != 1 {
|
||||||
t.Error("expected 1 entry in whitelist")
|
t.Error("expected 1 entry in whitelist")
|
||||||
}
|
}
|
||||||
@@ -1029,8 +999,8 @@ func TestNewAPIHandler(t *testing.T) {
|
|||||||
t.Run("multiple pubkeys", func(t *testing.T) {
|
t.Run("multiple pubkeys", func(t *testing.T) {
|
||||||
pubkey1 := nostr.Generate().Public().Hex()
|
pubkey1 := nostr.Generate().Public().Hex()
|
||||||
pubkey2 := nostr.Generate().Public().Hex()
|
pubkey2 := nostr.Generate().Public().Hex()
|
||||||
setTestEnv("API_WHITELIST", fmt.Sprintf("%s, %s", pubkey1, pubkey2))
|
whitelist := fmt.Sprintf("%s, %s", pubkey1, pubkey2)
|
||||||
api := NewAPIHandler()
|
api := NewAPIHandler(whitelist, "/tmp")
|
||||||
if len(api.whitelist) != 2 {
|
if len(api.whitelist) != 2 {
|
||||||
t.Error("expected 2 entries in whitelist")
|
t.Error("expected 2 entries in whitelist")
|
||||||
}
|
}
|
||||||
@@ -1041,8 +1011,8 @@ func TestNewAPIHandler(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("whitespace trimming", func(t *testing.T) {
|
t.Run("whitespace trimming", func(t *testing.T) {
|
||||||
pubkey := nostr.Generate().Public().Hex()
|
pubkey := nostr.Generate().Public().Hex()
|
||||||
setTestEnv("API_WHITELIST", " "+pubkey+" ")
|
whitelist := " " + pubkey + " "
|
||||||
api := NewAPIHandler()
|
api := NewAPIHandler(whitelist, "/tmp")
|
||||||
if len(api.whitelist) != 1 {
|
if len(api.whitelist) != 1 {
|
||||||
t.Error("expected 1 entry in whitelist after trimming")
|
t.Error("expected 1 entry in whitelist after trimming")
|
||||||
}
|
}
|
||||||
|
|||||||
+115
-122
@@ -16,6 +16,7 @@ import (
|
|||||||
awsconfig "github.com/aws/aws-sdk-go-v2/config"
|
awsconfig "github.com/aws/aws-sdk-go-v2/config"
|
||||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
"github.com/aws/aws-sdk-go-v2/credentials"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
|
"github.com/gosimple/slug"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,24 +25,131 @@ type BlossomStore struct {
|
|||||||
Events eventstore.Store
|
Events eventstore.Store
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func loadAWSConfigForBlossomS3(ctx context.Context, s *BlossomS3Settings) (aws.Config, error) {
|
||||||
|
return awsconfig.LoadDefaultConfig(ctx,
|
||||||
|
awsconfig.WithRegion(s.Region),
|
||||||
|
awsconfig.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(s.AccessKey, s.SecretKey, "")),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func s3APIClientForBlossomSettings(awsCfg aws.Config, s *BlossomS3Settings) *s3.Client {
|
||||||
|
customEndpoint := s.Endpoint != ""
|
||||||
|
return s3.NewFromConfig(awsCfg, func(o *s3.Options) {
|
||||||
|
if customEndpoint {
|
||||||
|
o.BaseEndpoint = aws.String(s.Endpoint)
|
||||||
|
// Custom endpoints (e.g. MinIO) expect path-style addressing.
|
||||||
|
o.UsePathStyle = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func blossomS3ObjectKey(slugName, sha256, keyPrefix string) string {
|
||||||
|
rel := slugName + "/" + sha256
|
||||||
|
if keyPrefix != "" {
|
||||||
|
return keyPrefix + "/" + rel
|
||||||
|
}
|
||||||
|
return rel
|
||||||
|
}
|
||||||
|
|
||||||
|
func attachBlossomLocalBlobs(bs *blossom.BlossomServer, slugName string) {
|
||||||
|
dir := filepath.Join(Env("MEDIA"), slugName)
|
||||||
|
osfs := afero.NewOsFs()
|
||||||
|
_ = osfs.MkdirAll(dir, 0755)
|
||||||
|
|
||||||
|
bs.StoreBlob = func(ctx context.Context, sha256 string, ext string, body []byte) error {
|
||||||
|
file, err := osfs.Create(filepath.Join(dir, sha256))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := io.Copy(file, bytes.NewReader(body)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
bs.LoadBlob = func(ctx context.Context, sha256 string, ext string) (io.ReadSeeker, *url.URL, error) {
|
||||||
|
file, err := osfs.Open(filepath.Join(dir, sha256))
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
return file, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
bs.DeleteBlob = func(ctx context.Context, sha256 string, ext string) error {
|
||||||
|
return osfs.Remove(filepath.Join(dir, sha256))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func attachBlossomS3Blobs(bs *blossom.BlossomServer, cfg *Config, slugName string) error {
|
||||||
|
s := &cfg.Blossom.S3
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
awsCfg, err := loadAWSConfigForBlossomS3(ctx, s)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("aws config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
client := s3APIClientForBlossomSettings(awsCfg, s)
|
||||||
|
bucket := s.Bucket
|
||||||
|
|
||||||
|
bs.StoreBlob = func(ctx context.Context, sha256 string, ext string, body []byte) error {
|
||||||
|
_, err := client.PutObject(ctx, &s3.PutObjectInput{
|
||||||
|
Bucket: aws.String(bucket),
|
||||||
|
Key: aws.String(blossomS3ObjectKey(slugName, sha256, s.KeyPrefix)),
|
||||||
|
Body: bytes.NewReader(body),
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
bs.LoadBlob = func(ctx context.Context, sha256 string, ext string) (io.ReadSeeker, *url.URL, error) {
|
||||||
|
out, err := client.GetObject(ctx, &s3.GetObjectInput{
|
||||||
|
Bucket: aws.String(bucket),
|
||||||
|
Key: aws.String(blossomS3ObjectKey(slugName, sha256, s.KeyPrefix)),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
defer out.Body.Close()
|
||||||
|
|
||||||
|
data, err := io.ReadAll(out.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return bytes.NewReader(data), nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
bs.DeleteBlob = func(ctx context.Context, sha256 string, ext string) error {
|
||||||
|
_, err := client.DeleteObject(ctx, &s3.DeleteObjectInput{
|
||||||
|
Bucket: aws.String(bucket),
|
||||||
|
Key: aws.String(blossomS3ObjectKey(slugName, sha256, s.KeyPrefix)),
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (bl *BlossomStore) Enable(instance *Instance) {
|
func (bl *BlossomStore) Enable(instance *Instance) {
|
||||||
|
slugName := slug.Make(bl.Config.Schema)
|
||||||
backend := blossom.New(instance.Relay, "https://"+bl.Config.Host)
|
backend := blossom.New(instance.Relay, "https://"+bl.Config.Host)
|
||||||
|
|
||||||
backend.Store = blossom.EventStoreBlobIndexWrapper{
|
backend.Store = blossom.EventStoreBlobIndexWrapper{
|
||||||
Store: bl.Events,
|
Store: bl.Events,
|
||||||
ServiceURL: "https://" + bl.Config.Host,
|
ServiceURL: "https://" + bl.Config.Host,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch bl.Config.Blossom.Adapter {
|
switch bl.Config.Blossom.Backend {
|
||||||
case "local":
|
case "local":
|
||||||
if err := bl.UseLocalAdapter(backend); err != nil {
|
attachBlossomLocalBlobs(backend, slugName)
|
||||||
log.Fatalf("blossom: failed to use local adapter %q", err)
|
|
||||||
}
|
|
||||||
case "s3":
|
case "s3":
|
||||||
if err := bl.UseS3Adapter(backend); err != nil {
|
if err := attachBlossomS3Blobs(backend, bl.Config, slugName); err != nil {
|
||||||
log.Fatalf("blossom: failed to use s3 adapter %q", err)
|
log.Fatalf("blossom: s3: %v", err)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log.Fatalf("blossom: unknown backend %q", bl.Config.Blossom.Adapter)
|
log.Fatalf("blossom: unknown backend %q (use local or s3)", bl.Config.Blossom.Backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
backend.RejectUpload = func(ctx context.Context, auth *nostr.Event, size int, ext string) (bool, string, int) {
|
backend.RejectUpload = func(ctx context.Context, auth *nostr.Event, size int, ext string) (bool, string, int) {
|
||||||
@@ -57,10 +165,6 @@ func (bl *BlossomStore) Enable(instance *Instance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
backend.RejectGet = func(ctx context.Context, auth *nostr.Event, sha256 string, ext string) (bool, string, int) {
|
backend.RejectGet = func(ctx context.Context, auth *nostr.Event, sha256 string, ext string) (bool, string, int) {
|
||||||
if !bl.Config.Blossom.AuthenticatedRead {
|
|
||||||
return false, "", 200
|
|
||||||
}
|
|
||||||
|
|
||||||
if auth == nil || !instance.Management.IsMember(auth.PubKey) {
|
if auth == nil || !instance.Management.IsMember(auth.PubKey) {
|
||||||
return true, "unauthorized", 403
|
return true, "unauthorized", 403
|
||||||
}
|
}
|
||||||
@@ -89,114 +193,3 @@ func (bl *BlossomStore) Enable(instance *Instance) {
|
|||||||
instance.Relay.Info.SupportedNIPs = append(instance.Relay.Info.SupportedNIPs, "BUD-02")
|
instance.Relay.Info.SupportedNIPs = append(instance.Relay.Info.SupportedNIPs, "BUD-02")
|
||||||
instance.Relay.Info.SupportedNIPs = append(instance.Relay.Info.SupportedNIPs, "BUD-11")
|
instance.Relay.Info.SupportedNIPs = append(instance.Relay.Info.SupportedNIPs, "BUD-11")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Local adapter
|
|
||||||
|
|
||||||
func (bl *BlossomStore) UseLocalAdapter(backend *blossom.BlossomServer) error {
|
|
||||||
dir := filepath.Join(Env("MEDIA"), bl.Config.Schema)
|
|
||||||
osfs := afero.NewOsFs()
|
|
||||||
_ = osfs.MkdirAll(dir, 0755)
|
|
||||||
|
|
||||||
backend.StoreBlob = func(ctx context.Context, sha256 string, ext string, body []byte) error {
|
|
||||||
file, err := osfs.Create(filepath.Join(dir, sha256))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := io.Copy(file, bytes.NewReader(body)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
backend.LoadBlob = func(ctx context.Context, sha256 string, ext string) (io.ReadSeeker, *url.URL, error) {
|
|
||||||
file, err := osfs.Open(filepath.Join(dir, sha256))
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
return file, nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
backend.DeleteBlob = func(ctx context.Context, sha256 string, ext string) error {
|
|
||||||
return osfs.Remove(filepath.Join(dir, sha256))
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// S3 adapter
|
|
||||||
|
|
||||||
func (bl *BlossomStore) S3Key(sha256 string) string {
|
|
||||||
key := bl.Config.Schema + "/" + sha256
|
|
||||||
|
|
||||||
if bl.Config.Blossom.S3.KeyPrefix != "" {
|
|
||||||
key = bl.Config.Blossom.S3.KeyPrefix + "/" + key
|
|
||||||
}
|
|
||||||
|
|
||||||
return key
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bl *BlossomStore) UseS3Adapter(backend *blossom.BlossomServer) error {
|
|
||||||
ctx := context.Background()
|
|
||||||
awsConfig, err := awsconfig.LoadDefaultConfig(ctx,
|
|
||||||
awsconfig.WithRegion(bl.Config.Blossom.S3.Region),
|
|
||||||
awsconfig.WithCredentialsProvider(
|
|
||||||
credentials.NewStaticCredentialsProvider(
|
|
||||||
bl.Config.Blossom.S3.AccessKey,
|
|
||||||
bl.Config.Blossom.S3.SecretKey,
|
|
||||||
"",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("aws config: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
client := s3.NewFromConfig(awsConfig, func(o *s3.Options) {
|
|
||||||
if bl.Config.Blossom.S3.Endpoint != "" {
|
|
||||||
o.BaseEndpoint = aws.String(bl.Config.Blossom.S3.Endpoint)
|
|
||||||
o.UsePathStyle = true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
backend.StoreBlob = func(ctx context.Context, sha256 string, ext string, body []byte) error {
|
|
||||||
_, err := client.PutObject(ctx, &s3.PutObjectInput{
|
|
||||||
Bucket: aws.String(bl.Config.Blossom.S3.Bucket),
|
|
||||||
Key: aws.String(bl.S3Key(sha256)),
|
|
||||||
Body: bytes.NewReader(body),
|
|
||||||
})
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
backend.LoadBlob = func(ctx context.Context, sha256 string, ext string) (io.ReadSeeker, *url.URL, error) {
|
|
||||||
out, err := client.GetObject(ctx, &s3.GetObjectInput{
|
|
||||||
Bucket: aws.String(bl.Config.Blossom.S3.Bucket),
|
|
||||||
Key: aws.String(bl.S3Key(sha256)),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
defer out.Body.Close()
|
|
||||||
|
|
||||||
data, err := io.ReadAll(out.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return bytes.NewReader(data), nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
backend.DeleteBlob = func(ctx context.Context, sha256 string, ext string) error {
|
|
||||||
_, err := client.DeleteObject(ctx, &s3.DeleteObjectInput{
|
|
||||||
Bucket: aws.String(bl.Config.Blossom.S3.Bucket),
|
|
||||||
Key: aws.String(bl.S3Key(sha256)),
|
|
||||||
})
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
+67
-62
@@ -1,14 +1,13 @@
|
|||||||
package zooid
|
package zooid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"slices"
|
"slices"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Role struct {
|
type Role struct {
|
||||||
@@ -48,8 +47,7 @@ type Config struct {
|
|||||||
|
|
||||||
Blossom struct {
|
Blossom struct {
|
||||||
Enabled bool `toml:"enabled" json:"enabled"`
|
Enabled bool `toml:"enabled" json:"enabled"`
|
||||||
AuthenticatedRead bool `toml:"authenticated_read" json:"authenticated_read"`
|
Backend string `toml:"backend" json:"backend"`
|
||||||
Adapter string `toml:"adapter" json:"adapter"`
|
|
||||||
S3 BlossomS3Settings `toml:"s3" json:"s3"`
|
S3 BlossomS3Settings `toml:"s3" json:"s3"`
|
||||||
} `toml:"blossom" json:"blossom"`
|
} `toml:"blossom" json:"blossom"`
|
||||||
|
|
||||||
@@ -61,13 +59,13 @@ type Config struct {
|
|||||||
|
|
||||||
Roles map[string]Role `toml:"roles" json:"roles"`
|
Roles map[string]Role `toml:"roles" json:"roles"`
|
||||||
|
|
||||||
// Parsed values
|
// Private/parsed values
|
||||||
path string
|
path string
|
||||||
secret nostr.SecretKey
|
secret nostr.SecretKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlossomS3Settings configures S3-compatible object storage for Blossom blobs
|
// BlossomS3Settings configures S3-compatible object storage for Blossom blobs
|
||||||
// when [blossom] adapter is "s3".
|
// when [blossom] backend is "s3".
|
||||||
type BlossomS3Settings struct {
|
type BlossomS3Settings struct {
|
||||||
Endpoint string `toml:"endpoint" json:"endpoint"`
|
Endpoint string `toml:"endpoint" json:"endpoint"`
|
||||||
Region string `toml:"region" json:"region"`
|
Region string `toml:"region" json:"region"`
|
||||||
@@ -77,12 +75,10 @@ type BlossomS3Settings struct {
|
|||||||
KeyPrefix string `toml:"key_prefix" json:"key_prefix"`
|
KeyPrefix string `toml:"key_prefix" json:"key_prefix"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfigNameFromId(id string) string {
|
func LoadConfig(filename string) (*Config, error) {
|
||||||
return id + ".toml"
|
path := filepath.Join(Env("CONFIG"), filename)
|
||||||
}
|
|
||||||
|
|
||||||
func ConfigPathFromName(name string) string {
|
return LoadConfigFromPath(path)
|
||||||
return filepath.Join(Env("CONFIG"), name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfigFromPath(path string) (*Config, error) {
|
func LoadConfigFromPath(path string) (*Config, error) {
|
||||||
@@ -91,80 +87,86 @@ func LoadConfigFromPath(path string) (*Config, error) {
|
|||||||
return nil, fmt.Errorf("Failed to parse config file %s: %w", path, err)
|
return nil, fmt.Errorf("Failed to parse config file %s: %w", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
config.path = path
|
normalizeBlossomConfig(&config)
|
||||||
|
|
||||||
if err := config.Validate(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func LoadConfigFromJson(path string, body []byte) (*Config, error) {
|
|
||||||
var config Config
|
|
||||||
if err := json.Unmarshal(body, &config); err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid json config: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
config.path = path
|
|
||||||
|
|
||||||
if err := config.Validate(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (config *Config) Validate() error {
|
|
||||||
if config.Blossom.Adapter == "" {
|
|
||||||
config.Blossom.Adapter = "local"
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.Host == "" {
|
if config.Host == "" {
|
||||||
return fmt.Errorf("host is required")
|
return nil, fmt.Errorf("host is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Schema == "" {
|
if config.Schema == "" {
|
||||||
return fmt.Errorf("schema is required")
|
return nil, fmt.Errorf("schema is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !regexp.MustCompile(`^[a-z_][a-z0-9_]*$`).MatchString(config.Schema) {
|
if config.Info.Pubkey == "" {
|
||||||
return fmt.Errorf("schema must contain only lowercase letters, numbers, and underscores")
|
return nil, fmt.Errorf("info.pubkey is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
secret, err := nostr.SecretKeyFromHex(config.Secret)
|
secret, err := nostr.SecretKeyFromHex(config.Secret)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid secret key: %w", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save the path for later
|
||||||
|
config.path = path
|
||||||
|
|
||||||
|
// Make the secret... secret
|
||||||
|
config.Secret = ""
|
||||||
config.secret = secret
|
config.secret = secret
|
||||||
|
|
||||||
if _, err := nostr.PubKeyFromHex(config.Info.Pubkey); err != nil {
|
if err := validateBlossomFileStorage(&config); err != nil {
|
||||||
return fmt.Errorf("invalid info.pubkey: %w", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Blossom.Adapter == "s3" {
|
return &config, nil
|
||||||
if config.Blossom.S3.Bucket == "" {
|
|
||||||
return fmt.Errorf("blossom.s3.bucket is required when blossom.adapter is s3")
|
|
||||||
}
|
|
||||||
if config.Blossom.S3.Region == "" {
|
|
||||||
return fmt.Errorf("blossom.s3.region is required when blossom.adapter is s3")
|
|
||||||
}
|
|
||||||
if config.Blossom.S3.AccessKey == "" {
|
|
||||||
return fmt.Errorf("blossom.s3.access_key is required when blossom.adapter is s3")
|
|
||||||
}
|
|
||||||
if config.Blossom.S3.SecretKey == "" {
|
|
||||||
return fmt.Errorf("blossom.s3.secret_key is required when blossom.adapter is s3")
|
|
||||||
}
|
|
||||||
} else if config.Blossom.Adapter != "local" {
|
|
||||||
return fmt.Errorf("invalid blossom adapter")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func normalizeBlossomConfig(c *Config) {
|
||||||
|
s := &c.Blossom.S3
|
||||||
|
s.Region = strings.TrimSpace(s.Region)
|
||||||
|
s.Bucket = strings.TrimSpace(s.Bucket)
|
||||||
|
s.AccessKey = strings.TrimSpace(s.AccessKey)
|
||||||
|
s.SecretKey = strings.TrimSpace(s.SecretKey)
|
||||||
|
s.Endpoint = strings.TrimRight(strings.TrimSpace(s.Endpoint), "/")
|
||||||
|
s.KeyPrefix = strings.Trim(strings.TrimSpace(s.KeyPrefix), "/")
|
||||||
|
|
||||||
|
c.Blossom.Backend = strings.ToLower(strings.TrimSpace(c.Blossom.Backend))
|
||||||
|
if c.Blossom.Backend == "" {
|
||||||
|
c.Blossom.Backend = "local"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateBlossomFileStorage(c *Config) error {
|
||||||
|
if !c.Blossom.Enabled {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
switch c.Blossom.Backend {
|
||||||
|
case "local":
|
||||||
|
return nil
|
||||||
|
case "s3":
|
||||||
|
// fall through
|
||||||
|
default:
|
||||||
|
return fmt.Errorf(`blossom.backend must be "local", "s3", or empty (defaults to local)`)
|
||||||
|
}
|
||||||
|
s := c.Blossom.S3
|
||||||
|
if s.Bucket == "" {
|
||||||
|
return fmt.Errorf("blossom.s3.bucket is required when blossom.backend is s3")
|
||||||
|
}
|
||||||
|
if s.Region == "" {
|
||||||
|
return fmt.Errorf("blossom.s3.region is required when blossom.backend is s3")
|
||||||
|
}
|
||||||
|
if s.AccessKey == "" {
|
||||||
|
return fmt.Errorf("blossom.s3.access_key is required when blossom.backend is s3")
|
||||||
|
}
|
||||||
|
if s.SecretKey == "" {
|
||||||
|
return fmt.Errorf("blossom.s3.secret_key is required when blossom.backend is s3")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) Save() error {
|
func (config *Config) Save() error {
|
||||||
|
// Restore the secret key to the public field for saving
|
||||||
|
config.Secret = config.secret.Hex()
|
||||||
|
|
||||||
file, err := os.Create(config.path)
|
file, err := os.Create(config.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to open config file %s: %w", config.path, err)
|
return fmt.Errorf("Failed to open config file %s: %w", config.path, err)
|
||||||
@@ -176,6 +178,9 @@ func (config *Config) Save() error {
|
|||||||
return fmt.Errorf("Failed to encode config file %s: %w", config.path, err)
|
return fmt.Errorf("Failed to encode config file %s: %w", config.path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear the secret again
|
||||||
|
config.Secret = ""
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+25
-36
@@ -157,64 +157,53 @@ func TestConfig_MemberRole(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// validBlossomTestConfig returns a config that passes Validate except for any
|
|
||||||
// Blossom settings the caller overrides, so blossom validation can be exercised
|
|
||||||
// in isolation.
|
|
||||||
func validBlossomTestConfig() *Config {
|
|
||||||
sk := nostr.Generate()
|
|
||||||
c := &Config{
|
|
||||||
Host: "r.example.com",
|
|
||||||
Schema: "myrelay",
|
|
||||||
Secret: sk.Hex(),
|
|
||||||
}
|
|
||||||
c.Info.Pubkey = sk.Public().Hex()
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestValidateBlossomFileStorage(t *testing.T) {
|
func TestValidateBlossomFileStorage(t *testing.T) {
|
||||||
t.Run("empty adapter defaults to local", func(t *testing.T) {
|
t.Run("blossom disabled skips validation", func(t *testing.T) {
|
||||||
c := validBlossomTestConfig()
|
c := &Config{}
|
||||||
c.Blossom.Enabled = true
|
c.Blossom.Enabled = false
|
||||||
if err := c.Validate(); err != nil {
|
c.Blossom.Backend = "s3"
|
||||||
|
normalizeBlossomConfig(c)
|
||||||
|
if err := validateBlossomFileStorage(c); err != nil {
|
||||||
t.Fatalf("expected nil, got %v", err)
|
t.Fatalf("expected nil, got %v", err)
|
||||||
}
|
}
|
||||||
if c.Blossom.Adapter != "local" {
|
|
||||||
t.Errorf("expected adapter normalized to local, got %q", c.Blossom.Adapter)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("local storage needs no s3 fields", func(t *testing.T) {
|
t.Run("local storage needs no s3 fields", func(t *testing.T) {
|
||||||
c := validBlossomTestConfig()
|
c := &Config{}
|
||||||
c.Blossom.Enabled = true
|
c.Blossom.Enabled = true
|
||||||
c.Blossom.Adapter = "local"
|
c.Blossom.Backend = "local"
|
||||||
if err := c.Validate(); err != nil {
|
normalizeBlossomConfig(c)
|
||||||
|
if err := validateBlossomFileStorage(c); err != nil {
|
||||||
t.Fatalf("expected nil, got %v", err)
|
t.Fatalf("expected nil, got %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("s3 requires bucket region keys and secret", func(t *testing.T) {
|
t.Run("s3 requires bucket region keys and secret", func(t *testing.T) {
|
||||||
c := validBlossomTestConfig()
|
c := &Config{}
|
||||||
c.Blossom.Enabled = true
|
c.Blossom.Enabled = true
|
||||||
c.Blossom.Adapter = "s3"
|
c.Blossom.Backend = "s3"
|
||||||
c.Blossom.S3.Region = "us-east-1"
|
c.Blossom.S3.Region = "us-east-1"
|
||||||
if err := c.Validate(); err == nil {
|
normalizeBlossomConfig(c)
|
||||||
|
if err := validateBlossomFileStorage(c); err == nil {
|
||||||
t.Fatal("expected error for missing bucket and credentials")
|
t.Fatal("expected error for missing bucket and credentials")
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Blossom.S3.Bucket = "b"
|
c.Blossom.S3.Bucket = "b"
|
||||||
c.Blossom.S3.AccessKey = "k"
|
c.Blossom.S3.AccessKey = "k"
|
||||||
c.Blossom.S3.SecretKey = "s"
|
c.Blossom.S3.SecretKey = "s"
|
||||||
if err := c.Validate(); err != nil {
|
normalizeBlossomConfig(c)
|
||||||
|
if err := validateBlossomFileStorage(c); err != nil {
|
||||||
t.Fatalf("expected nil with all s3 fields set, got %v", err)
|
t.Fatalf("expected nil with all s3 fields set, got %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invalid adapter value", func(t *testing.T) {
|
t.Run("invalid backend value", func(t *testing.T) {
|
||||||
c := validBlossomTestConfig()
|
c := &Config{}
|
||||||
c.Blossom.Enabled = true
|
c.Blossom.Enabled = true
|
||||||
c.Blossom.Adapter = "nfs"
|
c.Blossom.Backend = "nfs"
|
||||||
if err := c.Validate(); err == nil {
|
normalizeBlossomConfig(c)
|
||||||
t.Fatal("expected error for unknown adapter")
|
if err := validateBlossomFileStorage(c); err == nil {
|
||||||
|
t.Fatal("expected error for unknown backend")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -234,7 +223,7 @@ pubkey = "` + sk.Public().Hex() + `"
|
|||||||
|
|
||||||
[blossom]
|
[blossom]
|
||||||
enabled = true
|
enabled = true
|
||||||
adapter = "s3"
|
backend = "s3"
|
||||||
|
|
||||||
[blossom.s3]
|
[blossom.s3]
|
||||||
region = "auto"
|
region = "auto"
|
||||||
@@ -254,7 +243,7 @@ endpoint = "http://127.0.0.1:9000"
|
|||||||
if cfg.Blossom.S3.SecretKey != "topsecret" {
|
if cfg.Blossom.S3.SecretKey != "topsecret" {
|
||||||
t.Errorf("expected s3 secret_key retained in struct, got %q", cfg.Blossom.S3.SecretKey)
|
t.Errorf("expected s3 secret_key retained in struct, got %q", cfg.Blossom.S3.SecretKey)
|
||||||
}
|
}
|
||||||
if cfg.Blossom.Adapter != "s3" {
|
if cfg.Blossom.Backend != "s3" {
|
||||||
t.Errorf("adapter: got %q", cfg.Blossom.Adapter)
|
t.Errorf("backend: got %q", cfg.Blossom.Backend)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,10 +227,6 @@ func (g *GroupStore) HasAccess(h string, pubkey nostr.PubKey) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupStore) IsGroupEvent(event nostr.Event) bool {
|
func (g *GroupStore) IsGroupEvent(event nostr.Event) bool {
|
||||||
if !g.Config.Groups.Enabled {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if slices.Contains(nip29.MetadataEventKinds, event.Kind) {
|
if slices.Contains(nip29.MetadataEventKinds, event.Kind) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
"fiatjaf.com/nostr/khatru"
|
"fiatjaf.com/nostr/khatru"
|
||||||
|
"github.com/gosimple/slug"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Instance struct {
|
type Instance struct {
|
||||||
@@ -21,14 +22,13 @@ type Instance struct {
|
|||||||
Push *PushManager
|
Push *PushManager
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeInstance(name string) (*Instance, error) {
|
func MakeInstance(filename string) (*Instance, error) {
|
||||||
path := ConfigPathFromName(name)
|
config, err := LoadConfig(filename)
|
||||||
config, err := LoadConfigFromPath(path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return makeInstance(config, name)
|
return makeInstance(config, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeInstance(config *Config, source string) (*Instance, error) {
|
func makeInstance(config *Config, source string) (*Instance, error) {
|
||||||
@@ -38,7 +38,7 @@ func makeInstance(config *Config, source string) (*Instance, error) {
|
|||||||
Relay: relay,
|
Relay: relay,
|
||||||
Config: config,
|
Config: config,
|
||||||
Schema: &Schema{
|
Schema: &Schema{
|
||||||
Name: config.Schema,
|
Name: slug.Make(config.Schema),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,19 +28,6 @@ func Dispatch(hostname string) (*Instance, bool) {
|
|||||||
return instance, exists
|
return instance, exists
|
||||||
}
|
}
|
||||||
|
|
||||||
func DispatchBySchema(schema string) (*Instance, bool) {
|
|
||||||
instancesMux.RLock()
|
|
||||||
defer instancesMux.RUnlock()
|
|
||||||
|
|
||||||
for _, instance := range instancesByName {
|
|
||||||
if instance.Config.Schema == schema && !instance.Config.Inactive {
|
|
||||||
return instance, true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
func Start() {
|
func Start() {
|
||||||
dataDir := Env("DATA")
|
dataDir := Env("DATA")
|
||||||
if err := os.MkdirAll(dataDir, 0755); err != nil {
|
if err := os.MkdirAll(dataDir, 0755); err != nil {
|
||||||
|
|||||||
+2
-4
@@ -50,7 +50,7 @@ func generateLivekitServerToken(apiKey, apiSecret string) string {
|
|||||||
return jwt
|
return jwt
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureLivekitRoom(apiKey, apiSecret, serverURL, roomName, metadata string) error {
|
func ensureLivekitRoom(apiKey, apiSecret, serverURL, roomName string) error {
|
||||||
roomKey := serverURL + "'" + roomName
|
roomKey := serverURL + "'" + roomName
|
||||||
|
|
||||||
livekitRoomsMu.RLock()
|
livekitRoomsMu.RLock()
|
||||||
@@ -63,10 +63,8 @@ func ensureLivekitRoom(apiKey, apiSecret, serverURL, roomName, metadata string)
|
|||||||
httpURL := strings.Replace(strings.Replace(serverURL, "wss://", "https://", 1), "ws://", "http://", 1)
|
httpURL := strings.Replace(strings.Replace(serverURL, "wss://", "https://", 1), "ws://", "http://", 1)
|
||||||
url := fmt.Sprintf("%s/twirp/livekit.RoomService/CreateRoom", httpURL)
|
url := fmt.Sprintf("%s/twirp/livekit.RoomService/CreateRoom", httpURL)
|
||||||
|
|
||||||
// Use the relay's schema as room metadata so we can use the same livekit creds for multiple relay
|
|
||||||
reqBody, _ := json.Marshal(map[string]interface{}{
|
reqBody, _ := json.Marshal(map[string]interface{}{
|
||||||
"name": roomName,
|
"name": roomName,
|
||||||
"metadata": metadata,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(reqBody))
|
req, err := http.NewRequest("POST", url, bytes.NewBuffer(reqBody))
|
||||||
@@ -216,7 +214,7 @@ func (instance *Instance) livekitTokenHandler(w http.ResponseWriter, r *http.Req
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ensureLivekitRoom(cfg.APIKey, cfg.APISecret, cfg.ServerURL, groupId, instance.Config.Schema); err != nil {
|
if err := ensureLivekitRoom(cfg.APIKey, cfg.APISecret, cfg.ServerURL, groupId); err != nil {
|
||||||
http.Error(w, "failed to create room", http.StatusInternalServerError)
|
http.Error(w, "failed to create room", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-268
@@ -2,11 +2,6 @@ package zooid
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"slices"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
"fiatjaf.com/nostr/khatru"
|
"fiatjaf.com/nostr/khatru"
|
||||||
"fiatjaf.com/nostr/nip86"
|
"fiatjaf.com/nostr/nip86"
|
||||||
@@ -132,6 +127,10 @@ func (m *ManagementStore) PubkeyIsBanned(pubkey nostr.PubKey) bool {
|
|||||||
|
|
||||||
// Admins
|
// Admins
|
||||||
|
|
||||||
|
func (m *ManagementStore) IsAdmin(pubkey nostr.PubKey) bool {
|
||||||
|
return m.Config.IsOwner(pubkey) || m.Config.IsSelf(pubkey)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *ManagementStore) GetAdmins() []nostr.PubKey {
|
func (m *ManagementStore) GetAdmins() []nostr.PubKey {
|
||||||
members := make([]nostr.PubKey, 0)
|
members := make([]nostr.PubKey, 0)
|
||||||
|
|
||||||
@@ -148,10 +147,6 @@ func (m *ManagementStore) GetAdmins() []nostr.PubKey {
|
|||||||
return members
|
return members
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ManagementStore) IsAdmin(pubkey nostr.PubKey) bool {
|
|
||||||
return slices.Contains(m.GetAdmins(), pubkey)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Membership
|
// Membership
|
||||||
|
|
||||||
func (m *ManagementStore) GetMembers() []nostr.PubKey {
|
func (m *ManagementStore) GetMembers() []nostr.PubKey {
|
||||||
@@ -200,10 +195,6 @@ func (m *ManagementStore) AddMember(pubkey nostr.PubKey) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *ManagementStore) RemoveMember(pubkey nostr.PubKey) error {
|
func (m *ManagementStore) RemoveMember(pubkey nostr.PubKey) error {
|
||||||
if m.IsAdmin(pubkey) {
|
|
||||||
return errors.New("Can't remove permanent admins from relay.")
|
|
||||||
}
|
|
||||||
|
|
||||||
membersEvent := m.Events.GetOrCreateRelayMembersList()
|
membersEvent := m.Events.GetOrCreateRelayMembersList()
|
||||||
|
|
||||||
if membersEvent.Tags.FindWithValue("member", pubkey.Hex()) != nil {
|
if membersEvent.Tags.FindWithValue("member", pubkey.Hex()) != nil {
|
||||||
@@ -234,237 +225,6 @@ func (m *ManagementStore) RemoveMember(pubkey nostr.PubKey) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Roles
|
|
||||||
|
|
||||||
func (m *ManagementStore) GetRoleDefinition(id string) (nostr.Event, bool) {
|
|
||||||
filter := nostr.Filter{
|
|
||||||
Kinds: []nostr.Kind{RELAY_ROLE},
|
|
||||||
Tags: nostr.TagMap{"d": []string{id}},
|
|
||||||
}
|
|
||||||
|
|
||||||
for event := range m.Events.QueryEvents(filter, 1) {
|
|
||||||
return event, true
|
|
||||||
}
|
|
||||||
|
|
||||||
return nostr.Event{}, false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ManagementStore) buildRoleEvent(id, label, description string, color, order int) (nostr.Event, error) {
|
|
||||||
if id == "" {
|
|
||||||
return nostr.Event{}, errors.New("role id is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
if color < 0 || color > 255 {
|
|
||||||
return nostr.Event{}, errors.New("color must be a hue between 0 and 255")
|
|
||||||
}
|
|
||||||
|
|
||||||
tags := nostr.Tags{
|
|
||||||
nostr.Tag{"-"},
|
|
||||||
nostr.Tag{"d", id},
|
|
||||||
}
|
|
||||||
|
|
||||||
if label != "" {
|
|
||||||
tags = append(tags, nostr.Tag{"label", label})
|
|
||||||
}
|
|
||||||
|
|
||||||
if description != "" {
|
|
||||||
tags = append(tags, nostr.Tag{"description", description})
|
|
||||||
}
|
|
||||||
|
|
||||||
// color and order are optional integers. The nip86 layer can't distinguish an omitted
|
|
||||||
// value from a zero, so we only persist them when they're explicitly non-zero, letting
|
|
||||||
// clients fall back to their own defaults otherwise.
|
|
||||||
if color != 0 {
|
|
||||||
tags = append(tags, nostr.Tag{"color", strconv.Itoa(color)})
|
|
||||||
}
|
|
||||||
|
|
||||||
if order != 0 {
|
|
||||||
tags = append(tags, nostr.Tag{"order", strconv.Itoa(order)})
|
|
||||||
}
|
|
||||||
|
|
||||||
return nostr.Event{
|
|
||||||
Kind: RELAY_ROLE,
|
|
||||||
CreatedAt: nostr.Now(),
|
|
||||||
Tags: tags,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ManagementStore) CreateRole(id, label, description string, color, order int) error {
|
|
||||||
if _, exists := m.GetRoleDefinition(id); exists {
|
|
||||||
return fmt.Errorf("role %q already exists", id)
|
|
||||||
}
|
|
||||||
|
|
||||||
event, err := m.buildRoleEvent(id, label, description, color, order)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return m.Events.SignAndStoreEvent(&event, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ManagementStore) EditRole(id, label, description string, color, order int) error {
|
|
||||||
if _, exists := m.GetRoleDefinition(id); !exists {
|
|
||||||
return fmt.Errorf("role %q does not exist", id)
|
|
||||||
}
|
|
||||||
|
|
||||||
event, err := m.buildRoleEvent(id, label, description, color, order)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return m.Events.SignAndStoreEvent(&event, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ManagementStore) DeleteRole(id string) error {
|
|
||||||
if event, exists := m.GetRoleDefinition(id); exists {
|
|
||||||
if err := m.Events.DeleteEvent(event.ID); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
address := nostr.EntityPointer{
|
|
||||||
Kind: event.Kind,
|
|
||||||
PublicKey: event.PubKey,
|
|
||||||
Identifier: event.Tags.GetD(),
|
|
||||||
}.AsTagReference()
|
|
||||||
|
|
||||||
event := nostr.Event{
|
|
||||||
Kind: nostr.KindDeletion,
|
|
||||||
CreatedAt: nostr.Now(),
|
|
||||||
Tags: nostr.Tags{
|
|
||||||
nostr.Tag{"e", event.ID.Hex()},
|
|
||||||
nostr.Tag{"a", address},
|
|
||||||
nostr.Tag{"k", strconv.Itoa(int(event.Kind))},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := m.Events.SignAndStoreEvent(&event, true); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return m.removeRoleFromMembers(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Role assignment
|
|
||||||
|
|
||||||
func (m *ManagementStore) GetAssignedRoles(pubkey nostr.PubKey) []string {
|
|
||||||
tag := m.Events.GetOrCreateRelayMembersList().Tags.FindWithValue("member", pubkey.Hex())
|
|
||||||
|
|
||||||
if len(tag) < 3 {
|
|
||||||
return []string{}
|
|
||||||
}
|
|
||||||
|
|
||||||
return slices.Clone(tag[2:])
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ManagementStore) AssignRole(pubkey nostr.PubKey, roleID string) error {
|
|
||||||
if _, exists := m.GetRoleDefinition(roleID); !exists {
|
|
||||||
return fmt.Errorf("role %q does not exist", roleID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// A role is meaningless without membership, so ensure the pubkey is a member first.
|
|
||||||
if err := m.AddMember(pubkey); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
roles := m.GetAssignedRoles(pubkey)
|
|
||||||
|
|
||||||
if slices.Contains(roles, roleID) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return m.setAssignedRoles(pubkey, append(roles, roleID))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ManagementStore) UnassignRole(pubkey nostr.PubKey, roleID string) error {
|
|
||||||
roles := m.GetAssignedRoles(pubkey)
|
|
||||||
|
|
||||||
if !slices.Contains(roles, roleID) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return m.setAssignedRoles(pubkey, Remove(roles, roleID))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ManagementStore) setAssignedRoles(pubkey nostr.PubKey, roleIDs []string) error {
|
|
||||||
membersEvent := m.Events.GetOrCreateRelayMembersList()
|
|
||||||
|
|
||||||
found := false
|
|
||||||
tags := make(nostr.Tags, 0, len(membersEvent.Tags))
|
|
||||||
for _, tag := range membersEvent.Tags {
|
|
||||||
if len(tag) >= 2 && tag[0] == "member" && tag[1] == pubkey.Hex() {
|
|
||||||
found = true
|
|
||||||
tags = append(tags, append(nostr.Tag{"member", pubkey.Hex()}, roleIDs...))
|
|
||||||
} else {
|
|
||||||
tags = append(tags, tag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !found {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
membersEvent.CreatedAt = nostr.Now()
|
|
||||||
membersEvent.Tags = tags
|
|
||||||
|
|
||||||
return m.Events.SignAndStoreEvent(&membersEvent, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ManagementStore) removeRoleFromMembers(roleID string) error {
|
|
||||||
membersEvent := m.Events.GetOrCreateRelayMembersList()
|
|
||||||
|
|
||||||
changed := false
|
|
||||||
tags := make(nostr.Tags, 0, len(membersEvent.Tags))
|
|
||||||
for _, tag := range membersEvent.Tags {
|
|
||||||
if len(tag) >= 3 && tag[0] == "member" && slices.Contains(tag[2:], roleID) {
|
|
||||||
changed = true
|
|
||||||
roles := Filter(tag[2:], func(r string) bool { return r != roleID })
|
|
||||||
tags = append(tags, append(nostr.Tag{"member", tag[1]}, roles...))
|
|
||||||
} else {
|
|
||||||
tags = append(tags, tag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !changed {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
membersEvent.CreatedAt = nostr.Now()
|
|
||||||
membersEvent.Tags = tags
|
|
||||||
|
|
||||||
return m.Events.SignAndStoreEvent(&membersEvent, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Signing
|
|
||||||
|
|
||||||
// SignEvent signs an event template with the relay's identity key on an admin's behalf, then
|
|
||||||
// stores and broadcasts it before returning the signed event. Only kind 30078 (application-specific
|
|
||||||
// data) is supported for now; every other kind is rejected outright.
|
|
||||||
func (m *ManagementStore) SignEvent(kind nostr.Kind, createdAt nostr.Timestamp, tags nostr.Tags, content string) (nostr.Event, error) {
|
|
||||||
if kind != nostr.KindApplicationSpecificData {
|
|
||||||
return nostr.Event{}, errors.New("kind not allowed")
|
|
||||||
}
|
|
||||||
|
|
||||||
// A missing created_at would otherwise default to the epoch, which is almost never what
|
|
||||||
// the caller intends, so fall back to the current time.
|
|
||||||
if createdAt == 0 {
|
|
||||||
createdAt = nostr.Now()
|
|
||||||
}
|
|
||||||
|
|
||||||
event := nostr.Event{
|
|
||||||
Kind: kind,
|
|
||||||
CreatedAt: createdAt,
|
|
||||||
Tags: tags,
|
|
||||||
Content: content,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := m.Events.SignAndStoreEvent(&event, true); err != nil {
|
|
||||||
return nostr.Event{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return event, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Banning
|
// Banning
|
||||||
|
|
||||||
func (m *ManagementStore) BanPubkey(pubkey nostr.PubKey, reason string) error {
|
func (m *ManagementStore) BanPubkey(pubkey nostr.PubKey, reason string) error {
|
||||||
@@ -620,28 +380,4 @@ func (m *ManagementStore) Enable(instance *Instance) {
|
|||||||
instance.Relay.ManagementAPI.ListBannedEvents = func(ctx context.Context) ([]nip86.IDReason, error) {
|
instance.Relay.ManagementAPI.ListBannedEvents = func(ctx context.Context) ([]nip86.IDReason, error) {
|
||||||
return m.GetBannedEventItems(), nil
|
return m.GetBannedEventItems(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.Relay.ManagementAPI.CreateRole = func(ctx context.Context, id, label, description string, color, order int) error {
|
|
||||||
return m.CreateRole(id, label, description, color, order)
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.Relay.ManagementAPI.EditRole = func(ctx context.Context, id, label, description string, color, order int) error {
|
|
||||||
return m.EditRole(id, label, description, color, order)
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.Relay.ManagementAPI.DeleteRole = func(ctx context.Context, id string) error {
|
|
||||||
return m.DeleteRole(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.Relay.ManagementAPI.AssignRole = func(ctx context.Context, pubkey nostr.PubKey, roleID string) error {
|
|
||||||
return m.AssignRole(pubkey, roleID)
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.Relay.ManagementAPI.UnassignRole = func(ctx context.Context, pubkey nostr.PubKey, roleID string) error {
|
|
||||||
return m.UnassignRole(pubkey, roleID)
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.Relay.ManagementAPI.SignEvent = func(ctx context.Context, kind nostr.Kind, createdAt nostr.Timestamp, tags nostr.Tags, content string) (nostr.Event, error) {
|
|
||||||
return m.SignEvent(kind, createdAt, tags, content)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package zooid
|
package zooid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
@@ -13,7 +12,6 @@ func createTestManagementStore() *ManagementStore {
|
|||||||
Host: "test.com",
|
Host: "test.com",
|
||||||
secret: nostr.Generate(),
|
secret: nostr.Generate(),
|
||||||
}
|
}
|
||||||
config.Info.Pubkey = nostr.Generate().Public().Hex()
|
|
||||||
schema := &Schema{Name: "test_" + RandomString(8)}
|
schema := &Schema{Name: "test_" + RandomString(8)}
|
||||||
relay := khatru.NewRelay()
|
relay := khatru.NewRelay()
|
||||||
events := &EventStore{
|
events := &EventStore{
|
||||||
@@ -165,320 +163,6 @@ func TestManagementStore_AllowEvent(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func roleTagValue(event nostr.Event, key string) string {
|
|
||||||
tag := event.Tags.Find(key)
|
|
||||||
if len(tag) < 2 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
return tag[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestManagementStore_CreateRole(t *testing.T) {
|
|
||||||
mgmt := createTestManagementStore()
|
|
||||||
|
|
||||||
if err := mgmt.CreateRole("king", "King", "ruler of the relay", 37, 1); err != nil {
|
|
||||||
t.Fatalf("CreateRole() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
event, ok := mgmt.GetRoleDefinition("king")
|
|
||||||
if !ok {
|
|
||||||
t.Fatal("GetRoleDefinition() should return the created role")
|
|
||||||
}
|
|
||||||
|
|
||||||
if event.Kind != RELAY_ROLE {
|
|
||||||
t.Errorf("role event kind = %v, want %v", event.Kind, RELAY_ROLE)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !HasTag(event.Tags, "-") {
|
|
||||||
t.Error("role event should carry a NIP 70 \"-\" tag")
|
|
||||||
}
|
|
||||||
|
|
||||||
if got := roleTagValue(event, "d"); got != "king" {
|
|
||||||
t.Errorf("d tag = %q, want %q", got, "king")
|
|
||||||
}
|
|
||||||
|
|
||||||
if got := roleTagValue(event, "label"); got != "King" {
|
|
||||||
t.Errorf("label tag = %q, want %q", got, "King")
|
|
||||||
}
|
|
||||||
|
|
||||||
if got := roleTagValue(event, "description"); got != "ruler of the relay" {
|
|
||||||
t.Errorf("description tag = %q, want %q", got, "ruler of the relay")
|
|
||||||
}
|
|
||||||
|
|
||||||
if got := roleTagValue(event, "color"); got != "37" {
|
|
||||||
t.Errorf("color tag = %q, want %q", got, "37")
|
|
||||||
}
|
|
||||||
|
|
||||||
if got := roleTagValue(event, "order"); got != "1" {
|
|
||||||
t.Errorf("order tag = %q, want %q", got, "1")
|
|
||||||
}
|
|
||||||
|
|
||||||
if event.PubKey != mgmt.Config.GetSelf() {
|
|
||||||
t.Error("role event should be signed by the relay self key")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestManagementStore_CreateRole_Duplicate(t *testing.T) {
|
|
||||||
mgmt := createTestManagementStore()
|
|
||||||
|
|
||||||
if err := mgmt.CreateRole("king", "King", "", 0, 0); err != nil {
|
|
||||||
t.Fatalf("CreateRole() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := mgmt.CreateRole("king", "King", "", 0, 0); err == nil {
|
|
||||||
t.Error("CreateRole() should error when the role already exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestManagementStore_CreateRole_OmitsEmptyAndZero(t *testing.T) {
|
|
||||||
mgmt := createTestManagementStore()
|
|
||||||
|
|
||||||
if err := mgmt.CreateRole("plain", "", "", 0, 0); err != nil {
|
|
||||||
t.Fatalf("CreateRole() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
event, ok := mgmt.GetRoleDefinition("plain")
|
|
||||||
if !ok {
|
|
||||||
t.Fatal("GetRoleDefinition() should return the created role")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, key := range []string{"label", "description", "color", "order"} {
|
|
||||||
if HasTag(event.Tags, key) {
|
|
||||||
t.Errorf("role event should omit empty/zero %q tag", key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestManagementStore_CreateRole_InvalidColor(t *testing.T) {
|
|
||||||
mgmt := createTestManagementStore()
|
|
||||||
|
|
||||||
if err := mgmt.CreateRole("king", "King", "", 300, 0); err == nil {
|
|
||||||
t.Error("CreateRole() should error on out-of-range color")
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := mgmt.GetRoleDefinition("king"); ok {
|
|
||||||
t.Error("invalid role should not have been stored")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestManagementStore_EditRole(t *testing.T) {
|
|
||||||
mgmt := createTestManagementStore()
|
|
||||||
|
|
||||||
if err := mgmt.EditRole("king", "King", "", 0, 0); err == nil {
|
|
||||||
t.Error("EditRole() should error when the role does not exist")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := mgmt.CreateRole("king", "King", "ruler", 10, 1); err != nil {
|
|
||||||
t.Fatalf("CreateRole() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := mgmt.EditRole("king", "Monarch", "the boss", 200, 2); err != nil {
|
|
||||||
t.Fatalf("EditRole() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
event, ok := mgmt.GetRoleDefinition("king")
|
|
||||||
if !ok {
|
|
||||||
t.Fatal("GetRoleDefinition() should return the edited role")
|
|
||||||
}
|
|
||||||
|
|
||||||
if got := roleTagValue(event, "label"); got != "Monarch" {
|
|
||||||
t.Errorf("label tag = %q, want %q", got, "Monarch")
|
|
||||||
}
|
|
||||||
|
|
||||||
if got := roleTagValue(event, "color"); got != "200" {
|
|
||||||
t.Errorf("color tag = %q, want %q", got, "200")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Editing replaces the definition, so there should only be a single role event.
|
|
||||||
count := 0
|
|
||||||
for range mgmt.Events.QueryEvents(nostr.Filter{Kinds: []nostr.Kind{RELAY_ROLE}}, 0) {
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
if count != 1 {
|
|
||||||
t.Errorf("expected 1 role event after edit, got %d", count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestManagementStore_AssignAndUnassignRole(t *testing.T) {
|
|
||||||
mgmt := createTestManagementStore()
|
|
||||||
|
|
||||||
pubkey := nostr.Generate().Public()
|
|
||||||
|
|
||||||
if err := mgmt.CreateRole("king", "King", "", 0, 0); err != nil {
|
|
||||||
t.Fatalf("CreateRole() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := mgmt.AssignRole(pubkey, "king"); err != nil {
|
|
||||||
t.Fatalf("AssignRole() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assigning a role implies membership.
|
|
||||||
if !mgmt.IsMember(pubkey) {
|
|
||||||
t.Error("AssignRole() should make the pubkey a member")
|
|
||||||
}
|
|
||||||
|
|
||||||
if roles := mgmt.GetAssignedRoles(pubkey); len(roles) != 1 || roles[0] != "king" {
|
|
||||||
t.Errorf("GetAssignedRoles() = %v, want [king]", roles)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assignment is idempotent and must not duplicate the role.
|
|
||||||
if err := mgmt.AssignRole(pubkey, "king"); err != nil {
|
|
||||||
t.Fatalf("AssignRole() repeat error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if roles := mgmt.GetAssignedRoles(pubkey); len(roles) != 1 {
|
|
||||||
t.Errorf("GetAssignedRoles() after repeat = %v, want one entry", roles)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := mgmt.UnassignRole(pubkey, "king"); err != nil {
|
|
||||||
t.Fatalf("UnassignRole() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if roles := mgmt.GetAssignedRoles(pubkey); len(roles) != 0 {
|
|
||||||
t.Errorf("GetAssignedRoles() after unassign = %v, want empty", roles)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unassigning a role does not revoke membership.
|
|
||||||
if !mgmt.IsMember(pubkey) {
|
|
||||||
t.Error("UnassignRole() should leave the pubkey a member")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestManagementStore_AssignRole_UnknownRole(t *testing.T) {
|
|
||||||
mgmt := createTestManagementStore()
|
|
||||||
|
|
||||||
pubkey := nostr.Generate().Public()
|
|
||||||
|
|
||||||
if err := mgmt.AssignRole(pubkey, "ghost"); err == nil {
|
|
||||||
t.Error("AssignRole() should error for an undefined role")
|
|
||||||
}
|
|
||||||
|
|
||||||
if mgmt.IsMember(pubkey) {
|
|
||||||
t.Error("failed AssignRole() should not add membership")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestManagementStore_DeleteRole(t *testing.T) {
|
|
||||||
mgmt := createTestManagementStore()
|
|
||||||
|
|
||||||
pubkey := nostr.Generate().Public()
|
|
||||||
|
|
||||||
if err := mgmt.CreateRole("king", "King", "", 0, 0); err != nil {
|
|
||||||
t.Fatalf("CreateRole() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := mgmt.AssignRole(pubkey, "king"); err != nil {
|
|
||||||
t.Fatalf("AssignRole() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := mgmt.DeleteRole("king"); err != nil {
|
|
||||||
t.Fatalf("DeleteRole() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := mgmt.GetRoleDefinition("king"); ok {
|
|
||||||
t.Error("GetRoleDefinition() should return false after deletion")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deleting a role must strip dangling assignments from the members list.
|
|
||||||
if roles := mgmt.GetAssignedRoles(pubkey); len(roles) != 0 {
|
|
||||||
t.Errorf("GetAssignedRoles() after delete = %v, want empty", roles)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The pubkey remains a member, just without the deleted role.
|
|
||||||
if !mgmt.IsMember(pubkey) {
|
|
||||||
t.Error("DeleteRole() should leave the pubkey a member")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestManagementStore_DeleteRole_BroadcastsDeletion(t *testing.T) {
|
|
||||||
mgmt := createTestManagementStore()
|
|
||||||
|
|
||||||
if err := mgmt.CreateRole("king", "King", "", 0, 0); err != nil {
|
|
||||||
t.Fatalf("CreateRole() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
role, ok := mgmt.GetRoleDefinition("king")
|
|
||||||
if !ok {
|
|
||||||
t.Fatal("GetRoleDefinition() should return the created role")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := mgmt.DeleteRole("king"); err != nil {
|
|
||||||
t.Fatalf("DeleteRole() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
filter := nostr.Filter{Kinds: []nostr.Kind{nostr.KindDeletion}}
|
|
||||||
|
|
||||||
var deletion *nostr.Event
|
|
||||||
for event := range mgmt.Events.QueryEvents(filter, 1) {
|
|
||||||
e := event
|
|
||||||
deletion = &e
|
|
||||||
}
|
|
||||||
|
|
||||||
if deletion == nil {
|
|
||||||
t.Fatal("DeleteRole() should store a deletion event")
|
|
||||||
}
|
|
||||||
|
|
||||||
address := nostr.EntityPointer{
|
|
||||||
Kind: RELAY_ROLE,
|
|
||||||
PublicKey: role.PubKey,
|
|
||||||
Identifier: "king",
|
|
||||||
}.AsTagReference()
|
|
||||||
|
|
||||||
if tag := deletion.Tags.FindWithValue("e", role.ID.Hex()); tag == nil {
|
|
||||||
t.Errorf("deletion event missing e tag for %s", role.ID.Hex())
|
|
||||||
}
|
|
||||||
|
|
||||||
if tag := deletion.Tags.FindWithValue("a", address); tag == nil {
|
|
||||||
t.Errorf("deletion event missing a tag for %s", address)
|
|
||||||
}
|
|
||||||
|
|
||||||
if tag := deletion.Tags.FindWithValue("k", strconv.Itoa(RELAY_ROLE)); tag == nil {
|
|
||||||
t.Errorf("deletion event missing k tag for kind %d", RELAY_ROLE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestManagementStore_SignEvent_AllowedKind(t *testing.T) {
|
|
||||||
mgmt := createTestManagementStore()
|
|
||||||
|
|
||||||
tags := nostr.Tags{nostr.Tag{"d", "zooid/test"}}
|
|
||||||
|
|
||||||
event, err := mgmt.SignEvent(nostr.KindApplicationSpecificData, 0, tags, "hello")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("SignEvent() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if event.PubKey != mgmt.Config.GetSelf() {
|
|
||||||
t.Errorf("SignEvent() signed with %s, want relay key %s", event.PubKey, mgmt.Config.GetSelf())
|
|
||||||
}
|
|
||||||
|
|
||||||
if !event.VerifySignature() {
|
|
||||||
t.Error("SignEvent() produced an invalid signature")
|
|
||||||
}
|
|
||||||
|
|
||||||
// A zero created_at must be replaced with the current time.
|
|
||||||
if event.CreatedAt == 0 {
|
|
||||||
t.Error("SignEvent() should default a missing created_at to the current time")
|
|
||||||
}
|
|
||||||
|
|
||||||
// SignEvent must not persist the event, only return it.
|
|
||||||
filter := nostr.Filter{Kinds: []nostr.Kind{nostr.KindApplicationSpecificData}, Tags: nostr.TagMap{"d": []string{"zooid/test"}}}
|
|
||||||
|
|
||||||
for stored := range mgmt.Events.QueryEvents(filter, 1) {
|
|
||||||
if stored.ID == event.ID {
|
|
||||||
t.Error("SignEvent() should not store the signed event")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestManagementStore_SignEvent_RejectsOtherKinds(t *testing.T) {
|
|
||||||
mgmt := createTestManagementStore()
|
|
||||||
|
|
||||||
if _, err := mgmt.SignEvent(nostr.KindTextNote, 0, nil, ""); err == nil || err.Error() != "kind not allowed" {
|
|
||||||
t.Errorf("SignEvent() error = %v, want \"kind not allowed\"", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestManagementStore_PubkeyIsBanned_NotBanned(t *testing.T) {
|
func TestManagementStore_PubkeyIsBanned_NotBanned(t *testing.T) {
|
||||||
mgmt := createTestManagementStore()
|
mgmt := createTestManagementStore()
|
||||||
|
|
||||||
|
|||||||
+1
-8
@@ -21,7 +21,6 @@ const (
|
|||||||
RELAY_INVITE = 28935
|
RELAY_INVITE = 28935
|
||||||
RELAY_LEAVE = 28936
|
RELAY_LEAVE = 28936
|
||||||
PUSH_SUBSCRIPTION = 30390
|
PUSH_SUBSCRIPTION = 30390
|
||||||
RELAY_ROLE = 33534
|
|
||||||
BANNED_PUBKEYS = "zooid/banned_pubkeys"
|
BANNED_PUBKEYS = "zooid/banned_pubkeys"
|
||||||
BANNED_EVENTS = "zooid/banned_events"
|
BANNED_EVENTS = "zooid/banned_events"
|
||||||
)
|
)
|
||||||
@@ -43,7 +42,6 @@ func IsReadOnlyEvent(event nostr.Event) bool {
|
|||||||
RELAY_ADD_MEMBER,
|
RELAY_ADD_MEMBER,
|
||||||
RELAY_REMOVE_MEMBER,
|
RELAY_REMOVE_MEMBER,
|
||||||
RELAY_MEMBERS,
|
RELAY_MEMBERS,
|
||||||
RELAY_ROLE,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return slices.Contains(readOnlyEventKinds, event.Kind)
|
return slices.Contains(readOnlyEventKinds, event.Kind)
|
||||||
@@ -185,12 +183,7 @@ func validateNIP98Auth(r *http.Request) (nostr.PubKey, error) {
|
|||||||
return nostr.PubKey{}, fmt.Errorf("invalid event signature")
|
return nostr.PubKey{}, fmt.Errorf("invalid event signature")
|
||||||
}
|
}
|
||||||
|
|
||||||
scheme := "http"
|
expectedURL := fmt.Sprintf("%s://%s%s", scheme(r), r.Host, r.URL.Path)
|
||||||
if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" {
|
|
||||||
scheme = scheme + "s"
|
|
||||||
}
|
|
||||||
|
|
||||||
expectedURL := fmt.Sprintf("%s://%s%s", scheme, r.Host, r.URL.Path)
|
|
||||||
var hasURL, hasMethod bool
|
var hasURL, hasMethod bool
|
||||||
|
|
||||||
for _, tag := range event.Tags {
|
for _, tag := range event.Tags {
|
||||||
|
|||||||
Reference in New Issue
Block a user