2016-08-13 01:23:13 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
2018-06-06 13:00:42 -04:00
|
|
|
"time"
|
2016-08-13 01:23:13 -04:00
|
|
|
|
2018-03-11 11:48:04 -04:00
|
|
|
"github.com/genuinetools/reg/registry"
|
|
|
|
"github.com/genuinetools/reg/repoutils"
|
|
|
|
"github.com/genuinetools/reg/version"
|
2017-12-11 14:47:45 -05:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-09-05 22:44:19 -04:00
|
|
|
"github.com/urfave/cli"
|
2016-08-13 01:23:13 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-09-05 22:44:19 -04:00
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "reg"
|
2017-06-05 17:46:12 -04:00
|
|
|
app.Version = fmt.Sprintf("version %s, build %s", version.VERSION, version.GITCOMMIT)
|
2018-03-11 11:48:04 -04:00
|
|
|
app.Author = "The Genuinetools Authors"
|
2016-09-05 22:44:19 -04:00
|
|
|
app.Email = "no-reply@butts.com"
|
|
|
|
app.Usage = "Docker registry v2 client."
|
2018-03-06 09:12:29 -05:00
|
|
|
|
2016-09-05 22:44:19 -04:00
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "debug, d",
|
|
|
|
Usage: "run in debug mode",
|
|
|
|
},
|
2017-02-13 04:32:36 -05:00
|
|
|
cli.BoolFlag{
|
2017-02-13 14:42:33 -05:00
|
|
|
Name: "insecure, k",
|
2017-02-13 04:32:36 -05:00
|
|
|
Usage: "do not verify tls certificates",
|
|
|
|
},
|
2017-04-04 10:12:36 -04:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "force-non-ssl, f",
|
|
|
|
Usage: "force allow use of non-ssl",
|
|
|
|
},
|
2016-09-05 22:44:19 -04:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "username, u",
|
|
|
|
Usage: "username for the registry",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "password, p",
|
|
|
|
Usage: "password for the registry",
|
|
|
|
},
|
2017-10-20 09:26:54 -04:00
|
|
|
cli.StringFlag{
|
2018-06-06 12:52:47 -04:00
|
|
|
Name: "timeout",
|
2017-10-20 09:26:54 -04:00
|
|
|
Value: "1m",
|
|
|
|
Usage: "timeout for HTTP requests",
|
|
|
|
},
|
2018-01-17 11:52:39 -05:00
|
|
|
cli.BoolFlag{
|
2018-06-06 12:49:29 -04:00
|
|
|
Name: "skip-ping",
|
|
|
|
Usage: "skip pinging the registry while establishing connection",
|
2018-01-17 11:52:39 -05:00
|
|
|
},
|
2016-08-13 01:23:13 -04:00
|
|
|
}
|
2018-02-18 11:15:56 -05:00
|
|
|
|
2018-03-06 09:12:29 -05:00
|
|
|
app.Commands = []cli.Command{
|
|
|
|
deleteCommand,
|
2018-06-04 09:48:56 -04:00
|
|
|
digestCommand,
|
2018-03-06 09:12:29 -05:00
|
|
|
layerCommand,
|
|
|
|
listCommand,
|
|
|
|
manifestCommand,
|
|
|
|
tagsCommand,
|
|
|
|
vulnsCommand,
|
|
|
|
}
|
2016-09-20 21:16:34 -04:00
|
|
|
|
2018-03-06 09:12:29 -05:00
|
|
|
app.Before = func(c *cli.Context) (err error) {
|
|
|
|
// Preload initializes any global options and configuration
|
|
|
|
// before the main or sub commands are run.
|
|
|
|
if c.GlobalBool("debug") {
|
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
}
|
2016-09-20 21:16:34 -04:00
|
|
|
|
2018-03-06 09:19:55 -05:00
|
|
|
if len(c.Args()) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Args()[0] == "help" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-17 15:41:58 -04:00
|
|
|
return
|
|
|
|
}
|
2018-03-06 09:19:55 -05:00
|
|
|
|
2018-06-17 15:41:58 -04:00
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2018-03-06 09:19:55 -05:00
|
|
|
|
2018-06-17 15:41:58 -04:00
|
|
|
func createRegistryClient(c *cli.Context, domain string) (*registry.Registry, error) {
|
|
|
|
auth, err := repoutils.GetAuthConfig(c.GlobalString("username"), c.GlobalString("password"), domain)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-06-06 13:00:42 -04:00
|
|
|
|
2018-06-17 15:41:58 -04:00
|
|
|
// Prevent non-ssl unless explicitly forced
|
|
|
|
if !c.GlobalBool("force-non-ssl") && strings.HasPrefix(auth.ServerAddress, "http:") {
|
|
|
|
return nil, fmt.Errorf("Attempt to use insecure protocol! Use non-ssl option to force")
|
2016-08-13 01:23:13 -04:00
|
|
|
}
|
|
|
|
|
2018-06-17 15:41:58 -04:00
|
|
|
// Parse the timeout.
|
|
|
|
timeout, err := time.ParseDuration(c.GlobalString("timeout"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("parsing %s as duration failed: %v", c.GlobalString("timeout"), err)
|
2017-06-05 14:20:42 -04:00
|
|
|
}
|
2018-06-17 15:41:58 -04:00
|
|
|
|
|
|
|
// Create the registry client.
|
|
|
|
return registry.New(auth, registry.Opt{
|
|
|
|
Insecure: c.GlobalBool("insecure"),
|
|
|
|
Debug: c.GlobalBool("debug"),
|
|
|
|
SkipPing: c.GlobalBool("skip-ping"),
|
|
|
|
Timeout: timeout,
|
|
|
|
})
|
2016-09-05 22:44:19 -04:00
|
|
|
}
|