Skip to content

Commit 97aaf98

Browse files
committed
Public flag
1 parent 22af014 commit 97aaf98

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

client/main.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var (
2323
serverURL string
2424
verbose bool
2525
dryRun bool
26+
setPublic bool
2627
timeout int
2728
logger *zap.Logger
2829
inspectTraffic bool
@@ -302,7 +303,15 @@ func runPushSync(localPath string, remotePath string) error {
302303
Server: serverURL,
303304
}
304305
} else {
305-
serverURL = dbConfig.Server
306+
if serverURL == "" {
307+
serverURL = dbConfig.Server
308+
}
309+
if pushKey == "" {
310+
pushKey = dbConfig.PushKey
311+
}
312+
if remotePath == "" {
313+
remotePath = dbConfig.RemotePath
314+
}
306315
}
307316

308317
if remotePath == "" {
@@ -368,6 +377,7 @@ func runPushSync(localPath string, remotePath string) error {
368377
LocalAbsolutePath: absLocalPath,
369378
InspectionDepth: inspectionDepth,
370379
SendConfigCmd: needsToBuildDashSQLRSyncFile(localPath, remotePath),
380+
SetPublic: setPublic,
371381
})
372382

373383
if err != nil {
@@ -400,7 +410,7 @@ func runPushSync(localPath string, remotePath string) error {
400410

401411
dbConfig.LastPush = time.Now()
402412
if remoteClient.GetNewPushKey() != "" {
403-
fmt.Println("🔑 This database is now PUSH-enabled.")
413+
fmt.Println("🔑 This database is now PUSH-enabled on this system.")
404414
fmt.Println(" A new, replica-specific PUSH key has been stored at ~/.config/sqlrsync/local-secrets.toml")
405415
dbConfig.ReplicaID = remoteClient.GetReplicaID()
406416
dbConfig.RemotePath = remoteClient.GetReplicaPath()
@@ -412,6 +422,11 @@ func runPushSync(localPath string, remotePath string) error {
412422
logger.Warn("Failed to save local secrets config", zap.Error(err))
413423
}
414424

425+
if setPublic {
426+
fmt.Println("🌐 This replica is now publicly accessible.")
427+
fmt.Println(" Share this database with sqlrsync.com/" + remoteClient.GetReplicaPath())
428+
}
429+
415430
if needsToBuildDashSQLRSyncFile(localPath, remotePath) {
416431
token := remoteClient.GetNewPullKey()
417432
replicaID := remoteClient.GetReplicaID()
@@ -585,6 +600,7 @@ func init() {
585600
rootCmd.Flags().StringVar(&replicaID, "replicaID", "", "Replica ID for the remote database (overwrites the REMOTE path)")
586601
rootCmd.Flags().StringVarP(&serverURL, "server", "s", "wss://sqlrsync.com", "Server URL for push/pull operations")
587602
rootCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging")
603+
rootCmd.Flags().BoolVar(&setPublic, "public", false, "Enable public access to the replica (only for push operations)")
588604
rootCmd.Flags().BoolVar(&newReadToken, "storeNewReadToken", true, "After syncing, the server creates a new read-only token that is stored in the -sqlrsync file adjacent to the local database")
589605
rootCmd.Flags().BoolVar(&dryRun, "dry", false, "Perform a dry run without making changes")
590606
rootCmd.Flags().IntVarP(&timeout, "timeout", "t", 8000, "Connection timeout in milliseconds (Max 10 seconds)")

client/remote/client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ type Config struct {
158158
ServerURL string
159159
Version string
160160
ReplicaID string
161+
SetPublic bool // for PUSH
161162
Timeout int // in milliseconds
162163
Logger *zap.Logger
163164
EnableTrafficInspection bool // Enable detailed traffic logging
@@ -206,6 +207,7 @@ type Client struct {
206207
NewPushKey string
207208
ReplicaID string
208209
ReplicaPath string
210+
SetPublic bool
209211
}
210212

211213
// New creates a new remote WebSocket client
@@ -278,6 +280,10 @@ func (c *Client) Connect() error {
278280
headers.Set("X-ReplicaID", c.config.ReplicaID)
279281
}
280282

283+
if c.config.SetPublic {
284+
headers.Set("X-SetPublic", fmt.Sprintf("%t", c.config.SetPublic))
285+
}
286+
281287
conn, response, err := dialer.DialContext(connectCtx, u.String(), headers)
282288
if err != nil {
283289
respStr, _ := io.ReadAll(response.Body)

0 commit comments

Comments
 (0)