aqcli

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2021 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GenerateCommand = &cli.Command{
	Name:    "generate",
	Aliases: []string{"gen"},
	Usage:   "Generates a possible auth token",
	Flags: []cli.Flag{
		&cli.IntFlag{
			Name:    "length",
			Aliases: []string{"l"},
			Value:   32,
			Usage:   "Length of the token",
		},
	},
	Action: func(c *cli.Context) error {
		size := c.Int("length")
		if size <= 1 {
			return cli.Exit("You cannot generate a token with this length. Must be >=2.", 1)
		}

		fmt.Println(generateToken(size))
		return nil
	},
}
View Source
var UploadCommand = &cli.Command{
	Name:      "upload",
	Usage:     "Uploads a file to the aqua server",
	ArgsUsage: "<file [file2 file3 ...]>",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:  "host",
			Usage: "Specifies to which host to upload to",
			Value: "http://localhost:8765",
		},
		&cli.StringFlag{
			Name:    "token",
			Aliases: []string{"t"},
			Usage:   "Token used for authorization",
		},
		&cli.IntFlag{
			Name:    "expires",
			Aliases: []string{"e"},
			Value:   -1,
			Usage:   "Time in seconds when the file should expire. -1 = never.",
		},
	},
	Action: func(c *cli.Context) error {
		paths := c.Args().Slice()

		if len(paths) == 0 {
			return cli.Exit("You have to provide at least one file to upload", 1)
		}

		host := c.String("host")
		if !strings.HasPrefix(host, "http") {

			host = "https://" + host
		}

		token := c.String("token")
		expires := c.Int("expires")

		for _, path := range paths {
			file, err := os.Open(path)
			if err != nil {

				return fmt.Errorf("could not open file: %v", err)
			}

			id, err := doPostRequest(host, token, file, &request.RequestMetadata{
				Expiration: int64(expires),
			})
			if err != nil {

				return fmt.Errorf("could not upload file %s: %v", path, err)
			}
			file.Close()

			fmt.Printf("Uploaded file %s to %s/%s", path, host, id)
		}

		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL