Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ cmd/server/server
cmd/worker/worker
*.p12
config.json
.DS_Store
.DS_Store

.devenv
config.yaml
34 changes: 21 additions & 13 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ import (
)

type Server struct {
port int64
sdClient *statsd.Client
logger *logrus.Logger
db *storage.Database
queueClient *asynq.Client
cacheClient *cache.RedisStorage
port int64
sdClient *statsd.Client
logger *logrus.Logger
db *storage.Database
queueClient *asynq.Client
cacheClient *cache.RedisStorage
vapidPublicKey string
}

func NewServer(port int64, sdClient *statsd.Client,
db *storage.Database,
queueClient *asynq.Client,
cacheClient *cache.RedisStorage) (*Server, error) {
cacheClient *cache.RedisStorage,
vapidPublicKey string) (*Server, error) {
if port <= 0 {
return nil, fmt.Errorf("invalid port number: %d", port)
}
Expand All @@ -46,12 +48,13 @@ func NewServer(port int64, sdClient *statsd.Client,
return nil, fmt.Errorf("cache client is nil")
}
return &Server{
port: port,
sdClient: sdClient,
logger: logrus.WithField("module", "api").Logger,
db: db,
queueClient: queueClient,
cacheClient: cacheClient,
port: port,
sdClient: sdClient,
logger: logrus.WithField("module", "api").Logger,
db: db,
queueClient: queueClient,
cacheClient: cacheClient,
vapidPublicKey: vapidPublicKey,
}, nil
}

Expand All @@ -72,6 +75,7 @@ func (s *Server) StartServer() error {
e.POST("/register", s.Register)
e.GET("/vault/:vault_id", s.IsVaultRegistered)
e.POST("/notify", s.SendNotification)
e.GET("/vapid-public-key", s.GetVAPIDPublicKey)

return e.Start(fmt.Sprintf(":%d", s.port))
}
Expand All @@ -94,6 +98,10 @@ func (s *Server) Ping(c echo.Context) error {
return c.String(http.StatusOK, "Vultisig notification server is running")
}

func (s *Server) GetVAPIDPublicKey(c echo.Context) error {
return c.JSON(http.StatusOK, map[string]string{"public_key": s.vapidPublicKey})
}

// Register handles device registration for push notifications
// @Summary Register a device for push notifications
// @Description Registers a device using its token and platform (iOS/Android).
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func main() {
log.Printf("fail to close asynq client,err: %v", err)
}
}()
apiServer, err := api.NewServer(cfg.Server.Port, sdClient, db, client, cacheClient)
apiServer, err := api.NewServer(cfg.Server.Port, sdClient, db, client, cacheClient, cfg.VAPIDPublicKey)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
panic(err)
}

workerServce, err := service.NewNotificationService(sdClient, db, "https://api.vultisig.com", cfg.Certificate, cfg.CertificatePassword, cfg.Production)
workerServce, err := service.NewNotificationService(sdClient, db, "https://api.vultisig.com", cfg.Certificate, cfg.CertificatePassword, cfg.Production, cfg.VAPIDPublicKey, cfg.VAPIDPrivateKey, cfg.VAPIDSubscriber)
if err != nil {
panic(err)
}
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ type Config struct {
Certificate string `mapstructure:"certificate" json:"certificate,omitempty"`
CertificatePassword string `mapstructure:"certificate-password" json:"certificate-password,omitempty"`
Production bool `mapstructure:"production" json:"production,omitempty"`
VAPIDPublicKey string `mapstructure:"vapid-public-key" json:"vapid-public-key,omitempty"`
VAPIDPrivateKey string `mapstructure:"vapid-private-key" json:"vapid-private-key,omitempty"`
VAPIDSubscriber string `mapstructure:"vapid-subscriber" json:"vapid-subscriber,omitempty"`
}
type DatabaseConfig struct {
Database string `mapstructure:"database" json:"database,omitempty"`
Expand Down
Loading