Example #1
0
func cliGet(cfg *arx.ClientConfig, args []string) {
	if len(args) != 1 {
		fmt.Println("Get requires one argument: <ident>.")
		os.Exit(1)
	}
	ident := args[0]
	secret, err := cfg.RequestSecret(ident)
	if err != nil {
		fmt.Println("Request failed.")
		fmt.Printf("\t%v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Secret '%s': %X\n", ident, secret)
	os.Exit(0)
}
Example #2
0
func cliProvision(cfg *arx.ClientConfig, args []string) {
	if len(args) != 2 {
		fmt.Println("Provision requires two arguments: <ident> <length>.")
		os.Exit(1)
	}

	ident := args[0]
	length, err := strconv.Atoi(args[1])
	if err != nil {
		fmt.Printf("Invalid length (%v)\n", err)
		os.Exit(1)
	}

	secret, err := cfg.ProvisionSecret(ident, length)
	if err != nil {
		fmt.Printf("Provisioning failed (%v).\n", err)
		os.Exit(1)
	}
	fmt.Printf("Secret '%s': %X\n", ident, secret)
	os.Exit(0)
}
Example #3
0
func cliStore(cfg *arx.ClientConfig, args []string) {
	if len(args) != 2 {
		fmt.Println("Store requires two arguments: <ident> <secret key file>.")
		os.Exit(1)
	}
	ident := args[0]
	secret, err := ioutil.ReadFile(args[1])
	if err != nil {
		fmt.Println("Failed to read secret.")
		fmt.Printf("\t%v\n", err)
		os.Exit(1)
	}

	err = cfg.StoreSecret(ident, secret)
	if err != nil {
		fmt.Println("Request failed.")
		fmt.Printf("\t%v\n", err)
		os.Exit(1)
	}
	fmt.Println("OK.")
	os.Exit(0)
}