()
| 165 | } |
| 166 | |
| 167 | func writeSecretsToFile() error { |
| 168 | lock.Lock() |
| 169 | secretsCopy := make(map[string]string, len(secrets)+1) |
| 170 | for k, v := range secrets { |
| 171 | secretsCopy[k] = v |
| 172 | } |
| 173 | secretsCopy[WriteTsKey] = time.Now().UTC().Format(time.RFC3339) |
| 174 | lock.Unlock() |
| 175 | |
| 176 | jsonData, err := json.Marshal(secretsCopy) |
| 177 | if err != nil { |
| 178 | return fmt.Errorf("failed to marshal secrets: %w", err) |
| 179 | } |
| 180 | |
| 181 | rpcClient := wshclient.GetBareRpcClient() |
| 182 | ctx, cancel := context.WithTimeout(context.Background(), EncryptionTimeout*time.Millisecond) |
| 183 | defer cancel() |
| 184 | |
| 185 | encryptData := wshrpc.CommandElectronEncryptData{ |
| 186 | PlainText: string(jsonData), |
| 187 | } |
| 188 | rpcOpts := &wshrpc.RpcOpts{ |
| 189 | Route: wshutil.ElectronRoute, |
| 190 | Timeout: EncryptionTimeout, |
| 191 | } |
| 192 | |
| 193 | result, err := wshclient.ElectronEncryptCommand(rpcClient, encryptData, rpcOpts) |
| 194 | if err != nil { |
| 195 | return fmt.Errorf("failed to encrypt secrets: %w", err) |
| 196 | } |
| 197 | |
| 198 | if ctx.Err() != nil { |
| 199 | return fmt.Errorf("encryption timeout: %w", ctx.Err()) |
| 200 | } |
| 201 | |
| 202 | configDir := wavebase.GetWaveConfigDir() |
| 203 | secretsPath := filepath.Join(configDir, SecretsFileName) |
| 204 | |
| 205 | if err := os.WriteFile(secretsPath, []byte(result.CipherText), 0600); err != nil { |
| 206 | return fmt.Errorf("failed to write secrets file: %w", err) |
| 207 | } |
| 208 | |
| 209 | return nil |
| 210 | } |
| 211 | |
| 212 | func requestWrite() { |
| 213 | select { |
no test coverage detected