mirror of
https://github.com/lone-cloud/prism
synced 2026-06-03 08:43:10 -07:00
rename module, dont need prism CLI
This commit is contained in:
parent
e9e6e06138
commit
73356a9fed
17 changed files with 44 additions and 74 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
|
@ -46,4 +46,4 @@ jobs:
|
||||||
args: --timeout=5m
|
args: --timeout=5m
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: go build -v ./cmd/prism
|
run: go build -v .
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ COPY . .
|
||||||
|
|
||||||
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo \
|
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo \
|
||||||
-ldflags="-w -s -X main.version=$(git describe --tags --always) -X main.commit=$(git rev-parse --short HEAD)" \
|
-ldflags="-w -s -X main.version=$(git describe --tags --always) -X main.commit=$(git rev-parse --short HEAD)" \
|
||||||
-o prism ./cmd/prism
|
-o prism .
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
|
|
@ -33,4 +33,4 @@ ENV SIGNAL_CLI_SOCKET=/var/run/signal-cli/socket
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
CMD ["./prism", "serve"]
|
CMD ["./prism"]
|
||||||
|
|
|
||||||
8
Makefile
8
Makefile
|
|
@ -9,16 +9,16 @@ export PATH := $(GOBIN):$(PATH)
|
||||||
all: fmt lint build
|
all: fmt lint build
|
||||||
|
|
||||||
build:
|
build:
|
||||||
go build -ldflags="-X main.version=$(VERSION) -X main.commit=$(COMMIT)" -o $(BINARY_NAME) ./cmd/prism
|
go build -ldflags="-X main.version=$(VERSION) -X main.commit=$(COMMIT)" -o $(BINARY_NAME) .
|
||||||
|
|
||||||
build-linux:
|
build-linux:
|
||||||
GOOS=linux GOARCH=arm64 go build -ldflags="-X main.version=$(VERSION) -X main.commit=$(COMMIT)" -o $(BINARY_NAME)-linux-arm64 ./cmd/prism
|
GOOS=linux GOARCH=arm64 go build -ldflags="-X main.version=$(VERSION) -X main.commit=$(COMMIT)" -o $(BINARY_NAME)-linux-arm64 .
|
||||||
|
|
||||||
run: build
|
run: build
|
||||||
./$(BINARY_NAME) serve
|
./$(BINARY_NAME)
|
||||||
|
|
||||||
dev:
|
dev:
|
||||||
go run ./cmd/prism serve
|
go run .
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
gofmt -s -w .
|
gofmt -s -w .
|
||||||
|
|
|
||||||
5
go.mod
5
go.mod
|
|
@ -1,4 +1,4 @@
|
||||||
module github.com/lone-cloud/prism
|
module prism
|
||||||
|
|
||||||
go 1.25.6
|
go 1.25.6
|
||||||
|
|
||||||
|
|
@ -7,13 +7,10 @@ require (
|
||||||
github.com/go-chi/chi/v5 v5.2.4
|
github.com/go-chi/chi/v5 v5.2.4
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
github.com/mattn/go-sqlite3 v1.14.33
|
github.com/mattn/go-sqlite3 v1.14.33
|
||||||
github.com/spf13/cobra v1.10.2
|
|
||||||
golang.org/x/time v0.14.0
|
golang.org/x/time v0.14.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 // indirect
|
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
|
||||||
github.com/spf13/pflag v1.0.10 // indirect
|
|
||||||
golang.org/x/text v0.28.0 // indirect
|
golang.org/x/text v0.28.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
||||||
11
go.sum
11
go.sum
|
|
@ -1,4 +1,3 @@
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
|
||||||
github.com/emersion/go-imap v1.2.1 h1:+s9ZjMEjOB8NzZMVTM3cCenz2JrQIGGo5j1df19WjTA=
|
github.com/emersion/go-imap v1.2.1 h1:+s9ZjMEjOB8NzZMVTM3cCenz2JrQIGGo5j1df19WjTA=
|
||||||
github.com/emersion/go-imap v1.2.1/go.mod h1:Qlx1FSx2FTxjnjWpIlVNEuX+ylerZQNFE5NsmKFSejY=
|
github.com/emersion/go-imap v1.2.1/go.mod h1:Qlx1FSx2FTxjnjWpIlVNEuX+ylerZQNFE5NsmKFSejY=
|
||||||
github.com/emersion/go-message v0.15.0/go.mod h1:wQUEfE+38+7EW8p8aZ96ptg6bAb1iwdgej19uXASlE4=
|
github.com/emersion/go-message v0.15.0/go.mod h1:wQUEfE+38+7EW8p8aZ96ptg6bAb1iwdgej19uXASlE4=
|
||||||
|
|
@ -7,19 +6,10 @@ github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTe
|
||||||
github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U=
|
github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U=
|
||||||
github.com/go-chi/chi/v5 v5.2.4 h1:WtFKPHwlywe8Srng8j2BhOD9312j9cGUxG1SP4V2cR4=
|
github.com/go-chi/chi/v5 v5.2.4 h1:WtFKPHwlywe8Srng8j2BhOD9312j9cGUxG1SP4V2cR4=
|
||||||
github.com/go-chi/chi/v5 v5.2.4/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0=
|
github.com/go-chi/chi/v5 v5.2.4/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
|
||||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/mattn/go-sqlite3 v1.14.33 h1:A5blZ5ulQo2AtayQ9/limgHEkFreKj1Dv226a1K73s0=
|
github.com/mattn/go-sqlite3 v1.14.33 h1:A5blZ5ulQo2AtayQ9/limgHEkFreKj1Dv226a1K73s0=
|
||||||
github.com/mattn/go-sqlite3 v1.14.33/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
github.com/mattn/go-sqlite3 v1.14.33/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
|
||||||
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
|
|
||||||
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
|
|
||||||
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
|
||||||
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
|
||||||
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
|
||||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/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.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||||
|
|
@ -27,4 +17,3 @@ golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||||
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
|
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
|
||||||
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
|
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/lone-cloud/prism/internal/signal"
|
"prism/internal/signal"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Dispatcher struct {
|
type Dispatcher struct {
|
||||||
|
|
@ -26,7 +26,7 @@ func NewDispatcher(store *Store, signalClient *signal.Client, logger *slog.Logge
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dispatcher) Send(endpoint string, notif Notification) error {
|
func (d *Dispatcher) Send(endpoint string, notif Notification) error {
|
||||||
mapping, err := d.store.GetMapping(endpoint)
|
mapping, err := d.store.GetEndpointMapping(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get mapping: %w", err)
|
return fmt.Errorf("failed to get mapping: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +39,7 @@ func (d *Dispatcher) Send(endpoint string, notif Notification) error {
|
||||||
return fmt.Errorf("failed to register endpoint: %w", err)
|
return fmt.Errorf("failed to register endpoint: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mapping, err = d.store.GetMapping(endpoint)
|
mapping, err = d.store.GetEndpointMapping(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get mapping after registration: %w", err)
|
return fmt.Errorf("failed to get mapping after registration: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ func (s *Store) Register(endpoint, appName string, channel Channel, groupID, upE
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) GetMapping(endpoint string) (*Mapping, error) {
|
func (s *Store) GetEndpointMapping(endpoint string) (*Mapping, error) {
|
||||||
query := `
|
query := `
|
||||||
SELECT endpoint, groupId, appName, channel, upEndpoint
|
SELECT endpoint, groupId, appName, channel, upEndpoint
|
||||||
FROM mappings
|
FROM mappings
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
"github.com/lone-cloud/prism/internal/config"
|
"prism/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ActionHandler struct {
|
type ActionHandler struct {
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,11 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"prism/internal/config"
|
||||||
|
"prism/internal/notification"
|
||||||
|
|
||||||
"github.com/emersion/go-imap"
|
"github.com/emersion/go-imap"
|
||||||
"github.com/emersion/go-imap/client"
|
"github.com/emersion/go-imap/client"
|
||||||
"github.com/lone-cloud/prism/internal/config"
|
|
||||||
"github.com/lone-cloud/prism/internal/notification"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Monitor struct {
|
type Monitor struct {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package server
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/lone-cloud/prism/internal/notification"
|
"prism/internal/notification"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) handleDeleteEndpointAction(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleDeleteEndpointAction(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,10 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"prism/internal/notification"
|
||||||
|
"prism/internal/util"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/lone-cloud/prism/internal/notification"
|
|
||||||
"github.com/lone-cloud/prism/internal/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) handleGetMappings(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleGetMappings(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/lone-cloud/prism/internal/notification"
|
"prism/internal/notification"
|
||||||
"github.com/lone-cloud/prism/internal/signal"
|
"prism/internal/signal"
|
||||||
"github.com/lone-cloud/prism/internal/util"
|
"prism/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) handleFragmentHealth(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleFragmentHealth(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"prism/internal/notification"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/lone-cloud/prism/internal/notification"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) handleNtfyPublish(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleNtfyPublish(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/lone-cloud/prism/internal/notification"
|
"prism/internal/notification"
|
||||||
)
|
)
|
||||||
|
|
||||||
type registerWebhookRequest struct {
|
type registerWebhookRequest struct {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lone-cloud/prism/internal/util"
|
"prism/internal/util"
|
||||||
|
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,14 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"prism/internal/config"
|
||||||
|
"prism/internal/notification"
|
||||||
|
"prism/internal/proton"
|
||||||
|
"prism/internal/signal"
|
||||||
|
"prism/internal/util"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-chi/chi/v5/middleware"
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
"github.com/lone-cloud/prism/internal/config"
|
|
||||||
"github.com/lone-cloud/prism/internal/notification"
|
|
||||||
"github.com/lone-cloud/prism/internal/proton"
|
|
||||||
"github.com/lone-cloud/prism/internal/signal"
|
|
||||||
"github.com/lone-cloud/prism/internal/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ import (
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"prism/internal/config"
|
||||||
|
"prism/internal/server"
|
||||||
|
"prism/internal/util"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/lone-cloud/prism/internal/config"
|
|
||||||
"github.com/lone-cloud/prism/internal/server"
|
|
||||||
"github.com/lone-cloud/prism/internal/util"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -23,34 +23,13 @@ func init() {
|
||||||
_ = godotenv.Load() //nolint:errcheck // .env is optional
|
_ = godotenv.Load() //nolint:errcheck // .env is optional
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
|
||||||
Use: "prism",
|
|
||||||
Short: "Privacy-preserving push notifications via Signal",
|
|
||||||
}
|
|
||||||
|
|
||||||
var serveCmd = &cobra.Command{
|
|
||||||
Use: "serve",
|
|
||||||
Short: "Start the Prism server",
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
return runServer()
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var versionCmd = &cobra.Command{
|
|
||||||
Use: "version",
|
|
||||||
Short: "Show version information",
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
fmt.Printf("Prism %s (%s)\n", version, commit)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
rootCmd.AddCommand(serveCmd)
|
|
||||||
rootCmd.AddCommand(versionCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if len(os.Args) > 1 && os.Args[1] == "version" {
|
||||||
|
fmt.Printf("Prism %s (%s)\n", version, commit)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := runServer(); err != nil {
|
||||||
logger := util.NewLogger(false)
|
logger := util.NewLogger(false)
|
||||||
logger.Error("Fatal error", "error", err)
|
logger.Error("Fatal error", "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
Loading…
Add table
Reference in a new issue