8000 admindb: InviteService by cryptix · Pull Request #55 · ssbc/go-ssb-room · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

admindb: InviteService #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2021
Merged

admindb: InviteService #55

merged 1 commit into from
Mar 5, 2021

Conversation

cryptix
Copy link
Member
@cryptix cryptix commented Mar 2, 2021

updates #13

  • enable foreign key enforcement on sqlite
  • admindb.InviteService interface
    • Create
    • Consume
    • List
    • Revoke
  • tests for the sqlite implementation of the service

@cryptix cryptix marked this pull request as ready for review March 3, 2021 07:33
@cryptix
Copy link
Member Author
cryptix commented Mar 3, 2021

As these things go, most of the diff is from the new generated code for invites in mockdb and sqlite/models (sqlboiler).

// It uses sql-migrate (github.com/rubenv/sql-migrate) for it's schema definition and maintainace.
// For query construction/ORM it uses SQLBoiler (https://github.com/volatiletech/sqlboiler).
//
// The process of updating the schema and ORM can be summarized as follows:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I never spelled out how updating the sqlite impl was supposed to go. Hope this makes it clearer.

@cryptix
Copy link
Member Author
cryptix commented Mar 3, 2021

I'd prefer if we use godoc for package and function level documentation and READMEs for meta/setup level stuff.

I usually use go doc admindb for instance or go doc admindb AllowListServe from anywhere in the repo. If package names collide, you can use the full import path, like (at which point I usually prefer browsing https://pkg.go.dev/import/path/.., unless it's in the stdlib, since it's a a lot to type and browsers have a better history and completion.

allowList *AllowList
}

const tokenLength = 50
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic number? or why is it 50?

Copy link
Member Author
@cryptix cryptix Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rooms2 doc currently leaves this open. cc @staltz

Copy link
Member
@staltz staltz Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the size of normal pub invite codes? Should be the same as this one too, no? Is this something that needs to be spec'd? (I don't see why all the rooms would have to have the same tokenLengths)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the choice of encoding the tokens. url safe base64 seemed like a better choice then hex.

Also not super sure it needs to be defined strictly since it just needs to be returned and passed back as an opaque string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the size of normal pub invite codes?

In classic ssb-invites it's a seed for a keypair for ed22519, which is 32bytes. But that protocol is not susceptible to brute forcing an HTTP endpoint, which is why I made it longer.

Copy link
Contributor
@cblgh cblgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍 👍

edit: supposed to be a comment on make interface assertion comments less scary

}

invs = make([]admindb.Invite, len(entries))
for i, e := range entries {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overloading i Invites with i range count

Copy link
Member Author
@cryptix cryptix Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes. yea, that's bad.

I just checked and noticed the other sqlite sub-service also have inconsistent names.

How about having s for service as the last letter?

So

  • func (is Invites) ...
  • func (als AllowList) ...
  • func (afs AuthFallback) ..
  • func (as AliasService) ...
  • func (ns Notices) ...

Similar to the package name change I'd prefer this as a follow up, though.

Copy link
Contributor
@cblgh cblgh Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops didn't respond: i really like the idea of keeping things cohesive! i'm ambivalent on using s, i don't really know the code well enough yet to have a feeling for how it works. some weird semantic clashes with is, as, ns but 🤷

edit: i think maybe picking good-enough names & then using them consistently is more important than all names conforming to some schema that doesn't work out super duper in practice? bonus points for just tossing them all in a terminology document, so that people can easily look them up (never seen this anywhere, but it could be hecka useful at the earliest stages of getting into a codebase i think)

Comment on lines 89 to 96
go func() { // server might not restart as often
threeDays := 5 * 24 * time.Hour
ticker := time.NewTicker(threeDays)
for range ticker.C {
err := transact(db, func(tx *sql.Tx) error {
_, err := models.Invites(qm.Where("active = false")).DeleteAll(context.Background(), tx)
return err
})
if err != nil {
// TODO: hook up logging
log.Printf("admindb: failed to clean up old invites: %s", err.Error())
}
}
}()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wut

@cryptix cryptix mentioned this pull request Mar 4, 2021
13 tasks
Copy link
Contributor
@cblgh cblgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 batch the suggested changes you agree with, discard the rest & 📦 🚢 it!!

interface methods: create, consume, list and revoke.

SQLite implementation and some light testing.

Related changes:

* have authfallback.Create return the user id

At some point we will need to not assume that authfallback is our users
table but that will not become relevant before we start adding
moderation roles.

* Update package documentation of admindb and admindb/sqlite

* remove leftover generated.db

now using the roomdb file created by TestSimple

Review comments by @cblgh

* better documentation of hashed token storage
* space between %d and `bytes`
* make interface assertion comments less scary
@cryptix cryptix merged commit bbcab73 into master Mar 5, 2021
@cryptix cryptix deleted the invites branch March 5, 2021 07:42
@cryptix cryptix mentioned this pull request Mar 10, 2021
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0