@@ -12,7 +12,7 @@ import (
1212
1313// ResolveResult contains the resolved authentication information
1414type ResolveResult struct {
15- AccessToken string
15+ AccessKey string
1616 ReplicaID string
1717 ServerURL string
1818 RemotePath string
@@ -22,14 +22,14 @@ type ResolveResult struct {
2222
2323// ResolveRequest contains the parameters for authentication resolution
2424type ResolveRequest struct {
25- LocalPath string
26- RemotePath string
27- ServerURL string
28- ProvidedPullKey string
29- ProvidedPushKey string
25+ LocalPath string
26+ RemotePath string
27+ ServerURL string
28+ ProvidedPullKey string
29+ ProvidedPushKey string
3030 ProvidedReplicaID string
31- Operation string // "pull", "push", "subscribe"
32- Logger * zap.Logger
31+ Operation string // "pull", "push", "subscribe"
32+ Logger * zap.Logger
3333}
3434
3535// Resolver handles authentication and configuration resolution
@@ -53,24 +53,24 @@ func (r *Resolver) Resolve(req *ResolveRequest) (*ResolveResult, error) {
5353 }
5454
5555 // 1. Try environment variable first
56- if token := os .Getenv ("SQLRSYNC_AUTH_TOKEN " ); token != "" {
57- r .logger .Debug ("Using SQLRSYNC_AUTH_TOKEN from environment" )
58- result .AccessToken = token
56+ if key := os .Getenv ("SQLRSYNC_AUTH_KEY " ); key != "" {
57+ r .logger .Debug ("Using SQLRSYNC_AUTH_KEY from environment" )
58+ result .AccessKey = key
5959 result .ReplicaID = req .ProvidedReplicaID
6060 return result , nil
6161 }
6262
6363 // 2. Try explicitly provided keys
6464 if req .ProvidedPullKey != "" {
6565 r .logger .Debug ("Using provided pull key" )
66- result .AccessToken = req .ProvidedPullKey
66+ result .AccessKey = req .ProvidedPullKey
6767 result .ReplicaID = req .ProvidedReplicaID
6868 return result , nil
6969 }
7070
7171 if req .ProvidedPushKey != "" {
7272 r .logger .Debug ("Using provided push key" )
73- result .AccessToken = req .ProvidedPushKey
73+ result .AccessKey = req .ProvidedPushKey
7474 result .ReplicaID = req .ProvidedReplicaID
7575 return result , nil
7676 }
@@ -87,7 +87,7 @@ func (r *Resolver) Resolve(req *ResolveRequest) (*ResolveResult, error) {
8787 if req .ServerURL == "wss://sqlrsync.com" {
8888 if localSecretsConfig , err := LoadLocalSecretsConfig (); err == nil {
8989 if dbConfig := localSecretsConfig .FindDatabaseByPath (absLocalPath ); dbConfig != nil {
90- r .logger .Debug ("Using server URL from local secrets config" ,
90+ r .logger .Debug ("Using server URL from local secrets config" ,
9191 zap .String ("configuredServer" , dbConfig .Server ),
9292 zap .String ("defaultServer" , req .ServerURL ))
9393 result .ServerURL = dbConfig .Server
@@ -114,7 +114,7 @@ func (r *Resolver) Resolve(req *ResolveRequest) (*ResolveResult, error) {
114114 if req .Operation == "push" {
115115 if os .Getenv ("SQLRSYNC_ADMIN_KEY" ) != "" {
116116 r .logger .Debug ("Using SQLRSYNC_ADMIN_KEY from environment" )
117- result .AccessToken = os .Getenv ("SQLRSYNC_ADMIN_KEY" )
117+ result .AccessKey = os .Getenv ("SQLRSYNC_ADMIN_KEY" )
118118 result .ShouldPrompt = false
119119 return result , nil
120120 }
@@ -126,7 +126,7 @@ func (r *Resolver) Resolve(req *ResolveRequest) (*ResolveResult, error) {
126126
127127 // 5. If it's a pull, maybe no key needed
128128 if req .Operation == "pull" || req .Operation == "subscribe" {
129- result .AccessToken = ""
129+ result .AccessKey = ""
130130 result .ShouldPrompt = false
131131 return result , nil
132132 }
@@ -138,7 +138,7 @@ func (r *Resolver) Resolve(req *ResolveRequest) (*ResolveResult, error) {
138138// resolveFromLocalSecrets attempts to resolve auth from local-secrets.toml
139139func (r * Resolver ) resolveFromLocalSecrets (absLocalPath , serverURL string , result * ResolveResult ) (* ResolveResult , error ) {
140140 r .logger .Debug ("Attempting to resolve from local secrets" , zap .String ("absLocalPath" , absLocalPath ), zap .String ("serverURL" , serverURL ))
141-
141+
142142 localSecretsConfig , err := LoadLocalSecretsConfig ()
143143 if err != nil {
144144 r .logger .Debug ("Failed to load local secrets config" , zap .Error (err ))
@@ -162,14 +162,14 @@ func (r *Resolver) resolveFromLocalSecrets(absLocalPath, serverURL string, resul
162162 }
163163
164164 if dbConfig .Server != serverURL {
165- r .logger .Debug ("Server URL mismatch" ,
166- zap .String ("configured" , dbConfig .Server ),
165+ r .logger .Debug ("Server URL mismatch" ,
166+ zap .String ("configured" , dbConfig .Server ),
167167 zap .String ("requested" , serverURL ))
168168 return nil , fmt .Errorf ("server URL mismatch: configured=%s, requested=%s" , dbConfig .Server , serverURL )
169169 }
170170
171171 r .logger .Debug ("Found authentication in local secrets config" )
172- result .AccessToken = dbConfig .PushKey
172+ result .AccessKey = dbConfig .PushKey
173173 result .ReplicaID = dbConfig .ReplicaID
174174 result .RemotePath = dbConfig .RemotePath
175175 result .ServerURL = dbConfig .Server
@@ -193,32 +193,33 @@ func (r *Resolver) resolveFromDashFile(localPath string, result *ResolveResult)
193193 }
194194
195195 r .logger .Debug ("Found authentication in -sqlrsync file" )
196- result .AccessToken = dashSQLRsync .PullKey
196+ result .AccessKey = dashSQLRsync .PullKey
197197 result .ReplicaID = dashSQLRsync .ReplicaID
198198 result .RemotePath = dashSQLRsync .RemotePath
199199 result .ServerURL = dashSQLRsync .Server
200200
201201 return result , nil
202202}
203203
204- // PromptForAdminKey prompts the user for an admin key
205- func (r * Resolver ) PromptForAdminKey (serverURL string ) (string , error ) {
204+ // PromptForKey prompts the user for an key
205+ func (r * Resolver ) PromptForKey (serverURL string , remotePath string , keyType string ) (string , error ) {
206206 httpServer := strings .Replace (serverURL , "ws" , "http" , 1 )
207- fmt .Println ("No Key provided. Creating a new Replica? Get a key at " + httpServer + "/namespaces" )
208- fmt .Print (" Enter an Account Admin Key to create a new Replica: " )
207+ fmt .Println ("Replica not found when using unauthenticated access. Try again using a key or check your spelling." )
208+ fmt .Println (" Get a key at " + httpServer + "/namespaces or " + httpServer + "/" + remotePath )
209+ fmt .Print (" Provide a key to " + keyType + ": " )
209210
210211 reader := bufio .NewReader (os .Stdin )
211- token , err := reader .ReadString ('\n' )
212+ key , err := reader .ReadString ('\n' )
212213 if err != nil {
213- return "" , fmt .Errorf ("failed to read admin key: %w" , err )
214+ return "" , fmt .Errorf ("failed to read key: %w" , err )
214215 }
215216
216- token = strings .TrimSpace (token )
217- if token == "" {
218- return "" , fmt .Errorf ("admin key cannot be empty" )
217+ key = strings .TrimSpace (key )
218+ if key == "" {
219+ return "" , fmt .Errorf ("key cannot be empty" )
219220 }
220221
221- return token , nil
222+ return key , nil
222223}
223224
224225// SavePushResult saves the result of a successful push operation
@@ -279,4 +280,4 @@ func (r *Resolver) CheckNeedsDashFile(localPath, remotePath string) bool {
279280 }
280281
281282 return dashSQLRsync .RemotePath != remotePath
282- }
283+ }
0 commit comments