/
discover.go
51 lines (43 loc) · 1.03 KB
/
discover.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
package main
import (
"fmt"
"os"
"strings"
"github.com/appc/spec/discovery"
)
var (
cmdDiscover = &Command{
Name: "discover",
Description: "Discover the download URLs for an app",
Summary: "Discover the download URLs for one or more app container images",
Usage: "APP...",
Run: runDiscover,
}
)
func init() {
cmdDiscover.Flags.BoolVar(&transportFlags.Insecure, "insecure", false,
"Allow insecure non-TLS downloads over http")
}
func runDiscover(args []string) (exit int) {
if len(args) < 1 {
fmt.Fprintf(os.Stderr, "discover: at least one name required")
}
for _, name := range args {
app, err := discovery.NewAppFromString(name)
if err != nil {
stderr("%s: %s", name, err)
return 1
}
eps, err := discovery.DiscoverEndpoints(*app, transportFlags.Insecure)
if err != nil {
stderr("error fetching %s: %s", name, err)
return 1
}
for _, list := range [][]string{eps.Sig, eps.ACI, eps.Keys} {
if len(list) != 0 {
fmt.Println(strings.Join(list, ","))
}
}
}
return
}