2021-03-31 16:56:34 +01:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/zeebo/clingy"
|
|
|
|
|
|
|
|
"storj.io/uplink"
|
|
|
|
)
|
|
|
|
|
|
|
|
type cmdAccessList struct {
|
|
|
|
verbose bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cmdAccessList) Setup(a clingy.Arguments, f clingy.Flags) {
|
|
|
|
c.verbose = f.New("verbose", "Verbose output of accesses", false,
|
|
|
|
clingy.Short('v'),
|
|
|
|
clingy.Transform(strconv.ParseBool),
|
|
|
|
).(bool)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cmdAccessList) Execute(ctx clingy.Context) error {
|
|
|
|
accessDefault, accesses, err := gf.GetAccessInfo()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-04-06 04:40:04 +01:00
|
|
|
var tw *tabbedWriter
|
2021-03-31 16:56:34 +01:00
|
|
|
if c.verbose {
|
2021-04-06 04:40:04 +01:00
|
|
|
tw = newTabbedWriter(ctx.Stdout(), "CURRENT", "NAME", "SATELLITE", "VALUE")
|
2021-03-31 16:56:34 +01:00
|
|
|
} else {
|
2021-04-06 04:40:04 +01:00
|
|
|
tw = newTabbedWriter(ctx.Stdout(), "CURRENT", "NAME", "SATELLITE")
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|
2021-04-06 04:40:04 +01:00
|
|
|
defer tw.Done()
|
2021-03-31 16:56:34 +01:00
|
|
|
|
|
|
|
var names []string
|
|
|
|
for name := range accesses {
|
|
|
|
names = append(names, name)
|
|
|
|
}
|
|
|
|
sort.Strings(names)
|
|
|
|
|
|
|
|
for _, name := range names {
|
|
|
|
access, err := uplink.ParseAccess(accesses[name])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
address := access.SatelliteAddress()
|
|
|
|
if idx := strings.IndexByte(address, '@'); !c.verbose && idx >= 0 {
|
|
|
|
address = address[idx+1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
inUse := ' '
|
|
|
|
if name == accessDefault {
|
|
|
|
inUse = '*'
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.verbose {
|
2021-04-06 04:40:04 +01:00
|
|
|
tw.WriteLine(inUse, name, address, accesses[name])
|
2021-03-31 16:56:34 +01:00
|
|
|
} else {
|
2021-04-06 04:40:04 +01:00
|
|
|
tw.WriteLine(inUse, name, address)
|
2021-03-31 16:56:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|