-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker2aci.go
781 lines (636 loc) · 19.4 KB
/
docker2aci.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
// Package docker2aci implements a simple library for converting docker images to
// App Container Images (ACIs).
package docker2aci
import (
"archive/tar"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/coreos/rocket/Godeps/_workspace/src/github.com/appc/docker2aci/tarball"
"github.com/coreos/rocket/Godeps/_workspace/src/github.com/appc/spec/aci"
"github.com/coreos/rocket/Godeps/_workspace/src/github.com/appc/spec/schema"
"github.com/coreos/rocket/Godeps/_workspace/src/github.com/appc/spec/schema/types"
)
const (
defaultTag = "latest"
schemaVersion = "0.1.1"
)
// Convert generates ACI images from docker registry URLs.
// It takes as input a dockerURL of the form:
//
// {docker registry URL}/{image name}:{tag}
//
// It then gets all the layers of the requested image and converts each of
// them to ACI.
// If the squash flag is true, it squashes all the layers in one file and
// places this file in outputDir; if it is false, it places every layer in its
// own ACI in outputDir.
// It returns the list of generated ACI paths.
func Convert(dockerURL string, squash bool, outputDir string) ([]string, error) {
parsedURL, err := parseDockerURL(dockerURL)
if err != nil {
return nil, fmt.Errorf("error parsing docker url: %v\n", err)
}
repoData, err := getRepoData(parsedURL.IndexURL, parsedURL.ImageName)
if err != nil {
return nil, fmt.Errorf("error getting repository data: %v\n", err)
}
// TODO(iaguis) check more endpoints
appImageID, err := getImageIDFromTag(repoData.Endpoints[0], parsedURL.ImageName, parsedURL.Tag, repoData)
if err != nil {
return nil, fmt.Errorf("error getting ImageID from tag %s: %v\n", parsedURL.Tag, err)
}
ancestry, err := getAncestry(appImageID, repoData.Endpoints[0], repoData)
if err != nil {
return nil, fmt.Errorf("error getting ancestry: %v\n", err)
}
layersOutputDir := outputDir
if squash {
layersOutputDir, err = ioutil.TempDir("", "docker2aci-")
if err != nil {
return nil, fmt.Errorf("error creating dir: %v", err)
}
defer os.RemoveAll(layersOutputDir)
}
var aciLayerPaths []string
for i := len(ancestry) - 1; i >= 0; i-- {
layerID := ancestry[i]
aciPath, err := buildACI(layerID, repoData, parsedURL, layersOutputDir)
if err != nil {
return nil, fmt.Errorf("error building layer: %v\n", err)
}
aciLayerPaths = append(aciLayerPaths, aciPath)
}
if squash {
squashedFilename := strings.Replace(parsedURL.ImageName, "/", "-", -1)
if parsedURL.Tag != "" {
squashedFilename += "-" + parsedURL.Tag
}
squashedFilename += ".aci"
squashedImagePath := path.Join(outputDir, squashedFilename)
if err := SquashLayers(aciLayerPaths, squashedImagePath); err != nil {
return nil, fmt.Errorf("error squashing image: %v\n", err)
}
aciLayerPaths = []string{squashedImagePath}
}
return aciLayerPaths, nil
}
func parseDockerURL(arg string) (*ParsedDockerURL, error) {
taglessRemote, tag := parseRepositoryTag(arg)
if tag == "" {
tag = defaultTag
}
indexURL, imageName := splitReposName(taglessRemote)
return &ParsedDockerURL{
IndexURL: indexURL,
ImageName: imageName,
Tag: tag,
}, nil
}
func getRepoData(indexURL string, remote string) (*RepoData, error) {
client := &http.Client{}
repositoryURL := "https://" + path.Join(indexURL, "v1", "repositories", remote, "images")
req, err := http.NewRequest("GET", repositoryURL, nil)
if err != nil {
return nil, err
}
// TODO(iaguis) add auth?
req.Header.Set("X-Docker-Token", "true")
res, err := client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != 200 {
return nil, fmt.Errorf("HTTP code: %d, URL: %s", res.StatusCode, req.URL)
}
var tokens []string
if res.Header.Get("X-Docker-Token") != "" {
tokens = res.Header["X-Docker-Token"]
}
var cookies []string
if res.Header.Get("Set-Cookie") != "" {
cookies = res.Header["Set-Cookie"]
}
var endpoints []string
if res.Header.Get("X-Docker-Endpoints") != "" {
endpoints = makeEndpointsList(res.Header["X-Docker-Endpoints"])
} else {
// Assume same endpoint
endpoints = append(endpoints, indexURL)
}
return &RepoData{
Endpoints: endpoints,
Tokens: tokens,
Cookie: cookies,
}, nil
}
func getImageIDFromTag(registry string, appName string, tag string, repoData *RepoData) (string, error) {
client := &http.Client{}
req, err := http.NewRequest("GET", "https://"+path.Join(registry, "repositories", appName, "tags", tag), nil)
if err != nil {
return "", fmt.Errorf("failed to get Image ID: %s, URL: %s", err, req.URL)
}
setAuthToken(req, repoData.Tokens)
setCookie(req, repoData.Cookie)
res, err := client.Do(req)
if err != nil {
return "", fmt.Errorf("failed to get Image ID: %s, URL: %s", err, req.URL)
}
defer res.Body.Close()
if res.StatusCode != 200 {
return "", fmt.Errorf("HTTP code: %d. URL: %s", res.StatusCode, req.URL)
}
j, err := ioutil.ReadAll(res.Body)
if err != nil {
return "", err
}
var imageID string
if err := json.Unmarshal(j, &imageID); err != nil {
return "", fmt.Errorf("error unmarshaling: %v", err)
}
return imageID, nil
}
func getAncestry(imgID, registry string, repoData *RepoData) ([]string, error) {
client := &http.Client{}
req, err := http.NewRequest("GET", "https://"+path.Join(registry, "images", imgID, "ancestry"), nil)
if err != nil {
return nil, err
}
setAuthToken(req, repoData.Tokens)
setCookie(req, repoData.Cookie)
res, err := client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != 200 {
return nil, fmt.Errorf("HTTP code: %d. URL: %s", res.StatusCode, req.URL)
}
var ancestry []string
j, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("Failed to read downloaded json: %s (%s)", err, j)
}
if err := json.Unmarshal(j, &ancestry); err != nil {
return nil, fmt.Errorf("error unmarshaling: %v", err)
}
return ancestry, nil
}
func buildACI(layerID string, repoData *RepoData, dockerURL *ParsedDockerURL, outputDir string) (string, error) {
tmpDir, err := ioutil.TempDir("", "docker2aci-")
if err != nil {
return "", fmt.Errorf("error creating dir: %v", err)
}
defer os.RemoveAll(tmpDir)
layerDest := filepath.Join(tmpDir, "layer")
layerRootfs := filepath.Join(layerDest, "rootfs")
err = os.MkdirAll(layerRootfs, 0700)
if err != nil {
return "", fmt.Errorf("error creating dir: %s", layerRootfs)
}
j, size, err := getRemoteImageJSON(layerID, repoData.Endpoints[0], repoData)
if err != nil {
return "", fmt.Errorf("error getting image json: %v", err)
}
layerData := DockerImageData{}
if err := json.Unmarshal(j, &layerData); err != nil {
return "", fmt.Errorf("error unmarshaling layer data: %v", err)
}
layer, err := getRemoteLayer(layerID, repoData.Endpoints[0], repoData, int64(size))
if err != nil {
return "", fmt.Errorf("error getting the remote layer: %v", err)
}
defer layer.Close()
layerFile, err := ioutil.TempFile(tmpDir, "dockerlayer-")
if err != nil {
return "", fmt.Errorf("error creating layer: %v", err)
}
_, err = io.Copy(layerFile, layer)
if err != nil {
return "", fmt.Errorf("error getting layer: %v", err)
}
layerFile.Sync()
manifest, err := generateManifest(layerData, dockerURL)
if err != nil {
return "", fmt.Errorf("error generating the manifest: %v", err)
}
imageName := strings.Replace(dockerURL.ImageName, "/", "-", -1)
aciPath := imageName + "-" + layerID
if dockerURL.Tag != "" {
aciPath += "-" + dockerURL.Tag
}
if layerData.OS != "" {
aciPath += "-" + layerData.OS
if layerData.Architecture != "" {
aciPath += "-" + layerData.Architecture
}
}
aciPath += ".aci"
aciPath = path.Join(outputDir, aciPath)
if err := writeACI(layerFile, *manifest, aciPath); err != nil {
return "", fmt.Errorf("error writing ACI: %v", err)
}
if err := validateACI(aciPath); err != nil {
return "", fmt.Errorf("invalid aci generated: %v", err)
}
return aciPath, nil
}
func validateACI(aciPath string) error {
aciFile, err := os.Open(aciPath)
if err != nil {
return err
}
defer aciFile.Close()
reader, err := aci.NewCompressedTarReader(aciFile)
if err != nil {
return err
}
if err := aci.ValidateArchive(reader); err != nil {
return err
}
return nil
}
func getRemoteImageJSON(imgID, registry string, repoData *RepoData) ([]byte, int, error) {
client := &http.Client{}
req, err := http.NewRequest("GET", "https://"+path.Join(registry, "images", imgID, "json"), nil)
if err != nil {
return nil, -1, err
}
setAuthToken(req, repoData.Tokens)
setCookie(req, repoData.Cookie)
res, err := client.Do(req)
if err != nil {
return nil, -1, err
}
defer res.Body.Close()
if res.StatusCode != 200 {
return nil, -1, fmt.Errorf("HTTP code: %d, URL: %s", res.StatusCode, req.URL)
}
imageSize := -1
if hdr := res.Header.Get("X-Docker-Size"); hdr != "" {
imageSize, err = strconv.Atoi(hdr)
if err != nil {
return nil, -1, err
}
}
b, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, -1, fmt.Errorf("failed to read downloaded json: %v (%s)", err, b)
}
return b, imageSize, nil
}
func getRemoteLayer(imgID, registry string, repoData *RepoData, imgSize int64) (io.ReadCloser, error) {
client := &http.Client{}
req, err := http.NewRequest("GET", "https://"+path.Join(registry, "images", imgID, "layer"), nil)
if err != nil {
return nil, err
}
setAuthToken(req, repoData.Tokens)
setCookie(req, repoData.Cookie)
fmt.Printf("Downloading layer: %s\n", imgID)
res, err := client.Do(req)
if err != nil {
return nil, err
}
if res.StatusCode != 200 {
res.Body.Close()
return nil, fmt.Errorf("HTTP code: %d. URL: %s", res.StatusCode, req.URL)
}
return res.Body, nil
}
func generateManifest(layerData DockerImageData, dockerURL *ParsedDockerURL) (*schema.ImageManifest, error) {
dockerConfig := layerData.Config
genManifest := &schema.ImageManifest{}
appURL := dockerURL.IndexURL + "/" + dockerURL.ImageName + "-" + layerData.ID
name, err := types.NewACName(appURL)
if err != nil {
return nil, err
}
genManifest.Name = *name
acVersion, _ := types.NewSemVer(schemaVersion)
genManifest.ACVersion = *acVersion
genManifest.ACKind = types.ACKind("ImageManifest")
var labels types.Labels
var parentLabels types.Labels
layer, _ := types.NewACName("layer")
labels = append(labels, types.Label{Name: *layer, Value: layerData.ID})
tag := dockerURL.Tag
version, _ := types.NewACName("version")
labels = append(labels, types.Label{Name: *version, Value: tag})
if layerData.OS != "" {
os, _ := types.NewACName("os")
labels = append(labels, types.Label{Name: *os, Value: layerData.OS})
parentLabels = append(parentLabels, types.Label{Name: *os, Value: layerData.OS})
if layerData.Architecture != "" {
arch, _ := types.NewACName("arch")
parentLabels = append(parentLabels, types.Label{Name: *arch, Value: layerData.Architecture})
}
}
genManifest.Labels = labels
if dockerConfig != nil {
exec := getExecCommand(dockerConfig.Entrypoint, dockerConfig.Cmd)
if exec != nil {
user, group := parseDockerUser(dockerConfig.User)
var env types.Environment
for _, v := range dockerConfig.Env {
parts := strings.SplitN(v, "=", 2)
env.Set(parts[0], parts[1])
}
app := &types.App{
Exec: exec,
User: user,
Group: group,
Environment: env,
WorkingDirectory: dockerConfig.WorkingDir,
}
genManifest.App = app
}
}
if layerData.Parent != "" {
var dependencies types.Dependencies
parentAppNameString := dockerURL.IndexURL + "/" + dockerURL.ImageName + "-" + layerData.Parent
parentAppName, err := types.NewACName(parentAppNameString)
if err != nil {
return nil, err
}
dependencies = append(dependencies, types.Dependency{App: *parentAppName, Labels: parentLabels})
genManifest.Dependencies = dependencies
}
return genManifest, nil
}
func getExecCommand(entrypoint []string, cmd []string) types.Exec {
var command []string
if entrypoint == nil && cmd == nil {
return nil
}
command = append(entrypoint, cmd...)
// non-absolute paths are not allowed, fallback to "/bin/sh -c command"
if !filepath.IsAbs(command[0]) {
command_prefix := []string{"/bin/sh", "-c"}
command = append(command_prefix, strings.Join(command, " "))
}
return command
}
func parseDockerUser(dockerUser string) (string, string) {
// if the docker user is empty assume root user and group
if dockerUser == "" {
return "0", "0"
}
dockerUserParts := strings.Split(dockerUser, ":")
// when only the user is given, the docker spec says that the default and
// supplementary groups of the user in /etc/passwd should be applied.
// Assume root group for now in this case.
if len(dockerUserParts) < 2 {
return dockerUserParts[0], "0"
}
return dockerUserParts[0], dockerUserParts[1]
}
func writeACI(layer io.ReadSeeker, manifest schema.ImageManifest, output string) error {
reader, err := aci.NewCompressedTarReader(layer)
if err != nil {
return err
}
aciFile, err := os.Create(output)
if err != nil {
return fmt.Errorf("error creating ACI file: %v", err)
}
defer aciFile.Close()
trw := tar.NewWriter(aciFile)
defer trw.Close()
if err := addMinimalACIStructure(trw, manifest); err != nil {
return fmt.Errorf("error writing rootfs entry: %v", err)
}
// Write files in rootfs/
if err = tarball.Walk(*reader, func(t *tarball.TarFile) error {
name := t.Name()
if name == "./" {
return nil
}
t.Header.Name = path.Join("rootfs", name)
if strings.Contains(t.Header.Name, "/.wh.") {
return nil
}
if t.Header.Typeflag == tar.TypeLink {
t.Header.Linkname = path.Join("rootfs", t.Linkname())
}
if err := trw.WriteHeader(t.Header); err != nil {
return err
}
if _, err := io.Copy(trw, t.TarStream); err != nil {
return err
}
return nil
}); err != nil {
return err
}
return nil
}
func addMinimalACIStructure(tarWriter *tar.Writer, manifest schema.ImageManifest) error {
hdr := getGenericTarHeader()
hdr.Name = "rootfs"
hdr.Mode = 0755
hdr.Size = int64(0)
hdr.Typeflag = tar.TypeDir
if err := tarWriter.WriteHeader(hdr); err != nil {
return err
}
if err := writeManifest(tarWriter, manifest); err != nil {
return err
}
return nil
}
func getGenericTarHeader() *tar.Header {
// FIXME(iaguis) Use docker image time instead of the Unix Epoch?
hdr := &tar.Header{
Uid: 0,
Gid: 0,
ModTime: time.Unix(0, 0),
Uname: "0",
Gname: "0",
ChangeTime: time.Unix(0, 0),
}
return hdr
}
func writeManifest(outputWriter *tar.Writer, manifest schema.ImageManifest) error {
b, err := json.Marshal(manifest)
if err != nil {
return err
}
hdr := getGenericTarHeader()
hdr.Name = "manifest"
hdr.Mode = 0644
hdr.Size = int64(len(b))
hdr.Typeflag = tar.TypeReg
if err := outputWriter.WriteHeader(hdr); err != nil {
return err
}
if _, err := outputWriter.Write(b); err != nil {
return err
}
return nil
}
// SquashLayers receives a list of ACI layer file names ordered from base image
// to application image and squashes them into one ACI
func SquashLayers(layers []string, squashedImagePath string) error {
manifests, err := getManifests(layers)
if err != nil {
return err
}
fileMap, err := getFilesToLayersMap(layers)
if err != nil {
return err
}
squashedImageFile, err := os.Create(squashedImagePath)
if err != nil {
return err
}
defer squashedImageFile.Close()
if err := writeSquashedImage(squashedImageFile, layers, fileMap, manifests); err != nil {
return err
}
if err := validateACI(squashedImagePath); err != nil {
return err
}
return nil
}
func getManifests(layers []string) ([]schema.ImageManifest, error) {
var manifests []schema.ImageManifest
for _, aciPath := range layers {
currentFile, err := os.Open(aciPath)
if err != nil {
return nil, err
}
defer currentFile.Close()
manifestCur, err := aci.ManifestFromImage(currentFile)
if err != nil {
return nil, err
}
if _, err := currentFile.Seek(0, os.SEEK_SET); err != nil {
return nil, err
}
manifests = append(manifests, *manifestCur)
}
return manifests, nil
}
func getFilesToLayersMap(layers []string) (map[string]string, error) {
var err error
fileMap := make(map[string]string)
for _, aciPath := range layers {
fileMap, err = gatherFilesToLayersMap(fileMap, aciPath)
if err != nil {
return nil, err
}
}
return fileMap, nil
}
// gatherFilesToLayersMap accumulates a map associationg each file of the final
// image with the layer it comes from. It should be called starting from the
// base layer so that the order of files in the squashed layer is preserved
// and, if a file is present several times, the last layer is taken into
// account.
func gatherFilesToLayersMap(fileMap map[string]string, currentPath string) (map[string]string, error) {
currentFile, err := os.Open(currentPath)
if err != nil {
return nil, err
}
defer currentFile.Close()
reader, err := aci.NewCompressedTarReader(currentFile)
if err != nil {
return nil, err
}
if err = tarball.Walk(*reader, func(t *tarball.TarFile) error {
if t.Name() == "manifest" {
return nil
}
fileMap[t.Name()] = currentPath
return nil
}); err != nil {
return nil, err
}
return fileMap, nil
}
func writeSquashedImage(outputFile *os.File, layers []string, fileMap map[string]string, manifests []schema.ImageManifest) error {
outputWriter := tar.NewWriter(outputFile)
defer outputWriter.Close()
var err error
for _, aciPath := range layers {
outputWriter, err = reduceACIs(outputWriter, fileMap, aciPath)
if err != nil {
return err
}
}
finalManifest := mergeManifests(manifests)
if err := writeManifest(outputWriter, finalManifest); err != nil {
return err
}
return nil
}
func reduceACIs(outputWriter *tar.Writer, fileMap map[string]string, currentPath string) (*tar.Writer, error) {
currentFile, err := os.Open(currentPath)
if err != nil {
return nil, err
}
defer currentFile.Close()
reader, err := aci.NewCompressedTarReader(currentFile)
if err != nil {
return nil, err
}
if err = tarball.Walk(*reader, func(t *tarball.TarFile) error {
if t.Name() == "manifest" {
return nil
}
if fileMap[t.Name()] == currentPath {
if err := outputWriter.WriteHeader(t.Header); err != nil {
return fmt.Errorf("Error writing header: %v", err)
}
if _, err := io.Copy(outputWriter, t.TarStream); err != nil {
return fmt.Errorf("Error copying file into the tar out: %v", err)
}
}
return nil
}); err != nil {
return nil, err
}
return outputWriter, nil
}
func mergeManifests(manifests []schema.ImageManifest) schema.ImageManifest {
// FIXME(iaguis) we take last layer's manifest as the final manifest for now
manifest := manifests[len(manifests)-1]
manifest.Dependencies = nil
layerIndex := -1
for i, l := range manifest.Labels {
if l.Name.String() == "layer" {
layerIndex = i
}
}
if layerIndex != -1 {
manifest.Labels = append(manifest.Labels[:layerIndex], manifest.Labels[layerIndex+1:]...)
}
// strip layerID:
// myregistry.com/organization/app-name-85738f8f9a7f1b04b5329c590ebcb9e425925c6d0984089c43a022de4f19c281
// myregistry.com/organization/app-name
n := strings.LastIndex(manifest.Name.String(), "-")
// this can't fail because the old name is legal
nameWithoutLayerID, _ := types.NewACName(manifest.Name.String()[:n])
manifest.Name = *nameWithoutLayerID
return manifest
}
func setAuthToken(req *http.Request, token []string) {
if req.Header.Get("Authorization") == "" {
req.Header.Set("Authorization", "Token "+strings.Join(token, ","))
}
}
func setCookie(req *http.Request, cookie []string) {
if req.Header.Get("Cookie") == "" {
req.Header.Set("Cookie", strings.Join(cookie, ""))
}
}