1// SPDX-License-Identifier: ISC
2// Copyright (c) 2014-2020 Bitmark Inc.
3// Use of this source code is governed by an ISC
4// license that can be found in the LICENSE file.
5
6package main
7
8import (
9	"os/exec"
10)
11
12const (
13	passwordTag = "bitmark-cli:password:"
14)
15
16// expect to execute agent with parameters
17//   --confirm=1         - for additional confirm
18//   cache-id            - alows password to be cached for a time
19//   error-message       - blank
20//   prompt              - names the identity
21//   description         - shows create/transfer operation
22func passwordFromAgent(name string, title string, agent string, clear bool) (string, error) {
23
24	cacheId := passwordTag + name
25	errorMessage := ""
26	prompt := "Password for: " + name
27	description := "Enter password to: " + title
28
29	arguments := []string{}
30	if clear {
31		arguments = append(arguments, "--clear")
32	}
33	arguments = append(arguments, []string{
34		"--confirm=1",
35		cacheId,
36		errorMessage,
37		prompt,
38		description}...)
39
40	out, err := exec.Command(agent, arguments...).Output()
41	return string(out), err
42}
43