Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 78 additions & 2 deletions any-sync-acl-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import (
"strings"
"time"

"github.com/anyproto/any-sync/accountservice"
"github.com/anyproto/any-sync/app"
"github.com/anyproto/any-sync/app/logger"
"github.com/anyproto/any-sync/commonspace/object/accountdata"
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
"github.com/anyproto/any-sync/commonspace/object/acl/list"
"github.com/anyproto/any-sync/commonspace/object/acl/recordverifier"
"github.com/anyproto/any-sync/consensus/consensusproto"
"github.com/anyproto/any-sync/coordinator/coordinatorclient"
"github.com/anyproto/any-sync/coordinator/nodeconfsource"
Expand All @@ -33,7 +37,7 @@ var (
fNetwork = flag.String("n", "", "path to network config yml file")
fHelp = flag.Bool("h", false, "print this help")
fSpaceId = flag.String("s", "", "spaceId")
fLog = flag.Bool("l", true, "show log")
fLog = flag.Bool("l", false, "show log")
)

func main() {
Expand Down Expand Up @@ -71,14 +75,21 @@ func main() {
log.Fatal(err)
}
}
if err = cli.Summary(ctx, *fSpaceId); err != nil {
log.Fatal(err)
}
}

type AclCli struct {
coordinatorClient coordinatorclient.CoordinatorClient
account *accountdata.AccountKeys
recordsBySpaceId map[string][]*consensusproto.RawRecordWithId
}

func (a *AclCli) Init(ap *app.App) (err error) {
a.coordinatorClient = ap.MustComponent(coordinatorclient.CName).(coordinatorclient.CoordinatorClient)
a.account = ap.MustComponent(accountservice.CName).(accountservice.Service).Account()
a.recordsBySpaceId = make(map[string][]*consensusproto.RawRecordWithId)
return
}

Expand All @@ -102,6 +113,64 @@ func (a *AclCli) Log(ctx context.Context, spaceId string) (err error) {
}
}
}
a.recordsBySpaceId[spaceId] = records
return
}

func (a *AclCli) Summary(ctx context.Context, spaceId string) (err error) {
records, ok := a.recordsBySpaceId[spaceId]
if !ok {
records, err = a.coordinatorClient.AclGetRecords(ctx, spaceId, "")
if err != nil {
return fmt.Errorf("failed to get acl records: %w", err)
}
}
store, err := list.NewInMemoryStorage(spaceId, records)
if err != nil {
return fmt.Errorf("failed to create acl storage: %w", err)
}
aclList, err := list.BuildAclListWithIdentity(a.account, store, recordverifier.NewValidateFull())
if err != nil {
return fmt.Errorf("failed to build acl list: %w", err)
}
state := aclList.AclState()
owner, err := state.OwnerPubKey()
if err != nil {
return fmt.Errorf("failed to get acl owner: %w", err)
}
fmt.Println("ACL state summary:")
fmt.Printf("\tOwner=%s\n", formatAccount(owner.Account()))

fmt.Println("\tInvites:")
for _, inv := range state.Invites() {
fmt.Printf("\t\tid=%v; type=%v\n", formatId(inv.Id), inv.Type.String())
}

fmt.Println("\tAccount statuses:")
var accByState [7]int
var accByRole [6]int
for _, acc := range state.CurrentAccounts() {
accByRole[acc.Permissions]++
accByState[acc.Status]++
}

var statusNames = [7]string{"none", "joining", "active", "removed", "declined", "removing", "canceled"}

for i, cnt := range accByState {
status := statusNames[i]
if cnt > 0 {
fmt.Printf("\t\t%v=%d\n", status, cnt)
}
}

fmt.Println("\tAccount roles:")
for i, cnt := range accByRole {
role := aclrecordproto.AclUserPermissions(i).String()
if cnt > 0 {
fmt.Printf("\t\t%v=%d\n", role, cnt)
}
}

return
}

Expand Down Expand Up @@ -129,6 +198,9 @@ func printAclRoot(rec *consensusproto.RawRecordWithId) (err error) {
if aclRec.EncryptedReadKey != nil {
rootFlags = append(rootFlags, "readKey")
}
if aclRec.OneToOneInfo != nil {
rootFlags = append(rootFlags, "oneToOne")
}

fmt.Printf("%s\troot\t%s\t%s\t%s\n", formatId(rec.Id), formatIdentity(aclRec.Identity), acceptTime.Format(time.RFC3339), strings.Join(rootFlags, ","))
return
Expand All @@ -141,11 +213,15 @@ func formatIdentity(ident []byte) string {
}
if key != nil {
accId := key.Account()
return accId[:4] + ".." + accId[len(accId)-4:]
return formatAccount(accId)
}
return "invalid"
}

func formatAccount(accountId string) string {
return accountId[:4] + ".." + accountId[len(accountId)-4:]
}

func printAclRecord(rec *consensusproto.RawRecordWithId) (err error) {
var rawRec = &consensusproto.RawRecord{}
if err = rawRec.UnmarshalVT(rec.Payload); err != nil {
Expand Down
77 changes: 22 additions & 55 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,123 +1,90 @@
module github.com/anyproto/any-sync-tools

go 1.24.0

toolchain go1.24.3
go 1.24.6

require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/anyproto/any-store v0.3.5
github.com/anyproto/any-sync v0.10.1
github.com/anyproto/any-sync v0.11.4
github.com/anyproto/go-chash v0.1.0
github.com/charmbracelet/bubbles v0.21.0
github.com/charmbracelet/bubbletea v1.3.10
github.com/charmbracelet/lipgloss v1.1.0
github.com/hashicorp/yamux v0.1.2
github.com/matishsiao/goInfo v0.0.0-20241216093258-66a9250504d6
github.com/spf13/cobra v1.9.1
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/yaml.v3 v3.0.1
storj.io/drpc v0.0.34
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/anyproto/go-slip10 v1.0.0 // indirect
github.com/anyproto/any-store v0.4.3 // indirect
github.com/anyproto/go-slip10 v1.0.1-0.20250818123350-f910c27dd080 // indirect
github.com/anyproto/go-slip21 v1.0.0 // indirect
github.com/anyproto/go-sqlite v1.4.2-any // indirect
github.com/anyproto/lexid v0.0.6 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
github.com/charmbracelet/x/ansi v0.10.1 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/flopp/go-findfont v0.1.0 // indirect
github.com/fogleman/gg v1.3.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/goccy/go-graphviz v0.2.9 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/snappy v1.0.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/boxo v0.34.0 // indirect
github.com/ipfs/go-block-format v0.2.2 // indirect
github.com/ipfs/go-cid v0.5.0 // indirect
github.com/ipfs/go-log/v2 v2.8.1 // indirect
github.com/ipfs/boxo v0.35.2 // indirect
github.com/ipfs/go-block-format v0.2.3 // indirect
github.com/ipfs/go-cid v0.6.0 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-libp2p v0.43.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/libp2p/go-libp2p v0.45.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multiaddr v0.16.1 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multicodec v0.9.2 // indirect
github.com/multiformats/go-multicodec v0.10.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-multistream v0.6.1 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/multiformats/go-varint v0.1.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/planetscale/vtprotobuf v0.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.23.2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.17.0 // indirect
github.com/quic-go/quic-go v0.54.0 // indirect
github.com/quic-go/quic-go v0.56.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/stretchr/testify v1.11.1 // indirect
github.com/tetratelabs/wazero v1.8.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/valyala/fastjson v1.6.4 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/zeebo/errs v1.3.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/mock v0.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/crypto v0.42.0 // indirect
golang.org/x/image v0.21.0 // indirect
golang.org/x/mod v0.28.0 // indirect
golang.org/x/net v0.44.0 // indirect
golang.org/x/sync v0.17.0 // indirect
golang.org/x/sys v0.36.0 // indirect
golang.org/x/term v0.35.0 // indirect
golang.org/x/text v0.29.0 // indirect
golang.org/x/time v0.13.0 // indirect
golang.org/x/tools v0.37.0 // indirect
google.golang.org/protobuf v1.36.9 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
golang.org/x/crypto v0.43.0 // indirect
golang.org/x/net v0.46.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/term v0.36.0 // indirect
golang.org/x/text v0.30.0 // indirect
golang.org/x/time v0.14.0 // indirect
google.golang.org/protobuf v1.36.10 // indirect
lukechampine.com/blake3 v1.4.1 // indirect
modernc.org/libc v1.66.8 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
modernc.org/sqlite v1.37.1 // indirect
)

replace github.com/anyproto/any-sync => ../any-sync
Loading