(baseURL string)
| 91 | } |
| 92 | |
| 93 | func newClientFromURL(baseURL string) *Client { |
| 94 | baseURL = strings.TrimRight(baseURL, "/") |
| 95 | c := &Client{ |
| 96 | baseURL: baseURL + "/api/v1", |
| 97 | httpClient: &http.Client{ |
| 98 | Timeout: 10 * time.Second, |
| 99 | }, |
| 100 | // Long-running transfer client for streaming endpoints |
| 101 | // (workspace export bundles in/out, future S3 downloads). |
| 102 | // 10s on the default client is the right SLA for normal API |
| 103 | // calls but kills a multi-GiB bundle upload mid-stream over |
| 104 | // anything but a fast local link. 1 hour is generous enough |
| 105 | // for ~100 MB/s uplinks shipping a 350 GiB bundle and still |
| 106 | // caps a hung connection eventually. (PR |
| 107 | // #306.) |
| 108 | streamClient: &http.Client{ |
| 109 | Timeout: 1 * time.Hour, |
| 110 | }, |
| 111 | } |
| 112 | |
| 113 | // Auth resolution order: PAD_TOKEN env override first (explicit, |
| 114 | // per-process — lets concurrent agents on one machine act as |
| 115 | // different users, issue #879), then the saved credential for THIS |
| 116 | // server URL. We use the original baseURL (without the /api/v1 |
| 117 | // suffix added below) so the lookup matches what login/save |
| 118 | // commands key on. Credentials for other servers are left untouched |
| 119 | // in the store — see TASK-1228 / IDEA-1226 for the per-server design. |
| 120 | if tok := EnvTokenFor(baseURL); tok != "" { |
| 121 | c.authToken = tok |
| 122 | } else if store, err := LoadStore(); err == nil { |
| 123 | if creds := store.Get(baseURL); creds != nil { |
| 124 | c.authToken = creds.Token |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | return c |
| 129 | } |
| 130 | |
| 131 | // SetAgentName sets X-Pad-Agent verbatim; an empty name omits the header. |
| 132 | // Call it before the first request. |
no test coverage detected