add list of inactives
This commit is contained in:
parent
ca72ad6d8b
commit
309ecf89f5
|
@ -1,4 +1,8 @@
|
||||||
TOKEN=$(go run cmd/signjwt/*.go)
|
TOKEN=$(go run cmd/signjwt/*.go)
|
||||||
echo "TOKEN: $TOKEN"
|
echo "TOKEN: $TOKEN"
|
||||||
|
|
||||||
|
echo "Active:"
|
||||||
curl -L http://localhost:3000/api/devices -H "Authorization: Bearer ${TOKEN}"
|
curl -L http://localhost:3000/api/devices -H "Authorization: Bearer ${TOKEN}"
|
||||||
|
|
||||||
|
echo "Inactive:"
|
||||||
|
curl -L http://localhost:3000/api/devices?inactive=true -H "Authorization: Bearer ${TOKEN}"
|
||||||
|
|
|
@ -30,6 +30,7 @@ type Store interface {
|
||||||
Add(auth *Authorization) error
|
Add(auth *Authorization) error
|
||||||
Set(auth *Authorization) error
|
Set(auth *Authorization) error
|
||||||
Active() ([]Authorization, error)
|
Active() ([]Authorization, error)
|
||||||
|
Inactive() ([]Authorization, error)
|
||||||
Touch(id string) error
|
Touch(id string) error
|
||||||
Get(id string) (*Authorization, error)
|
Get(id string) (*Authorization, error)
|
||||||
GetBySlug(id string) (*Authorization, error)
|
GetBySlug(id string) (*Authorization, error)
|
||||||
|
|
|
@ -174,6 +174,25 @@ func (s *PGStore) Active() ([]Authorization, error) {
|
||||||
return auths, nil
|
return auths, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *PGStore) Inactive() ([]Authorization, error) {
|
||||||
|
ctx, done := context.WithDeadline(context.Background(), time.Now().Add(5*time.Second))
|
||||||
|
defer done()
|
||||||
|
|
||||||
|
auths := []Authorization{}
|
||||||
|
query := `
|
||||||
|
SELECT * FROM authorizations
|
||||||
|
WHERE deleted_at = '1970-01-01 00:00:00'
|
||||||
|
AND updated_at <= $1
|
||||||
|
AND slug != '*'
|
||||||
|
`
|
||||||
|
ago15Min := time.Now().Add(-15 * time.Minute)
|
||||||
|
err := s.dbx.SelectContext(ctx, &auths, query, ago15Min)
|
||||||
|
if nil != err {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return auths, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *PGStore) Get(id string) (*Authorization, error) {
|
func (s *PGStore) Get(id string) (*Authorization, error) {
|
||||||
ctx, done := context.WithDeadline(context.Background(), time.Now().Add(5*time.Second))
|
ctx, done := context.WithDeadline(context.Background(), time.Now().Add(5*time.Second))
|
||||||
defer done()
|
defer done()
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.coolaj86.com/coolaj86/go-telebitd/mplexer/mgmt/authstore"
|
"git.coolaj86.com/coolaj86/go-telebitd/mplexer/mgmt/authstore"
|
||||||
|
@ -92,7 +93,13 @@ func handleDeviceRoutes(r chi.Router) {
|
||||||
})
|
})
|
||||||
|
|
||||||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
things, err := store.Active()
|
var things []authstore.Authorization
|
||||||
|
var err error
|
||||||
|
if "true" == strings.Join(r.URL.Query()["inactive"], " ") {
|
||||||
|
things, err = store.Inactive()
|
||||||
|
} else {
|
||||||
|
things, err = store.Active()
|
||||||
|
}
|
||||||
if nil != err {
|
if nil != err {
|
||||||
msg := `{"error":"not really sure what happened, but it didn't go well (check the logs)"}`
|
msg := `{"error":"not really sure what happened, but it didn't go well (check the logs)"}`
|
||||||
log.Printf("/api/devices/\n")
|
log.Printf("/api/devices/\n")
|
||||||
|
@ -101,7 +108,7 @@ func handleDeviceRoutes(r chi.Router) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, _ := range things {
|
for i := range things {
|
||||||
auth := things[i]
|
auth := things[i]
|
||||||
// Redact private data
|
// Redact private data
|
||||||
if "" != auth.MachinePPID {
|
if "" != auth.MachinePPID {
|
||||||
|
|
Loading…
Reference in New Issue