2019-05-28 01:16:50 +00:00
|
|
|
package commands
|
2019-05-22 15:22:40 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2019-05-30 06:32:56 +00:00
|
|
|
"gopkg.in/AlecAivazis/survey.v1"
|
2019-05-22 15:22:40 +00:00
|
|
|
)
|
|
|
|
|
2019-05-28 01:16:50 +00:00
|
|
|
func MakeList(initClient CredentialClientInit) *cobra.Command {
|
2019-05-22 15:22:40 +00:00
|
|
|
var sourceHost string
|
|
|
|
|
|
|
|
listCmd := &cobra.Command{
|
|
|
|
Use: "list",
|
|
|
|
Short: "List the metadata for all credentials",
|
|
|
|
Long: `List the metadata for all credentials, with the option to filter by source host. Metadata
|
|
|
|
includes almost all the information but the most sensitive.`,
|
|
|
|
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
2019-05-30 06:32:56 +00:00
|
|
|
ctx := context.Background()
|
2019-05-22 15:22:40 +00:00
|
|
|
mdch, errch := initClient(ctx).GetAllMetadata(ctx, sourceHost)
|
|
|
|
|
2019-05-30 06:32:56 +00:00
|
|
|
fmt.Println()
|
|
|
|
|
2019-05-22 15:22:40 +00:00
|
|
|
receive:
|
2019-05-30 06:32:56 +00:00
|
|
|
for count := 0; ; count++ {
|
2019-05-22 15:22:40 +00:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
check(fmt.Errorf("context timeout"))
|
|
|
|
|
|
|
|
case err := <-errch:
|
|
|
|
check(err)
|
|
|
|
|
|
|
|
case md, ok := <-mdch:
|
|
|
|
if !ok {
|
|
|
|
break receive
|
|
|
|
}
|
|
|
|
|
2019-05-30 06:32:56 +00:00
|
|
|
if count != 0 && count%3 == 0 {
|
|
|
|
var proceed bool
|
|
|
|
prompt := &survey.Confirm{Message: "Next page?", Default: true}
|
|
|
|
check(survey.AskOne(prompt, &proceed, nil))
|
|
|
|
|
|
|
|
if !proceed {
|
|
|
|
break receive
|
|
|
|
}
|
|
|
|
|
2019-05-30 15:45:11 +00:00
|
|
|
fmt.Println()
|
2019-05-30 06:32:56 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 01:16:50 +00:00
|
|
|
fmt.Println(md)
|
2019-05-22 15:22:40 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-28 01:16:50 +00:00
|
|
|
|
|
|
|
fmt.Println("Done listing.")
|
2019-05-22 15:22:40 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
listCmd.Flags().StringVarP(
|
|
|
|
&sourceHost,
|
|
|
|
"source-host",
|
|
|
|
"s",
|
|
|
|
"",
|
|
|
|
"specify which source host to filter the results by",
|
|
|
|
)
|
|
|
|
|
|
|
|
return listCmd
|
|
|
|
}
|