Export exports an existing namespace into an opaque data stream This stream is actually a tarball containing context metadata and TLS materials, but it does not map 1:1 the layout of the context store (don't try to restore it manually without calling store.Import)
(name string, s Reader)
| 261 | // This stream is actually a tarball containing context metadata and TLS materials, but it does |
| 262 | // not map 1:1 the layout of the context store (don't try to restore it manually without calling store.Import) |
| 263 | func Export(name string, s Reader) io.ReadCloser { |
| 264 | reader, writer := io.Pipe() |
| 265 | go func() { |
| 266 | tw := tar.NewWriter(writer) |
| 267 | defer tw.Close() |
| 268 | defer writer.Close() |
| 269 | meta, err := s.GetMetadata(name) |
| 270 | if err != nil { |
| 271 | writer.CloseWithError(err) |
| 272 | return |
| 273 | } |
| 274 | metaBytes, err := json.Marshal(&meta) |
| 275 | if err != nil { |
| 276 | writer.CloseWithError(err) |
| 277 | return |
| 278 | } |
| 279 | if err = tw.WriteHeader(&tar.Header{ |
| 280 | Name: metaFile, |
| 281 | Mode: 0o644, |
| 282 | Size: int64(len(metaBytes)), |
| 283 | }); err != nil { |
| 284 | writer.CloseWithError(err) |
| 285 | return |
| 286 | } |
| 287 | if _, err = tw.Write(metaBytes); err != nil { |
| 288 | writer.CloseWithError(err) |
| 289 | return |
| 290 | } |
| 291 | tlsFiles, err := s.ListTLSFiles(name) |
| 292 | if err != nil { |
| 293 | writer.CloseWithError(err) |
| 294 | return |
| 295 | } |
| 296 | if err = tw.WriteHeader(&tar.Header{ |
| 297 | Name: "tls", |
| 298 | Mode: 0o700, |
| 299 | Size: 0, |
| 300 | Typeflag: tar.TypeDir, |
| 301 | }); err != nil { |
| 302 | writer.CloseWithError(err) |
| 303 | return |
| 304 | } |
| 305 | for endpointName, endpointFiles := range tlsFiles { |
| 306 | if err = tw.WriteHeader(&tar.Header{ |
| 307 | Name: path.Join("tls", endpointName), |
| 308 | Mode: 0o700, |
| 309 | Size: 0, |
| 310 | Typeflag: tar.TypeDir, |
| 311 | }); err != nil { |
| 312 | writer.CloseWithError(err) |
| 313 | return |
| 314 | } |
| 315 | for _, fileName := range endpointFiles { |
| 316 | data, err := s.GetTLSData(name, endpointName, fileName) |
| 317 | if err != nil { |
| 318 | writer.CloseWithError(err) |
| 319 | return |
| 320 | } |
searching dependent graphs…