forked from tangled.org/core
this repo has no description

be consistent about using Did instead of DID

As much as possible. The atproto libs aren't themselves consistent about this.

Changed files
+17 -17
appview
auth
state
cmd
repoguard
knotserver
+1 -1
appview/auth/auth.go
···
return a.Store.Get(r, appview.SessionName)
}
-
func (a *Auth) GetDID(r *http.Request) string {
clientSession, err := a.Store.Get(r, appview.SessionName)
if err != nil || clientSession.IsNew {
return ""
···
return a.Store.Get(r, appview.SessionName)
}
+
func (a *Auth) GetDid(r *http.Request) string {
clientSession, err := a.Store.Get(r, appview.SessionName)
if err != nil || clientSession.IsNew {
return ""
+1 -1
appview/state/state.go
···
log.Println("unimplemented")
return
case http.MethodPut:
-
did := s.auth.GetDID(r)
key := r.FormValue("key")
name := r.FormValue("name")
client, _ := s.auth.AuthorizedClient(r)
···
log.Println("unimplemented")
return
case http.MethodPut:
+
did := s.auth.GetDid(r)
key := r.FormValue("key")
name := r.FormValue("name")
client, _ := s.auth.AuthorizedClient(r)
+2 -2
cmd/repoguard/main.go
···
// example.com/repo
handlePath := strings.Trim(cmdParts[1], "'")
-
repoName := handleToDID(handlePath)
validCommands := map[string]bool{
"git-receive-pack": true,
···
})
}
-
func handleToDID(handlePath string) string {
handle := path.Dir(handlePath)
ident, err := auth.ResolveIdent(context.Background(), handle)
···
// example.com/repo
handlePath := strings.Trim(cmdParts[1], "'")
+
repoName := handleToDid(handlePath)
validCommands := map[string]bool{
"git-receive-pack": true,
···
})
}
+
func handleToDid(handlePath string) string {
handle := path.Dir(handlePath)
ident, err := auth.ResolveIdent(context.Background(), handle)
+4 -4
knotserver/db/known_dids.go
···
package db
-
func (d *DB) AddDID(did string) error {
_, err := d.db.Exec(`insert into known_dids (did) values (?)`, did)
return err
}
-
func (d *DB) RemoveDID(did string) error {
_, err := d.db.Exec(`delete from known_dids where did = ?`, did)
return err
}
-
func (d *DB) GetAllDIDs() ([]string, error) {
var dids []string
rows, err := d.db.Query(`select did from known_dids`)
···
return dids, nil
}
-
func (d *DB) HasKnownDIDs() bool {
var count int
err := d.db.QueryRow(`select count(*) from known_dids`).Scan(&count)
if err != nil {
···
package db
+
func (d *DB) AddDid(did string) error {
_, err := d.db.Exec(`insert into known_dids (did) values (?)`, did)
return err
}
+
func (d *DB) RemoveDid(did string) error {
_, err := d.db.Exec(`delete from known_dids where did = ?`, did)
return err
}
+
func (d *DB) GetAllDids() ([]string, error) {
var dids []string
rows, err := d.db.Query(`select did from known_dids`)
···
return dids, nil
}
+
func (d *DB) HasKnownDids() bool {
var count int
err := d.db.QueryRow(`select count(*) from known_dids`).Scan(&count)
if err != nil {
+3 -3
knotserver/handler.go
···
return nil, fmt.Errorf("failed to start jetstream: %w", err)
}
-
// Check if the knot knows about any DIDs;
// if it does, it is already initialized and we can repopulate the
// Jetstream subscriptions.
-
dids, err := db.GetAllDIDs()
if err != nil {
-
return nil, fmt.Errorf("failed to get all DIDs: %w", err)
}
if len(dids) > 0 {
h.knotInitialized = true
···
return nil, fmt.Errorf("failed to start jetstream: %w", err)
}
+
// Check if the knot knows about any Dids;
// if it does, it is already initialized and we can repopulate the
// Jetstream subscriptions.
+
dids, err := db.GetAllDids()
if err != nil {
+
return nil, fmt.Errorf("failed to get all Dids: %w", err)
}
if len(dids) > 0 {
h.knotInitialized = true
+1 -1
knotserver/jsclient/jetstream.go
···
j.triggerReconnect()
}
-
// UpdateDids updates the DIDs list and triggers a reconnection
func (j *JetstreamClient) UpdateDids(dids []string) {
j.mu.Lock()
j.dids = dids
···
j.triggerReconnect()
}
+
// UpdateDids updates the Dids list and triggers a reconnection
func (j *JetstreamClient) UpdateDids(dids []string) {
j.mu.Lock()
j.dids = dids
+5 -5
knotserver/routes.go
···
func (h *Handle) NewRepo(w http.ResponseWriter, r *http.Request) {
data := struct {
-
DID string `json:"did"`
Name string `json:"name"`
}{}
···
return
}
-
did := data.DID
name := data.Name
repoPath := filepath.Join(h.c.Repo.ScanPath, did, name)
···
}
data := struct {
-
DID string `json:"did"`
PublicKey string `json:"key"`
Created string `json:"created"`
}{}
···
return
}
-
did := data.DID
key := data.PublicKey
created := data.Created
···
return
}
-
if err := h.db.AddDID(did); err == nil {
pk := db.PublicKey{
Did: did,
}
···
func (h *Handle) NewRepo(w http.ResponseWriter, r *http.Request) {
data := struct {
+
Did string `json:"did"`
Name string `json:"name"`
}{}
···
return
}
+
did := data.Did
name := data.Name
repoPath := filepath.Join(h.c.Repo.ScanPath, did, name)
···
}
data := struct {
+
Did string `json:"did"`
PublicKey string `json:"key"`
Created string `json:"created"`
}{}
···
return
}
+
did := data.Did
key := data.PublicKey
created := data.Created
···
return
}
+
if err := h.db.AddDid(did); err == nil {
pk := db.PublicKey{
Did: did,
}